change to instruction template parsing, create one file per instruction
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Tue, 25 Sep 2018 22:04:09 +0000 (23:04 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Tue, 25 Sep 2018 22:04:09 +0000 (23:04 +0100)
id_regs.py looks for patterns in riscv/insns/*.h to find the use of
registers

id_regs.py

index c3fbf791672cbe1c037ee565e6cff1b59dc467b7..1dd6cf458c78543dac5a2118947c897940d6389d 100644 (file)
@@ -20,8 +20,8 @@
 
 import os
 
+insns_dir = "./riscv/insns"
 def list_insns():
-    insns_dir = "./riscv/insns"
     res = []
     for fname in os.listdir(insns_dir):
         if not fname.endswith(".h"):
@@ -48,13 +48,15 @@ def find_registers(fname):
             p = pattern
             if p.startswith('WRITE_'):
                 p = p[6:]
-            res.append('REG_%s' % p)
+            res.append('#define USING_REG_%s' % p)
     if len(res) == 0:
         return "0"
-    return ' | '.join(res)
+    return '\n'.join(res)
 
 if __name__ == '__main__':
-    template = "#define REGS_%-12s %s"
     files = list_insns()
     for (fname, insn) in files:
-        print template % (insn, find_registers(fname))
+        regsname = "regs_%s.h" % insn
+        regsname = os.path.join(insns_dir, regsname)
+        with open(regsname, "w") as f:
+            f.write(find_registers(fname))