From: Luke Kenneth Casson Leighton Date: Thu, 2 Apr 2020 17:25:12 +0000 (+0100) Subject: add power isa python-writer X-Git-Tag: div_pipeline~1561 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=7e3b17be3e374b764b0aa63a7ca57365e63c572d;p=soc.git add power isa python-writer --- 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')