pywriter: redirect helpers into self
authorDmitry Selyutin <dmitry.selyutin@3mdeb.com>
Sat, 25 Sep 2021 17:15:43 +0000 (17:15 +0000)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Sat, 25 Sep 2021 20:07:09 +0000 (21:07 +0100)
src/openpower/decoder/pseudo/parser.py
src/openpower/decoder/pseudo/pywriter.py

index 94090281d3dd5de16f625c58cd3fa2ea3a66307d..afe8cad671c72c4ad1a77b20eab6cd963e6b86c9 100644 (file)
@@ -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, [], [])
index 1387e89003914b7d58ee467e46b1dabede5abac6..e883b326a66148160580e775395344b457663b33 100644 (file)
@@ -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')