class ISA:
- def __init__(self, first_encountered_instr=False):
+ def __init__(self):
self.instr = OrderedDict()
self.forms = {}
self.page = {}
self.verbose = False
- # only add the first-encountered instruction (marked by "*")
- self.first_encountered_instr = first_encountered_instr
for pth in os.listdir(os.path.join(get_isa_dir())):
if self.verbose:
print("examining", get_isa_dir(), pth)
# add in opcode
for o in opcodes:
self.add_op(o, d)
- if self.first_encountered_instr:
- # turns out that because the pseudocode is identical,
- # you don't actually need to add any more than the
- # first listed opcode for pseudocode-generation.
- # therefore, save compiler time and skip all others.
- # detection of "." and "o" etc is handled in ISACaller
- # and ends up replicating the instruction that way
- break
# expect and drop whitespace
while lines:
isadir = get_isafn_src_dir()
os.makedirs(isadir, exist_ok=True)
fname = os.path.join(isadir, "%s.py" % pagename)
+ sourcecache = dict()
with open(fname, "w") as f:
f.write(header % function['desc']) # write out header
# go through all instructions
pcode = function['pcode']
print(pcode)
- pycode = convert_to_pure_python(pcode, True)
+ # check if the code has already been compiled
+ phash = hash(pcode)
+ if phash in sourcecache:
+ pycode = sourcecache[phash]
+ else:
+ pycode = convert_to_pure_python(pcode, True)
+ sourcecache[phash] = pycode
f.write(pycode)
def write_isa_class(self):
class PyISAWriter(ISA):
def __init__(self):
- ISA.__init__(self, first_encountered_instr=True)
+ ISA.__init__(self)
self.pages_written = []
def write_pysource(self, pagename):