| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- #!/bin/sh
- #
- # V3 self-hosting fixpoint.
- #
- # Stage 1: build V3 with GNU Modula-2 (CR -m, gm2) -> $TMP/m2s1
- # Stage 2: $TMP/m2s1 compiles the whole compiler -> $TMP/stage2.ssa
- # (and that image is assembled into $TMP/m2s2)
- # Stage 3: $TMP/m2s2 compiles the whole compiler -> $TMP/stage3.ssa
- #
- # Success = Stage2.ssa and Stage3.ssa are byte-identical (the compiler
- # reproduces its own image exactly). Stage 1's image equals Stage 2's
- # too, but the meaningful check is between V3 stages.
- #
- # Notes: CR must be run WITHOUT -m for V3-facing sources (real FORWARD
- # declarations); gm2's link pass rejects FORWARD, so Stage 1 uses -m.
- # Stage 1 uses the host FileIO; the compiled image embeds the
- # self-hosted runtime/syslib/FileIO from the session.
- #
- # Usage: bootstrap/fixpoint.sh (from anywhere)
- set -e
- ROOT=$(cd "$(dirname "$0")/.." && pwd)
- CC_DIR="$ROOT/compiler"
- CR="${CR:-$HOME/Projets/Projets-Modula2/MyWork/CocoGm2/CR}"
- QBE="${QBE:-qbe}"
- CC="${CC:-cc}"
- TMP="${TMP:-/tmp/opencode}"
- mkdir -p "$TMP"
- SYS="../stdlib/storage.def ../stdlib/storage.mod \
- ../runtime/syslib/SysShim.def ../runtime/syslib/SysShim.mod \
- ../runtime/syslib/FileIO.def ../runtime/syslib/FileIO.mod \
- ../stdlib/strings.def ../stdlib/strings.mod"
- SRC="src/SymTab.def src/SymTab.mod \
- src/QbeGen.def src/QbeGen.mod \
- src/M2S.def src/M2S.mod src/M2P.def src/M2P.mod src/M2.mod"
- echo "=== Stage 1: gm2 build (CR -m) ==="
- cd "$CC_DIR"
- ./build.sh
- cp M2 "$TMP/m2s1"
- echo "=== V3-facing sources (CR without -m) ==="
- cd "$CC_DIR/src"
- CRFRAMES="$(pwd)" "$CR" -C M2.atg >/dev/null
- stage() {
- # $1 = compiler binary, $2 = output .ssa path, $3 = output binary (or "")
- cd "$CC_DIR"
- rm -f gen_ssa/M2.ssa
- $1 $SYS $SRC >/dev/null
- [ -f gen_ssa/M2.ssa ] || { echo "no gen_ssa/M2.ssa from $1"; exit 1; }
- cp gen_ssa/M2.ssa "$2"
- if [ -n "$3" ]; then
- "$QBE" -o "$TMP/m2.s" gen_ssa/M2.ssa
- "$CC" -w "$TMP/m2.s" "$ROOT/runtime/syslib/shim.c" -o "$3" -lm
- fi
- }
- echo "=== Stage 2: V3 (gm2-built) compiles the compiler ==="
- stage "$TMP/m2s1" "$TMP/stage2.ssa" "$TMP/m2s2"
- echo "=== Stage 3: V3 (self-built) compiles the compiler ==="
- stage "$TMP/m2s2" "$TMP/stage3.ssa" ""
- echo "=== compare ==="
- if cmp -s "$TMP/stage2.ssa" "$TMP/stage3.ssa"; then
- echo "FIXPOINT OK: stage2.ssa == stage3.ssa ($(wc -c < "$TMP/stage2.ssa") bytes)"
- else
- echo "FIXPOINT FAILED:"; cmp "$TMP/stage2.ssa" "$TMP/stage3.ssa" || true
- exit 1
- fi
|