split out sig set from sig setup
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Tue, 31 Mar 2020 15:19:39 +0000 (16:19 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Tue, 31 Mar 2020 15:19:39 +0000 (16:19 +0100)
src/soc/decoder/power_decoder.py

index dfd5cb6727e772dc7a6de18401faccd40e0aeba6..c8e0600f9b14085de147a8215f9537fea3601866 100644 (file)
@@ -249,6 +249,21 @@ class TopPowerDecoder(PowerDecoder):
             sig = Signal(value[0:-1].shape(), reset_less=True, name=name)
             setattr(self, name, sig)
 
+        # create signals for all field forms
+        self.form_names = forms = self.fields.instrs.keys()
+        self.sigforms = {}
+        for form in forms:
+            fields = self.fields.instrs[form]
+            fk = fields.keys()
+            Fields = namedtuple("Fields", fk)
+            sf = {}
+            for k, value in fields.items():
+                name = "%s_%s" % (form, k)
+                sig = Signal(value[0:-1].shape(), reset_less=True, name=name)
+                sf[k] = sig
+            instr = Fields(**sf)
+            setattr(self, "Form%s" % form, instr)
+            self.sigforms[form] = instr
 
     def elaborate(self, platform):
         m = PowerDecoder.elaborate(self, platform)
@@ -266,22 +281,14 @@ class TopPowerDecoder(PowerDecoder):
             sig = getattr(self, name)
             comb += sig.eq(value[0:-1])
 
-        # create signals for all field forms
-        self.form_names = forms = self.fields.instrs.keys()
-        self.sigforms = {}
+        # link signals for all field forms
+        forms = self.form_names
         for form in forms:
+            sf = self.sigforms[form]
             fields = self.fields.instrs[form]
-            fk = fields.keys()
-            Fields = namedtuple("Fields", fk)
-            sf = {}
             for k, value in fields.items():
-                name = "%s_%s" % (form, k)
-                sig = Signal(value[0:-1].shape(), reset_less=True, name=name)
-                sf[k] = sig
+                sig = getattr(sf, k)
                 comb += sig.eq(value[0:-1])
-            instr = Fields(**sf)
-            setattr(self, "Form%s" % form, instr)
-            self.sigforms[form] = instr
 
         return m