summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBrian Campbell2019-01-31 17:00:11 +0000
committerBrian Campbell2019-01-31 17:00:11 +0000
commit116f55b569d68602e8c1f04622100a37e68e91c6 (patch)
tree3902bbc0132b22df823f8e62478f9cb0d3d8e66f /src
parent88dda99529fd0e151c932ab1bf22b3c101dd8309 (diff)
Turn on cast insertion for -lem_mwords and revert b826df25
now that cast insertion can handle RISC-V Also inserts specs for casts in they're not present
Diffstat (limited to 'src')
-rw-r--r--src/monomorphise.ml26
-rw-r--r--src/pretty_print_lem.ml16
-rw-r--r--src/rewrites.ml10
3 files changed, 40 insertions, 12 deletions
diff --git a/src/monomorphise.ml b/src/monomorphise.ml
index 0a26c8b0..ccaceec7 100644
--- a/src/monomorphise.ml
+++ b/src/monomorphise.ml
@@ -3964,6 +3964,13 @@ let simplify_size_nexp env quant_kids nexp =
| _ -> None
in aux nexp
+let specs_required = ref IdSet.empty
+let check_for_spec env name =
+ let id = mk_id name in
+ match Env.get_val_spec id env with
+ | _ -> ()
+ | exception _ -> specs_required := IdSet.add id !specs_required
+
(* These functions add cast functions across case splits, so that when a
bitvector size becomes known in sail, the generated Lem code contains a
function call to change mword 'n to (say) mword ty16, and vice versa. *)
@@ -4023,6 +4030,7 @@ let make_bitvector_cast_fns cast_name env quant_kids src_typ target_typ =
let pat, e' = aux src_typ' target_typ' in
match !at_least_one with
| Some one_target_typ -> begin
+ check_for_spec env cast_name;
let src_ann = mk_tannot env src_typ no_effect in
let tar_ann = mk_tannot env target_typ no_effect in
match src_typ' with
@@ -4246,7 +4254,23 @@ let add_bitvector_casts (Defs defs) =
| DEF_fundef (FD_aux (FD_function (r,t,e,fcls),fd_ann)) ->
DEF_fundef (FD_aux (FD_function (r,t,e,List.map rewrite_funcl fcls),fd_ann))
| d -> d
- in Defs (List.map rewrite_def defs)
+ in
+ specs_required := IdSet.empty;
+ let defs = List.map rewrite_def defs in
+ let l = Generated Unknown in
+ let Defs cast_specs,_ =
+ (* TODO: use default/relevant order *)
+ let kid = mk_kid "n" in
+ let bitsn = vector_typ (nvar kid) dec_ord bit_typ in
+ let ts = mk_typschm (mk_typquant [mk_qi_id K_int kid])
+ (function_typ [bitsn] bitsn no_effect) in
+ let extfn _ = Some "zeroExtend" in
+ let mkfn name =
+ mk_val_spec (VS_val_spec (ts,name,extfn,false))
+ in
+ let defs = List.map mkfn (IdSet.elements !specs_required) in
+ check Env.empty (Defs defs)
+ in Defs (cast_specs @ defs)
end
let replace_nexp_in_typ env typ orig new_nexp =
diff --git a/src/pretty_print_lem.ml b/src/pretty_print_lem.ml
index c0af581a..5c67f93a 100644
--- a/src/pretty_print_lem.ml
+++ b/src/pretty_print_lem.ml
@@ -349,14 +349,14 @@ let replace_typ_size ctxt env (Typ_aux (t,a)) =
let mk_typ nexp =
Some (Typ_aux (Typ_app (id, [A_aux (A_nexp nexp,Parse_ast.Unknown);ord;typ']),a))
in
- let is_equal nexp =
- prove env (NC_aux (NC_equal (size,nexp),Parse_ast.Unknown))
- in match List.find is_equal (NexpSet.elements ctxt.bound_nexps) with
- | nexp -> mk_typ nexp
- | exception Not_found ->
- match Type_check.solve env size with
- | Some n -> mk_typ (nconstant n)
- | None -> None
+ match Type_check.solve env size with
+ | Some n -> mk_typ (nconstant n)
+ | None ->
+ let is_equal nexp =
+ prove env (NC_aux (NC_equal (size,nexp),Parse_ast.Unknown))
+ in match List.find is_equal (NexpSet.elements ctxt.bound_nexps) with
+ | nexp -> mk_typ nexp
+ | exception Not_found -> None
end
| _ -> None
diff --git a/src/rewrites.ml b/src/rewrites.ml
index 382f9c8f..4ea953cf 100644
--- a/src/rewrites.ml
+++ b/src/rewrites.ml
@@ -4981,6 +4981,10 @@ let if_mono f defs =
| [], false -> defs
| _, _ -> f defs
+(* Also turn mwords stages on when we're just trying out mono *)
+let if_mwords f defs =
+ if !Pretty_print_lem.opt_mwords then f defs else if_mono f defs
+
let rewrite_defs_lem = [
("realise_mappings", rewrite_defs_realise_mappings);
("remove_mapping_valspecs", remove_mapping_valspecs);
@@ -4991,10 +4995,10 @@ let rewrite_defs_lem = [
("recheck_defs", if_mono recheck_defs);
("rewrite_toplevel_nexps", if_mono rewrite_toplevel_nexps);
("monomorphise", if_mono monomorphise);
- ("recheck_defs", if_mono recheck_defs);
- ("add_bitvector_casts", if_mono Monomorphise.add_bitvector_casts);
+ ("recheck_defs", if_mwords recheck_defs);
+ ("add_bitvector_casts", if_mwords Monomorphise.add_bitvector_casts);
("rewrite_atoms_to_singletons", if_mono Monomorphise.rewrite_atoms_to_singletons);
- ("recheck_defs", if_mono recheck_defs);
+ ("recheck_defs", if_mwords recheck_defs);
("rewrite_undefined", rewrite_undefined_if_gen false);
("rewrite_defs_vector_string_pats_to_bit_list", rewrite_defs_vector_string_pats_to_bit_list);
("remove_not_pats", rewrite_defs_not_pats);