@@ -279,7 +279,7 @@ def add_wirevector(self, wirevector):
279
279
self .wirevector_by_name [wirevector .name ] = wirevector
280
280
281
281
def remove_wirevector (self , wirevector ):
282
- """ Remove a wirevector object to the block."""
282
+ """ Remove a wirevector object from the block."""
283
283
self .wirevector_set .remove (wirevector )
284
284
del self .wirevector_by_name [wirevector .name ]
285
285
@@ -505,7 +505,6 @@ def sanity_check(self):
505
505
built according to the assumptions stated in the Block comments.
506
506
"""
507
507
508
- # TODO: check that the wirevector_by_name is sane
509
508
from .wire import Input , Const , Output
510
509
from .helperfuncs import get_stack , get_stacks
511
510
@@ -529,9 +528,6 @@ def sanity_check(self):
529
528
'or "const_" as a signal name because those are reserved for '
530
529
'internal use)' % repr (wirevector_names_list ))
531
530
532
- # check for dead input wires (not connected to anything)
533
- all_input_and_consts = self .wirevector_subset ((Input , Const ))
534
-
535
531
# The following line also checks for duplicate wire drivers
536
532
wire_src_dict , wire_dst_dict = self .net_connections ()
537
533
dest_set = set (wire_src_dict .keys ())
@@ -542,9 +538,12 @@ def sanity_check(self):
542
538
bad_wire_names = '\n ' .join (str (x ) for x in connected_minus_allwires )
543
539
raise PyrtlError ('Unknown wires found in net:\n %s \n \n %s' % (bad_wire_names ,
544
540
get_stacks (* connected_minus_allwires )))
541
+
542
+ all_input_and_consts = self .wirevector_subset ((Input , Const ))
543
+
544
+ # Check for wires that aren't connected to anything (inputs and consts can be unconnected)
545
545
allwires_minus_connected = self .wirevector_set .difference (full_set )
546
546
allwires_minus_connected = allwires_minus_connected .difference (all_input_and_consts )
547
- # ^ allow inputs and consts to be unconnected
548
547
if len (allwires_minus_connected ) > 0 :
549
548
bad_wire_names = '\n ' .join (str (x ) for x in allwires_minus_connected )
550
549
raise PyrtlError ('Wires declared but not connected:\n %s \n \n %s' % (bad_wire_names ,
@@ -561,6 +560,24 @@ def sanity_check(self):
561
560
# Check for async memories not specified as such
562
561
self .sanity_check_memory_sync (wire_src_dict )
563
562
563
+ # Check that all mappings in wirevector_by_name are consistent
564
+ bad_wv_by_name = [w for n , w in self .wirevector_by_name .items () if n != w .name ]
565
+ if bad_wv_by_name :
566
+ raise PyrtlInternalError ('Wires with inconsistent entry in wirevector_by_name '
567
+ 'dict: %s' % [w .name for w in bad_wv_by_name ])
568
+
569
+ # Check that all wires are in wirevector_by_name
570
+ wv_by_name_set = set (self .wirevector_by_name .keys ())
571
+ missing_wires = wirevector_names_set .difference (wv_by_name_set )
572
+ if missing_wires :
573
+ raise PyrtlInternalError ('Missing entries in wirevector_by_name for the '
574
+ 'following wires: %s' % missing_wires )
575
+
576
+ unknown_wires = wv_by_name_set .difference (wirevector_names_set )
577
+ if unknown_wires :
578
+ raise PyrtlInternalError ('Unknown wires found in wirevector_by_name: %s'
579
+ % unknown_wires )
580
+
564
581
if debug_mode :
565
582
# Check for wires that are destinations of a logicNet, but are not outputs and are never
566
583
# used as args.
0 commit comments