-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGenericValues.v
312 lines (287 loc) · 7.08 KB
/
GenericValues.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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
Require Import syntax.
Require Import alist.
Require Import FMapWeakList.
Require Import Classical.
Require Import Coqlib.
Require Import infrastructure.
Require Import Metatheory.
Require Import vellvm.
Require Import TODO.
Require Import TODOProof.
Import Opsem.
Require Import sflib.
Module GVs.
Definition lessdef (v1 v2:GenericValue): Prop :=
list_forall2
(fun vc1 vc2 =>
Val.lessdef vc1.(fst) vc2.(fst) /\
vc1.(snd) = vc2.(snd) /\
(vc1.(fst) = Vundef -> vc2.(fst) <> Vundef -> Val.has_chunkb vc2.(fst) vc2.(snd)))
v1 v2.
Definition inject (alpha:meminj) (v1 v2:GenericValue): Prop :=
list_forall2
(fun vc1 vc2 =>
val_inject alpha vc1.(fst) vc2.(fst) /\
vc1.(snd) = vc2.(snd))
v1 v2.
Lemma lessdef_refl x:
<<REFL: lessdef x x>>.
Proof.
induction x; ii; ss; des.
{ econs. }
econs.
- esplits; eauto. i. ss.
- apply IHx.
Qed.
Lemma lessdef_trans
x y z
(LD01: lessdef x y)
(LD12: lessdef y z)
:
<<LD02: lessdef x z>>
.
Proof.
ginduction LD01; ii; ss.
inv LD12. des. destruct b0, b1, a1; ss. clarify.
econs; eauto.
- ss. splits; ss.
+ eapply Val.lessdef_trans; eauto.
+ i; clarify.
inv H2.
* eapply H5; eauto.
* eapply H1; eauto.
- eapply IHLD01; eauto.
Qed.
Lemma lessdef_inject_compose_single mij a b c
(LD: Val.lessdef a b)
(INJECT: memory_sim.MoreMem.val_inject mij b c):
<< INJECT: memory_sim.MoreMem.val_inject mij a c >>.
Proof.
inv LD; inv INJECT; ss; try (econs; eauto; fail).
Qed.
Lemma inject_lessdef_compose_single mij a b c
(INJECT: memory_sim.MoreMem.val_inject mij a b)
(LD: Val.lessdef b c):
<< INJECT: memory_sim.MoreMem.val_inject mij a c >>.
Proof.
inv LD; inv INJECT; ss; try (econs; eauto; fail).
Qed.
Lemma lessdef_inject_compose mij a b c
(LD: lessdef a b)
(INJECT: genericvalues_inject.gv_inject mij b c):
<< INJECT: genericvalues_inject.gv_inject mij a c >>.
Proof.
red.
generalize dependent a.
generalize dependent c.
induction b; ii; ss.
{ inv LD. destruct c; ss. }
inv INJECT.
inv LD; ss. des. destruct a1; ss. clarify.
econs; eauto.
{ i. clarify. inv H4; ss.
- eapply CHUNK; eauto.
- destruct (classic (v1 = Vundef)).
+ clarify.
inv H1. eapply CHUNK; eauto.
+ inv H1; try eapply H2; ss.
}
eapply lessdef_inject_compose_single; eauto.
Qed.
Lemma inject_lessdef_compose mij a b c
(INJECT: genericvalues_inject.gv_inject mij a b)
(LD: lessdef b c):
<< INJECT: genericvalues_inject.gv_inject mij a c >>.
Proof.
red.
generalize dependent a.
generalize dependent c.
induction b; ii; ss.
{ inv LD. destruct a; ss. }
inv INJECT.
inv LD; ss. des. destruct b1; ss. clarify.
econs; eauto.
- i. clarify.
destruct (classic (v2 = Vundef)).
+ clarify. apply H4; ss.
+ inv H1; ss.
apply CHUNK; ss.
- eapply inject_lessdef_compose_single; eauto.
Qed.
End GVs.
(* TODO: position *)
Inductive error_state conf st: Prop :=
| error_state_intro
(STUCK: stuck_state conf st)
(NFINAL: s_isFinalState conf st = None)
.
Lemma final_stuck
conf st retval
(FINAL: s_isFinalState conf st = Some retval):
stuck_state conf st.
Proof.
ii. des. destruct st, EC0. ss.
destruct CurCmds0, Terminator0, ECS0; ss.
- inv H.
- inv H.
Qed.
Lemma nerror_stuck_final
conf st
(NERROR: ~ error_state conf st)
(STUCK: stuck_state conf st):
exists retval, s_isFinalState conf st = Some retval.
Proof.
destruct (s_isFinalState conf st) eqn:X; eauto.
exfalso. apply NERROR. econs; ss.
Qed.
Lemma nerror_nfinal_nstuck
conf st1
(NERROR: ~ error_state conf st1)
(NFINAL: s_isFinalState conf st1 = None):
exists st2 e, sInsn conf st1 st2 e.
Proof.
destruct (classic (stuck_state conf st1)).
- contradict NERROR. econs; ss.
- apply NNPP in H. ss.
Qed.
Definition val2block val :=
match val with
| Vptr blck _ => Some blck
| _ => None
end.
Definition GV2blocks (gval: GenericValue) := filter_map (val2block <*> fst) gval.
Lemma GV2ptr_In_GV2blocks
td sz gv b i
(GV2PTR: GV2ptr td sz gv = Some (Values.Vptr b i))
:
<<GV2BLOCKS: In b (GV2blocks gv)>>
.
Proof.
induction gv; ii; des; ss.
destruct a; ss. des_ifs. ss.
left. ss.
Qed.
Lemma GV2blocks_cons
v m gv
:
<<CONS_INV: GV2blocks ((v, m) :: gv) = GV2blocks [(v, m)] ++ GV2blocks gv>>
.
Proof.
red.
unfold GV2blocks in *.
unfold compose in *.
ss.
des_ifs.
Qed.
Lemma GV2blocks_In_cons
b v1 m gv1
(IN: In b (GV2blocks ((v1, m) :: gv1)))
:
<<IN: In b (GV2blocks [(v1, m)]) \/ In b (GV2blocks gv1)>>
.
Proof.
erewrite GV2blocks_cons in IN.
apply in_app in IN.
ss.
Qed.
Lemma GV2blocks_in_inv
a gvs
(IN: In a (GV2blocks gvs))
:
<<INV: exists ofs mc, In ((Values.Vptr a ofs), mc) gvs>>
.
Proof.
induction gvs; ii; ss; des; ss.
destruct a0; ss.
eapply GV2blocks_In_cons in IN.
des.
- destruct v; ss. des; ss.
clarify.
esplits; eauto.
- exploit IHgvs; eauto; []; ii; des.
esplits; eauto.
Qed.
Lemma GV2blocks_incl
gvs1 gvs2
(INCL: incl gvs1 gvs2)
:
<<INCL: incl (GV2blocks gvs1) (GV2blocks gvs2)>>
.
Proof.
ii.
apply GV2blocks_in_inv in H.
des.
eapply TODOProof.filter_map_spec; eauto.
Qed.
Lemma GV2blocks_lift
z ofs mc gvs'
(IN : In (Values.Vptr z ofs, mc) gvs')
:
<<IN: In z (GV2blocks gvs')>>
.
Proof.
induction gvs'; ii; ss; des; ss; clarify.
- cbn. left; ss.
- exploit IHgvs'; eauto; []; ii; des.
cbn.
unfold compose in *.
des_ifs.
cbn.
right; ss.
Qed.
Lemma GV2blocks_app_inv z xs ys
(IN: In z (GV2blocks (xs ++ ys)))
:
<<IN: In z (GV2blocks xs) \/ In z (GV2blocks ys)>>
.
Proof.
generalize dependent ys.
induction xs; ii; ss; des; ss.
{ right; ss. }
cbn in IN.
unfold compose in *; ss.
destruct a; ss.
(* destruct v; ss. *)
des_ifs; ss; cbn.
- unfold compose; ss.
des; ss; subst.
+ left. des_ifs.
ss. left; ss.
+ des_ifs.
eapply TODOProof.filter_map_inv in IN.
des.
eapply in_app in IN.
des.
* left.
ss. right; ss.
eapply TODOProof.filter_map_spec; eauto.
* right.
eapply TODOProof.filter_map_spec; eauto.
-
unfold compose; ss.
eapply TODOProof.filter_map_inv in IN.
des.
eapply in_app in IN.
des.
+ left. des_ifs.
eapply TODOProof.filter_map_spec; eauto.
+ right.
eapply TODOProof.filter_map_spec; eauto.
Qed.
(* TODO: Why error_state is defined in GenericValues? *)
(* -> It is used in SoundPostcondCmdAdd. Is it essential? *)
Lemma error_state_neg conf st
(NERROR_SRC: ~error_state conf st)
:
<<NERROR_SRC: ~(stuck_state conf st) \/ exists retval, s_isFinalState conf st = Some retval>>
.
Proof.
red. unfold not in NERROR_SRC.
apply imply_to_or.
i.
destruct (s_isFinalState conf st) eqn:T.
{ esplits; eauto. }
exploit NERROR_SRC; eauto.
{ econs; eauto. }
i; ss.
Qed.