aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/dump_asm.sh34
-rwxr-xr-xscripts/run_suite.sh4
-rwxr-xr-xscripts/test_examples.sh19
3 files changed, 52 insertions, 5 deletions
diff --git a/scripts/dump_asm.sh b/scripts/dump_asm.sh
new file mode 100755
index 0000000..cb8a710
--- /dev/null
+++ b/scripts/dump_asm.sh
@@ -0,0 +1,34 @@
+#!/usr/bin/env bash
+set -euo pipefail
+
+root="$(cd "$(dirname "$0")/.." && pwd)"
+cd "$root"
+
+assemblers="${1:-${ASSEMBLER:-nasm fasm}}"
+
+docker compose up -d >/dev/null
+
+docker compose exec -T -e ASMS="$assemblers" hdass bash -c '
+ set -e
+ cd /hdass
+ [ -d build-linux ] || meson setup build-linux >/dev/null
+ meson compile -C build-linux >/dev/null
+
+cat > /tmp/sidebyside.awk <<"AWK"
+NR == FNR { left[FNR] = $0; if (length($0) > width) width = length($0); ln = FNR; next }
+{ right[FNR] = $0; if (FNR > rn) rn = FNR }
+END {
+ total = ln > rn ? ln : rn
+ for (i = 1; i <= total; i += 1)
+ printf "%-*s | %s\n", width, (i in left ? left[i] : ""), (i in right ? right[i] : "")
+}
+AWK
+
+ for asm in $ASMS; do
+ for src in examples/*.hdass; do
+ printf "\n===== %s (%s) =====\n" "$(basename "$src")" "$asm"
+ ./build-linux/hdass -t "$asm" "$src" -o /tmp/gen.asm
+ awk -f /tmp/sidebyside.awk <(expand -t 4 "$src") <(expand -t 4 /tmp/gen.asm)
+ done
+ done
+' </dev/null
diff --git a/scripts/run_suite.sh b/scripts/run_suite.sh
index 38598ad..56854e5 100755
--- a/scripts/run_suite.sh
+++ b/scripts/run_suite.sh
@@ -27,4 +27,6 @@ else
exit 1
fi
-exec bash ./scripts/test_examples.sh
+ASSEMBLER=nasm bash ./scripts/test_examples.sh || exit 1
+printf '\n'
+ASSEMBLER=fasm bash ./scripts/test_examples.sh
diff --git a/scripts/test_examples.sh b/scripts/test_examples.sh
index f8d1462..ab4f184 100755
--- a/scripts/test_examples.sh
+++ b/scripts/test_examples.sh
@@ -17,13 +17,24 @@ if [ ! -x "$hdass" ]; then
exit 1
fi
-for tool in nasm ld; do
+assembler="${ASSEMBLER:-nasm}"
+
+for tool in "$assembler" ld; do
if ! command -v "$tool" >/dev/null 2>&1; then
echo "${red}error:${reset} '$tool' not found; run this inside the Docker environment" >&2
exit 1
fi
done
+assemble()
+{
+ if [ "$assembler" = "fasm" ]; then
+ fasm "$1" "$2" >/dev/null
+ else
+ nasm -f elf64 "$1" -o "$2"
+ fi
+}
+
work="$(mktemp -d)"
trap 'rm -rf "$work"' EXIT
@@ -35,9 +46,9 @@ check()
local name="$1" desc="$2" source="$3" expected_exit="$4" expected_stdout="$5"
local asm="$work/$name.asm" obj="$work/$name.o" bin="$work/$name" stage=""
- if ! "$hdass" "$source" -o "$asm" 2>"$work/err"; then
+ if ! "$hdass" -t "$assembler" "$source" -o "$asm" 2>"$work/err"; then
stage="transpile"
- elif ! nasm -f elf64 "$asm" -o "$obj" 2>"$work/err"; then
+ elif ! assemble "$asm" "$obj" 2>"$work/err"; then
stage="assemble"
elif ! ld -e main "$obj" -o "$bin" 2>"$work/err"; then
stage="link"
@@ -71,7 +82,7 @@ check()
pass=$((pass + 1))
}
-printf '%s━━ example programs ━━%s\n' "$bold" "$reset"
+printf '%s━━ example programs (%s) ━━%s\n' "$bold" "$assembler" "$reset"
check hello_world "writes a greeting to stdout" examples/hello_world.hdass 0 "Hello, World!"
check greet "writes a fixed string" examples/greet.hdass 0 "hdass works!"