move generated files to .../decoder/isa/generated
authorJacob Lifshay <programmerjake@gmail.com>
Mon, 31 Jul 2023 01:23:01 +0000 (18:23 -0700)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Fri, 22 Dec 2023 19:26:20 +0000 (19:26 +0000)
add code to check for old generated files and prompt you to remove
them, to avoid accidentally commiting them.
doesn't move all.py so we don't need to change all the imports

src/openpower/decoder/isa/.gitignore
src/openpower/decoder/isa/generated/.gitignore [new file with mode: 0644]
src/openpower/decoder/pseudo/pywriter.py

index 45f8711bb8ff14a17444d6f55022c6d8433fa15d..fdbba71e76109d33dda5ee8158e2f473e54e8927 100644 (file)
@@ -1,39 +1,3 @@
 /all.py
-/av.py
-/bcd.py
-/bitmanip.py
-/branch.py
-/byterev.py
-/comparefixed.py
-/condition.py
-/fixedarith.py
-/fixedldstcache.py
-/fixedload.py
-/fixedlogical.py
-/fixedshift.py
-/fixedstore.py
-/fixedsync.py
-/fixedtrap.py
-/fparith.py
-/fpcvt.py
-/fpload.py
-/fpmove.py
-/fpstore.py
-/fptrans.py
-/maddsubrs.py
-/maddrs.py
-/msubrs.py
-/pifixedload.py
-/pifixedstore.py
-/sprset.py
-/stringldst.py
-/system.py
-/simplev.py
-/svbranch.py
-/svfixedarith.py
-/svfixedload.py
-/svfparith.py
-/svfpload.py
-/prefix_codes.py
 *.orig
 *.rej
diff --git a/src/openpower/decoder/isa/generated/.gitignore b/src/openpower/decoder/isa/generated/.gitignore
new file mode 100644 (file)
index 0000000..7807d54
--- /dev/null
@@ -0,0 +1,4 @@
+!__init__.py
+*.py
+*.orig
+*.rej
index a45ca07917f34ae7870ef9dd92f5a29c057e37bb..5b678bc5c774872f71419d50899e19b856fd6a5c 100644 (file)
@@ -52,16 +52,48 @@ iinfo_template = """instruction_info(func=%s,
                 asmregs=%s)"""
 
 
+OLD_GENERATED_FILES_EXCEPTIONS = {
+    "example_exception.py",
+}
+
 class PyISAWriter(ISA):
     def __init__(self):
         ISA.__init__(self)
         self.pages_written = []
 
+    def check_for_old_generated_files(self, pagenames):
+        isadir = get_isasrc_dir()
+        found = []
+        first_fname = None
+        for pagename in sorted(pagenames):
+            fbasename = pagename + ".py"
+            if fbasename in OLD_GENERATED_FILES_EXCEPTIONS:
+                continue
+            old_fname = os.path.join(isadir, fbasename)
+            if os.path.exists(old_fname):
+                if first_fname is None:
+                    first_fname = os.path.join(isadir, "generated", fbasename)
+                found.append(fbasename)
+        for first_old_fname in found:
+            found_str = " ".join(f"'{i}'" for i in found)
+            lines = [
+                f"found likely old generated file: {first_old_fname!r}",
+                f"new location: {first_fname!r}",
+                "please remove the old generated files or add to:",
+                ("openpower.decoder.pseudo.pywriter."
+                 "OLD_GENERATED_FILES_EXCEPTIONS"),
+                "commands to remove all likely old generated files:",
+                f"(cd {isadir}; rm -v {found_str})",
+            ]
+            raise ValueError(
+                "\n".join(lines)
+            )
+
     def write_pysource(self, pagename):
         self.pages_written.append(pagename)
         instrs = self.page[pagename]
         isadir = get_isasrc_dir()
-        fname = os.path.join(isadir, "%s.py" % pagename)
+        fname = os.path.join(isadir, "generated", pagename + ".py")
         check_in_gitignore(fname)
         with open(fname, "w") as f:
             iinf = ''
@@ -122,7 +154,7 @@ class PyISAWriter(ISA):
 
     def patch_if_needed(self, source):
         isadir = get_isasrc_dir()
-        fname = os.path.join(isadir, "%s.py" % source)
+        fname = os.path.join(isadir, "generated", "%s.py" % source)
         patchname = os.path.join(isadir, "%s.patch" % source)
 
         try:
@@ -145,7 +177,7 @@ class PyISAWriter(ISA):
             f.write('from openpower.decoder.isafunctions.all '
                     'import ISACallerFnHelper\n')
             for page in self.pages_written:
-                f.write('from openpower.decoder.isa.%s ' \
+                f.write('from openpower.decoder.isa.generated.%s '
                         'import %s\n' % (page, page))
             f.write('\n')
 
@@ -172,7 +204,8 @@ def pywriter():
         if sources[0] == "noall": # don't rewrite all.py
             write_isa_class = False
             sources.pop(0)
-    print ("sources", write_isa_class, sources)
+    print("sources", write_isa_class, sources)
+    isa.check_for_old_generated_files(sources)
     for source in sources:
         isa.write_pysource(source)
         isa.patch_if_needed(source)