# SPDX-License-Identifier: GPL-3.0-or-later """Check the actual CMOC indexed-load peephole rule in a source build.""" import argparse import subprocess import tempfile from pathlib import Path def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("source_build", type=Path, help="build.py output's work/cmoc directory") args = parser.parse_args() src = args.source_build.resolve(strict=True) / "src" objects = sorted(path for path in src.glob("cmoc-*.o") if path.name != "cmoc-main.o") if not objects: parser.error("Build CMOC first; compiler objects are required") fixture = Path(__file__).resolve().parent / "optimizer-rule.cpp" with tempfile.TemporaryDirectory(prefix="vcc-cmoc-rule-") as work: out = Path(work) # Retain all normal compiler definitions and rename only its CLI entry # in this extra object. The rule itself comes from unchanged build objects. subprocess.run(["xcrun", "clang++", "-std=c++11", "-Dmain=vccCompilerDriverMain", '-DPACKAGE="cmoc"', '-DVERSION="0.1.100"', '-DPKGDATADIR="."', "-D__unix", "-I", src, "-c", src / "main.cpp", "-o", out / "driver.o"], check=True) subprocess.run(["xcrun", "clang++", "-std=c++11", "-I", src, fixture, out / "driver.o", *objects, "-o", out / "rule-check"], check=True) subprocess.run([out / "rule-check"], check=True) if __name__ == "__main__": main()