fixpoint.sh 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/bin/sh
  2. #
  3. # V3 self-hosting fixpoint.
  4. #
  5. # Stage 1: build V3 with GNU Modula-2 (CR -m, gm2) -> $TMP/m2s1
  6. # Stage 2: $TMP/m2s1 compiles the whole compiler -> $TMP/stage2.ssa
  7. # (and that image is assembled into $TMP/m2s2)
  8. # Stage 3: $TMP/m2s2 compiles the whole compiler -> $TMP/stage3.ssa
  9. #
  10. # Success = Stage2.ssa and Stage3.ssa are byte-identical (the compiler
  11. # reproduces its own image exactly). Stage 1's image equals Stage 2's
  12. # too, but the meaningful check is between V3 stages.
  13. #
  14. # Notes: CR must be run WITHOUT -m for V3-facing sources (real FORWARD
  15. # declarations); gm2's link pass rejects FORWARD, so Stage 1 uses -m.
  16. # Stage 1 uses the host FileIO; the compiled image embeds the
  17. # self-hosted runtime/syslib/FileIO from the session.
  18. #
  19. # Usage: bootstrap/fixpoint.sh (from anywhere)
  20. set -e
  21. ROOT=$(cd "$(dirname "$0")/.." && pwd)
  22. CC_DIR="$ROOT/compiler"
  23. CR="${CR:-$HOME/Projets/Projets-Modula2/MyWork/CocoGm2/CR}"
  24. QBE="${QBE:-qbe}"
  25. CC="${CC:-cc}"
  26. TMP="${TMP:-/tmp/opencode}"
  27. mkdir -p "$TMP"
  28. SYS="../stdlib/storage.def ../stdlib/storage.mod \
  29. ../runtime/syslib/SysShim.def ../runtime/syslib/SysShim.mod \
  30. ../runtime/syslib/FileIO.def ../runtime/syslib/FileIO.mod \
  31. ../stdlib/strings.def ../stdlib/strings.mod"
  32. SRC="src/SymTab.def src/SymTab.mod \
  33. src/QbeGen.def src/QbeGen.mod \
  34. src/M2S.def src/M2S.mod src/M2P.def src/M2P.mod src/M2.mod"
  35. echo "=== Stage 1: gm2 build (CR -m) ==="
  36. cd "$CC_DIR"
  37. ./build.sh
  38. cp M2 "$TMP/m2s1"
  39. echo "=== V3-facing sources (CR without -m) ==="
  40. cd "$CC_DIR/src"
  41. CRFRAMES="$(pwd)" "$CR" -C M2.atg >/dev/null
  42. stage() {
  43. # $1 = compiler binary, $2 = output .ssa path, $3 = output binary (or "")
  44. cd "$CC_DIR"
  45. rm -f gen_ssa/M2.ssa
  46. $1 $SYS $SRC >/dev/null
  47. [ -f gen_ssa/M2.ssa ] || { echo "no gen_ssa/M2.ssa from $1"; exit 1; }
  48. cp gen_ssa/M2.ssa "$2"
  49. if [ -n "$3" ]; then
  50. "$QBE" -o "$TMP/m2.s" gen_ssa/M2.ssa
  51. "$CC" -w "$TMP/m2.s" "$ROOT/runtime/syslib/shim.c" -o "$3" -lm
  52. fi
  53. }
  54. echo "=== Stage 2: V3 (gm2-built) compiles the compiler ==="
  55. stage "$TMP/m2s1" "$TMP/stage2.ssa" "$TMP/m2s2"
  56. echo "=== Stage 3: V3 (self-built) compiles the compiler ==="
  57. stage "$TMP/m2s2" "$TMP/stage3.ssa" ""
  58. echo "=== compare ==="
  59. if cmp -s "$TMP/stage2.ssa" "$TMP/stage3.ssa"; then
  60. echo "FIXPOINT OK: stage2.ssa == stage3.ssa ($(wc -c < "$TMP/stage2.ssa") bytes)"
  61. else
  62. echo "FIXPOINT FAILED:"; cmp "$TMP/stage2.ssa" "$TMP/stage3.ssa" || true
  63. exit 1
  64. fi