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)
"\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 = ''
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:
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()