From: Luke Kenneth Casson Leighton Date: Tue, 18 May 2021 08:56:48 +0000 (+0100) Subject: add python function writer, takes Appendix v3.0B pseudocode functions X-Git-Tag: xlen-bcd~602 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=ab5bd623c9150eda7702a44b38acb2444910ec49;p=openpower-isa.git add python function writer, takes Appendix v3.0B pseudocode functions and generates executable python --- diff --git a/src/openpower/decoder/pseudo/pyfnwriter.py b/src/openpower/decoder/pseudo/pyfnwriter.py new file mode 100644 index 00000000..c6e37b40 --- /dev/null +++ b/src/openpower/decoder/pseudo/pyfnwriter.py @@ -0,0 +1,72 @@ +# python code-writer for OpenPOWER ISA pseudo-code parsing + +import os +import sys +import shutil +import subprocess +from openpower.decoder.pseudo.functionreader import ISAFunctions +from openpower.decoder.power_pseudo import convert_to_pure_python + + +def get_isafn_src_dir(): + fdir = os.path.abspath(os.path.dirname(__file__)) + fdir = os.path.split(fdir)[0] + return os.path.join(fdir, "isafunctions") + + +header = """\ +# auto-generated by pyfnwriter.py, do not edit or commit + +from openpower.decoder.isa.caller import inject +from openpower.decoder.helpers import (EXTS, EXTS64, EXTZ64, ROTL64, ROTL32, + MASK, MASK32, + ne, eq, gt, ge, lt, le, ltu, gtu, length, + trunc_divs, trunc_rems, MULS, DIVS, MODS, + EXTS128, undefined, + DOUBLE, SINGLE, + FPADD32, FPSUB32, FPMUL32, FPDIV32, + FPADD64, FPSUB64, FPMUL64, FPDIV64, + ) +from openpower.decoder.selectable_int import SelectableInt +from openpower.decoder.selectable_int import selectconcat as concat + +# %s +""" + + +class PyISAFnWriter(ISAFunctions): + def __init__(self): + ISAFunctions.__init__(self) + self.pages_written = [] + + def write_pysource(self, pagename): + self.pages_written.append(pagename) + function = self.fns[pagename] + isadir = get_isafn_src_dir() + fname = os.path.join(isadir, "%s.py" % pagename) + with open(fname, "w") as f: + f.write(header % function['desc']) # write out header + # go through all instructions + pcode = function['pcode'] + print(pcode) + pycode = convert_to_pure_python(pcode) + f.write(pycode) + + +def pyfnwriter(): + isa = PyISAFnWriter() + write_isa_class = True + if len(sys.argv) == 1: # quick way to do it + print(dir(isa)) + sources = isa.fns.keys() + else: + sources = sys.argv[1:] + if sources[0] == "noall": # don't rewrite all.py + write_isa_class = False + sources.pop(0) + print ("sources", write_isa_class, sources) + for source in sources: + isa.write_pysource(source) + +if __name__ == '__main__': + pyfnwriter()