-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathIdSimMutrecAB.v
409 lines (362 loc) · 11.4 KB
/
IdSimMutrecAB.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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
Require Import Sem SimProg Skeleton Mod ModSem SimMod SimModSem SimSymb SimMem Sound SimSymb.
Require Import Cop Ctypes ClightC.
Require SimMemId SimMemExt SimMemInj.
Require SoundTop UnreachC.
Require SimSymbId SimSymbDrop.
Require Import MutrecABspec.
Require Import CoqlibC.
Require Import ValuesC.
Require Import LinkingC.
Require Import MapsC.
Require Import AxiomsC.
Require Import Ord.
Require Import MemoryC.
Require Import SmallstepC.
Require Import Events.
Require Import Preservation.
Require Import Integers.
Require Import LocationsC Conventions.
Require Import MatchSimModSem ModSemProps.
Require Import IdSimExtra.
Require Import CopC.
Require Import sflib.
Set Implicit Arguments.
Local Opaque Z.mul Z.add Z.sub Z.div.
Inductive match_states_ext_ab
: unit -> state -> state -> SimMemExt.t' -> Prop :=
| match_ext_Callstate
i m_src m_tgt sm0
(MWFSRC: m_src = sm0.(SimMemExt.src))
(MWFTGT: m_tgt = sm0.(SimMemExt.tgt))
(MWF: Mem.extends m_src m_tgt)
:
match_states_ext_ab
tt
(Callstate i m_src)
(Callstate i m_tgt)
sm0
| match_return_Callstate
i m_src m_tgt sm0
(MWFSRC: m_src = sm0.(SimMemExt.src))
(MWFTGT: m_tgt = sm0.(SimMemExt.tgt))
(MWF: Mem.extends m_src m_tgt)
:
match_states_ext_ab
tt
(Returnstate i m_src)
(Returnstate i m_tgt)
sm0.
Section ABSOUNDSTATE.
Variable skenv_link: SkEnv.t.
Variable su: Sound.t.
Inductive sound_state_ab
: state -> Prop :=
| sound_Callstate
i m
(WF: Sound.wf su)
(MEM: UnreachC.mem' su m)
(SKE: su.(Unreach.ge_nb) = skenv_link.(Genv.genv_next))
:
sound_state_ab (Callstate i m)
| sound_Returnstate
i m
(WF: Sound.wf su)
(MEM: UnreachC.mem' su m)
(SKE: su.(Unreach.ge_nb) = skenv_link.(Genv.genv_next))
:
sound_state_ab (Returnstate i m)
.
End ABSOUNDSTATE.
Section ABSOUND.
Variable skenv_link: SkEnv.t.
Lemma ab_unreach_local_preservation
:
exists sound_state, <<PRSV: local_preservation (modsem skenv_link tt) sound_state>>
.
Proof.
esplits.
eapply local_preservation_strong_horizontal_spec with (lift := UnreachC.le') (sound_state := sound_state_ab skenv_link); eauto.
econs; ss; i.
{ eapply UnreachC.liftspec; et. }
- inv INIT. ss. unfold Sound.args in SUARG. des_ifs. des. esplits.
+ refl.
+ ss. econs; eauto. inv SKENV. ss.
+ instantiate (1:=get_mem). ss. refl.
- inv STEP; inv SUST. esplits; eauto.
+ refl.
+ econs; eauto.
+ ss. refl.
- inv FINAL; inv SUST. esplits; eauto.
+ refl.
+ econs; eauto. ss.
+ ss. refl.
Qed.
End ABSOUND.
Inductive match_states_ab_internal:
state -> state -> meminj -> mem -> mem -> Prop :=
| match_Callstate
i m_src m_tgt j
:
match_states_ab_internal
(Callstate i m_src)
(Callstate i m_tgt)
j m_src m_tgt
| match_Returnstate
i m_src m_tgt j
:
match_states_ab_internal
(Returnstate i m_src)
(Returnstate i m_tgt)
j m_src m_tgt
.
Inductive match_states_ab
: unit -> state -> state -> SimMemInj.t' -> Prop :=
| match_states_ab_intro
st_src st_tgt j m_src m_tgt sm0
(MWFSRC: m_src = sm0.(SimMemInj.src))
(MWFTGT: m_tgt = sm0.(SimMemInj.tgt))
(MWFINJ: j = sm0.(SimMemInj.inj))
(MATCHST: match_states_ab_internal st_src st_tgt j m_src m_tgt)
(MWF: SimMemInj.wf' sm0)
:
match_states_ab
tt st_src st_tgt sm0
.
Lemma a_id
(WF: Sk.wf MutrecABspec.module)
:
exists mp,
(<<SIM: @ModPair.sim SimMemId.SimMemId SimMemId.SimSymbId SoundTop.Top mp>>)
/\ (<<SRC: mp.(ModPair.src) = (MutrecABspec.module)>>)
/\ (<<TGT: mp.(ModPair.tgt) = (MutrecABspec.module)>>)
.
Proof.
eapply any_id; auto.
Qed.
Lemma a_ext_unreach
(WF: Sk.wf MutrecABspec.module)
:
exists mp,
(<<SIM: @ModPair.sim SimMemExt.SimMemExt SimMemExt.SimSymbExtends UnreachC.Unreach mp>>)
/\ (<<SRC: mp.(ModPair.src) = (MutrecABspec.module)>>)
/\ (<<TGT: mp.(ModPair.tgt) = (MutrecABspec.module)>>)
.
Proof.
eexists (ModPair.mk _ _ _); s.
esplits; eauto. instantiate (1:=SimSymbId.mk _ _).
econs; ss; i.
destruct SIMSKENVLINK.
exploit ab_unreach_local_preservation. i. des.
eapply match_states_sim with (match_states := match_states_ext_ab)
(match_states_at := top4); ss.
- apply unit_ord_wf.
- eauto.
- i. ss. inv INITTGT. inv SAFESRC. inv H. clarify.
inv SIMARGS; ss. esplits; eauto; ss.
+ econs; eauto.
+ assert (i = i0).
{ subst. inv VALS. inv H2. ss. }
subst. econs; eauto. ss.
- i. ss. des. inv SAFESRC. esplits. econs; ss.
+ inv SIMARGS; ss. inv FPTR; eauto. clarify.
+ instantiate (1:=i). inv SIMARGS; ss.
rewrite VS in *. inv VALS. inv H3. inv H1. ss.
+ auto.
- i. inv MATCH; auto.
- i. ss. inv FINALSRC. inv MATCH.
esplits; eauto.
+ econs.
+ econs; eauto. econs.
- right. ii. des.
esplits.
+ i. inv MATCH; ss.
* unfold ModSem.is_step. do 2 eexists. ss.
* unfold safe_modsem in H.
exploit H. eapply star_refl. ii. des; clarify. inv EVSTEP.
+ ii. inv STEPTGT; inv MATCH; ss.
esplits; eauto.
{ left. eapply plus_one. econs. }
econs; eauto.
Qed.
Lemma a_ext_top
(WF: Sk.wf MutrecABspec.module)
:
exists mp,
(<<SIM: @ModPair.sim SimMemExt.SimMemExt SimMemExt.SimSymbExtends SoundTop.Top mp>>)
/\ (<<SRC: mp.(ModPair.src) = (MutrecABspec.module)>>)
/\ (<<TGT: mp.(ModPair.tgt) = (MutrecABspec.module)>>)
.
Proof.
eexists (ModPair.mk _ _ _); s.
esplits; eauto. instantiate (1:=SimSymbId.mk _ _).
econs; ss; i.
destruct SIMSKENVLINK.
eapply match_states_sim with (match_states := match_states_ext_ab)
(match_states_at := top4); ss.
- apply unit_ord_wf.
- eapply SoundTop.sound_state_local_preservation.
- i. ss. inv INITTGT. inv SAFESRC. inv H. clarify.
inv SIMARGS; ss. esplits; eauto; ss.
+ econs; eauto.
+ assert (i = i0).
{ subst. inv VALS. inv H2. ss. }
subst. econs; eauto. ss.
- i. ss. des. inv SAFESRC. esplits. econs; ss.
+ inv SIMARGS; ss. inv FPTR; eauto. clarify.
+ instantiate (1:=i). inv SIMARGS; ss.
rewrite VS in *. inv VALS. inv H3. inv H1. ss.
+ auto.
- i. inv MATCH; auto.
- i. ss. inv FINALSRC. inv MATCH.
esplits; eauto.
+ econs.
+ econs; eauto. econs.
- right. ii. des.
esplits.
+ i. inv MATCH; ss.
* unfold ModSem.is_step. do 2 eexists. ss.
* unfold safe_modsem in H.
exploit H. eapply star_refl. ii. des; clarify. inv EVSTEP.
+ ii. inv STEPTGT; inv MATCH; ss.
esplits; eauto.
{ left. eapply plus_one. econs. }
econs; eauto.
Qed.
Lemma ab_inj_drop_bot
(WF: Sk.wf (MutrecABspec.module))
:
exists mp,
(<<SIM: @ModPair.sim SimMemInjC.SimMemInj SimSymbDrop.SimSymbDrop SoundTop.Top mp>>)
/\ (<<SRC: mp.(ModPair.src) = (MutrecABspec.module)>>)
/\ (<<TGT: mp.(ModPair.tgt) = (MutrecABspec.module)>>)
/\ (<<SSBOT: mp.(ModPair.ss) = SimSymbDrop.mk bot1 (MutrecABspec.module) (MutrecABspec.module)>>)
.
Proof.
eexists (ModPair.mk _ _ _); s.
esplits; eauto.
econs; ss; i.
{ econs; ss; i; clarify.
inv WF. auto. }
eapply match_states_sim with (match_states := match_states_ab)
(match_states_at := top4); ss.
- apply unit_ord_wf.
- eapply SoundTop.sound_state_local_preservation.
- i. ss. inv INITTGT. inv SAFESRC. inv SIMARGS; ss. inv H.
esplits; eauto.
+ econs; eauto.
+ refl.
+ econs; eauto.
assert (i = i0).
{ subst. inv VALS. inv H2; ss. inv VS0. ss. }
subst i0. econs.
- i. des. inv SAFESRC. inv SIMARGS; ss.
rewrite VS in *. inv VALS. inv H1. inv H3.
unfold Genv.find_funct, Genv.find_funct_ptr in *. des_ifs.
inv SIMSKENV. ss. inv SIMSKE. ss. inv FPTR. exploit SIMDEF; eauto.
i. des. clarify. esplits; eauto. econs; ss; eauto.
unfold Genv.find_funct_ptr. des_ifs.
- i. inv MATCH; eauto.
- i. ss. inv FINALSRC. inv MATCH. inv MATCHST. esplits; eauto.
+ econs.
+ econs; eauto. econs.
+ refl.
- right. ii. des.
esplits.
+ i. inv MATCH; inv MATCHST; ss.
* unfold ModSem.is_step. do 2 eexists. ss.
* unfold safe_modsem in H.
exploit H. eapply star_refl. ii. des; clarify. inv EVSTEP.
+ ii. inv STEPTGT; inv MATCH; inv MATCHST; ss.
esplits; eauto.
{ left. eapply plus_one. econs. }
{ refl. }
econs; eauto. econs; eauto.
Qed.
Lemma ab_inj_drop
(WF: Sk.wf (MutrecABspec.module))
:
exists mp,
(<<SIM: @ModPair.sim SimMemInjC.SimMemInj SimSymbDrop.SimSymbDrop SoundTop.Top mp>>)
/\ (<<SRC: mp.(ModPair.src) = (MutrecABspec.module)>>)
/\ (<<TGT: mp.(ModPair.tgt) = (MutrecABspec.module)>>)
.
Proof.
exploit ab_inj_drop_bot; eauto. i. des. eauto.
Qed.
Lemma ab_inj_id
(WF: Sk.wf (MutrecABspec.module))
:
exists mp,
(<<SIM: @ModPair.sim SimMemInjC.SimMemInj SimMemInjC.SimSymbId SoundTop.Top mp>>)
/\ (<<SRC: mp.(ModPair.src) = (MutrecABspec.module)>>)
/\ (<<TGT: mp.(ModPair.tgt) = (MutrecABspec.module)>>)
.
Proof.
eapply sim_inj_drop_bot_id. apply ab_inj_drop_bot; auto.
Qed.
Require Import IdSimInvExtra.
Section INJINV.
Local Existing Instance SimSymbDropInv.SimMemInvTop.
Local Existing Instance SimSymbDropInv.SimSymbDropInv.
Local Existing Instance SoundTop.Top.
Inductive match_states_ab_inv
: unit -> state -> state -> SimMem.t -> Prop :=
| match_states_ab_inv_intro
st_src st_tgt j m_src m_tgt sm0
(MWFSRC: m_src = sm0.(SimMem.src))
(MWFTGT: m_tgt = sm0.(SimMem.tgt))
(MWFINJ: j = sm0.(SimMemInjInv.minj).(SimMemInj.inj))
(MATCHST: match_states_ab_internal st_src st_tgt j m_src m_tgt)
(MWF: SimMem.wf sm0)
:
match_states_ab_inv
tt st_src st_tgt sm0.
Lemma ab_inj_inv_id
(WF: Sk.wf (MutrecABspec.module))
:
exists mp,
(<<SIM: ModPair.sim mp>>)
/\ (<<SRC: mp.(ModPair.src) = (MutrecABspec.module)>>)
/\ (<<TGT: mp.(ModPair.tgt) = (MutrecABspec.module)>>)
.
Proof.
eexists (ModPair.mk _ _ _); s.
esplits; eauto. instantiate (1:=SimSymbDropInv.mk bot1 _ _).
econs; ss; i.
{ econs; ss; i; clarify. inv WF. eauto. }
eapply match_states_sim with (match_states := match_states_ab_inv)
(match_states_at := top4); ss.
- apply unit_ord_wf.
- eapply SoundTop.sound_state_local_preservation.
- i. ss. inv INITTGT. inv SAFESRC. inv SIMARGS; ss. inv H.
esplits; eauto.
+ econs; eauto.
+ refl.
+ econs; eauto.
assert (i = i0).
{ subst. inv VALS. inv H2; ss. inv VS0. ss. }
subst i0. econs.
- i. des. inv SAFESRC. inv SIMARGS; ss.
rewrite VS in *. inv VALS. inv H1. inv H3.
unfold Genv.find_funct, Genv.find_funct_ptr in *. des_ifs.
inv SIMSKENV. ss. inv SIMSKE. ss. inv FPTR. exploit SIMDEF; eauto.
i. des. clarify. esplits; eauto. econs; ss; eauto.
unfold Genv.find_funct_ptr. des_ifs.
- i. inv MATCH; eauto.
- i. ss. inv FINALSRC. inv MATCH. inv MATCHST. esplits; eauto.
+ econs.
+ econs; eauto. econs.
+ refl.
- right. ii. des.
esplits.
+ i. inv MATCH; inv MATCHST; ss.
* unfold ModSem.is_step. do 2 eexists. ss.
* unfold safe_modsem in H.
exploit H. eapply star_refl. ii. des; clarify. inv EVSTEP.
+ ii. inv STEPTGT; inv MATCH; inv MATCHST; ss.
esplits; eauto.
{ left. eapply plus_one. econs. }
{ refl. }
econs; eauto. econs; eauto.
Qed.
End INJINV.