From 3d526b799eeb699fab913994e0739959688e9963 Mon Sep 17 00:00:00 2001 From: Brian Campbell Date: Thu, 19 Nov 2020 13:53:14 +0000 Subject: 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.) --- src/monomorphise.ml | 5 +++-- test/mono/rewrites.sail | 1 + 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); } -- cgit v1.2.3