-
Notifications
You must be signed in to change notification settings - Fork 0
/
encodeConstraint.ml
64 lines (56 loc) · 1.9 KB
/
encodeConstraint.ml
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
open Z3
open Z3.Symbol
open Z3.Sort
open Z3.Expr
open Z3.Boolean
open Z3.FuncDecl
open Z3.Arithmetic
open Z3.Arithmetic.Integer
open RwOperations
open Printf
(* asserts an atomic constraint.
cpair - consists of the instruction label, and value to check. *)
let assertAtom ctx rval cpair efftbl =
(*printf "-----%s\n" (fst cpair);*)
let eff = Hashtbl.find efftbl (fst cpair) in
let f1 = mk_app ctx rval [eff] in
mk_eq ctx f1 (Integer.mk_numeral_i ctx (snd (snd cpair)))
(* asserts the property.
p - type of property. *)
let rec assertProperty ctx rval p efftbl =
match p with
| Atom (i,v) -> assertAtom ctx rval (i,v) efftbl
| Not v -> assertNot ctx rval v efftbl
| And v -> ((*printf "came to and"; *)
assertAnd ctx rval (List.hd v) (List.tl v) efftbl)
| Or v -> assertOr ctx rval (List.hd v) (List.tl v) efftbl
| Implies (v1,v2) -> assertImplies ctx rval v1 v2 efftbl
and assertNot ctx rval p efftbl =
(mk_not ctx (assertProperty ctx rval p efftbl))
and assertAnd ctx rval chd ctl efftbl =
match ctl with
| [] -> assertProperty ctx rval chd efftbl
| h::t -> let eq = assertProperty ctx rval h efftbl in
mk_and ctx
(eq :: (assertAnd ctx rval chd t efftbl)::[])
and assertOr ctx rval chd ctl efftbl =
match ctl with
| [] -> assertProperty ctx rval chd efftbl
| h::t -> let eq = assertProperty ctx rval h efftbl in
mk_or ctx
(eq :: (assertAnd ctx rval chd t efftbl)::[])
and assertImplies ctx rval pfst psnd efftbl =
let eq1 = assertProperty ctx rval pfst efftbl in
let eq2 = assertProperty ctx rval psnd efftbl in
mk_implies ctx eq1 eq2
(* Asserts the constraints.
ctx - context
rval - z3 function declaration for rval
cnstr - testcase constraint
efftbl - hashtable of effects. *)
let assertConstraints ctx rval cnstr efftbl =
match cnstr with
| ForallStates p
| ExistsStates p (* TODO - Make negative constraint. *)
| NotExistsState p ->
assertProperty ctx rval p efftbl