corpus.sh 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/bin/sh
  2. # Runs the V3 compiler (compiler/M2) over a corpus of standard Modula-2
  3. # sources and reports how many compile cleanly.
  4. #
  5. # Each source is copied into a scratch tree (so its .LST listing never
  6. # touches the corpus) and compiled alone. A file with 0 errors is a
  7. # pass. Failures are split into:
  8. # CRASH -- M2 died (rc >= 128): a real compiler bug
  9. # LIB -- the file imports a module outside V3's known stdlib set
  10. # (gm2's StrIO/NumberIO/STextIO/...), so "undeclared" is
  11. # expected and not a language gap
  12. # LANG -- otherwise: a genuine parse/semantic gap in V3
  13. #
  14. # Usage: ./corpus.sh [corpus-dir ...]
  15. cd "$(dirname "$0")"
  16. ROOT="$(cd ../.. && pwd)"
  17. M2="$ROOT/compiler/M2"
  18. WORK=/tmp/opencode/v3corpus
  19. KNOWN="SYSTEM SysIO TextIO Strings Math Conversions RealIO ProgramArgs IOChan Files Storage WholeIO CharClass SysClock"
  20. [ -x "$M2" ] || { echo "compiler/M2 missing -- run compiler/build.sh"; exit 1; }
  21. [ "$#" -gt 0 ] || set -- \
  22. "$HOME/Projets/Projets-Modula2/MyWork/gcc-git/gcc/testsuite/gm2/pim/pass" \
  23. "$HOME/Projets/Projets-Modula2/MyWork/gcc-git/gcc/testsuite/gm2/iso/run/pass"
  24. known() { for k in $KNOWN; do [ "$1" = "$k" ] && return 0; done; return 1; }
  25. rm -rf "$WORK"; mkdir -p "$WORK"; : > "$WORK/results.txt"
  26. n=0
  27. for dir in "$@"; do
  28. find "$dir" -maxdepth 1 \( -iname '*.mod' -o -iname '*.def' \) 2>/dev/null | sort |
  29. while read -r f; do
  30. n=$((n+1))
  31. w="$WORK/f$n"; mkdir -p "$w"; base=$(basename "$f")
  32. cp "$f" "$w/$base"
  33. "$M2" "$w/$base" >/dev/null 2>&1
  34. rc=$?
  35. lst="$w/$(echo "$base" | sed 's/\.[^.]*$//').LST"
  36. if [ "$rc" -ge 128 ]; then echo "CRASH||$f" >> "$WORK/results.txt"; continue; fi
  37. if [ ! -f "$lst" ]; then echo "LANG|no listing|$f" >> "$WORK/results.txt"; continue; fi
  38. e=$(grep -oE '[0-9]+ errors?' "$lst" | head -1 | grep -oE '[0-9]+')
  39. [ -z "$e" ] && e=-1
  40. if [ "$e" = 0 ]; then echo "OK||$f" >> "$WORK/results.txt"; continue; fi
  41. # classify: does it import a module outside the known set?
  42. names=$( { sed -nE 's/^[[:space:]]*FROM[[:space:]]+([A-Za-z][A-Za-z0-9_]*).*/\1/p' "$w/$base"
  43. sed -nE 's/^[[:space:]]*IMPORT[[:space:]]+(.*)/\1/p' "$w/$base" | sed 's/;.*//' | tr ',' '\n'
  44. } | sed -E 's/[[:space:]]//g' | grep -E '^[A-Za-z][A-Za-z0-9_]*$' )
  45. lib=0
  46. for m in $names; do known "$m" || lib=1; done
  47. m=$(grep -E '^\*\*\*\*\*' "$lst" | head -1 | sed -E 's/^\*\*\*\*\* *\^? *//; s/^\*\*\*\*\*//')
  48. if [ "$lib" = 1 ]; then echo "LIB|$m|$f" >> "$WORK/results.txt"
  49. else echo "LANG|$m|$f" >> "$WORK/results.txt"; fi
  50. done
  51. done
  52. total=$(wc -l < "$WORK/results.txt")
  53. cnt() { grep -c "^$1" "$WORK/results.txt" 2>/dev/null || true; }
  54. echo "total : $total"
  55. echo "compile-OK : $(cnt OK)"
  56. echo "CRASH : $(cnt CRASH)"
  57. echo "LIB (needs a gm2 library): $(cnt LIB)"
  58. echo "LANG (V3 gap) : $(cnt LANG)"
  59. echo "=== LANG error kinds (top) ==="
  60. grep '^LANG' "$WORK/results.txt" | cut -d'|' -f2 | sed -E 's/[0-9]+/N/g' | sort | uniq -c | sort -rn | head -15
  61. echo "=== LANG files (first 40) ==="
  62. grep '^LANG' "$WORK/results.txt" | head -40 | sed -E 's/^LANG\|([^|]*)\|/ [\1] /'