1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
|
(****************************************************************************)
(* the diy toolsuite *)
(* *)
(* Jade Alglave, University College London, UK. *)
(* Luc Maranget, INRIA Paris-Rocquencourt, France. *)
(* *)
(* Copyright 2013-present Institut National de Recherche en Informatique et *)
(* en Automatique and the authors. All rights reserved. *)
(* *)
(* This software is governed by the CeCILL-B license under French law and *)
(* abiding by the rules of distribution of free software. You can use, *)
(* modify and/ or redistribute the software under the terms of the CeCILL-B *)
(* license as circulated by CEA, CNRS and INRIA at the following URL *)
(* "http://www.cecill.info". We also give a copy in LICENSE.txt. *)
(****************************************************************************)
open ConstrGen
module M =
MyMap.Make
(struct
type t = MiscParser.location
let compare = MiscParser.location_compare
end)
module V = struct
type t = ToolsConstant.v
let compare = ToolsConstant.compare
end
module VS = MySet.Make(V)
module X =
LogConstr.Make
(struct
module V = ToolsConstant
type v = V.v
type state = v M.t
let state_mem env loc v = match loc with
| ConstrGen.Loc loc ->
begin
try
let w = M.find loc env in
V.compare v w = 0
with Not_found -> assert false
end
| ConstrGen.Deref _ ->
Warn.fatal
"Array access %s in CondUtils.state_mem"
(ConstrGen.dump_rloc MiscParser.dump_location loc)
let state_eqloc _ _ _ = assert false
let state_fault _env _f = assert false
end)
let rec collect p m = match p with
| Atom (LV (Loc loc,v)) ->
let old = M.safe_find VS.empty loc m in
M.add loc (VS.add v old) m
| And ps|Or ps ->
List.fold_right collect ps m
| Implies _
| Atom (LV (Deref _,_)|LL _|FF _)|Not _ -> raise Exit
let rec as_outcome p = match p with
| Atom (LV (Loc loc,v)) -> [loc,v]
| Or [p] -> as_outcome p
| And ps ->
List.fold_left (fun k p -> as_outcome p@k) [] ps
| Atom (LV (Deref _,_)|LL _|FF _)|Or (_::_::_|[])|Not _|Implies (_, _)
-> raise Exit
let rec as_outcomes p = match p with
| Or ps ->
List.fold_left (fun k p -> as_outcomes p @ k) [] ps
| _ -> [as_outcome p]
let fold_outcomes c kont k =
let p = prop_of c in
try
let bdss = as_outcomes p in
List.fold_left (fun k bds -> kont bds k) k bdss
with Exit -> try
let m = collect p M.empty in
let xss =
M.fold
(fun loc vs k -> (loc,VS.elements vs)::k)
m [] in
let xss = List.rev xss in (* follow map order for locations *)
let locs,vss = List.split xss in
Misc.fold_cross vss
(fun vs k ->
let bds = List.combine locs vs in
(*
Printf.eprintf "Test: %s\n%!"
(String.concat " "
(List.map
(fun (loc,v) ->
MiscParser.dump_location loc ^ "=" ^
SymbConstant.pp_v v)
bds)) ;
*)
if X.check_prop p (M.from_bindings bds) then begin
kont bds k
end else k)
k
with Exit -> k
|