def declaration(self): return '\n'.join([ svgen_typedef(self.dtype, f"{self.name}"), f"dti_verif_if#({self.name}_t) {self.name}_vif (clk, rst);", f"dti#({self.dtype.width}) {self.name} ();", f"bit[{self.dtype.width-1}:0] {self.name}_data;", self.tenv.snippets.connect_vif(self.name, self.port.direction), ])
def test_tuple_unit(): test_ref = """ typedef struct packed { // (u1, ()) logic [0:0] f0; // u1 } data_t; """ svtype = svgen_typedef(Tuple[Uint[1], Unit], 'data') assert equal_on_nonspace(svtype, test_ref)
def test_tuple(): test_ref = """ typedef struct packed { // (u1, u2) logic [1:0] f1; // u2 logic [0:0] f0; // u1 } data_t; """ svtype = svgen_typedef(Tuple[Uint[1], Uint[2]], 'data') assert equal_on_nonspace(svtype, test_ref)
def test_multiqueue(): test_ref = """ typedef struct packed { // [u16] logic [5:0] eot; // u1 logic [1:0] data; // u16 } data_t; """ svtype = svgen_typedef(Queue[Uint[2], 6], 'data') assert equal_on_nonspace(svtype, test_ref)
def test_array_subtype(): test_ref = ''' typedef struct packed { // (u1, u3) logic [2:0] f1; // u3 logic [0:0] f0; // u1 } data_data_t; typedef data_data_t [3:0] data_t; // Array[(u1, u3), 4] ''' svtype = svgen_typedef(Array[Tuple[Uint[1], Uint[3]], 4], 'data') assert equal_on_nonspace(svtype, test_ref)
def test_namedtuple(): test_ref = """ typedef struct packed { // (u1, u2) logic [1:0] field2; // u2 logic [0:0] field1; // u1 } data_t; """ svtype = svgen_typedef(Tuple[{ 'field1': Uint[1], 'field2': Uint[2] }], 'data') assert equal_on_nonspace(svtype, test_ref)
def __init__(self, name='dflt', cons=[], dtype=None, cls='dflt_tcon', cls_params=None, tenv=None): self.name = name self.cons = cons.copy() self.dtype = dtype self.cls = cls self.cls_params = cls_params self.cvars = {} self.cvars['dout'] = svgen_typedef(dtype, 'dout') self.tenv = tenv
def test_union_shallow(): test_ref = """ typedef struct packed { // u1 | u2 logic [0:0] ctrl; // u1 logic [1:0] data; // u1 | u2 } data_t; """ svtype = svgen_typedef(Union[{ 'alt1': Uint[1], 'alt2': Uint[2] }], 'data', depth=0) assert equal_on_nonspace(svtype, test_ref)
def test_tuple_multilevel(): test_ref = """ typedef struct packed { // (u3, u4) logic [3:0] f1; // u4 logic [2:0] f0; // u3 } data_f1_t; typedef struct packed { // (u1, u2) logic [1:0] f1; // u2 logic [0:0] f0; // u1 } data_f0_t; typedef struct packed { // ((u1, u2), (u3, u4)) data_f1_t f1; // (u3, u4) data_f0_t f0; // (u1, u2) } data_t; """ svtype = svgen_typedef( Tuple[Tuple[Uint[1], Uint[2]], Tuple[Uint[3], Uint[4]]], 'data') assert equal_on_nonspace(svtype, test_ref)
def test_array_subtype(): test_ref = ''' typedef struct packed { // (u1, u3) logic [2:0] f1; // u3 logic [0:0] f0; // u1 } data_data_t; typedef data_data_t [3:0] data_t; // Array[(u1, u3), 4] ''' # TODO: Check why we need this second option sometimes test_ref_1 = ''' typedef struct packed { // (u1, u3) logic [2:0] f1; // u3 logic f0; // u1 } data_data_t; typedef data_data_t [3:0] data_t; // Array[(u1, u3), 4] ''' svtype = svgen_typedef(Array[Tuple[Uint[1], Uint[3]], 4], 'data') assert equal_on_nonspace(svtype, test_ref) or equal_on_nonspace( svtype, test_ref_1)
def add_var(self, name, dtype): self.cvars[name] = svgen_typedef(dtype, name)
def test_multiarray(): test_ref = "typedef logic [3:0] [1:0] [15:0] data_t; // Array[Array[u16, 2], 4]" svtype = svgen_typedef(Array[Array[Uint[16], 2], 4], 'data') assert equal_on_nonspace(svtype, test_ref)
def test_uint(): test_ref = "typedef logic [15:0] data_t; // u16" svtype = svgen_typedef(Uint[16], 'data') assert equal_on_nonspace(svtype, test_ref)
def test_array_signed(): test_ref = "typedef logic signed [3:0] [15:0] data_t; // Array[i16, 4]" svtype = svgen_typedef(Array[Int[16], 4], 'data') assert equal_on_nonspace(svtype, test_ref)
def test_int(): test_ref = "typedef logic signed [15:0] data_t; // i16" svtype = svgen_typedef(Int[16], 'data') assert equal_on_nonspace(svtype, test_ref)