summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Campbell2017-08-18 16:36:52 +0100
committerBrian Campbell2017-08-18 16:36:52 +0100
commitbbdb011b8364ceaed867abb9d6b580ba8b2a60e8 (patch)
tree7b54bc62ded248d6269cf603f0107fecdd9b3390
parent5527ed5ce34e77f452ca90d1b4a5126255b4ee43 (diff)
Bit more monomorphisation testing
-rw-r--r--test/mono/.gitignore1
-rw-r--r--test/mono/test.ml2
-rwxr-xr-xtest/mono/test.sh37
-rw-r--r--test/mono/tests3
-rw-r--r--test/mono/varmatch.sail19
-rw-r--r--test/mono/vector.sail21
6 files changed, 72 insertions, 11 deletions
diff --git a/test/mono/.gitignore b/test/mono/.gitignore
new file mode 100644
index 00000000..2dd3daa3
--- /dev/null
+++ b/test/mono/.gitignore
@@ -0,0 +1 @@
+test-out \ No newline at end of file
diff --git a/test/mono/test.ml b/test/mono/test.ml
index cd6c6041..f99abfb8 100644
--- a/test/mono/test.ml
+++ b/test/mono/test.ml
@@ -1 +1 @@
-if Fnreduce_embed_sequential.run() then print_endline "OK" else print_endline "Failed";;
+if Testout_embed_sequential.run() then print_endline "OK" else print_endline "Failed";;
diff --git a/test/mono/test.sh b/test/mono/test.sh
index 7b1eeb64..153b09f8 100755
--- a/test/mono/test.sh
+++ b/test/mono/test.sh
@@ -1,21 +1,38 @@
#!/bin/bash
-set -ex
+set -e
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
SAILDIR="$DIR/../.."
LEMDIR="$DIR/../../../lem"
-OUTDIR="$DIR/fnreduce-ml"
+OUTDIR="$DIR/test-out"
ZARITH="$LEMDIR/ocaml-lib/dependencies/zarith"
-"$SAILDIR/sail" -lem "$SAILDIR/lib/prelude.sail" -mono-split fnreduce.sail:43:x "$DIR/fnreduce.sail" -o "$DIR/fnreduce"
-if [ -d "$OUTDIR" ]; then
- rm -- "$OUTDIR"/*
-else
+if [ ! -d "$OUTDIR" ]; then
mkdir -- "$OUTDIR"
fi
-"$LEMDIR/bin/lem" -ocaml -lib "$SAILDIR/src/lem_interp" "$SAILDIR/src/gen_lib/sail_values.lem" "$SAILDIR/src/gen_lib/state.lem" "$DIR/fnreduce_embed_types.lem" "$DIR/fnreduce_embed_sequential.lem" -outdir "$OUTDIR"
-cp -- "$DIR"/test.ml "$OUTDIR"
cd "$OUTDIR"
-ocamlc -I "$ZARITH" "$ZARITH/zarith.cma" -dllpath "$ZARITH" -I "$LEMDIR/ocaml-lib" "$LEMDIR/ocaml-lib/extract.cma" -I "$SAILDIR/src/_build/lem_interp" "$SAILDIR/src/_build/lem_interp/extract.cma" sail_values.ml state.ml fnreduce_embed_types.ml fnreduce_embed_sequential.ml test.ml -o test
-./test
+
+TESTONLY="$1"
+if [ -n "$TESTONLY" ]; then shift; fi
+
+exec 3< "$DIR/tests"
+while read -u 3 TEST ARGS; do
+ if [ -z "$TESTONLY" -o "$TEST" = "$TESTONLY" ]; then
+# echo "$TEST ocaml"
+# rm -f -- "$OUTDIR"/*
+# "$SAILDIR/sail" -ocaml "$SAILDIR/lib/prelude.sail" "$DIR/$TEST" -o "$OUTDIR/testout" $ARGS
+# cp -- "$SAILDIR"/src/gen_lib/sail_values.ml .
+# cp -- "$DIR"/test.ml .
+# ocamlc -I "$ZARITH" "$ZARITH/zarith.cma" -dllpath "$ZARITH" -I "$LEMDIR/ocaml-lib" "$LEMDIR/ocaml-lib/extract.cma" -I "$SAILDIR/src/_build/lem_interp" "$SAILDIR/src/_build/lem_interp/extract.cma" sail_values.ml testout.ml test.ml -o test
+# ./test
+
+ echo "$TEST lem - ocaml"
+ rm -f -- "$OUTDIR"/*
+ "$SAILDIR/sail" -lem "$SAILDIR/lib/prelude.sail" "$DIR/$TEST".sail -o "$OUTDIR/testout" $ARGS $@
+ "$LEMDIR/bin/lem" -ocaml -lib "$SAILDIR/src/lem_interp" "$SAILDIR/src/gen_lib/sail_values.lem" "$SAILDIR/src/gen_lib/state.lem" testout_embed_types.lem testout_embed_sequential.lem -outdir "$OUTDIR"
+ cp -- "$DIR"/test.ml "$OUTDIR"
+ ocamlc -I "$ZARITH" "$ZARITH/zarith.cma" -dllpath "$ZARITH" -I "$LEMDIR/ocaml-lib" "$LEMDIR/ocaml-lib/extract.cma" -I "$SAILDIR/src/_build/lem_interp" "$SAILDIR/src/_build/lem_interp/extract.cma" sail_values.ml state.ml testout_embed_types.ml testout_embed_sequential.ml test.ml -o test
+ ./test
+ fi
+done
diff --git a/test/mono/tests b/test/mono/tests
new file mode 100644
index 00000000..425230da
--- /dev/null
+++ b/test/mono/tests
@@ -0,0 +1,3 @@
+fnreduce -mono-split fnreduce.sail:43:x
+varmatch -mono-split varmatch.sail:7:x
+vector -mono-split vector.sail:7:sel
diff --git a/test/mono/varmatch.sail b/test/mono/varmatch.sail
new file mode 100644
index 00000000..7d2b9b73
--- /dev/null
+++ b/test/mono/varmatch.sail
@@ -0,0 +1,19 @@
+(* Check that when we case split on a variable that the constant propagation
+ handles the default case correctly. *)
+
+typedef AnEnum = enumerate { One; Two; Three }
+
+function AnEnum foo((AnEnum) x) = {
+ switch (x) {
+ case One -> Two
+ case y -> y
+ }
+}
+
+val unit -> bool effect pure run
+
+function run () = {
+ foo(One) == Two &
+ foo(Two) == Two &
+ foo(Three) == Three
+}
diff --git a/test/mono/vector.sail b/test/mono/vector.sail
new file mode 100644
index 00000000..03f36da5
--- /dev/null
+++ b/test/mono/vector.sail
@@ -0,0 +1,21 @@
+(* Check case splitting on a vector *)
+
+default Order dec
+
+val bit[32] -> nat effect pure test
+
+function nat test((bit[2]) sel : (bit[30]) _) = {
+ switch (sel) {
+ case 0b00 -> 5
+ case 0b10 -> 1
+ case _ -> 0
+ }
+}
+
+val unit -> bool effect pure run
+
+function run () = {
+ test(0x0f353533) == 5 &
+ test(0x84534656) == 1 &
+ test(0xf3463903) == 0
+}