#!/usr/bin/env python3 # SPDX-License-Identifier: MIT """The crate's handler and opcode tables against the reference's. check_tables.py TRACE_BINARY ``TRACE_BINARY --tables`` prints the crate's 256 handler names and 256 opcode rows; each must equal the reference's ``_dispatch.HANDLER_NAMES`` and ``_opcodes.OPCODES``. ``SPC700_PYTHON`` names the checkout. """ import json import os import subprocess import sys from pathlib import Path sys.path.insert(0, str(Path(os.environ["SPC700_PYTHON"]) / "src")) from spc700_python._dispatch import HANDLER_NAMES # noqa: E402 from spc700_python._opcodes import OPCODES # noqa: E402 def main() -> int: tables = json.loads(subprocess.run([sys.argv[1], "--tables"], capture_output=True, text=True, check=True).stdout) # fmt: skip differ = [] for opcode in range(256): if tables["handlers"][opcode] != HANDLER_NAMES[opcode]: differ.append(f"{opcode:02X}: handler {tables['handlers'][opcode]}, reference {HANDLER_NAMES[opcode]}") row = OPCODES[opcode] want = [row.mnemonic, row.operands, row.length, list(row.cycles), row.flags] if tables["opcodes"][opcode] != want: differ.append(f"{opcode:02X}: row {tables['opcodes'][opcode]}, reference {want}") if differ: print("\n".join(differ)) return 1 print("tables: all 256 handlers and 256 opcode rows equal the reference's") return 0 if __name__ == "__main__": sys.exit(main())