From 6f856a0ff795cd630f9d4c5739909fae262b408f Mon Sep 17 00:00:00 2001 From: Jacob Lifshay Date: Sun, 30 Jul 2023 18:23:01 -0700 Subject: [PATCH] move generated files to .../decoder/isa/generated 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 | 36 ---------------- .../decoder/isa/generated/.gitignore | 4 ++ src/openpower/decoder/pseudo/pywriter.py | 41 +++++++++++++++++-- 3 files changed, 41 insertions(+), 40 deletions(-) create mode 100644 src/openpower/decoder/isa/generated/.gitignore diff --git a/src/openpower/decoder/isa/.gitignore b/src/openpower/decoder/isa/.gitignore index 45f8711b..fdbba71e 100644 --- a/src/openpower/decoder/isa/.gitignore +++ b/src/openpower/decoder/isa/.gitignore @@ -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 index 00000000..7807d544 --- /dev/null +++ b/src/openpower/decoder/isa/generated/.gitignore @@ -0,0 +1,4 @@ +!__init__.py +*.py +*.orig +*.rej diff --git a/src/openpower/decoder/pseudo/pywriter.py b/src/openpower/decoder/pseudo/pywriter.py index a45ca079..5b678bc5 100644 --- a/src/openpower/decoder/pseudo/pywriter.py +++ b/src/openpower/decoder/pseudo/pywriter.py @@ -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) -- 2.30.2