fixpoint.sh 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #!/bin/sh
  2. #
  3. # V3 self-hosting fixpoint, driven by M2make.
  4. #
  5. # Stage 1: build V3 with GNU Modula-2 (host FileIO) -> $TMP/m2s1
  6. # Stage 2: m2s1 compiles the compiler (self-hosted FileIO)
  7. # -> $TMP/stage2.ssa, $TMP/m2s2
  8. # Stage 3: m2s2 compiles the compiler (self-hosted FileIO)
  9. # -> $TMP/stage3.ssa
  10. # Success: stage2.ssa == stage3.ssa (byte-identical).
  11. #
  12. # Cross-stage FileIO selection (explicit):
  13. # - Stage 1 (gm2) uses the **host** FileIO: compiler/src/FileIO.def/.mod
  14. # (GNU-Modula-2 specific; see compiler/build.sh).
  15. # - Stages 2+ (V3) use the **self-hosted** FileIO:
  16. # runtime/syslib/FileIO.def/.mod. To make M2make pick it, the V3
  17. # source tree is staged WITHOUT compiler/src/FileIO*, and
  18. # runtime/syslib is on the -I search path.
  19. #
  20. # Stage 1 uses `-m` (gm2's link pass rejects FORWARD); V3-facing sources
  21. # are regenerated WITHOUT `-m` (real FORWARD declarations).
  22. #
  23. # Usage: bootstrap/fixpoint.sh (from anywhere)
  24. set -e
  25. ROOT=$(cd "$(dirname "$0")/.." && pwd)
  26. CC_DIR="$ROOT/compiler"
  27. CR="${CR:-$HOME/Projets/Projets-Modula2/MyWork/CocoGm2/CR}"
  28. M2MAKE="${M2MAKE:-$ROOT/tools/m2make/b_v3/M2make}"
  29. TMP="${TMP:-/tmp/opencode}"
  30. V3SRC="$TMP/v3src"
  31. mkdir -p "$TMP"
  32. if [ ! -x "$M2MAKE" ]; then
  33. echo "=== building M2make (b_v3) ==="
  34. (cd "$ROOT/tools/m2make" && ./build_m2.sh)
  35. fi
  36. echo "=== Stage 1: gm2 build (host FileIO, CR -m) ==="
  37. cd "$CC_DIR"
  38. ./build.sh
  39. cp M2 "$TMP/m2s1"
  40. echo "=== preparing V3 sources (CR without -m; self-hosted FileIO) ==="
  41. cd "$CC_DIR/src"
  42. CRFRAMES="$(pwd)" "$CR" -C M2.atg >/dev/null
  43. # Stage the compiler sources WITHOUT the host FileIO so that M2make
  44. # resolves FileIO from runtime/syslib (the self-hosted one).
  45. rm -rf "$V3SRC"; mkdir -p "$V3SRC"
  46. for f in "$CC_DIR"/src/*.def "$CC_DIR"/src/*.mod; do
  47. case "$f" in
  48. */FileIO.def|*/FileIO.mod) ;; # host FileIO: stage-1 only
  49. *) cp "$f" "$V3SRC/" ;;
  50. esac
  51. done
  52. build_stage() {
  53. # $1 = --m2bin compiler, $2 = output .ssa, $3 = output binary
  54. echo "=== $(basename "$3") built by $1 ==="
  55. cd "$V3SRC"
  56. rm -f gen_ssa/M2.ssa
  57. "$M2MAKE" -c m2 --m2bin "$1" --shim "$ROOT/runtime/syslib/shim.c" \
  58. -I "$ROOT/runtime/syslib" -I "$ROOT/stdlib" -o "$3" M2.mod
  59. cp gen_ssa/M2.ssa "$2"
  60. }
  61. build_stage "$TMP/m2s1" "$TMP/stage2.ssa" "$TMP/m2s2"
  62. build_stage "$TMP/m2s2" "$TMP/stage3.ssa" "$TMP/m2s3"
  63. echo "=== compare ==="
  64. if cmp -s "$TMP/stage2.ssa" "$TMP/stage3.ssa"; then
  65. echo "FIXPOINT OK: stage2.ssa == stage3.ssa ($(wc -c < "$TMP/stage2.ssa") bytes)"
  66. else
  67. echo "FIXPOINT FAILED:"; cmp "$TMP/stage2.ssa" "$TMP/stage3.ssa" || true
  68. exit 1
  69. fi