#!/usr/bin/env python3 # SPDX-License-Identifier: MIT """Write src/dispatch.rs's handler table and src/opcodes.rs's rows from the reference. gen_tables.py dispatch > rows.rs.in (the 256 handlers of _dispatch.HANDLER_NAMES) gen_tables.py opcodes > rows.rs.in (the 256 rows of _opcodes.OPCODES) Run with ``SPC700_PYTHON`` naming the checkout; rung 1's ``check_tables.py`` then holds the crate's tables equal to the reference's on every run. """ import os import sys sys.path.insert(0, os.path.join(os.environ["SPC700_PYTHON"], "src")) from spc700_python._dispatch import HANDLER_NAMES # noqa: E402 from spc700_python._opcodes import OPCODES # noqa: E402 def camel(name: str) -> str: return "".join(part.capitalize() for part in name.removeprefix("_op_").split("_")) def main() -> None: if sys.argv[1] == "dispatch": for opcode, name in enumerate(HANDLER_NAMES): print(f" Op::{camel(name)}, // {opcode:02X} {OPCODES[opcode].mnemonic} {OPCODES[opcode].operands}") else: for opcode, row in enumerate(OPCODES): cycles = ", ".join(str(c) for c in row.cycles) print(f' Opcode {{ mnemonic: "{row.mnemonic}", operands: "{row.operands}", length: {row.length}, ' f'cycles: &[{cycles}], flags: "{row.flags}" }}, // {opcode:02X}') if __name__ == "__main__": main()