# SPDX-License-Identifier: GPL-3.0-or-later """Check signed and unsigned base conversion under both guest CPUs and CMOC optimizations.""" import argparse import os from pathlib import Path import subprocess import tempfile def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("runtime", type=Path, help="staged toolchain with base-aware vcccompat") parser.add_argument("core", type=Path, help="current libVCCCore.a") parser.add_argument("rom", type=Path, help="private CoCo 3 ROM") args = parser.parse_args() runtime, core, rom = [p.resolve(strict=True) for p in (args.runtime, args.core, args.rom)] fixture = Path(__file__).resolve().parent root = fixture.parents[2] env = dict(os.environ, VCC_CMOC_COMPAT="1") with tempfile.TemporaryDirectory(prefix="vcc-number-conversion-") 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", core, "-o", runner], cwd=work, check=True) compiler = [runtime / "bin/cmoc", "--coco", "-Werror"] for opt in ("-O0", "-O2"): caller = [*compiler, opt, "--org=2800", "-o", "TEST.BIN"] if opt == "-O2": caller.append("-DCMOC_HEADER_FIRST") caller.append(fixture / "qualification.c") # The installed library is optimized. Check it with both app # settings, then exercise the conversion code itself unoptimized. subprocess.run([*caller, "-lvcccompat"], cwd=work, env=env, check=True) print(f"{opt} caller, staged archive", flush=True) subprocess.run([runner, rom, "TEST.BIN", "NUMBER CONVERSIONS PASSED", "450"], cwd=work, check=True) if opt == "-O0": subprocess.run([*compiler, opt, "-c", "-o", "strto.o", root / "sdk/cmoc/compat/strto.c"], cwd=work, env=env, check=True) subprocess.run([*caller, "strto.o"], cwd=work, env=env, check=True) print("-O0 caller and conversion implementation", flush=True) subprocess.run([runner, rom, "TEST.BIN", "NUMBER CONVERSIONS PASSED", "450"], cwd=work, check=True) if __name__ == "__main__": main()