Ver Fonte

bootstrap: drive the fixpoint with M2make; explicit cross-stage FileIO selection

- Stage1 (gm2, CR -m) uses the host FileIO (compiler/src/FileIO)
- Stages 2/3 (V3) stage the sources WITHOUT src/FileIO* and put
  runtime/syslib on -I, so M2make selects the self-hosted FileIO
- M2make orders the session, runs M2 + qbe + cc
- FIXPOINT OK: stage2.ssa == stage3.ssa (1991297 bytes)
Eric Streit há 1 semana atrás
pai
commit
96bb449314
1 ficheiros alterados com 41 adições e 37 exclusões
  1. 41 37
      bootstrap/fixpoint.sh

+ 41 - 37
bootstrap/fixpoint.sh

@@ -1,20 +1,24 @@
 #!/bin/sh
 #
-# V3 self-hosting fixpoint.
+# V3 self-hosting fixpoint, driven by M2make.
 #
-#   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
+#   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).
 #
-# 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.
+# 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.
 #
-# 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.
+# 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
@@ -22,46 +26,46 @@ 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}"
+M2MAKE="${M2MAKE:-$ROOT/tools/m2make/b_v3/M2make}"
 TMP="${TMP:-/tmp/opencode}"
+V3SRC="$TMP/v3src"
 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"
+if [ ! -x "$M2MAKE" ]; then
+  echo "=== building M2make (b_v3) ==="
+  (cd "$ROOT/tools/m2make" && ./build_m2.sh)
+fi
 
-echo "=== Stage 1: gm2 build (CR -m) ==="
+echo "=== Stage 1: gm2 build (host FileIO, CR -m) ==="
 cd "$CC_DIR"
 ./build.sh
 cp M2 "$TMP/m2s1"
 
-echo "=== V3-facing sources (CR without -m) ==="
+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
 
-stage() {
-  # $1 = compiler binary, $2 = output .ssa path, $3 = output binary (or "")
-  cd "$CC_DIR"
+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
-  $1 $SYS $SRC >/dev/null
-  [ -f gen_ssa/M2.ssa ] || { echo "no gen_ssa/M2.ssa from $1"; exit 1; }
+  "$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"
-  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" ""
+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