add form-extraction parsing
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Thu, 2 Apr 2020 15:40:13 +0000 (16:40 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Thu, 2 Apr 2020 15:40:13 +0000 (16:40 +0100)
src/soc/decoder/pseudo/pagereader.py

index 13c9c8698803a9e2361fc340929a6fb07352ef14..0b3a3c368323a7fefdf0851cb4a7925181bdcc42 100644 (file)
@@ -63,6 +63,7 @@ class ISA:
 
     def __init__(self):
         self.instr = OrderedDict()
+        self.forms = {}
 
     def read_file(self, fname):
         fname = os.path.join(get_isa_dir(), fname)
@@ -132,17 +133,25 @@ class ISA:
 
             # add in opcode
             for o in opcodes:
-                opcode, regs = o[0], o[1:]
-                op = copy(d)
-                op['regs'] = regs
-                op['opcode'] = opcode
-                self.instr[opcode] = op
+                self.add_op(o, d)
 
             # expect and drop whitespace
             while lines:
                 l = lines.pop(0).rstrip()
                 if len(l) != 0: break
 
+    def add_op(self, o, d):
+        opcode, regs = o[0], o[1:]
+        op = copy(d)
+        op['regs'] = regs
+        op['opcode'] = opcode
+        self.instr[opcode] = op
+
+        # create list of instructions by form
+        form = op['form']
+        fl = self.forms.get(form, [])
+        self.forms[form] = fl + [opcode]
+
     def pprint_ops(self):
         for k, v in self.instr.items():
             print ("# %s %s" % (v['opcode'], v['desc']))
@@ -151,6 +160,8 @@ class ISA:
             print ("Specials")
             print ('\n'.join(map(lambda x: "    %s" % x, v['sregs'])))
             print ()
+        for k, v in isa.forms.items():
+            print (k, v)
 
 if __name__ == '__main__':
     isa = ISA()