11from unittest_utils import RDLSourceTestCase
22from systemrdl .rdltypes import PrecedenceType
3- from systemrdl .node import RegNode , FieldNode
3+ from systemrdl .node import RegNode , FieldNode , RegfileNode , AddrmapNode , SignalNode , MemNode
44
55class TestNodeUtils (RDLSourceTestCase ):
66
@@ -346,10 +346,10 @@ def test_names(self):
346346 ["rdl_src/nested_params.rdl" ],
347347 "nested_params"
348348 )
349- r1 = top .find_by_path ("nested_params.r1_inst" )
350- r1_2 = top .find_by_path ("nested_params.r1_inst2" )
351- f = top .find_by_path ("nested_params.r1_inst.f" )
352- f2 = top .find_by_path ("nested_params.r1_inst.f2" )
349+ r1 : RegNode = top .find_by_path ("nested_params.r1_inst" )
350+ r1_2 : RegNode = top .find_by_path ("nested_params.r1_inst2" )
351+ f : FieldNode = top .find_by_path ("nested_params.r1_inst.f" )
352+ f2 : FieldNode = top .find_by_path ("nested_params.r1_inst.f2" )
353353
354354 self .assertEqual (r1 .inst_name , "r1_inst" )
355355 self .assertEqual (r1 .type_name , "r1_WIDTH_5" )
@@ -373,7 +373,7 @@ def test_owning_addrmap(self):
373373 ["rdl_src/references_default_lhs.rdl" ],
374374 "top"
375375 )
376- top_addrmap = top .find_by_path ("top" )
376+ top_addrmap : AddrmapNode = top .find_by_path ("top" )
377377 self .assertIsNone (top .owning_addrmap )
378378 self .assertIsNone (top .find_by_path ("glbl_sig" ).owning_addrmap )
379379 self .assertEqual (top_addrmap .owning_addrmap , top_addrmap )
@@ -386,9 +386,9 @@ def test_find_by_path_via_parent(self):
386386 "hier"
387387 )
388388
389- a = top .find_by_path ("hier.x.a" )
390- b = top .find_by_path ("hier.y.b" )
391- ba = top .find_by_path ("hier.y.b.a" )
389+ a : RegNode = top .find_by_path ("hier.x.a" )
390+ b : RegNode = top .find_by_path ("hier.y.b" )
391+ ba : FieldNode = top .find_by_path ("hier.y.b.a" )
392392
393393 self .assertEqual (top .find_by_path ("hier.x.b.^.a" ), a )
394394 self .assertEqual (ba .find_by_path ("^" ), b )
@@ -400,8 +400,8 @@ def test_typed_iterators(self):
400400 "hier"
401401 )
402402
403- x = top .find_by_path ("hier.x" )
404- a = top .find_by_path ("hier.x.a" )
403+ x : RegfileNode = top .find_by_path ("hier.x" )
404+ a : RegNode = top .find_by_path ("hier.x.a" )
405405
406406 with self .subTest ("registers" ):
407407 paths = [n .get_path () for n in top .top .registers ()]
@@ -432,22 +432,22 @@ def test_field_prop_helpers(self):
432432 "top"
433433 )
434434
435- f1 = root .find_by_path ("top.r1.f1" )
436- f2 = root .find_by_path ("top.r1.f2" )
437- f3 = root .find_by_path ("top.r1.f3" )
438- f4 = root .find_by_path ("top.r1.f4" )
439- f5 = root .find_by_path ("top.r1.f5" )
440- f6 = root .find_by_path ("top.r1.f6" )
441- f7 = root .find_by_path ("top.r1.f7" )
442- f8 = root .find_by_path ("top.r1.f8" )
443- f9 = root .find_by_path ("top.r1.f9" )
444- f10 = root .find_by_path ("top.r1.f10" )
445- f11 = root .find_by_path ("top.r1.f11" )
446- f12 = root .find_by_path ("top.r1.f12" )
447-
448- r1 = root .find_by_path ("top.r1" )
449- r2 = root .find_by_path ("top.r2" )
450- r3 = root .find_by_path ("top.r3" )
435+ f1 : FieldNode = root .find_by_path ("top.r1.f1" )
436+ f2 : FieldNode = root .find_by_path ("top.r1.f2" )
437+ f3 : FieldNode = root .find_by_path ("top.r1.f3" )
438+ f4 : FieldNode = root .find_by_path ("top.r1.f4" )
439+ f5 : FieldNode = root .find_by_path ("top.r1.f5" )
440+ f6 : FieldNode = root .find_by_path ("top.r1.f6" )
441+ f7 : FieldNode = root .find_by_path ("top.r1.f7" )
442+ f8 : FieldNode = root .find_by_path ("top.r1.f8" )
443+ f9 : FieldNode = root .find_by_path ("top.r1.f9" )
444+ f10 : FieldNode = root .find_by_path ("top.r1.f10" )
445+ f11 : FieldNode = root .find_by_path ("top.r1.f11" )
446+ f12 : FieldNode = root .find_by_path ("top.r1.f12" )
447+
448+ r1 : RegNode = root .find_by_path ("top.r1" )
449+ r2 : RegNode = root .find_by_path ("top.r2" )
450+ r3 : RegNode = root .find_by_path ("top.r3" )
451451
452452 self .assertFalse (f1 .is_volatile )
453453 self .assertTrue (f2 .is_volatile )
@@ -557,3 +557,17 @@ def tup(field: FieldNode):
557557 self .assertEqual ( f [4 ], (17 , 16 ))
558558 self .assertEqual (tup (f [5 ]), (29 , 18 ))
559559 self .assertEqual ( f [6 ], (31 , 30 ))
560+
561+
562+ def test_component_type_name (self ):
563+
564+ top = self .compile (
565+ ["rdl_src/address_packing.rdl" ],
566+ "hier"
567+ )
568+ self .assertEqual (top .component_type_name , "$root" )
569+ self .assertEqual (top .find_by_path ("hier" ).component_type_name , "addrmap" )
570+ self .assertEqual (top .find_by_path ("hier.x" ).component_type_name , "regfile" )
571+ self .assertEqual (top .find_by_path ("hier.x.a" ).component_type_name , "reg" )
572+ self .assertEqual (top .find_by_path ("hier.x.a.a" ).component_type_name , "field" )
573+ self .assertEqual (top .find_by_path ("hier.z_mem" ).component_type_name , "mem" )
0 commit comments