-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathIdSimDemoSpec.v
363 lines (335 loc) · 10.2 KB
/
IdSimDemoSpec.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
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 DemoSpec.
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 CtypingC.
Require Import CopC.
Require Import sflib.
Set Implicit Arguments.
Local Opaque Z.mul Z.add Z.sub Z.div.
Inductive match_states_ext_demo
: unit -> state -> state -> SimMemExt.t' -> Prop :=
| match_ext
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_demo
tt
(mkstate i m_src)
(mkstate i m_tgt)
sm0
.
Section DEMOSOUNDSTATE.
Variable skenv_link: SkEnv.t.
Variable su: Sound.t.
Inductive sound_state_demo
: state -> Prop :=
| sound_state
i m
(WF: Sound.wf su)
(MEM: UnreachC.mem' su m)
(VALS: Sound.val su (Vlong i))
(SKE: su.(Unreach.ge_nb) = skenv_link.(Genv.genv_next))
:
sound_state_demo (mkstate i m).
End DEMOSOUNDSTATE.
Section DEMOSOUND.
Variable skenv_link: SkEnv.t.
Lemma demo_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_demo skenv_link); eauto.
econs; ss; i.
{ eapply UnreachC.liftspec; et. }
- inv INIT. ss. unfold Sound.args in SUARG. des_ifs. des. esplits.
+ refl.
+ destruct st_init.
econs; eauto; ss; inv SKENV; ss.
+ instantiate (1:=get_mem). ss. rewrite M. refl.
- exists su0. esplits; eauto.
+ refl.
+ inv SUST. inv FINAL. ss. econs; eauto. ss. clarify.
+ inv SUST. inv FINAL. ss. refl.
Qed.
End DEMOSOUND.
Inductive match_states_demo_internal:
state -> state -> meminj -> mem -> mem -> Prop :=
| match_inj_internal
i j m_src m_tgt
:
match_states_demo_internal
(mkstate i m_src)
(mkstate i m_tgt)
j m_src m_tgt
.
Inductive match_states_demo
: unit -> state -> state -> SimMemInj.t' -> Prop :=
| match_states_demo_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_demo_internal st_src st_tgt j m_src m_tgt)
(MWF: SimMemInj.wf' sm0)
:
match_states_demo
tt st_src st_tgt sm0
.
Lemma demo_id
(WF: Sk.wf DemoSpec.module)
:
exists mp,
(<<SIM: @ModPair.sim SimMemId.SimMemId SimMemId.SimSymbId SoundTop.Top mp>>)
/\ (<<SRC: mp.(ModPair.src) = (DemoSpec.module)>>)
/\ (<<TGT: mp.(ModPair.tgt) = (DemoSpec.module)>>)
.
Proof.
eapply any_id; eauto.
Qed.
Lemma demo_ext_unreach
(WF: Sk.wf DemoSpec.module)
:
exists mp,
(<<SIM: @ModPair.sim SimMemExt.SimMemExt SimMemExt.SimSymbExtends UnreachC.Unreach mp>>)
/\ (<<SRC: mp.(ModPair.src) = (DemoSpec.module)>>)
/\ (<<TGT: mp.(ModPair.tgt) = (DemoSpec.module)>>)
.
Proof.
eexists (ModPair.mk _ _ _); s.
esplits; eauto. instantiate (1:=SimSymbId.mk _ _).
econs; ss; i.
destruct SIMSKENVLINK.
exploit demo_unreach_local_preservation. i. des.
eapply match_states_sim with (match_states := match_states_ext_demo); ss.
- apply unit_ord_wf.
- ss. eauto.
- i. ss.
inv INITTGT. inv SAFESRC. inv H. clarify.
inv SIMARGS. ss.
esplits; eauto.
+ econs; eauto.
+ instantiate (2:=tt).
destruct x, st_init_tgt. ss.
rewrite VS, VS0 in VALS. inv VALS. inv H4. inv H2; ss.
+ ss.
- i. ss. des. inv SAFESRC.
set (sm_init_tgt := mkstate (get_arg st_init_src) (SimMemExt.tgt sm_arg)).
exists sm_init_tgt.
esplits. econs; ss.
+ inv SIMARGS; ss. rewrite VS in *. inv VALS. inv H1; inv H3. eauto.
+ inv SIMARGS; ss.
- i. ss. inv MATCH; eauto.
- i. ss. inv FINALSRC. inv MATCH.
esplits; eauto.
+ econs. ss.
+ econs; eauto. ss. clarify.
- right. ii. des.
esplits.
+ i. inv MATCH; ss.
unfold safe_modsem in H.
exploit H. eapply star_refl. ii. des; clarify.
+ ii. inv STEPTGT; inv MATCH; ss.
Unshelve. ss. eapply bot4.
Qed.
Lemma demo_ext_top
(WF: Sk.wf DemoSpec.module)
:
exists mp,
(<<SIM: @ModPair.sim SimMemExt.SimMemExt SimMemExt.SimSymbExtends SoundTop.Top mp>>)
/\ (<<SRC: mp.(ModPair.src) = (DemoSpec.module)>>)
/\ (<<TGT: mp.(ModPair.tgt) = (DemoSpec.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_demo); 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.
+ econs; eauto.
+ instantiate (2:=tt).
destruct x, st_init_tgt. ss.
rewrite VS, VS0 in VALS. inv VALS. inv H4. inv H2; ss.
+ ss.
- i. ss. des. inv SAFESRC.
set (sm_init_tgt := mkstate (get_arg st_init_src) (SimMemExt.tgt sm_arg)).
exists sm_init_tgt.
esplits. econs; ss.
+ inv SIMARGS; ss. rewrite VS in *. inv VALS. inv H1; inv H3. eauto.
+ inv SIMARGS; ss.
- i. ss. inv MATCH; eauto.
- i. ss. inv FINALSRC. inv MATCH.
esplits; eauto.
+ econs. ss.
+ econs; eauto. ss. clarify.
- right. ii. des.
esplits.
+ i. inv MATCH; ss.
unfold safe_modsem in H.
exploit H. eapply star_refl. ii. des; clarify.
+ ii. inv STEPTGT; inv MATCH; ss.
Unshelve. ss. eapply bot4.
Qed.
Lemma demo_inj_drop_bot
(WF: Sk.wf DemoSpec.module)
:
exists mp,
(<<SIM: @ModPair.sim SimMemInjC.SimMemInj SimSymbDrop.SimSymbDrop SoundTop.Top mp>>)
/\ (<<SRC: mp.(ModPair.src) = (DemoSpec.module)>>)
/\ (<<TGT: mp.(ModPair.tgt) = (DemoSpec.module)>>)
/\ (<<SSBOT: mp.(ModPair.ss) = SimSymbDrop.mk bot1 (DemoSpec.module) (DemoSpec.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_demo); 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.
+ econs; eauto.
+ refl.
+ destruct x, st_init_tgt. ss.
rewrite VS, VS0 in VALS. inv VALS. inv H4. inv H2; ss.
econs; ss; eauto.
+ ss.
- i. ss. des. inv SAFESRC.
set (sm_init_tgt := mkstate (get_arg st_init_src) (SimMemInj.tgt sm_arg)).
exists sm_init_tgt.
esplits. econs; ss.
+ inv SIMARGS; ss. rewrite VS in *. inv VALS. inv H1; inv H3. eauto.
+ inv SIMARGS; ss.
- i. ss. inv MATCH; eauto.
- i. ss. inv FINALSRC. inv MATCH; inv MATCHST.
esplits; eauto.
+ econs. ss.
+ econs; eauto; ss. clarify.
+ refl.
- right. ii. des.
esplits.
+ i. inv MATCH; ss.
unfold safe_modsem in H.
exploit H. eapply star_refl. ii. des; clarify.
+ ii. inv STEPTGT; inv MATCH; ss.
Unshelve. ss. eapply bot4.
Qed.
Lemma demo_inj_drop
(WF: Sk.wf (DemoSpec.module))
:
exists mp,
(<<SIM: @ModPair.sim SimMemInjC.SimMemInj SimSymbDrop.SimSymbDrop SoundTop.Top mp>>)
/\ (<<SRC: mp.(ModPair.src) = (DemoSpec.module)>>)
/\ (<<TGT: mp.(ModPair.tgt) = (DemoSpec.module)>>)
.
Proof.
exploit demo_inj_drop_bot; eauto. i. des. eauto.
Qed.
Lemma demo_inj_id
(WF: Sk.wf (DemoSpec.module))
:
exists mp,
(<<SIM: @ModPair.sim SimMemInjC.SimMemInj SimMemInjC.SimSymbId SoundTop.Top mp>>)
/\ (<<SRC: mp.(ModPair.src) = (DemoSpec.module)>>)
/\ (<<TGT: mp.(ModPair.tgt) = (DemoSpec.module)>>)
.
Proof.
eapply sim_inj_drop_bot_id. apply demo_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_demo_inv
: unit -> state -> state -> SimMem.t -> Prop :=
| match_states_demo_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_demo_internal st_src st_tgt j m_src m_tgt)
(MWF: SimMem.wf sm0)
:
match_states_demo_inv
tt st_src st_tgt sm0
.
Lemma demo_inj_inv
(WF: Sk.wf (DemoSpec.module))
:
exists mp,
(<<SIM: ModPair.sim mp>>)
/\ (<<SRC: mp.(ModPair.src) = (DemoSpec.module)>>)
/\ (<<TGT: mp.(ModPair.tgt) = (DemoSpec.module)>>)
.
Proof.
eexists (ModPair.mk _ _ _); s.
esplits; eauto. instantiate (1:=SimSymbDropInv.mk bot1 _ _).
econs; ss; i.
{ econs; ss; i; clarify.
inv WF. auto. }
eapply match_states_sim with (match_states := match_states_demo_inv); 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.
+ econs; eauto.
+ refl.
+ destruct x, st_init_tgt. ss.
rewrite VS, VS0 in VALS. inv VALS. inv H4. inv H2; ss.
econs; ss; eauto.
+ ss.
- i. ss. des. inv SAFESRC.
inv MWF. ss. inv WF0. ss.
set (sm_init_tgt := mkstate (get_arg st_init_src) (SimMemInj.tgt (SimMemInjInv.minj sm_arg))).
exists sm_init_tgt.
esplits. econs; ss.
+ inv SIMARGS; ss. rewrite VS in *. inv VALS. inv H1; inv H3. eauto.
+ inv SIMARGS; ss.
- i. ss. inv MATCH; eauto.
- i. ss. inv FINALSRC. inv MATCH; inv MATCHST.
esplits; eauto.
+ econs. ss.
+ econs; eauto; ss. clarify.
+ refl.
- right. ii. des.
esplits.
+ i. inv MATCH; ss.
unfold safe_modsem in H.
exploit H. eapply star_refl. ii. des; clarify.
+ ii. inv STEPTGT; inv MATCH; ss.
Unshelve. ss. eapply bot4.
Qed.
End INJINV.