From: Luke Kenneth Casson Leighton Date: Fri, 3 Apr 2020 18:45:01 +0000 (+0100) Subject: output as class not set of functions X-Git-Tag: div_pipeline~1548 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=3f0df13e6f3d54ef1488c6a7b07b0b78acb6a1b6;p=soc.git output as class not set of functions --- diff --git a/src/soc/decoder/power_pseudo.py b/src/soc/decoder/power_pseudo.py index 8a34507c..86306b01 100644 --- a/src/soc/decoder/power_pseudo.py +++ b/src/soc/decoder/power_pseudo.py @@ -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(): diff --git a/src/soc/decoder/pseudo/pywriter.py b/src/soc/decoder/pseudo/pywriter.py index af42c15a..dade1fce 100644 --- a/src/soc/decoder/pseudo/pywriter.py +++ b/src/soc/decoder/pseudo/pywriter.py @@ -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)