def test_component_double_star_args_ungroup(do_test): class A(Component): def construct(s, foo, bar): assert foo == Bits4(0) assert bar == Bits16(42) kwargs = {'foo': Bits4(0), 'bar': Bits16(42)} a = A(**kwargs) a._ref_name = 'A__foo_0__bar_002a' a._ref_src = \ """\ component {} ( port_decls: interface_decls: ); const_decls: freevars: wire_decls: component_decls: tmpvars: upblk_srcs: connections: endcomponent """.format( a._ref_name ) do_test(a)
def test_component_mixed_kw_args(do_test): class A(Component): def construct(s, foo, bar, woo=Bits32(0)): pass a = A(Bits4(0), bar=Bits16(42)) a._ref_name = 'A__foo_0__bar_002a__woo_00000000' a._ref_src = \ """\ component {} ( port_decls: interface_decls: ); const_decls: freevars: wire_decls: component_decls: tmpvars: upblk_srcs: connections: endcomponent """.format( a._ref_name ) do_test(a)
def test_component_kw_args(do_test): class A(Component): def construct(s, foo, bar): assert foo == Bits4(0) assert bar == Bits16(42) a = A(foo=Bits4(0), bar=Bits16(42)) a._ref_name = 'A__foo_0__bar_002a' a._ref_src = \ """\ component {} ( port_decls: interface_decls: ); const_decls: freevars: wire_decls: component_decls: tmpvars: upblk_srcs: connections: endcomponent """.format( a._ref_name ) do_test(a)
def construct(s): s.foo = Bits32(0) s.bar = Bits4(0) s.out = OutPort(Bits32) @s.update def upblk(): s.out = s.foo s.out = Bits32(s.bar)
def test_component_star_args(do_test): class A(Component): def construct(s, *args): assert args[0] == Bits4(0) assert args[1] == Bits16(42) args = [Bits4(0), Bits16(42)] a = A(*args) with expected_failure(RTLIRConversionError, "varargs are not allowed"): do_test(a)
def test_component_double_star_args(do_test): class A(Component): def construct(s, **kwargs): assert kwargs['foo'] == Bits4(0) assert kwargs['bar'] == Bits16(42) kwargs = {'foo': Bits4(0), 'bar': Bits16(42)} a = A(**kwargs) with expected_failure(RTLIRConversionError, "keyword args are not allowed"): do_test(a)
def upblk(): for s.in_ in range(4): s.out = Bits4(1)
def upblk(): for i in range(4): s.out = Bits4(1) else: s.out = Bits4(1)
def upblk(): s.out = u + Bits4(1)
def __init__( s, foo=42 ): s.foo = [ Bits4( 42 ) for _ in range(4) ]
def up_wr_y(): s.y @= Bits4(0xf)
def up_wr_As(): s.A[0:4] @= Bits4(0xf)
def upblk(): for i in range(): s.out = Bits4(1)
def upblk(): for i in s.in_: s.out = Bits4(1)
def upblk(): s.foo = 42 s.bar = Bits4(0)
def construct(s, *args): assert args[0] == Bits4(0) assert args[1] == Bits16(42)
def construct(s, **kwargs): assert kwargs['foo'] == Bits4(0) assert kwargs['bar'] == Bits16(42)
def upblk(): for i in foo(): s.out = Bits4(1)
def construct(s, foo, bar): assert foo == Bits4(0) assert bar == Bits16(42)
def upblk(): for i in range(0, 4, 1, 1): s.out = Bits4(1)
def tv_out(m, tv): assert m.out == Bits4(tv[1])