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,
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):
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')