whoops, use cache of pseudocode rather than attempt to truncate
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Thu, 30 Sep 2021 18:31:14 +0000 (19:31 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Thu, 30 Sep 2021 18:31:14 +0000 (19:31 +0100)
the list of instructions, causes them to disappear. oops

src/openpower/decoder/pseudo/pagereader.py
src/openpower/decoder/pseudo/pyfnwriter.py
src/openpower/decoder/pseudo/pywriter.py

index 44c94b856d29b2e0583de294a848066f1eef2f2d..d5cae081c0438adebd35d72bb26dbcf6c2def979 100644 (file)
@@ -64,13 +64,11 @@ def get_isa_dir():
 
 class ISA:
 
-    def __init__(self, first_encountered_instr=False):
+    def __init__(self):
         self.instr = OrderedDict()
         self.forms = {}
         self.page = {}
         self.verbose = False
-        # only add the first-encountered instruction (marked by "*")
-        self.first_encountered_instr = first_encountered_instr
         for pth in os.listdir(os.path.join(get_isa_dir())):
             if self.verbose:
                 print("examining", get_isa_dir(), pth)
@@ -284,14 +282,6 @@ class ISA:
             # add in opcode
             for o in opcodes:
                 self.add_op(o, d)
-                if self.first_encountered_instr:
-                    # turns out that because the pseudocode is identical,
-                    # you don't actually need to add any more than the
-                    # first listed opcode for pseudocode-generation.
-                    # therefore, save compiler time and skip all others.
-                    # detection of "." and "o" etc is handled in ISACaller
-                    # and ends up replicating the instruction that way
-                    break
 
             # expect and drop whitespace
             while lines:
index 74185b2a4de138824f93720ca156f3cb39b26b62..001c0f0a600dbb634eeee5799dd6962fe0ce1a5c 100644 (file)
@@ -39,12 +39,19 @@ class PyISAFnWriter(ISAFunctions):
         isadir = get_isafn_src_dir()
         os.makedirs(isadir, exist_ok=True)
         fname = os.path.join(isadir, "%s.py" % pagename)
+        sourcecache = dict()
         with open(fname, "w") as f:
             f.write(header % function['desc'])  # write out header
             # go through all instructions
             pcode = function['pcode']
             print(pcode)
-            pycode = convert_to_pure_python(pcode, True)
+            # check if the code has already been compiled
+            phash = hash(pcode)
+            if phash in sourcecache:
+                pycode = sourcecache[phash]
+            else:
+                pycode = convert_to_pure_python(pcode, True)
+                sourcecache[phash] = pycode
             f.write(pycode)
 
     def write_isa_class(self):
index 2b405e26d4e028d659b8ab59efeeb59aff18e266..b01fc4cc0a0008f492b35bd1e397f2a1862271b7 100644 (file)
@@ -53,7 +53,7 @@ iinfo_template = """instruction_info(func=%s,
 
 class PyISAWriter(ISA):
     def __init__(self):
-        ISA.__init__(self, first_encountered_instr=True)
+        ISA.__init__(self)
         self.pages_written = []
 
     def write_pysource(self, pagename):