#!/bin/sh # # V3 self-hosting fixpoint, driven by M2make. # # Stage 1: build V3 with GNU Modula-2 (host FileIO) -> $TMP/m2s1 # Stage 2: m2s1 compiles the compiler (self-hosted FileIO) # -> $TMP/stage2.ssa, $TMP/m2s2 # Stage 3: m2s2 compiles the compiler (self-hosted FileIO) # -> $TMP/stage3.ssa # Success: stage2.ssa == stage3.ssa (byte-identical). # # Cross-stage FileIO selection (explicit): # - Stage 1 (gm2) uses the **host** FileIO: compiler/src/FileIO.def/.mod # (GNU-Modula-2 specific; see compiler/build.sh). # - Stages 2+ (V3) use the **self-hosted** FileIO: # runtime/syslib/FileIO.def/.mod. To make M2make pick it, the V3 # source tree is staged WITHOUT compiler/src/FileIO*, and # runtime/syslib is on the -I search path. # # Stage 1 uses `-m` (gm2's link pass rejects FORWARD); V3-facing sources # are regenerated WITHOUT `-m` (real FORWARD declarations). # # 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}" M2MAKE="${M2MAKE:-$ROOT/tools/m2make/b_v3/M2make}" TMP="${TMP:-/tmp/opencode}" V3SRC="$TMP/v3src" mkdir -p "$TMP" if [ ! -x "$M2MAKE" ]; then echo "=== building M2make (b_v3) ===" (cd "$ROOT/tools/m2make" && ./build_m2.sh) fi echo "=== Stage 1: gm2 build (host FileIO, CR -m) ===" cd "$CC_DIR" ./build.sh cp M2 "$TMP/m2s1" echo "=== preparing V3 sources (CR without -m; self-hosted FileIO) ===" cd "$CC_DIR/src" CRFRAMES="$(pwd)" "$CR" -C M2.atg >/dev/null # Stage the compiler sources WITHOUT the host FileIO so that M2make # resolves FileIO from runtime/syslib (the self-hosted one). rm -rf "$V3SRC"; mkdir -p "$V3SRC" for f in "$CC_DIR"/src/*.def "$CC_DIR"/src/*.mod; do case "$f" in */FileIO.def|*/FileIO.mod) ;; # host FileIO: stage-1 only *) cp "$f" "$V3SRC/" ;; esac done build_stage() { # $1 = --m2bin compiler, $2 = output .ssa, $3 = output binary echo "=== $(basename "$3") built by $1 ===" cd "$V3SRC" rm -f gen_ssa/M2.ssa "$M2MAKE" -c m2 --m2bin "$1" --shim "$ROOT/runtime/syslib/shim.c" \ -I "$ROOT/runtime/syslib" -I "$ROOT/stdlib" -o "$3" M2.mod cp gen_ssa/M2.ssa "$2" } build_stage "$TMP/m2s1" "$TMP/stage2.ssa" "$TMP/m2s2" build_stage "$TMP/m2s2" "$TMP/stage3.ssa" "$TMP/m2s3" 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