Skip to content

Commit

Permalink
Re-add attribute for records generated from bitfields
Browse files Browse the repository at this point in the history
Necessary for the rewrite used by theorem prover backends that lowers them
to plain bitvectors.
  • Loading branch information
bacam committed Jan 10, 2025
1 parent 18b0aec commit 707f53d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/lib/rewrites.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4328,8 +4328,9 @@ let rewrite_unroll_constant_loops _type_env defs =
A type-checking pass is expected to be run after this rewrite. *)
let remove_bitfield_records type_env =
let rewrite_def rewriters = function
| DEF_aux (DEF_type (TD_aux (TD_record (id, tq, _, _), t_annot)), def_annot) when Env.is_bitfield id type_env ->
let typ, _ = Env.get_bitfield id type_env in
(* Avoid using Env.get_bitfield in case the typing environment is out of date (e.g., due to nexp_ids) *)
| DEF_aux (DEF_type (TD_aux (TD_record (id, tq, [(typ, _)], _), t_annot)), def_annot)
when Env.is_bitfield id type_env ->
DEF_aux (DEF_type (TD_aux (TD_abbrev (id, tq, mk_typ_arg (A_typ typ)), t_annot)), def_annot)
| d -> rewriters_base.rewrite_def rewriters d
in
Expand Down
11 changes: 6 additions & 5 deletions src/lib/type_check.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4790,8 +4790,11 @@ let check_record l env def_annot id typq fields =
let env =
try
match get_def_attribute "bitfield" def_annot with
| Some (_, Some (AD_aux (AD_num size, _))) when not (Env.is_bitfield id env) ->
Env.add_bitfield id (bitvector_typ (nconstant size)) Bindings.empty env
| Some _ when not (Env.is_bitfield id env) -> begin
match fields with
| [(typ, Id_aux (Id "bits", _))] -> Env.add_bitfield id typ Bindings.empty env
| _ -> typ_raise l (Err_other "bitfield record has wrong fields")
end
| _ -> env
with _ -> env
in
Expand Down Expand Up @@ -4957,9 +4960,7 @@ let rec check_typedef : Env.t -> env def_annot -> uannot type_def -> typed_def l
This is used as the default name for all the bits in the bitfield, so should not be overridden."
)
ranges;
(*
let def_annot = add_def_attribute l "bitfield" (Some (AD_aux (AD_num size, l))) def_annot in
*)
let def_annot = add_def_attribute l "bitfield" None def_annot in
let defs =
DEF_aux (DEF_type (TD_aux (record_tdef, (l, empty_uannot))), strip_def_annot def_annot)
:: Bitfield.macro id size (Env.get_default_order env) ranges
Expand Down

0 comments on commit 707f53d

Please sign in to comment.