Skip to content
Snippets Groups Projects
Commit 12d4242b authored by Virgile Prevosto's avatar Virgile Prevosto
Browse files

[kernel] first steps for refining asm contracts

parent 2f4384a6
No related branches found
No related tags found
No related merge requests found
...@@ -168,6 +168,24 @@ class visit_assembly = ...@@ -168,6 +168,24 @@ class visit_assembly =
(fun x -> (to_id_term x, From (List.map to_id_from lv_from))) (fun x -> (to_id_term x, From (List.map to_id_from lv_from)))
lv_out) lv_out)
in in
let mk_initialized x =
let typ = Cil.typeOfTermLval x in
if Logic_utils.isLogicVoidType typ then None
else begin
let t = Logic_utils.mk_logic_AddrOf ~loc x typ in
let pred =
Logic_const.(
new_predicate
(pinitialized ~loc (here_label,t)))
in
Some (Normal, pred)
end
in
let initialized () =
if Kernel.AsmContractsInitialized.get() then begin
List.filter_map mk_initialized lv_out
end else []
in
let filter ca = let filter ca =
match ca.annot_content with match ca.annot_content with
(* search for a statement contract that applies to all cases. *) (* search for a statement contract that applies to all cases. *)
...@@ -178,7 +196,8 @@ class visit_assembly = ...@@ -178,7 +196,8 @@ class visit_assembly =
(match contracts with (match contracts with
| [] -> | [] ->
let assigns = assigns () in let assigns = assigns () in
let bhv = Cil.mk_behavior ~assigns () in let post_cond = initialized () in
let bhv = Cil.mk_behavior ~assigns ~post_cond () in
let spec = Cil.empty_funspec () in let spec = Cil.empty_funspec () in
spec.spec_behavior <- [ bhv ]; spec.spec_behavior <- [ bhv ];
let ca = let ca =
...@@ -236,6 +255,7 @@ let transform file = ...@@ -236,6 +255,7 @@ let transform file =
let () = let () =
File.add_code_transformation_after_cleanup File.add_code_transformation_after_cleanup
~deps:[(module Kernel.AsmContractsGenerate); ~deps:[(module Kernel.AsmContractsGenerate);
(module Kernel.AsmContractsInitialized);
(module Kernel.AsmContractsAutoValidate) ] (module Kernel.AsmContractsAutoValidate) ]
category category
transform transform
...@@ -1358,6 +1358,17 @@ module AsmContractsGenerate = ...@@ -1358,6 +1358,17 @@ module AsmContractsGenerate =
to gcc's extended syntax" to gcc's extended syntax"
end) end)
let () = Parameter_customize.set_group normalisation
module AsmContractsInitialized =
False
(struct
let option_name = "-asm-contracts-ensure-init"
let module_name = "AsmContractsInitialized"
let help = "when contracts for assembly code are generated, add \
postconditions stating that the output are initialized."
end)
let () = Parameter_customize.set_group normalisation let () = Parameter_customize.set_group normalisation
module AsmContractsAutoValidate = module AsmContractsAutoValidate =
False False
......
...@@ -537,6 +537,9 @@ module AggressiveMerging: Parameter_sig.Bool ...@@ -537,6 +537,9 @@ module AggressiveMerging: Parameter_sig.Bool
module AsmContractsGenerate: Parameter_sig.Bool module AsmContractsGenerate: Parameter_sig.Bool
(** Behavior of option "-asm-contracts" *) (** Behavior of option "-asm-contracts" *)
module AsmContractsInitialized: Parameter_sig.Bool
(** Behavior of option "-asm-contracts-ensure-init" *)
module AsmContractsAutoValidate: Parameter_sig.Bool module AsmContractsAutoValidate: Parameter_sig.Bool
(** Behavior of option "-asm-contracts-auto-validate." *) (** Behavior of option "-asm-contracts-auto-validate." *)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment