add signals for all fields, accessible by named tuples as fields
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Mon, 30 Mar 2020 15:06:33 +0000 (16:06 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Mon, 30 Mar 2020 15:06:33 +0000 (16:06 +0100)
src/soc/decoder/power_decoder.py
src/soc/decoder/power_fields.py

index f349e6bb7d34fa3c3f7b57de2515e74d98193b77..a3d67fb166a050a6c5d3f69a0498fde32fea400a 100644 (file)
@@ -53,6 +53,7 @@ Top Level:
 
 """
 
+from collections import namedtuple
 from nmigen import Module, Elaboratable, Signal, Cat, Mux
 from nmigen.cli import rtlil
 from soc.decoder.power_enums import (Function, Form, InternalOp,
@@ -239,7 +240,7 @@ class TopPowerDecoder(PowerDecoder):
 
     def __init__(self, width, dec):
         PowerDecoder.__init__(self, width, dec)
-        self.fields = DecodeFields(SignalBitRange, [self.opcode_in])
+        self.fields = df = DecodeFields(SignalBitRange, [self.opcode_in])
         self.fields.create_specs()
         self.raw_opcode_in = Signal.like(self.opcode_in, reset_less=True)
         self.bigendian = Signal(reset_less=True)
@@ -249,6 +250,7 @@ class TopPowerDecoder(PowerDecoder):
             sig = Signal(value[0:-1].shape(), reset_less=True, name=name)
             setattr(self, name, sig)
 
+
     def elaborate(self, platform):
         m = PowerDecoder.elaborate(self, platform)
         comb = m.d.comb
@@ -259,10 +261,30 @@ class TopPowerDecoder(PowerDecoder):
         l.reverse()
         raw_le = Cat(*l)
         comb += self.opcode_in.eq(Mux(self.bigendian, raw_be, raw_le))
+
+        # add all signal from commonly-used fields
         for name in self.fields.common_fields:
             value = getattr(self.fields, name)
             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 = {}
+        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
+                comb += sig.eq(value[0:-1])
+            instr = Fields(**sf)
+            setattr(self, "Form%s" % form, instr)
+            self.sigforms[form] = instr
+
         return m
 
     def ports(self):
index cf0544d2557cdadcd4ff4bed343c8584f82a72a5..e0c01427bf68398f55efd51be155c73d0ceffae8 100644 (file)
@@ -112,7 +112,7 @@ class DecodeFields:
     def create_specs(self):
         self.forms, self.instrs = self.decode_fields()
         self.form_names = forms = self.instrs.keys()
-        print ("specs", self.forms, forms)
+        #print ("specs", self.forms, forms)
         for form in forms:
             fields = self.instrs[form]
             fk = fields.keys()
@@ -163,7 +163,7 @@ class DecodeFields:
     def decode_fields(self):
         with open(self.fname) as f:
             txt = f.readlines()
-        print ("decode", txt)
+        #print ("decode", txt)
         forms = {}
         reading_data = False
         for l in txt: