| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- #!/bin/sh
- # Per-object self-hosting gate.
- #
- # Build the V3 compiler as separate objects with the current M2, link
- # stage2, use stage2 to build the same objects/link stage3, and compare
- # every generated .ssa. The compiler itself is built with the legacy
- # 1-D open-array ABI (the same rule as bootstrap/fixpoint.sh).
- #
- # Usage: ./bootstrap/fixpoint-separate.sh
- # Requires: compiler/M2 and tools/m2make/b_v3/M2make.
- set -eu
- ROOT="$(cd "$(dirname "$0")/.." && pwd)"
- M2="${M2:-$ROOT/compiler/M2}"
- M2MAKE="${M2MAKE:-$ROOT/tools/m2make/b_v3/M2make}"
- SHIM="$ROOT/runtime/syslib/shim.c"
- SRC="$ROOT/compiler/src/M2.mod"
- TMP="${TMP:-$ROOT/.scratch/fixpoint-separate}"
- FLAGS="-legacyopen1d"
- INCS="-I $ROOT/runtime/syslib -I $ROOT/compiler/src -I $ROOT/lib/common"
- [ -x "$M2" ] || { echo "missing $M2 (run compiler/build.sh)"; exit 1; }
- [ -x "$M2MAKE" ] || { echo "missing $M2MAKE (run tools/m2make/build_m2.sh)"; exit 1; }
- rm -rf "$TMP"
- mkdir -p "$TMP/s2" "$TMP/s3"
- build_stage() {
- bin="$1"; out="$2"; dir="$3"
- ( cd "$dir" && "$M2MAKE" --separate --m2flag "$FLAGS" \
- --m2bin "$bin" --shim "$SHIM" $INCS -o "$out" "$SRC" )
- }
- echo "=== separate stage2 (built by $M2) ==="
- build_stage "$M2" "$TMP/s2/M2" "$TMP/s2"
- echo "=== separate stage3 (built by stage2) ==="
- build_stage "$TMP/s2/M2" "$TMP/s3/M2" "$TMP/s3"
- # Compare the generated per-object IR; object files and executables can
- # contain timestamps/build ids and are not the fixpoint contract.
- fail=0
- for f in "$TMP/s2/gen_ssa"/*.ssa; do
- b=$(basename "$f")
- if [ ! -f "$TMP/s3/gen_ssa/$b" ]; then
- echo "MISSING stage3 object: $b"; fail=1
- elif ! cmp -s "$f" "$TMP/s3/gen_ssa/$b"; then
- echo "DIFF: $b"; fail=1
- fi
- done
- for f in "$TMP/s3/gen_ssa"/*.ssa; do
- b=$(basename "$f")
- [ -f "$TMP/s2/gen_ssa/$b" ] || { echo "EXTRA stage3 object: $b"; fail=1; }
- done
- if [ "$fail" -ne 0 ]; then
- echo "SEPARATE FIXPOINT FAILED"
- exit 1
- fi
- echo "SEPARATE FIXPOINT OK: stage2 == stage3 ($(ls "$TMP/s2/gen_ssa"/*.ssa | wc -l) objects)"
|