From: Jacob Lifshay Date: Mon, 31 Jul 2023 01:23:01 +0000 (-0700) Subject: move generated files to .../decoder/isa/generated X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=6f856a0ff795cd630f9d4c5739909fae262b408f;p=openpower-isa.git 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 --- 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)