31 lines
1.2 KiB
Python
31 lines
1.2 KiB
Python
from instruction_table import untabulate_instructions_sh2
|
|
from instruction_function_name import instruction_function_name
|
|
|
|
def main():
|
|
function_names = {}
|
|
instruction_table = untabulate_instructions_sh2()
|
|
for ins in instruction_table:
|
|
function_name = instruction_function_name(ins)
|
|
instruction_operands = (ins.instruction, ins.operands)
|
|
assert function_name not in function_names, (instruction_operands, function_names[function_name])
|
|
function_names[function_name] = instruction_operands
|
|
if ins.variables:
|
|
args = f', {", ".join(ins.variables)}'
|
|
else:
|
|
args = ''
|
|
print(f"def {function_name}(cpu, mem{args}):")
|
|
print(f" # {ins.instruction} {ins.operands}")
|
|
print(f" raise NotImplementedError()")
|
|
print()
|
|
|
|
print("lookup = {")
|
|
for ins in instruction_table:
|
|
function_name = instruction_function_name(ins)
|
|
i_space = ' ' * (len('CMP/STR') - len(ins.instruction))
|
|
o_space = ' ' * (len('@(disp,GBR),R0') - len(ins.operands))
|
|
print(f" ('{ins.instruction}'{i_space}, '{ins.operands}'{o_space}): {function_name},")
|
|
print("}")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|