summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Campbell2020-11-19 13:53:14 +0000
committerBrian Campbell2020-11-19 13:53:14 +0000
commit3d526b799eeb699fab913994e0739959688e9963 (patch)
treefa9323c6b7f0ed77919b5a7c3526796d49ae0968
parent2173dc28a24bc829ca93205e2fafc1a3daf404d5 (diff)
Make mono rewrites be more careful to produce constant-sized types
While the backends will usually manage to find the constant size anyway, this ensures that implicit arguments will be filled in with the constant value too. (For example, this was affecting isla execution in one corner case because the slice_mask primitive didn't see that the size was constant.)
-rw-r--r--src/monomorphise.ml5
-rw-r--r--test/mono/rewrites.sail1
2 files changed, 4 insertions, 2 deletions
diff --git a/src/monomorphise.ml b/src/monomorphise.ml
index d86db99d..7c958ffe 100644
--- a/src/monomorphise.ml
+++ b/src/monomorphise.ml
@@ -2936,8 +2936,9 @@ let rec rewrite_app env typ (id,args) =
in
let try_cast_to_typ (E_aux (e,(l, _)) as exp) =
let (size,order,bittyp) = vector_typ_args_of (Env.base_typ_of env typ) in
- match size with
- | Nexp_aux (Nexp_constant _,_) -> E_cast (typ,exp)
+ (* vector_typ_args_of might simplify size, so rebuild the type even if it's constant *)
+ match size with
+ | Nexp_aux (Nexp_constant c,_) -> E_cast (bitvector_typ (nconstant c) order, exp)
| _ -> match solve_unique env size with
| Some c -> E_cast (bitvector_typ (nconstant c) order, exp)
| None -> e
diff --git a/test/mono/rewrites.sail b/test/mono/rewrites.sail
index b08af90f..5f409cdf 100644
--- a/test/mono/rewrites.sail
+++ b/test/mono/rewrites.sail
@@ -23,4 +23,5 @@ function run() = {
assert(sign_ext_fun(x, z, 32) == 0x00000200);
assert(sail_zero_extend(y[7..4] @ sail_zeros(8), 32) == 0x00000800);
assert(sign_ext_fun(y, z, 32) == 0xfffff800);
+ assert(sail_ones(i) @ sail_zeros(9) == 0xfe00);
}