From: Luke Kenneth Casson Leighton Date: Sun, 21 May 2023 14:02:44 +0000 (+0100) Subject: hack-add @inject() into pyfnwriter, also take the X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=30a7a14f48170ada7a05ed1db3a802dcbe4d18a7;p=openpower-isa.git hack-add @inject() into pyfnwriter, also take the opportunity to stop doing "import ISACallerFnHelper as something" by doing a hack-substitute on the class name --- diff --git a/src/openpower/decoder/pseudo/pyfnwriter.py b/src/openpower/decoder/pseudo/pyfnwriter.py index 3560f782..417706a4 100644 --- a/src/openpower/decoder/pseudo/pyfnwriter.py +++ b/src/openpower/decoder/pseudo/pyfnwriter.py @@ -18,6 +18,7 @@ def get_isafn_src_dir(): header = """\ # auto-generated by pyfnwriter.py, do not edit or commit +from openpower.decoder.isa.caller import inject from openpower.decoder.helpers import (ISACallerHelper, ne, eq, gt, ge, lt, le, ltu, gtu, length, trunc_divs, trunc_rems, copy_assign_rhs, @@ -55,6 +56,17 @@ class PyISAFnWriter(ISAFunctions): filename = os.path.join(get_isafn_dir(), pagename + ".mdwn") pycode = convert_to_pure_python(pcode, True, filename=filename) sourcecache[phash] = pycode + # sigh ok, anything as a function needs an "@inject()" in front + # but it is too late here: the code has already been written out. + # therefore scan lines looking for "def ..." at the front. it works. + res = [] + for line in pycode.split('\n'): + if line.startswith("class ISACallerFnHelper("): + line = line.replace("(", "_%s(" % pagename) + elif line.startswith(" def "): + res.append(" @inject()") + res.append(line) + pycode = '\n'.join(res) f.write(pycode) def write_isa_class(self): @@ -63,16 +75,17 @@ class PyISAFnWriter(ISAFunctions): with open(fname, "w") as f: helpers = [] - f.write('# auto-generated by pyfnwriter.py: do not edit or commit\n') + f.write('# auto-generated by pyfnwriter.py do not edit or commit\n') f.write('from openpower.decoder.helpers import ISACallerHelper\n') for page in self.pages_written: module = 'openpower.decoder.isafunctions.' + page helper = 'ISACallerFnHelper_' + page helpers.append(helper) - f.write('from %s import ISACallerFnHelper as %s\n' % (module, helper)) + f.write('from %s import ISACallerFnHelper_%s\n' % \ + (module, page)) f.write('\n') f.write('\n') - f.write('class ISACallerFnHelper(%s):\n' % ', '.join(helpers + ['ISACallerHelper'])) + f.write('class ISACallerFnHelper(%s):\n' % ', '.join(helpers)) f.write(' pass\n')