-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontext.v
180 lines (144 loc) · 5.45 KB
/
context.v
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
Require Import List.
Import ListNotations.
Require Import bbv.Word.
Require Import Nat.
Require Import Coq.NArith.NArith.
Require Import FORVES2.octagon.
Import Octagon.
Require Import FORVES2.constraints.
Import Constraints.
Require Import FORVES2.symbolic_state.
Import SymbolicState.
Module Context.
Record ctx_t : Type :=
{
ctx_cs : constraints;
ctx_imp_chkr: imp_checker
}.
Inductive available_imp_chkr :=
| ImpChkr_Dummy
| ImpChkr_Syntactic
| ImpChkr_Oct.
Definition compute_n_iter_for_oct (cs : constraints) :=
(fold_right (fun l n => (max (length l) n)) 0 cs).
Definition get_impl_chkr (tag: available_imp_chkr) (cs: constraints) : imp_checker :=
match tag with
| ImpChkr_Dummy => dummy_imp_checker
| ImpChkr_Syntactic => inclusion_imp_checker
| ImpChkr_Oct => mk_imp_checker (ForvesIntegration.conj_trans_closure_checker (compute_n_iter_for_oct cs))
end.
Definition mk_ctx (imp_chkr: imp_checker) (cs: constraints) : ctx_t :=
{|
ctx_cs := cs;
ctx_imp_chkr := imp_chkr
|}.
Definition sstack_val_to_cliteral (sv : sstack_val) : option cliteral :=
match sv with
| Val w => Some (C_VAL (wordToN w))
| InVar n => Some (C_VAR n)
| _ => None
end.
Definition sstack_val_to_cliteral_w_shift (sv : sstack_val) (shift: N) : option cliteral :=
match sv with
| Val w => Some (C_VAL ((wordToN w) + shift))
| InVar n => Some (C_VAR_DELTA n shift)
| _ => None
end.
Definition sstack_val_to_cliteral_smap (sv : sstack_val) (maxidx: nat) (bs : sbindings) : option cliteral :=
match follow_in_smap sv maxidx bs with
| Some (FollowSmapVal (SymBasicVal sv') _ _) => sstack_val_to_cliteral sv'
| _ => None
end.
Definition chk_eq_wrt_ctx (ctx: ctx_t) (sv1 sv2: sstack_val) :=
let imp_chkr := imp_checker_fun (ctx_imp_chkr ctx) in
let cs := ctx_cs ctx in
let ocl1 := sstack_val_to_cliteral sv1 in
let ocl2 := sstack_val_to_cliteral sv2 in
match ocl1, ocl2 with
| Some cl1, Some cl2 => imp_chkr cs (C_EQ cl1 cl2)
| _, _ => false
end.
Definition chk_lt_wrt_ctx (ctx: ctx_t) (sv1 sv2: sstack_val) :=
let imp_chkr := imp_checker_fun (ctx_imp_chkr ctx) in
let cs := ctx_cs ctx in
let ocl1 := sstack_val_to_cliteral sv1 in
let ocl2 := sstack_val_to_cliteral sv2 in
match ocl1, ocl2 with
| Some cl1, Some cl2 => imp_chkr cs (C_LT cl1 cl2)
| _, _ => false
end.
Definition chk_lt_wrt_ctx_smap (ctx: ctx_t) (sv1 sv2: sstack_val) (maxidx: nat) (bs : sbindings) :=
let imp_chkr := imp_checker_fun (ctx_imp_chkr ctx) in
let cs := ctx_cs ctx in
let ocl1 := sstack_val_to_cliteral_smap sv1 maxidx bs in
let ocl2 := sstack_val_to_cliteral_smap sv2 maxidx bs in
match ocl1, ocl2 with
| Some cl1, Some cl2 => imp_chkr cs (C_LT cl1 cl2)
| _, _ => false
end.
Definition chk_neq_wrt_ctx (ctx: ctx_t) (sv1 sv2: sstack_val) :=
if chk_lt_wrt_ctx ctx sv1 sv2 then true else chk_lt_wrt_ctx ctx sv2 sv1.
Definition chk_lt_lshift_wrt_ctx (ctx: ctx_t) (sv1 sv2: sstack_val) (shift: N) :=
let imp_chkr := imp_checker_fun (ctx_imp_chkr ctx) in
let cs := ctx_cs ctx in
let ocl1 := sstack_val_to_cliteral_w_shift sv1 shift in
let ocl2 := sstack_val_to_cliteral sv2 in
match ocl1, ocl2 with
| Some cl1, Some cl2 => imp_chkr cs (C_LT cl1 cl2)
| _, _ => false
end.
Definition chk_lt_rshift_wrt_ctx (ctx: ctx_t) (sv1 sv2: sstack_val) (shift: N) :=
let imp_chkr := imp_checker_fun (ctx_imp_chkr ctx) in
let cs := ctx_cs ctx in
let ocl1 := sstack_val_to_cliteral sv1 in
let ocl2 := sstack_val_to_cliteral_w_shift sv2 shift in
match ocl1, ocl2 with
| Some cl1, Some cl2 => imp_chkr cs (C_LT cl1 cl2)
| _, _ => false
end.
Definition chk_lt_lrshift_wrt_ctx (ctx: ctx_t) (sv1 sv2: sstack_val) (shift1: N) (shift2: N) :=
let imp_chkr := imp_checker_fun (ctx_imp_chkr ctx) in
let cs := ctx_cs ctx in
let ocl1 := sstack_val_to_cliteral_w_shift sv1 shift1 in
let ocl2 := sstack_val_to_cliteral_w_shift sv2 shift2 in
match ocl1, ocl2 with
| Some cl1, Some cl2 => imp_chkr cs (C_LT cl1 cl2)
| _, _ => false
end.
Definition chk_le_wrt_ctx (ctx: ctx_t) (sv1 sv2: sstack_val) :=
let imp_chkr := imp_checker_fun (ctx_imp_chkr ctx) in
let cs := ctx_cs ctx in
let ocl1 := sstack_val_to_cliteral sv1 in
let ocl2 := sstack_val_to_cliteral sv2 in
match ocl1, ocl2 with
| Some cl1, Some cl2 => imp_chkr cs (C_LE cl1 cl2)
| _, _ => false
end.
Definition chk_le_lshift_wrt_ctx (ctx: ctx_t) (sv1 sv2: sstack_val) (shift: N) :=
let imp_chkr := imp_checker_fun (ctx_imp_chkr ctx) in
let cs := ctx_cs ctx in
let ocl1 := sstack_val_to_cliteral_w_shift sv1 shift in
let ocl2 := sstack_val_to_cliteral sv2 in
match ocl1, ocl2 with
| Some cl1, Some cl2 => imp_chkr cs (C_LE cl1 cl2)
| _, _ => false
end.
Definition chk_le_rshift_wrt_ctx (ctx: ctx_t) (sv1 sv2: sstack_val) (shift: N) :=
let imp_chkr := imp_checker_fun (ctx_imp_chkr ctx) in
let cs := ctx_cs ctx in
let ocl1 := sstack_val_to_cliteral sv1 in
let ocl2 := sstack_val_to_cliteral_w_shift sv2 shift in
match ocl1, ocl2 with
| Some cl1, Some cl2 => imp_chkr cs (C_LE cl1 cl2)
| _, _ => false
end.
Definition chk_le_lrshift_wrt_ctx (ctx: ctx_t) (sv1 sv2: sstack_val) (shift1: N) (shift2: N) :=
let imp_chkr := imp_checker_fun (ctx_imp_chkr ctx) in
let cs := ctx_cs ctx in
let ocl1 := sstack_val_to_cliteral_w_shift sv1 shift1 in
let ocl2 := sstack_val_to_cliteral_w_shift sv2 shift2 in
match ocl1, ocl2 with
| Some cl1, Some cl2 => imp_chkr cs (C_LE cl1 cl2)
| _, _ => false
end.
End Context.