@@ -627,7 +627,7 @@ def compile(self, prefix_names=False):
627
627
# We create a compiled output port
628
628
assg = ParameterAssignment (destination .symbol , source .symbol )
629
629
compiled .output_ports [destination .name ] = CompiledOutputPort (
630
- source , assg
630
+ destination , assg
631
631
)
632
632
else :
633
633
raise WiringError (
@@ -703,8 +703,22 @@ def compile(self, prefix_names=False):
703
703
compiled .internal_variable_assignments [name ] = port .assignment
704
704
705
705
compiled .sub_symbol_identifications ()
706
+
707
+ # Align the dictionary keys with the names of the symbols
708
+ # whose assignments the dictionary is storing.
709
+ # This has to happen after all the wiring compilation,
710
+ # because the wires refer to the child + port name within the child,
711
+ # so the child name cannot be part of the dictionary key while
712
+ # the wiring is compiled.
713
+ compiled .remap_dict_keys ()
714
+
706
715
if prefix_names :
716
+ # After this, all variables/parameters appearing everywhere
717
+ # are prefixed by the name of the ported object.
718
+ # This, however, does not apply to the dictionary keys,
719
+ # see above for the reasoning
707
720
compiled .sub_prefixed_symbols ()
721
+
708
722
return compiled
709
723
710
724
@@ -756,6 +770,19 @@ def sub_prefixed_symbols(self):
756
770
new_symbol = sym .Symbol (HIERARCHY_SEPARATOR .join ([self .name , name ]))
757
771
self .sub_everywhere (old_symbol , new_symbol )
758
772
773
+ def remap_dict_keys (self ):
774
+ # Remap dictionary keys to add prefix
775
+ for containers in [
776
+ self .input_ports ,
777
+ self .output_ports ,
778
+ self .variable_ports ,
779
+ self .internal_variable_assignments ,
780
+ self .internal_parameter_assignments
781
+ ]:
782
+ re_keyed = {content .name : content for name , content in containers .items ()}
783
+ containers .clear ()
784
+ containers .update (re_keyed )
785
+
759
786
def sub_everywhere (self , old_symbol , new_symbol ):
760
787
assert isinstance (old_symbol , sym .Symbol )
761
788
assert isinstance (new_symbol , sym .Symbol )
0 commit comments