create #defines from identified registers, per opcode
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Mon, 24 Sep 2018 02:56:21 +0000 (03:56 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Mon, 24 Sep 2018 02:56:21 +0000 (03:56 +0100)
id_regs.py

index cc1596ab8e22f37b7c3a009ab9c54a5fcc6f93f3..c3fbf791672cbe1c037ee565e6cff1b59dc467b7 100644 (file)
@@ -26,7 +26,8 @@ def list_insns():
     for fname in os.listdir(insns_dir):
         if not fname.endswith(".h"):
             continue
-        res.append(os.path.join(insns_dir, fname))
+        insn = fname[:-2]
+        res.append((os.path.join(insns_dir, fname), insn))
     return res
 
 patterns = ['WRITE_RD', 'RS1', 'RS2', 'RS3',
@@ -44,10 +45,16 @@ def find_registers(fname):
                 # botch-job/hack: RS1 also matches against FRS1 (etc.)
                 # check letter before match: if "F", skip it.
                 continue
-            res.append('REG_%s' % pattern)
+            p = pattern
+            if p.startswith('WRITE_'):
+                p = p[6:]
+            res.append('REG_%s' % p)
+    if len(res) == 0:
+        return "0"
     return ' | '.join(res)
 
 if __name__ == '__main__':
+    template = "#define REGS_%-12s %s"
     files = list_insns()
-    for fname in files:
-        print fname, find_registers(fname)
+    for (fname, insn) in files:
+        print template % (insn, find_registers(fname))