From ce6369c87d7331c07d6ea27c5117e3976cf2b688 Mon Sep 17 00:00:00 2001 From: Dmitry Selyutin Date: Sat, 25 Sep 2021 17:15:43 +0000 Subject: [PATCH] pywriter: redirect helpers into self --- src/openpower/decoder/pseudo/parser.py | 33 +++++++++++++++++++++--- src/openpower/decoder/pseudo/pywriter.py | 4 ++- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/openpower/decoder/pseudo/parser.py b/src/openpower/decoder/pseudo/parser.py index 94090281..afe8cad6 100644 --- a/src/openpower/decoder/pseudo/parser.py +++ b/src/openpower/decoder/pseudo/parser.py @@ -25,6 +25,32 @@ import ast regs = ['RA', 'RS', 'RB', 'RC', 'RT'] fregs = ['FRA', 'FRS', 'FRB', 'FRC', 'FRT', 'FRS'] +HELPERS = { + "EXTS", + "EXTS128", + "EXTS64", + "EXTZ64", + "FPADD32", + "FPADD64", + "FPCOS32", + "FPDIV32", + "FPDIV64", + "FPMUL32", + "FPMUL64", + "FPMULADD32", + "FPSIN32", + "FPSUB32", + "FPSUB64", + "MASK", + "MASK32", + "MULS", + "ROTL32", + "ROTL64", + "SHL64", + "SINGLE", + "SVSTATE_NEXT", + "TRAP", +} def Assign(autoassign, assignname, left, right, iea_mode): names = [] @@ -215,8 +241,8 @@ def apply_trailer(atom, trailer, read_regs): name = arg.id if name in regs + fregs: read_regs.add(name) - # special-case, function named "SVSTATE_NEXT" must be made "self.xxxx" - if atom.id == 'SVSTATE_NEXT': + # special-case, these functions must be made "self.xxxx" + if atom.id in HELPERS: name = ast.Name("self", ast.Load()) atom = ast.Attribute(name, atom, ast.Load()) return ast.Call(atom, trailer[1], []) @@ -411,9 +437,8 @@ class PowerParser: | expr_stmt""" if isinstance(p[1], ast.Call): p[0] = ast.Expr(p[1]) - elif isinstance(p[1], ast.Name) and p[1].id in ['TRAP', 'SVSTATE_NEXT']: + elif isinstance(p[1], ast.Name) and p[1].id in HELPERS: fname = p[1].id - # TRAP and SVSTATE_NEXT needs to actually be a function name = ast.Name("self", ast.Load()) name = ast.Attribute(name, fname, ast.Load()) p[0] = ast.Call(name, [], []) diff --git a/src/openpower/decoder/pseudo/pywriter.py b/src/openpower/decoder/pseudo/pywriter.py index 1387e890..e883b326 100644 --- a/src/openpower/decoder/pseudo/pywriter.py +++ b/src/openpower/decoder/pseudo/pywriter.py @@ -27,6 +27,7 @@ from openpower.decoder.helpers import (EXTS, EXTS64, EXTZ64, ROTL64, ROTL32, EXTS128, undefined, bitrev, SHL64, RANGE, + ISACallerHelper, ) from openpower.decoder.selectable_int import SelectableInt from openpower.decoder.selectable_int import selectconcat as concat @@ -141,12 +142,13 @@ class PyISAWriter(ISA): with open(fname, "w") as f: f.write('# auto-generated by pywriter.py: do not edit or commit\n') f.write('from openpower.decoder.isa.caller import ISACaller\n') + f.write('from openpower.decoder.helpers import ISACallerHelper\n') for page in self.pages_written: f.write('from openpower.decoder.isa.%s ' \ 'import %s\n' % (page, page)) f.write('\n') - classes = ', '.join(['ISACaller'] + self.pages_written) + classes = ', '.join(['ISACaller', 'ISACallerHelper'] + self.pages_written) f.write('class ISA(%s):\n' % classes) f.write(' def __init__(self, *args, **kwargs):\n') f.write(' super().__init__(*args, **kwargs)\n') -- 2.30.2