move to header-template, fix bug in page name (use instruction name)
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Sat, 4 Apr 2020 12:48:49 +0000 (13:48 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Sat, 4 Apr 2020 12:48:49 +0000 (13:48 +0100)
src/soc/decoder/pseudo/pywriter.py

index ad0b09e088e9d763b4f0fc87c3f0b76006af365b..a8eeb3ab8579e0e4969ded1a64d9fc7e5ed54648 100644 (file)
@@ -18,6 +18,14 @@ def create_args(reglist, extra=None):
         args = [extra] + args
     return ', '.join(args)
 
+header = """\
+# auto-generated by pywriter.py, do not edit or commit
+
+from soc.decoder.isa import ISACaller
+from soc.decoder.helpers import (EXTS64, EXTZ64, ROTL64, ROTL32, MASK,)
+
+class %s(ISACaller):
+"""
 
 class PyISAWriter(ISA):
     def __init__(self):
@@ -29,12 +37,8 @@ class PyISAWriter(ISA):
         fname = os.path.join(isadir, "%s.py" % pagename)
         with open(fname, "w") as f:
             iinf = ''
-            f.write("# auto-generated by pywriter.py, do not edit or commit\n")
-            f.write("from soc.decoder.isa import ISACaller\n\n")
-            f.write("from soc.decoder.helpers import " + \
-                    "(EXTS64, EXTZ64, ROTL64, ROTL32, MASK,)\n")
-
-            f.write("class %s(ISACaller):\n" % pagename)
+            f.write(header % pagename) # write out header
+            # go through all instructions
             for page in instrs:
                 d = self.instr[page]
                 print (fname, d.opcode)
@@ -55,11 +59,12 @@ class PyISAWriter(ISA):
                     f.write("        return (%s,)\n\n" % retargs)
                 else:
                     f.write("\n")
-                # cumulate the instruction info
+                # accumulate the instruction info
                 iinfo = "(%s, %s, %s, %s)" % \
-                            (pagename, rused['read_regs'],
+                            (page, rused['read_regs'],
                             rused['uninit_regs'], rused['write_regs'])
                 iinf += "    instrs['%s'] = %s\n" % (pagename, iinfo)
+            # write out initialisation of info, for ISACaller to use
             f.write("    instrs = {}\n")
             f.write(iinf)