summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/c/enum_match.expect1
-rw-r--r--test/c/enum_match.sail16
-rw-r--r--test/c/sail.h12
-rw-r--r--test/c/vmatch.expect3
-rw-r--r--test/c/vmatch.sail21
5 files changed, 47 insertions, 6 deletions
diff --git a/test/c/enum_match.expect b/test/c/enum_match.expect
new file mode 100644
index 00000000..f70f10e4
--- /dev/null
+++ b/test/c/enum_match.expect
@@ -0,0 +1 @@
+A
diff --git a/test/c/enum_match.sail b/test/c/enum_match.sail
new file mode 100644
index 00000000..591e2695
--- /dev/null
+++ b/test/c/enum_match.sail
@@ -0,0 +1,16 @@
+
+val "eq_anything" : forall ('a : Type). ('a, 'a) -> bool
+
+overload operator == = {eq_anything}
+
+val print = "print_endline" : string -> unit
+
+enum test = A | B
+
+function main (() : unit) -> unit = {
+ let x = A;
+ match x {
+ B => print("B"),
+ A => print("A")
+ }
+} \ No newline at end of file
diff --git a/test/c/sail.h b/test/c/sail.h
index 92127a1b..abd86a71 100644
--- a/test/c/sail.h
+++ b/test/c/sail.h
@@ -21,8 +21,8 @@ typedef char *sail_string;
// This function should be called whenever a pattern match failure
// occurs. Pattern match failures are always fatal.
-void sail_match_failure(void) {
- fprintf(stderr, "Pattern match failure\n");
+void sail_match_failure(sail_string msg) {
+ fprintf(stderr, "Pattern match failure in %s\n", msg);
exit(1);
}
@@ -41,12 +41,12 @@ void elf_entry(mpz_t *rop, const unit u) {
mpz_set_ui(*rop, 0x400130ul);
}
-// Sail bits are mapped to ints where bitzero = 0 and bitone = 1
-bool eq_bit(const int a, const int b) {
+// Sail bits are mapped to uint64_t where bitzero = 0ul and bitone = 1ul
+bool eq_bit(const uint64_t a, const uint64_t b) {
return a == b;
}
-int undefined_bit(unit u) { return 0; }
+uint64_t undefined_bit(unit u) { return 0; }
// ***** Sail booleans *****
@@ -683,7 +683,7 @@ void read_ram(bv_t *data, const mpz_t m, const mpz_t n, const bv_t x, const bv_t
mpz_set_ui(*data->bits, instr);
data->len = 32;
- print_bits("instruction = ", *data);
+ // print_bits("instruction = ", *data);
}
// ***** Setup and cleanup functions for library code *****
diff --git a/test/c/vmatch.expect b/test/c/vmatch.expect
new file mode 100644
index 00000000..cfd469a0
--- /dev/null
+++ b/test/c/vmatch.expect
@@ -0,0 +1,3 @@
+0b00111100
+0b0_____1_
+0b0_____10
diff --git a/test/c/vmatch.sail b/test/c/vmatch.sail
new file mode 100644
index 00000000..2501788c
--- /dev/null
+++ b/test/c/vmatch.sail
@@ -0,0 +1,21 @@
+default Order dec
+
+$include <vector_dec.sail>
+
+val print = "print_endline" : string -> unit
+
+val test : bits(8) -> unit
+
+function test 0b00 @ 0xF @ 0b00 = print("0b00111100")
+and test 0b0 @ _ : bits(5) @ 0b1 @ [bitzero] = print ("0b0_____10")
+and test 0b0 @ _ : bits(5) @ 0b1 @ [_] = print("0b0_____1_")
+and test 0b0 @ _ : bits(5) @ 0b1 @ [bitone] = print ("0b0_____11")
+and test _ = print("wildcard")
+
+val main : unit -> unit
+
+function main () = {
+ test(0b00111100);
+ test(0b01111111);
+ test(0b01111110);
+} \ No newline at end of file