fixpoint-separate.sh 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/bin/sh
  2. # Per-object self-hosting gate.
  3. #
  4. # Build the V3 compiler as separate objects with the current M2, link
  5. # stage2, use stage2 to build the same objects/link stage3, and compare
  6. # every generated .ssa. The compiler itself is built with the legacy
  7. # 1-D open-array ABI (the same rule as bootstrap/fixpoint.sh).
  8. #
  9. # Usage: ./bootstrap/fixpoint-separate.sh
  10. # Requires: compiler/M2 and tools/m2make/b_v3/M2make.
  11. set -eu
  12. ROOT="$(cd "$(dirname "$0")/.." && pwd)"
  13. M2="${M2:-$ROOT/compiler/M2}"
  14. M2MAKE="${M2MAKE:-$ROOT/tools/m2make/b_v3/M2make}"
  15. SHIM="$ROOT/runtime/syslib/shim.c"
  16. SRC="$ROOT/compiler/src/M2.mod"
  17. TMP="${TMP:-$ROOT/.scratch/fixpoint-separate}"
  18. FLAGS="-legacyopen1d"
  19. INCS="-I $ROOT/runtime/syslib -I $ROOT/compiler/src -I $ROOT/lib/common"
  20. [ -x "$M2" ] || { echo "missing $M2 (run compiler/build.sh)"; exit 1; }
  21. [ -x "$M2MAKE" ] || { echo "missing $M2MAKE (run tools/m2make/build_m2.sh)"; exit 1; }
  22. rm -rf "$TMP"
  23. mkdir -p "$TMP/s2" "$TMP/s3"
  24. build_stage() {
  25. bin="$1"; out="$2"; dir="$3"
  26. ( cd "$dir" && "$M2MAKE" --separate --m2flag "$FLAGS" \
  27. --m2bin "$bin" --shim "$SHIM" $INCS -o "$out" "$SRC" )
  28. }
  29. echo "=== separate stage2 (built by $M2) ==="
  30. build_stage "$M2" "$TMP/s2/M2" "$TMP/s2"
  31. echo "=== separate stage3 (built by stage2) ==="
  32. build_stage "$TMP/s2/M2" "$TMP/s3/M2" "$TMP/s3"
  33. # Compare the generated per-object IR; object files and executables can
  34. # contain timestamps/build ids and are not the fixpoint contract.
  35. fail=0
  36. for f in "$TMP/s2/gen_ssa"/*.ssa; do
  37. b=$(basename "$f")
  38. if [ ! -f "$TMP/s3/gen_ssa/$b" ]; then
  39. echo "MISSING stage3 object: $b"; fail=1
  40. elif ! cmp -s "$f" "$TMP/s3/gen_ssa/$b"; then
  41. echo "DIFF: $b"; fail=1
  42. fi
  43. done
  44. for f in "$TMP/s3/gen_ssa"/*.ssa; do
  45. b=$(basename "$f")
  46. [ -f "$TMP/s2/gen_ssa/$b" ] || { echo "EXTRA stage3 object: $b"; fail=1; }
  47. done
  48. if [ "$fail" -ne 0 ]; then
  49. echo "SEPARATE FIXPOINT FAILED"
  50. exit 1
  51. fi
  52. echo "SEPARATE FIXPOINT OK: stage2 == stage3 ($(ls "$TMP/s2/gen_ssa"/*.ssa | wc -l) objects)"