no python files to be committed in isafunctions
[openpower-isa.git] / src / openpower / decoder / pseudo / pywriter.py
index 79f2edab7ea7c1023082b2b4cd68405842ba8948..efca91c9094a0c473affb50f666901fc968d45a7 100644 (file)
@@ -25,12 +25,25 @@ from openpower.decoder.helpers import (EXTS, EXTS64, EXTZ64, ROTL64, ROTL32,
                                  ne, eq, gt, ge, lt, le, ltu, gtu, length,
                                  trunc_divs, trunc_rems, MULS, DIVS, MODS,
                                  EXTS128, undefined,
-                                 DOUBLE, SINGLE)
+                                 bitrev, SHL64,
+                                )
 from openpower.decoder.selectable_int import SelectableInt
 from openpower.decoder.selectable_int import selectconcat as concat
 from openpower.decoder.orderedset import OrderedSet
+from openpower.decoder.isafunctions.bcd import BCD_TO_DPD, DPD_TO_BCD
 
-class %s:
+"""
+
+fpheader = """
+from openpower.decoder.helpers import (
+                                 SINGLE,
+                                 FPADD32, FPSUB32, FPMUL32, FPDIV32,
+                                 FPADD64, FPSUB64, FPMUL64, FPDIV64,
+                                 FPMULADD32,
+                                 FPSIN32, FPCOS32,
+                                )
+from openpower.decoder.isafunctions.fpfromint import INT2FP
+from openpower.decoder.isafunctions.double2single import DOUBLE
 
 """
 
@@ -54,7 +67,13 @@ class PyISAWriter(ISA):
         fname = os.path.join(isadir, "%s.py" % pagename)
         with open(fname, "w") as f:
             iinf = ''
-            f.write(header % pagename)  # write out header
+            # write headers: FP gets extra imports
+            f.write(header)  # write out header
+            if (pagename.startswith("fp") or
+                pagename.startswith("svfp")):
+                f.write(fpheader)
+            f.write("class %s:\n" % pagename)
+
             # go through all instructions
             for page in instrs:
                 d = self.instr[page]
@@ -74,8 +93,12 @@ class PyISAWriter(ISA):
                 op_fname = "op_%s" % page.replace(".", "_")
                 f.write("    @inject()\n")
                 f.write("    def %s(%s):\n" % (op_fname, args))
-                if 'NIA' in pycode:  # HACK - TODO fix
-                    f.write("        global NIA\n")
+                # blech! this works in combination with ISACaller
+                # @inject decorator, which works by injecting
+                # global variables into the function namespace.
+                for blech in ['NIA', 'end_loop']:
+                    if blech in pycode:  # HACK - TODO fix
+                        f.write("        global %s\n" % blech)
                 pycode = pycode.split("\n")
                 pycode = '\n'.join(map(lambda x: "        %s" % x, pycode))
                 pycode = pycode.rstrip()