# SPDX-License-Identifier: GPL-3.0-or-later """Execute indexed-argument-load regressions on both emulated guest CPUs.""" import argparse import os import subprocess import tempfile from pathlib import Path def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("runtime", type=Path, help="staged CMOC toolchain") parser.add_argument("core", type=Path, help="libVCCCore.a") parser.add_argument("rom", type=Path, help="locally supplied CoCo 3 ROM") parser.add_argument("--host-arch", choices=("arm64", "x86_64"), help="select a macOS compiler slice (x86_64 uses Rosetta on Apple Silicon)") args = parser.parse_args() fixture = Path(__file__).resolve().parent runtime = args.runtime.resolve(strict=True) compiler = runtime / "bin/cmoc" command = (["/usr/bin/arch", "-" + args.host_arch] if args.host_arch else []) + [compiler] env = dict(os.environ, PATH=str(runtime / "bin") + os.pathsep + os.environ["PATH"]) # Same adjacent-element call at runtime indices 0 and 2, using a byte # parameter, word parameter and pointer bases. Expectations are host-owned. pair = (4, 12, 8, 16, 20, 28, 24, 32) expected = "ARGS " + "".join(f"{value:02X}" for value in pair * 3) + " END" with tempfile.TemporaryDirectory(prefix="vcc-indexed-arguments-") as work: runner = Path(work) / "run-compiled" subprocess.run(["xcrun", "clang++", "-std=c++17", "-O2", "-mmacosx-version-min=14.0", fixture.parent / "run-compiled.cpp", args.core.resolve(strict=True), "-o", runner], check=True) for optimization in ("-O0", "-O2"): print("Checking indexed arguments", optimization, flush=True) subprocess.run(command + ["--coco", optimization, "--no-relocate", "--switch=jump", "--org=2800", "--intermediate", "-Werror", "-o", "TEST.BIN", fixture / "qualification.c"], cwd=work, env=env, check=True) subprocess.run([runner, args.rom.resolve(strict=True), "TEST.BIN", expected], cwd=work, check=True) if __name__ == "__main__": main()