compiler/
lib/
scripts/
seed/
sublime/
test/
support/
tests/
command
5.2 KiB
driver
3.3 KiB
package-golden
1.6 KiB
run
3.1 KiB
runner.rad
10.5 KiB
vim/
.gitignore
336 B
.gitsigners
112 B
CONTRIBUTING
2.1 KiB
LICENSE
1.1 KiB
Makefile
5.4 KiB
README
2.5 KiB
STYLE
2.5 KiB
std.lib
1.5 KiB
std.lib.test
662 B
test/package-golden
raw
| 1 | #!/bin/sh |
| 2 | # Compare one package's emitted IL with its golden file and session support. |
| 3 | set -eu |
| 4 | |
| 5 | source=$1 |
| 6 | expected=${source%.rad}.ril |
| 7 | module=$(basename "${source%.rad}") |
| 8 | work=$(mktemp -d) |
| 9 | trap 'rm -rf "$work"' EXIT HUP INT TERM |
| 10 | |
| 11 | set -- -pkg std |
| 12 | while IFS= read -r source_module; do |
| 13 | set -- "$@" -mod "$source_module" |
| 14 | done < test/support/std.lib |
| 15 | set -- "$@" -pkg test -mod "$source" -entry test -dump il |
| 16 | for source_module in "${source%.rad}"/*.rad; do |
| 17 | if [ -f "$source_module" ]; then |
| 18 | set -- "$@" -mod "$source_module" |
| 19 | fi |
| 20 | done |
| 21 | |
| 22 | if ! ${RAD_EMULATOR:-emulator} -memory-size=385024 -data-size=348160 \ |
| 23 | -stack-size=1024 -run bin/radiance.rv64.dev "$@" >"$work/program.il" 2>"$work/compiler.log"; then |
| 24 | cat "$work/compiler.log" |
| 25 | cat "$work/program.il" |
| 26 | exit 1 |
| 27 | fi |
| 28 | |
| 29 | # Top-level function and data definitions carry the source module's prefix. |
| 30 | awk -v prefix="\$\"$module::" ' |
| 31 | /^(fn |data )/ { keep = index($0, prefix) > 0 } |
| 32 | keep { print } |
| 33 | /^}/ { if (keep) print ""; keep = 0 } |
| 34 | ' "$work/program.il" >"$work/actual.ril" |
| 35 | if [ ! -s "$work/actual.ril" ]; then |
| 36 | echo "error: no IL definitions found for $module" |
| 37 | exit 1 |
| 38 | fi |
| 39 | |
| 40 | # Golden comparisons ignore comments, indentation, and blank lines. |
| 41 | for kind in actual expected; do |
| 42 | input=$expected |
| 43 | if [ "$kind" = actual ]; then input=$work/actual.ril; fi |
| 44 | awk '{ sub(/\/\/.*/, ""); gsub(/^[ \t]+|[ \t]+$/, ""); if (length) print }' \ |
| 45 | "$input" >"$work/$kind.normalized" |
| 46 | done |
| 47 | if ! cmp -s "$work/expected.normalized" "$work/actual.normalized"; then |
| 48 | diff -u "$expected" "$work/actual.ril" || true |
| 49 | exit 1 |
| 50 | fi |