From 7e3b17be3e374b764b0aa63a7ca57365e63c572d Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Thu, 2 Apr 2020 18:25:12 +0100 Subject: [PATCH] add power isa python-writer --- src/soc/decoder/pseudo/pywriter.py | 36 ++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/soc/decoder/pseudo/pywriter.py diff --git a/src/soc/decoder/pseudo/pywriter.py b/src/soc/decoder/pseudo/pywriter.py new file mode 100644 index 00000000..3ecc2f87 --- /dev/null +++ b/src/soc/decoder/pseudo/pywriter.py @@ -0,0 +1,36 @@ +# python code-writer for OpenPOWER ISA pseudo-code parsing + +import os +from soc.decoder.pseudo.pagereader import ISA +from soc.decoder.power_pseudo import convert_to_python + +def get_isasrc_dir(): + fdir = os.path.abspath(os.path.dirname(__file__)) + fdir = os.path.split(fdir)[0] + return os.path.join(fdir, "isa") + + +class PyISAWriter(ISA): + def __init__(self): + ISA.__init__(self) + + def write_pysource(self, pagename): + instrs = isa.page[pagename] + isadir = get_isasrc_dir() + fname = os.path.join(isadir, "%s.py" % pagename) + with open(fname, "w") as f: + 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 = pycode.split("\n") + pycode = '\n'.join(map(lambda x: " %s" % x, pycode)) + f.write("%s\n\n" % pycode) + + +if __name__ == '__main__': + isa = PyISAWriter() + isa.write_pysource('comparefixed') -- 2.30.2