Add ability to patch generated isa files
authorMichael Nolan <mtnolan2640@gmail.com>
Wed, 6 May 2020 14:43:27 +0000 (10:43 -0400)
committerMichael Nolan <mtnolan2640@gmail.com>
Wed, 6 May 2020 14:43:27 +0000 (10:43 -0400)
src/soc/decoder/isa/branch.patch [new file with mode: 0644]
src/soc/decoder/pseudo/pywriter.py

diff --git a/src/soc/decoder/isa/branch.patch b/src/soc/decoder/isa/branch.patch
new file mode 100644 (file)
index 0000000..ac79f51
--- /dev/null
@@ -0,0 +1,11 @@
+--- branch.py.orig     2020-05-06 10:27:17.096835546 -0400
++++ branch.py  2020-05-06 10:27:40.353752508 -0400
+@@ -141,7 +141,7 @@
+             M = 32
+         if ~BO[2]:
+             CTR = CTR - 1
+-        ctr_ok = BO[2] | (CTR[M:64] != 0) ^ BO[3]
++        ctr_ok = BO[2] | SelectableInt((CTR[M:64] != 0), bits=1) ^ BO[3]
+         cond_ok = BO[0] | ~(CR[BI + 32] ^ BO[1])
+         if ctr_ok & cond_ok:
+             NIA = concat(LR[0:62], SelectableInt(value=0x0, bits=2))
index abdf99408e41a88d2ee624ad90085462af23ac8e..3cb6bef1a10efaa1ffdacb48081e3b30586d6001 100644 (file)
@@ -2,6 +2,8 @@
 
 import os
 import sys
+import shutil
+import subprocess
 from soc.decoder.pseudo.pagereader import ISA
 from soc.decoder.power_pseudo import convert_to_python
 from soc.decoder.orderedset import OrderedSet
@@ -86,6 +88,21 @@ class PyISAWriter(ISA):
             f.write("    %s_instrs = {}\n" % pagename)
             f.write(iinf)
 
+    def patch_if_needed(self, source):
+        isadir = get_isasrc_dir()
+        fname = os.path.join(isadir, "%s.py" % source)
+        patchname = os.path.join(isadir, "%s.patch" % source)
+
+        try:
+            with open(patchname, 'r') as patch:
+                newfname = fname + '.orig'
+                shutil.copyfile(fname, newfname)
+                subprocess.check_call(['patch', fname],
+                                      stdin=patch)
+        except:
+            pass
+
+
     def write_isa_class(self):
         isadir = get_isasrc_dir()
         fname = os.path.join(isadir, "all.py")
@@ -115,4 +132,5 @@ if __name__ == '__main__':
         sources = sys.argv[1:]
     for source in sources:
         isa.write_pysource(source)
+        isa.patch_if_needed(source)
     isa.write_isa_class()