output as class not set of functions
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Fri, 3 Apr 2020 18:45:01 +0000 (19:45 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Fri, 3 Apr 2020 18:45:01 +0000 (19:45 +0100)
src/soc/decoder/power_pseudo.py
src/soc/decoder/pseudo/pywriter.py

index 8a34507c57b288596fcbc6b1cb5f6eda8333f6c3..86306b01f5c9e454ecfaa081efb568c0194a9126 100644 (file)
@@ -145,7 +145,10 @@ def convert_to_python(pcode):
 
     tree = gsc.compile(pcode, mode="exec", filename="string")
     tree = ast.fix_missing_locations(tree)
-    return astor.to_source(tree)
+    regsused = {'read_regs': gsc.parser.read_regs,
+                'write_regs': gsc.parser.write_regs,
+                'uninit_regs': gsc.parser.uninit_regs}
+    return astor.to_source(tree), regsused
 
 
 def test():
index af42c15a4b7fa462abffcca2e5466c68167ad18e..dade1fceff2b47031b9adc3c63404e40cdd6d245 100644 (file)
@@ -19,15 +19,17 @@ class PyISAWriter(ISA):
         isadir = get_isasrc_dir()
         fname = os.path.join(isadir, "%s.py" % pagename)
         with open(fname, "w") as f:
+            f.write("class %s:\n" % pagename)
             for page in instrs:
                 d = self.instr[page]
                 print (fname, d.opcode)
-                f.write("def %s():\n" % page.replace(".", "_"))
                 pcode = '\n'.join(d.pcode) + '\n'
                 print (pcode)
-                pycode = convert_to_python(pcode)
+                pycode, regsused = convert_to_python(pcode)
+                f.write("    #%s\n" % repr(regsused))
+                f.write("    def %s(self):\n" % page.replace(".", "_"))
                 pycode = pycode.split("\n")
-                pycode = '\n'.join(map(lambda x: "    %s" % x, pycode))
+                pycode = '\n'.join(map(lambda x: "        %s" % x, pycode))
                 f.write("%s\n\n" % pycode)