summaryrefslogtreecommitdiff
path: root/test/c
diff options
context:
space:
mode:
Diffstat (limited to 'test/c')
-rw-r--r--test/c/extend_simple.expect2
-rw-r--r--test/c/extend_simple.sail10
-rw-r--r--test/c/fast_signed.expect12
-rw-r--r--test/c/fast_signed.sail30
-rw-r--r--test/c/int_struct.expect1
-rw-r--r--test/c/int_struct.sail24
-rw-r--r--test/c/int_struct_constrained.expect1
-rw-r--r--test/c/int_struct_constrained.sail24
-rw-r--r--test/c/issue37.expect1
-rw-r--r--test/c/issue37.sail9
-rwxr-xr-xtest/c/run_tests.py3
11 files changed, 116 insertions, 1 deletions
diff --git a/test/c/extend_simple.expect b/test/c/extend_simple.expect
new file mode 100644
index 00000000..3a652eaf
--- /dev/null
+++ b/test/c/extend_simple.expect
@@ -0,0 +1,2 @@
+x = 0xFFFFFFFF
+y = 0x00000000FFFFFFFF
diff --git a/test/c/extend_simple.sail b/test/c/extend_simple.sail
new file mode 100644
index 00000000..23f14235
--- /dev/null
+++ b/test/c/extend_simple.sail
@@ -0,0 +1,10 @@
+default Order dec
+
+$include <prelude.sail>
+
+function main((): unit) -> unit = {
+ let x = sail_sign_extend(0xFF, 32);
+ let y = sail_zero_extend(x, 64);
+ print_bits("x = ", x);
+ print_bits("y = ", y)
+} \ No newline at end of file
diff --git a/test/c/fast_signed.expect b/test/c/fast_signed.expect
new file mode 100644
index 00000000..9fcfea23
--- /dev/null
+++ b/test/c/fast_signed.expect
@@ -0,0 +1,12 @@
+x = -1
+y = -1
+z = -1
+w = -1
+x = -128
+y = -32768
+z = -9223372036854775808
+w = -170141183460469231731687303715884105728
+x = 127
+y = 32767
+z = 9223372036854775807
+w = 170141183460469231731687303715884105727
diff --git a/test/c/fast_signed.sail b/test/c/fast_signed.sail
new file mode 100644
index 00000000..b0f16f89
--- /dev/null
+++ b/test/c/fast_signed.sail
@@ -0,0 +1,30 @@
+default Order dec
+
+$include <prelude.sail>
+
+function main((): unit) -> unit = {
+ let x = signed(0xFF);
+ let y = signed(0xFFFF);
+ let z = signed(0xFFFFFFFF_FFFFFFFF);
+ let w = signed(0xFFFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF);
+ print_int("x = ", x);
+ print_int("y = ", y);
+ print_int("z = ", z);
+ print_int("w = ", w);
+ let x = signed(0x80);
+ let y = signed(0x8000);
+ let z = signed(0x80000000_00000000);
+ let w = signed(0x80000000_00000000_00000000_00000000);
+ print_int("x = ", x);
+ print_int("y = ", y);
+ print_int("z = ", z);
+ print_int("w = ", w);
+ let x = signed(0x7F);
+ let y = signed(0x7FFF);
+ let z = signed(0x7FFFFFFF_FFFFFFFF);
+ let w = signed(0x7FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF);
+ print_int("x = ", x);
+ print_int("y = ", y);
+ print_int("z = ", z);
+ print_int("w = ", w);
+} \ No newline at end of file
diff --git a/test/c/int_struct.expect b/test/c/int_struct.expect
new file mode 100644
index 00000000..f70f10e4
--- /dev/null
+++ b/test/c/int_struct.expect
@@ -0,0 +1 @@
+A
diff --git a/test/c/int_struct.sail b/test/c/int_struct.sail
new file mode 100644
index 00000000..42554593
--- /dev/null
+++ b/test/c/int_struct.sail
@@ -0,0 +1,24 @@
+default Order dec
+
+$include <prelude.sail>
+
+val print = "print_endline" : string -> unit
+
+struct Foo('n: Int) = {
+ field: bits('n)
+}
+
+type Foo32 = Foo(32)
+
+function bar(foo: Foo32) -> unit = {
+ if foo.field == 0xFFFF_FFFF then {
+ print("A")
+ } else {
+ print("B")
+ }
+}
+
+function main((): unit) -> unit = {
+ let x: Foo32 = struct { field = 0xFFFF_FFFF };
+ bar(x)
+} \ No newline at end of file
diff --git a/test/c/int_struct_constrained.expect b/test/c/int_struct_constrained.expect
new file mode 100644
index 00000000..f70f10e4
--- /dev/null
+++ b/test/c/int_struct_constrained.expect
@@ -0,0 +1 @@
+A
diff --git a/test/c/int_struct_constrained.sail b/test/c/int_struct_constrained.sail
new file mode 100644
index 00000000..95cb6e9b
--- /dev/null
+++ b/test/c/int_struct_constrained.sail
@@ -0,0 +1,24 @@
+default Order dec
+
+$include <prelude.sail>
+
+val print = "print_endline" : string -> unit
+
+struct Foo('n: Int), 'n <= 64 = {
+ field: bits('n)
+}
+
+type Foo32 = Foo(32)
+
+function bar(foo: Foo32) -> unit = {
+ if foo.field == 0xFFFF_FFFF then {
+ print("A")
+ } else {
+ print("B")
+ }
+}
+
+function main((): unit) -> unit = {
+ let x: Foo32 = struct { field = 0xFFFF_FFFF };
+ bar(x)
+} \ No newline at end of file
diff --git a/test/c/issue37.expect b/test/c/issue37.expect
new file mode 100644
index 00000000..6e77c916
--- /dev/null
+++ b/test/c/issue37.expect
@@ -0,0 +1 @@
+foo = 0xE
diff --git a/test/c/issue37.sail b/test/c/issue37.sail
new file mode 100644
index 00000000..404c4ef4
--- /dev/null
+++ b/test/c/issue37.sail
@@ -0,0 +1,9 @@
+default Order dec
+
+$include <vector_dec.sail>
+
+function main () : unit->unit = {
+ foo = 0xf;
+ foo[0] = bitzero;
+ print_bits("foo = ", foo)
+} \ No newline at end of file
diff --git a/test/c/run_tests.py b/test/c/run_tests.py
index 4a02dd78..2ee44fca 100755
--- a/test/c/run_tests.py
+++ b/test/c/run_tests.py
@@ -95,7 +95,8 @@ xml += test_c('optimized C', '-O2', '-O', True)
xml += test_c('constant folding', '', '-Oconstant_fold', True)
xml += test_c('monomorphised C', '-O2', '-O -Oconstant_fold -auto_mono', True)
xml += test_c('full optimizations', '-O2 -mbmi2 -DINTRINSICS', '-O -Oconstant_fold', True)
-xml += test_c('address sanitised', '-O2 -fsanitize=undefined', '-O', False)
+xml += test_c('specialization', '-O1', '-O -c_specialize', True)
+xml += test_c('undefined behavior sanitised', '-O2 -fsanitize=undefined', '-O', False)
xml += test_interpreter('interpreter')