From: Dmitry Selyutin Date: Sun, 3 Dec 2023 11:48:39 +0000 (+0300) Subject: pywriter: introduce C mode X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=d1e3252ff7ae5c321f6bba05f93abcc5c662b477;p=openpower-isa.git pywriter: introduce C mode --- diff --git a/src/openpower/decoder/pseudo/pywriter.py b/src/openpower/decoder/pseudo/pywriter.py index 0bf918c8..89eca0a0 100644 --- a/src/openpower/decoder/pseudo/pywriter.py +++ b/src/openpower/decoder/pseudo/pywriter.py @@ -62,12 +62,12 @@ class PyISAWriter(ISA): ISA.__init__(self) self.pages_written = [] - def check_for_old_generated_files(self, pagenames): + def check_for_old_generated_files(self, pagenames, ext): isadir = get_isasrc_dir() found = [] first_fname = None for pagename in sorted(pagenames): - fbasename = pagename + ".py" + fbasename = (pagename + ext) if fbasename in OLD_GENERATED_FILES_EXCEPTIONS: continue old_fname = os.path.join(isadir, fbasename) @@ -91,11 +91,11 @@ class PyISAWriter(ISA): "\n".join(lines) ) - def write_pysource(self, pagename): + def write_code(self, pagename, ext): self.pages_written.append(pagename) instrs = self.page[pagename] isadir = get_isasrc_dir() - fname = os.path.join(isadir, "generated", pagename + ".py") + fname = os.path.join(isadir, "generated", (pagename + ext)) check_in_gitignore(fname) with open(fname, "w") as f: iinf = '' @@ -156,9 +156,11 @@ class PyISAWriter(ISA): f.write(" %s_instrs = {}\n" % pagename) f.write(iinf) - def patch_if_needed(self, source): + def patch_if_needed(self, source, ext): isadir = get_isasrc_dir() - fname = os.path.join(isadir, "generated", "%s.py" % source) + fname = os.path.join(isadir, "generated", (source + ext)) + + # FIXME: differ between modes patchname = os.path.join(isadir, "%s.patch" % source) try: @@ -200,19 +202,26 @@ class PyISAWriter(ISA): def pywriter(): isa = PyISAWriter() write_isa_class = True - if len(sys.argv) == 1: # quick way to do it + args = dict.fromkeys(sys.argv[1:]) + ext = ".py" + if "--c" in args: + ext = ".c" + del args["--c"] + if len(args) == 0: # quick way to do it log(dir(isa)) sources = isa.page.keys() else: - sources = sys.argv[1:] + sources = list(args) if sources[0] == "noall": # don't rewrite all.py write_isa_class = False sources.pop(0) + if ext == ".c": + raise NotImplementedError("C mode is not supported yet") log("sources", write_isa_class, sources) - isa.check_for_old_generated_files(sources) + isa.check_for_old_generated_files(pagenames=sources, ext=ext) for source in sources: - isa.write_pysource(source) - isa.patch_if_needed(source) + isa.write_code(pagename=source, ext=ext) + isa.patch_if_needed(source=source, ext=ext) if write_isa_class: isa.write_isa_class()