summaryrefslogtreecommitdiff
path: root/test/typecheck
diff options
context:
space:
mode:
authorAlasdair Armstrong2019-05-13 18:03:35 +0100
committerAlasdair Armstrong2019-05-14 15:13:29 +0100
commit41e6fe10e7d28193fa62711fcdad797b1f0103a0 (patch)
tree0113597f0c1b5ba909028f576a6a51c8dbead6ac /test/typecheck
parent7257b23239a3f8d6a45f973b9d953b31772abe06 (diff)
Add feature that allows functions to require type variables are constant
can now write e.g. forall (constant 'n : Int) rather than forall ('n: Int) which requires 'n to be a constant integer value whenever the function is called. I added this to the 'addrsize variable on memory reads/writes to absolutely guarantee in the SMT generation that we don't have to worry about the address being a variable length bitvector.
Diffstat (limited to 'test/typecheck')
-rw-r--r--test/typecheck/pass/constant_nexp.sail13
-rw-r--r--test/typecheck/pass/constant_nexp/v1.expect7
-rw-r--r--test/typecheck/pass/constant_nexp/v1.sail13
-rw-r--r--test/typecheck/pass/constant_nexp/v2.expect8
-rw-r--r--test/typecheck/pass/constant_nexp/v2.sail14
5 files changed, 55 insertions, 0 deletions
diff --git a/test/typecheck/pass/constant_nexp.sail b/test/typecheck/pass/constant_nexp.sail
new file mode 100644
index 00000000..d8213d42
--- /dev/null
+++ b/test/typecheck/pass/constant_nexp.sail
@@ -0,0 +1,13 @@
+default Order dec
+
+$include <prelude.sail>
+
+val czeros = "zeros" : forall (constant 'n : Int), 'n >= 0. int('n) -> bits('n)
+
+val multi_param : forall (constant 'n 'm : Int) ('o : Int). (int('n), int('m), int('o)) -> unit
+
+function test forall 'n, 'n >= 0. (n: int('n)) -> unit = {
+ let _ = czeros(64);
+ multi_param(2 + 3, 5, n);
+ ()
+} \ No newline at end of file
diff --git a/test/typecheck/pass/constant_nexp/v1.expect b/test/typecheck/pass/constant_nexp/v1.expect
new file mode 100644
index 00000000..71ed455b
--- /dev/null
+++ b/test/typecheck/pass/constant_nexp/v1.expect
@@ -0,0 +1,7 @@
+Type error:
+[constant_nexp/v1.sail]:11:2-26
+11 | multi_param(2 + 3, n, 5);
+  | ^----------------------^
+  | Could not resolve quantifiers for multi_param
+  | * is_constant(('m : Int))
+  |
diff --git a/test/typecheck/pass/constant_nexp/v1.sail b/test/typecheck/pass/constant_nexp/v1.sail
new file mode 100644
index 00000000..eca83a44
--- /dev/null
+++ b/test/typecheck/pass/constant_nexp/v1.sail
@@ -0,0 +1,13 @@
+default Order dec
+
+$include <prelude.sail>
+
+val czeros = "zeros" : forall (constant 'n : Int), 'n >= 0. int('n) -> bits('n)
+
+val multi_param : forall (constant 'n 'm : Int) ('o : Int). (int('n), int('m), int('o)) -> unit
+
+function test forall 'n, 'n >= 0. (n: int('n)) -> unit = {
+ let _ = czeros(64);
+ multi_param(2 + 3, n, 5);
+ ()
+} \ No newline at end of file
diff --git a/test/typecheck/pass/constant_nexp/v2.expect b/test/typecheck/pass/constant_nexp/v2.expect
new file mode 100644
index 00000000..3c4dcc16
--- /dev/null
+++ b/test/typecheck/pass/constant_nexp/v2.expect
@@ -0,0 +1,8 @@
+Type error:
+[constant_nexp/v2.sail]:12:10-38
+12 | let _ = czeros(sizeof('n - 10) + 20);
+  | ^--------------------------^
+  | Could not resolve quantifiers for czeros
+  | * is_constant(('fv47#n : Int))
+  | * (('n - 10) + 20) >= 0
+  |
diff --git a/test/typecheck/pass/constant_nexp/v2.sail b/test/typecheck/pass/constant_nexp/v2.sail
new file mode 100644
index 00000000..b3799eed
--- /dev/null
+++ b/test/typecheck/pass/constant_nexp/v2.sail
@@ -0,0 +1,14 @@
+default Order dec
+
+$include <prelude.sail>
+
+val czeros = "zeros" : forall (constant 'n : Int), 'n >= 0. int('n) -> bits('n)
+
+val multi_param : forall (constant 'n 'm : Int) ('o : Int). (int('n), int('m), int('o)) -> unit
+
+function test forall 'n, 'n >= 0. (n: int('n)) -> unit = {
+ let _ = czeros(64);
+ multi_param(2 + 3, 5, n);
+ let _ = czeros(sizeof('n - 10) + 20);
+ ()
+} \ No newline at end of file