#!/usr/bin/env python3 # SPDX-License-Identifier: MIT """Compare two boundary traces with the reference's own reader and comparison. compare_traces.py ROW REFERENCE.jsonl OURS.jsonl ``ROW`` is the part both traces ran (``w65c02s``, ``r65c02``, ``g65sc02``, ``lynx2cell``): the reader decodes each record's instruction bytes as that row executes them. Prints "traces are identical" and exits 0, or the first divergence (its position and every differing field) and exits 1. Run it with the reference's interpreter. """ from __future__ import annotations import json import sys from w65c02_python.harness import ROWS from w65c02_python.trace import first_trace_divergence, read_trace def main() -> int: if len(sys.argv) != 4: print(__doc__, file=sys.stderr) return 2 row = ROWS[sys.argv[1].lower()] with open(sys.argv[2]) as left, open(sys.argv[3]) as right: divergence = first_trace_divergence(read_trace(left, row), read_trace(right, row)) if divergence is None: print("traces are identical") return 0 print(json.dumps(divergence.as_dict(), indent=1)) return 1 if __name__ == "__main__": sys.exit(main())