source: src/Clight/CexecSound.ma @ 891

Last change on this file since 891 was 891, checked in by campbell, 8 years ago

Revise proofs affected by recent matita change.

File size: 23.7 KB
Line 
1include "Clight/Cexec.ma".
2
3(*include "Plogic/connectives.ma".*)
4
5(* Is rather careful about using destruct because it currently uses excessive
6   normalization. *)
7lemma exec_bool_of_val_sound: ∀v,ty,r.
8 exec_bool_of_val v ty = OK ? r → bool_of_val v ty (of_bool r).
9#v #ty #r
10cases v; [ | #i | #f | #r1 | #r' #b #pc #of ]
11cases ty; [ 2,11,20,29,38: #sz #sg | 3,12,21,30,39: #sz | 4,13,22,31,40: #rg #ty | 5,14,23,32,41: #r #ty #n | 6,15,24,33,42: #args #rty | 7,8,16,17,25,26,34,35,43,44: #id #fs | 9,18,27,36,45: #r #id ]
12#H whd in H:(??%?);
13[ 2: lapply (eq_spec i zero) cases (eq i zero) in H ⊢ %
14  [ #E1 #E2 destruct @bool_of_val_false @is_false_int
15  | #E1 #E2 >(?:r=¬false) [ @bool_of_val_true @is_true_int_int @E2 | destruct @refl ]
16  ]
17| 8: cases (eq_dec f Fzero)
18  [ #e >e in H ⊢ % >Feq_zero_true #E destruct @bool_of_val_false @is_false_float
19  | #ne >Feq_zero_false in H // #E >(?:r=¬false) [ @bool_of_val_true @is_true_float @ne | destruct @refl ]
20  ]
21| 14: >(?:r=false) [ @bool_of_val_false @is_false_pointer | destruct @refl ]
22| 15: >(?:r=true) [ @bool_of_val_true @is_true_pointer_pointer | destruct @refl ]
23| *: destruct
24] qed.
25
26lemma bool_val_distinct: Vtrue ≠ Vfalse.
27% #H whd in H:(??%%); destruct; @(absurd ? e0 one_not_zero)
28qed.
29
30lemma bool_of: ∀v,ty,b. bool_of_val v ty (of_bool b) →
31  if b then is_true v ty else is_false v ty.
32#v #ty #b cases b; #H inversion H; #v' #ty' #H' #ev #et #ev //;
33@False_ind @(absurd ? ev ?)
34[ 2: @sym_neq ] @bool_val_distinct
35qed.
36
37lemma try_cast_null_sound: ∀m,i,ty,ty',v'. try_cast_null m i ty ty' = OK ? v' → cast m (Vint i) ty ty' v'.
38#m #i #ty #ty' #v'
39whd in ⊢ (??%? → ?);
40lapply (eq_spec i zero); cases (eq i zero);
41[ #e >e
42    cases ty; [ | #sz #sg | #fs | #sp #ty | #sp #ty #n | #args #rty | #id #fs | #id #fs | #r #id ]
43    whd in ⊢ (??%? → ?); #H destruct;
44    cases ty' in H ⊢ %; [ | #sz #sg | #fs | #sp #ty | #sp #ty #n | #args #rty | #id #fs | #id #fs | #r #id ]
45    whd in ⊢ (??%? → ?); #H destruct (H); @cast_ip_z //;
46| #_ whd in ⊢ (??%? → ?); #H destruct
47]
48qed.
49
50definition exec_cast_sound : ∀m:mem. ∀v:val. ∀ty:type. ∀ty':type. ∀v':val. exec_cast m v ty ty' = OK ? v' → cast m v ty ty' v'.
51#m #v #ty #ty' #v'
52cases v;
53[ #H whd in H:(??%?); destruct;
54| #i cases ty;
55  [ #H whd in H:(??%?); destruct;
56  | 3: #a #H whd in H:(??%?); destruct;
57  | 7,8,9: #a #b #H whd in H:(??%?); destruct;
58  | #sz1 #si1 cases ty';
59    [ #H whd in H:(??%?); destruct;
60    | 3: #a #H whd in H:(??%?); destruct; //
61    | 2,7,8,9: #a #b #H whd in H:(??%?); destruct; //
62    | 4,5,6: [ #sp #ty'' letin t ≝ (Tpointer sp ty'')
63                 | #sp #ty'' #n letin t ≝ (Tarray sp ty'' n)
64                 | #args #rty letin t ≝ (Tfunction args rty) ]
65        whd in ⊢ (??%? → ?);
66        lapply (try_cast_null_sound m i (Tint sz1 si1) t v');
67        cases (try_cast_null m i (Tint sz1 si1) t);
68        [ 1,3,5: #v'' #H' #e @H' @e
69        | *: #m #_ whd in ⊢ (??%? → ?); #H destruct (H);
70        ]
71    ]
72  | *: [ #sp #ty'' letin t ≝ (Tpointer sp ty'')
73           | #sp #ty'' #n letin t ≝ (Tarray sp ty'' n)
74           | #args #rty letin t ≝ (Tfunction args rty) ]
75        whd in ⊢ (??%? → ?);
76        lapply (try_cast_null_sound m i t ty' v');
77        cases (try_cast_null m i t ty');
78        [ 1,3,5: #v'' #H' #e @H' @e
79        | *: #m #_ whd in ⊢ (??%? → ?); #H destruct (H);
80        ]
81  ]
82| #f cases ty;  [ 3: #x | 2,4,6,7,8,9: #x #y | 5: #x #y #z ]
83                    [ cases ty'; [ #e | 3: #a #e | 2,4,6,7,8,9: #a #b #e | #a #b #c #e ]
84                        whd in e:(??%?); destruct; //;
85                    | *: #e whd in e:(??%?); destruct
86                    ]
87| #r cases ty; [ 3: #x | 2,4,6,7,8,9: #x #y | 5: #x #y #z ]
88    whd in ⊢ (??%? → ?); #H destruct; cases (eq_region_dec r ?) in H;
89    whd in ⊢ (? → ??%? → ?); #H1 #H2 destruct;
90    cases ty' in H2; normalize; try #a try #b try #c try #d destruct;
91    @cast_pp_z //;
92| #r #b #pc #of whd in ⊢ (??%? → ?) #e
93    elim (bind_inversion ????? e) #s * #es #e'
94    elim (bind_inversion ????? e') #u * #eu #e'' -e';
95    elim (bind_inversion ????? e'') #s' * #es' #e'''; -e'';
96    cut (type_region ty s);
97    [ cases ty in es:(??%?) ⊢ %; [ #e | 3: #a #e | 2,4,6,7,8,9: #a #b #e | #a #b #c #e ]
98        whd in e:(??%?); destruct; //;
99    | #Hty
100        cut (type_region ty' s');
101        [ cases ty' in es' ⊢ %; [ #e | 3: #a #e | 2,4,6,7,8,9: #a #b #e | #a #b #c #e ]
102            whd in e:(??%?); destruct; //;
103        | #Hty'
104            cut (s = r). elim (eq_region_dec r s) in eu; //; normalize; #_ #e destruct.
105            #e >e in Hty #Hty
106            cases (pointer_compat_dec b s') in e'''
107            #Hcompat #e''' whd in e''':(??%?); destruct (e'''); /2/
108        ]
109    ]
110] qed.
111
112let rec expr_lvalue_ind
113  (P:expr → Prop)
114  (Q:expr_descr → type → Prop)
115  (ci:∀ty,i.P (Expr (Econst_int i) ty))
116  (cf:∀ty,f.P (Expr (Econst_float f) ty))
117  (lv:∀e,ty. Q e ty → Plvalue P e ty)
118  (vr:∀v,ty.Q (Evar v) ty)
119  (dr:∀e,ty.P e → Q (Ederef e) ty)
120  (ao:∀ty,e,ty'.Q e ty' → P (Expr (Eaddrof (Expr e ty')) ty))
121  (uo:∀ty,op,e.P e → P (Expr (Eunop op e) ty))
122  (bo:∀ty,op,e1,e2.P e1 → P e2 → P (Expr (Ebinop op e1 e2) ty))
123  (ca:∀ty,ty',e.P e → P (Expr (Ecast ty' e) ty))
124  (cd:∀ty,e1,e2,e3.P e1 → P e2 → P e3 → P (Expr (Econdition e1 e2 e3) ty))
125  (ab:∀ty,e1,e2.P e1 → P e2 → P (Expr (Eandbool e1 e2) ty))
126  (ob:∀ty,e1,e2.P e1 → P e2 → P (Expr (Eorbool e1 e2) ty))
127  (sz:∀ty,ty'. P (Expr (Esizeof ty') ty))
128  (fl:∀ty,e,ty',i. Q e ty' → Q (Efield (Expr e ty') i) ty)
129  (co:∀ty,l,e. P e → P (Expr (Ecost l e) ty))
130  (xx:∀e,ty. is_not_lvalue e → Q e ty)
131  (e:expr) on e : P e ≝
132match e with
133[ Expr e' ty ⇒
134  match e' with
135  [ Econst_int i ⇒ ci ty i
136  | Econst_float f ⇒ cf ty f
137  | Evar v ⇒ lv (Evar v) ty (vr v ty)
138  | Ederef e'' ⇒ lv (Ederef e'') ty (dr e'' ty (expr_lvalue_ind P Q ci cf lv vr dr ao uo bo ca cd ab ob sz fl co xx e''))
139  | Eaddrof e'' ⇒ match e'' with [ Expr e0 ty0 ⇒ ao ty e0 ty0 (lvalue_expr_ind P Q ci cf lv vr dr ao uo bo ca cd ab ob sz fl co xx e0 ty0) ]
140  | Eunop op e'' ⇒ uo ty op e'' (expr_lvalue_ind P Q ci cf lv vr dr ao uo bo ca cd ab ob sz fl co xx e'')
141  | Ebinop op e1 e2 ⇒ bo ty op e1 e2 (expr_lvalue_ind P Q ci cf lv vr dr ao uo bo ca cd ab ob sz fl co xx e1) (expr_lvalue_ind P Q ci cf lv vr dr ao uo bo ca cd ab ob sz fl co xx e2)
142  | Ecast ty' e'' ⇒ ca ty ty' e'' (expr_lvalue_ind P Q ci cf lv vr dr ao uo bo ca cd ab ob sz fl co xx e'')
143  | Econdition e1 e2 e3 ⇒ cd ty e1 e2 e3 (expr_lvalue_ind P Q ci cf lv vr dr ao uo bo ca cd ab ob sz fl co xx e1) (expr_lvalue_ind P Q ci cf lv vr dr ao uo bo ca cd ab ob sz fl co xx e2) (expr_lvalue_ind P Q ci cf lv vr dr ao uo bo ca cd ab ob sz fl co xx e3)
144  | Eandbool e1 e2 ⇒ ab ty e1 e2 (expr_lvalue_ind P Q ci cf lv vr dr ao uo bo ca cd ab ob sz fl co xx e1) (expr_lvalue_ind P Q ci cf lv vr dr ao uo bo ca cd ab ob sz fl co xx e2)
145  | Eorbool e1 e2 ⇒ ob ty e1 e2 (expr_lvalue_ind P Q ci cf lv vr dr ao uo bo ca cd ab ob sz fl co xx e1) (expr_lvalue_ind P Q ci cf lv vr dr ao uo bo ca cd ab ob sz fl co xx e2)
146  | Esizeof ty' ⇒ sz ty ty'
147  | Efield e'' i ⇒ match e'' with [ Expr ef tyf ⇒ lv (Efield (Expr ef tyf) i) ty (fl ty ef tyf i (lvalue_expr_ind P Q ci cf lv vr dr ao uo bo ca cd ab ob sz fl co xx ef tyf)) ]
148  | Ecost l e'' ⇒ co ty l e'' (expr_lvalue_ind P Q ci cf lv vr dr ao uo bo ca cd ab ob sz fl co xx e'')
149  ]
150]
151and lvalue_expr_ind
152  (P:expr → Prop)
153  (Q:expr_descr → type → Prop)
154  (ci:∀ty,i.P (Expr (Econst_int i) ty))
155  (cf:∀ty,f.P (Expr (Econst_float f) ty))
156  (lv:∀e,ty. Q e ty → Plvalue P e ty)
157  (vr:∀v,ty.Q (Evar v) ty)
158  (dr:∀e,ty.P e → Q (Ederef e) ty)
159  (ao:∀ty,e,ty'.Q e ty' → P (Expr (Eaddrof (Expr e ty')) ty))
160  (uo:∀ty,op,e.P e → P (Expr (Eunop op e) ty))
161  (bo:∀ty,op,e1,e2.P e1 → P e2 → P (Expr (Ebinop op e1 e2) ty))
162  (ca:∀ty,ty',e.P e → P (Expr (Ecast ty' e) ty))
163  (cd:∀ty,e1,e2,e3.P e1 → P e2 → P e3 → P (Expr (Econdition e1 e2 e3) ty))
164  (ab:∀ty,e1,e2.P e1 → P e2 → P (Expr (Eandbool e1 e2) ty))
165  (ob:∀ty,e1,e2.P e1 → P e2 → P (Expr (Eorbool e1 e2) ty))
166  (sz:∀ty,ty'. P (Expr (Esizeof ty') ty))
167  (fl:∀ty,e,ty',i. Q e ty' → Q (Efield (Expr e ty') i) ty)
168  (co:∀ty,l,e. P e → P (Expr (Ecost l e) ty))
169  (xx:∀e,ty. is_not_lvalue e → Q e ty)
170  (e:expr_descr) (ty:type) on e : Q e ty ≝
171  match e return λe0. Q e0 ty with
172  [ Evar v ⇒ vr v ty
173  | Ederef e'' ⇒ dr e'' ty (expr_lvalue_ind P Q ci cf lv vr dr ao uo bo ca cd ab ob sz fl co xx e'')
174  | Efield e' i ⇒ match e' return λe1.Q (Efield e1 i) ty with [ Expr e'' ty'' ⇒ fl ty e'' ty'' i (lvalue_expr_ind P Q ci cf lv vr dr ao uo bo ca cd ab ob sz fl co xx e'' ty'') ]
175  | _ ⇒ xx ? ty ?
176  ]. whd; @I qed.
177
178
179theorem exec_expr_sound: ∀ge:genv. ∀en:env. ∀m:mem. ∀e:expr.
180(P_res ? (λx.eval_expr ge en m e (\fst x) (\snd x)) (exec_expr ge en m e)).
181#ge #en #m #e @(expr_lvalue_ind ? (λe',ty.P_res ? (λr.eval_lvalue ge en m (Expr e' ty) (\fst (\fst r)) (\snd (\fst r)) (\snd r)) (exec_lvalue' ge en m e' ty)) … e)
182(* XXX // fails [ 1,2: #ty #c whd //  *)
183[ #ty #c whd %
184| #ty #c whd %2
185(* expressions that are lvalues *)
186| #e' #ty cases e'; //; [ #i #He' | #e #He' | #e #i #He' ] whd in He' ⊢ %;
187    @bind2_OK #x cases x; #y cases y; #sp #loc #ofs #tr #H
188    @opt_bind_OK #vl #evl whd in evl:(??%?); @(eval_Elvalue … evl)
189    >H in He' #He' @He'
190| #v #ty
191    whd in ⊢ (???%);
192    lapply (refl ? (get ident PTree block v en));
193    cases (get ident PTree block v en) in ⊢ (???% → %);
194    [ #eget @opt_bind_OK #sploc cases sploc; #sp #loc #efind
195        whd; @(eval_Evar_global … eget efind)
196    | #loc #eget @(eval_Evar_local … eget)
197    ]
198| #ty #e #He whd in ⊢ (???%)
199    @bind2_OK #v cases v // #r #l #pc #ofs #tr #Hv whd
200    >Hv in He #He
201    @eval_Ederef [ 3: @He | *: skip ]
202| #ty #e'' #ty'' #He'' @bind2_OK * #loc #ofs #tr #H
203  cases ty // * #pty
204  cases loc in H ⊢ % * #loc' #H
205  whd try @I
206  @eval_Eaddrof whd in H:(??%?) >H in He'' #He'' @He''
207| #ty #op #e1 #He1 @bind2_OK #v1 #tr #Hv1
208    @opt_bind_OK #v #ev
209    @(eval_Eunop … ev)
210    >Hv1 in He1 #He1 @He1
211| #ty #op #e1 #e2 #He1 #He2
212    @bind2_OK #v1 #tr1 #ev1 >ev1 in He1 #He1
213    @bind2_OK #v2 #tr2 #ev2 >ev2 in He2 #He2
214    @opt_bind_OK #v #ev whd in He1 He2; whd;
215    @(eval_Ebinop … He1 He2 ev)
216| #ty #ty' #e' #He'
217    @bind2_OK #v #tr #Hv >Hv in He' #He'
218    @bind_OK #v' #ev'
219    @(eval_Ecast … He' ?)
220    (* XXX /2/; *)
221    @(exec_cast_sound … ev')
222| #ty #e1 #e2 #e3 #He1 #He2 #He3
223    @bind2_OK #vb #tr1 #Hvb >Hvb in He1 #He1
224    @bind_OK #b
225    cases b; #eb lapply (exec_bool_of_val_sound … eb); #Hb
226    @bind2_OK #v #tr #Hv whd in Hv:(??%?)
227    [ >Hv in He2 #He2 whd in He2 Hv:(??%?) ⊢%;
228        @(eval_Econdition_true … He1 ? He2) @(bool_of ??? Hb)
229    | >Hv in He3 #He3 whd in He3 Hv:(??%?) ⊢%;
230        @(eval_Econdition_false … He1 ? He3) @(bool_of ??? Hb)
231    ]
232| #ty #e1 #e2 #He1 #He2
233    @bind2_OK #v1 #tr1 #Hv1 >Hv1 in He1 #He1
234    @bind_OK #b1 cases b1; #eb1 lapply (exec_bool_of_val_sound … eb1); #Hb1
235    [ @bind2_OK #v2 #tr2 #Hv2 >Hv2 in He2 #He2
236        @bind_OK #b2 #eb2
237        @(eval_Eandbool_2 … He1 … He2)
238        [ @(bool_of … Hb1) | @(exec_bool_of_val_sound … eb2) ]
239    | @(eval_Eandbool_1 … He1) @(bool_of … Hb1)
240    ]
241| #ty #e1 #e2 #He1 #He2
242    @bind2_OK #v1 #tr1 #Hv1 >Hv1 in He1 #He1
243    @bind_OK #b1 cases b1; #eb1 lapply (exec_bool_of_val_sound … eb1); #Hb1
244    [ @(eval_Eorbool_1 … He1) @(bool_of … Hb1)
245    | @bind2_OK #v2 #tr2 #Hv2 >Hv2 in He2 #He2
246        @bind_OK #b2 #eb2
247        @(eval_Eorbool_2 … He1 … He2)
248        [ @(bool_of … Hb1) | @(exec_bool_of_val_sound … eb2) ]
249    ]
250| #ty #ty' whd; (* XXX //*) @eval_Esizeof
251| #ty #e' #ty' #i cases ty'; //;
252    [ #id #fs #He' @bind2_OK #x cases x; #sp #l #ofs #H
253        @bind_OK #delta #Hdelta whd in H:(??%?) >H in He' #He'
254        @(eval_Efield_struct …  He' (refl ??) Hdelta)
255    | #id #fs #He' @bind2_OK #x cases x; #sp #l #ofs #H whd in H:(??%?)
256        >H in He' #He'
257        @(eval_Efield_union … He' (refl ??))
258    ]
259| #ty #l #e' #He' @bind2_OK #v #tr1 #H >H in He' #He'
260    @(eval_Ecost … He')
261(* exec_lvalue fails on non-lvalues. *)
262| #e' #ty cases e';
263    [ 1,2,5,12: #a #H | 3,4: #a * | 13,14: #a #b * | 6,8,10,11: #a #b #H | 7,9: #a #b #c #H ]
264    @I
265] qed.
266
267lemma addrof_eval_lvalue: ∀ge,en,m,e,r,loc,pc,off,tr,ty.
268eval_expr ge en m (Expr (Eaddrof e) ty) (Vptr r loc pc off) tr →
269eval_lvalue ge en m e loc off tr.
270#ge #en #m #e #r #loc #pc #off #tr #ty #H inversion H;
271[ 1,2,5: #a #b #H @False_ind destruct (H);
272| #a #b #c #d #e #f #H1 #g #H2 <H2 in H1 #H1 @False_ind
273    @(eval_lvalue_inv_ind … H1)
274    [ #a #b #c #d #bad destruct (bad);
275    | #a #b #c #d #e #bad destruct (bad);
276    | #a #b #c #d #e #f #g #h #bad destruct (bad);
277    | #a #b #c #d #e #f #g #h #i #j #k #l #m #bad @False_ind destruct (bad);
278    | #a #b #c #d #e #f #g #h #i #j #k #bad destruct (bad);
279    ]
280| #e' #ty' #r' #loc' #ofs' #tr' #H' #pc' #e1 #e2 #e3 destruct (e1 e2 e3); @H'
281| #a #b #c #d #e #f #g #h #i #bad destruct (bad);
282| #a #b #c #d #e #f #g #h #i #j #k #l #k #l #bad destruct (bad);
283| #a #b #c #d #e #f #g #h #i #j #k #l #m #bad destruct (bad);
284| #a #b #c #d #e #f #g #h #i #j #k #l #m #bad destruct (bad);
285| #a #b #c #d #e #f #g #h #bad destruct (bad);
286| #a #b #c #d #e #f #g #h #i #j #k #l #m #n #bad destruct (bad);
287| #a #b #c #d #e #f #g #h #bad destruct (bad);
288| #a #b #c #d #e #f #g #h #i #j #k #l #m #n #bad  destruct (bad);
289| #a #b #c #d #e #f #g #h #i #bad destruct (bad);
290| #a #b #c #d #e #f #g #bad destruct (bad);
291] qed.
292
293lemma addrof_exec_lvalue: ∀ge,en,m,e,r,loc,off,tr.
294exec_lvalue ge en m e = OK ? 〈〈mk_block r loc,off〉,tr〉 →
295exec_expr ge en m (Expr (Eaddrof e) (Tpointer r Tvoid)) = OK ? 〈Vptr r (mk_block r loc) (same_compat ??) off, tr〉.
296#ge #en #m #e #r #loc #off #tr #H whd in ⊢ (??%?)
297>H whd in ⊢ (??%?) cases r @refl
298qed.
299
300theorem exec_lvalue_sound: ∀ge,en,m,e.
301P_res ? (λr.eval_lvalue ge en m e (\fst (\fst r)) (\snd (\fst r)) (\snd r)) (exec_lvalue ge en m e).
302#ge #en #m #e lapply (refl ? (exec_lvalue ge en m e));
303cases (exec_lvalue ge en m e) in ⊢ (???% → %);
304[ #x cases x #y cases y #loc #off #tr #H whd cases loc in H ⊢ % #locr #loci #H
305    @(addrof_eval_lvalue … locr … (Tpointer locr Tvoid)) [ @same_compat ]
306    lapply (addrof_exec_lvalue … H) #H'
307    lapply (exec_expr_sound ge en m (Expr (Eaddrof e) (Tpointer locr Tvoid)))
308    >H' #H'' @H''
309| #msg #_ whd @I
310] qed.
311
312(* Plain equality versions of the above *)
313
314definition exec_expr_sound' ≝ λge,en,m,e,v.
315  λH:exec_expr ge en m e = OK ? v.
316  P_res_to_P ???? (exec_expr_sound ge en m e) H.
317
318definition exec_lvalue_sound' ≝ λge,en,m,e,loc,off,tr.
319  λH:exec_lvalue ge en m e = OK ? 〈〈loc,off〉,tr〉.
320  P_res_to_P ???? (exec_lvalue_sound ge en m e) H.
321
322lemma exec_exprlist_sound: ∀ge,e,m,l. P_res ? (λvltr:list val×trace. eval_exprlist ge e m l (\fst vltr) (\snd vltr)) (exec_exprlist ge e m l).
323#ge #e #m #l elim l;
324 whd; (* XXX //; *)
325[ %
326| #e1 #es #IH
327  @bind2_OK #v #tr1 #Hv
328  @bind2_OK #vs #tr2 #Hvs
329  whd; @eval_Econs
330  [ @(P_res_to_P … (exec_expr_sound ge e m e1) Hv)
331  | @(P_res_to_P … IH Hvs)
332  ]
333] qed.
334
335lemma exec_alloc_variables_sound : ∀l,en,m,en',m'.
336  exec_alloc_variables en m l = 〈en',m'〉 →
337  alloc_variables en m l en' m'.
338#l elim l
339[ #en #m #en' #m' #EXEC whd in EXEC:(??%?); destruct %
340| * #id #ty #t #IH #en #m #en' #m'
341  lapply (refl ? (alloc m O (sizeof ty) Any)) #ALLOC #EXEC
342  whd in EXEC:(??%?) ALLOC:(???%)
343 @(alloc_variables_cons … ALLOC)
344 @IH @EXEC
345qed.
346
347lemma exec_bind_parameters_sound : ∀ps,vs,en,m.
348  P_res ? (λm'. bind_parameters en m ps vs m') (exec_bind_parameters en m ps vs).
349#ps elim ps
350[ * //
351| * #id #ty #ps' #IH *
352    [ //
353    | #v #vs #en #m
354      @opt_bind_OK #b #GET
355      @opt_bind_OK #m' #STORE
356      lapply (refl ? (exec_bind_parameters en m' ps' vs))
357      cases (exec_bind_parameters en m' ps' vs) in ⊢ (???% → %) [2: #msg #_ %]
358      #m'' #BIND
359      @(bind_parameters_cons … GET STORE)
360      lapply (IH vs en m') whd in ⊢ (% → ?) >BIND //
361    ]
362] qed.
363
364lemma check_eventval_list_sound : ∀vs,tys.
365  P_res ? (λevs. eventval_list_match evs tys vs) (check_eventval_list vs tys).
366#vs0 elim vs0
367[ * //
368| #v #vs #IH *
369  [ //
370  | #ty #tys whd in ⊢ (???%)
371    cases ty cases v // #v' #sz try #sg
372    @bind_OK #evs #CHECK
373    @(evl_match_cons ??????? (P_res_to_P ???? (IH ?) CHECK)) //
374  ]
375] qed.
376
377theorem exec_step_sound: ∀ge,st.
378  P_io ??? (λr. step ge st (\fst r) (\snd r)) (exec_step ge st).
379#ge #st cases st;
380[ #f #s #k #e #m cases s;
381  [ cases k;
382    [ whd in ⊢ (?????%);
383        lapply (refl ? (fn_return f)); cases (fn_return f) in ⊢ (???% → %);
384        //; #H whd;
385        @step_skip_call //;
386    | #s' #k' whd; (* XXX //; *) @step_skip_seq
387    | #ex #s' #k' @step_skip_or_continue_while % //;
388    | #ex #s' #k'
389        @res_bindIO2_OK #v #tr #Hv
390        letin bexpr ≝ (exec_bool_of_val v (typeof ex));
391        lapply (refl ? bexpr);
392        cases bexpr in ⊢ (???% → %);
393        [ #b cases b; #eb lapply (exec_bool_of_val_sound … eb); #Hb
394            whd in ⊢ (?????%);
395            [ @(step_skip_or_continue_dowhile_true … (exec_expr_sound' … Hv))
396              [ % // | @(bool_of … Hb) ]
397            | @(step_skip_or_continue_dowhile_false … (exec_expr_sound' … Hv))
398              [ % // | @(bool_of … Hb) ]
399            ]
400        | #msg #_ //;
401        ]
402    | #ex #s1 #s2 #k' @step_skip_or_continue_for2 % //;
403    | #ex #s1 #s2 #k' @step_skip_for3
404    | #k' @step_skip_break_switch % //;
405    | #r #f' #e' #k' whd in ⊢ (?????%);
406        lapply (refl ? (fn_return f)); cases (fn_return f) in ⊢ (???% → %);
407        //; #H whd;
408        @step_skip_call //;
409    ]
410  | #ex1 #ex2
411    @res_bindIO2_OK #x cases x; #y cases y; #pcl #loc #ofs #tr1 #Hlval
412    @res_bindIO2_OK #v2 #tr2 #Hv2
413    @opt_bindIO_OK #m' #em'
414    whd; @(step_assign … (exec_lvalue_sound' … Hlval) (exec_expr_sound' … Hv2) em')
415  | #lex #fex #args
416    @res_bindIO2_OK #vf #tr1 #Hvf0 lapply (exec_expr_sound' … Hvf0); #Hvf
417    @res_bindIO2_OK #vargs #tr2 #Hvargs0 lapply (P_res_to_P ???? (exec_exprlist_sound …) Hvargs0); #Hvargs
418    @opt_bindIO_OK #fd #efd
419    @bindIO_OK #ety
420    cases lex; whd;
421    [ @(step_call_none … Hvf Hvargs efd ety)
422    | #lhs'
423        @res_bindIO2_OK #x cases x; #y cases y; #pcl #loc #ofs #tr3 #Hlocofs
424        whd; @(step_call_some … (exec_lvalue_sound' … Hlocofs) Hvf Hvargs efd ety)
425    ]
426  | #s1 #s2 whd; (* XXX //; *) @step_seq
427  | #ex #s1 #s2
428    @res_bindIO2_OK #v #tr #Hv
429    letin bexpr ≝ (exec_bool_of_val v (typeof ex));
430    lapply (refl ? bexpr); cases bexpr in ⊢ (???% → %); //;
431    #b cases b; #eb lapply (exec_bool_of_val_sound … eb); #Hb
432    [ @(step_ifthenelse_true … (exec_expr_sound' … Hv)) @(bool_of … Hb)
433    | @(step_ifthenelse_false … (exec_expr_sound' … Hv)) @(bool_of … Hb)
434    ]
435  | #ex #s'
436    @res_bindIO2_OK #v #tr #Hv
437    letin bexpr ≝ (exec_bool_of_val v (typeof ex));
438    lapply (refl ? bexpr); cases bexpr in ⊢ (???% → %); //;
439    #b cases b; #eb lapply (exec_bool_of_val_sound … eb); #Hb
440    [ @(step_while_true … (exec_expr_sound' … Hv)) @(bool_of … Hb)
441    | @(step_while_false … (exec_expr_sound' … Hv)) @(bool_of … Hb)
442    ]
443  | #ex #s' whd; (* XXX //; *) @step_dowhile
444  | #s1 #ex #s2 #s3 whd in ⊢ (?????%); elim (is_Sskip s1); #Hs1 whd in ⊢ (?????%);
445    [ >Hs1
446      @res_bindIO2_OK #v #tr #Hv
447      letin bexpr ≝ (exec_bool_of_val v (typeof ex));
448      lapply (refl ? bexpr); cases bexpr in ⊢ (???% → %); //;
449      #b cases b; #eb lapply (exec_bool_of_val_sound … eb); #Hb
450      [ @(step_for_true … (exec_expr_sound' … Hv)) @(bool_of … Hb)
451      | @(step_for_false … (exec_expr_sound' … Hv)) @(bool_of … Hb)
452      ]
453    | @step_for_start //;
454    ]
455  | whd in ⊢ (?????%); cases k; //;
456    [ #s' #k' whd (* XXX // *) @step_break_seq
457    | #ex #s' #k' whd (* //; *) @step_break_while
458    | #ex #s' #k' whd (* //; *) @step_break_dowhile
459    | #ex #s1 #s2 #k' whd (* //; *) @step_break_for2
460    | #k' @step_skip_break_switch %2  //
461    ]
462  | whd in ⊢ (?????%); cases k; //;
463    [ #s' #k' whd; (* XXX //;*) @step_continue_seq
464    | #ex #s' #k' whd; @step_skip_or_continue_while %2 ; //;
465    | #ex #s' #k' whd;
466      @res_bindIO2_OK #v #tr #Hv
467      letin bexpr ≝ (exec_bool_of_val v (typeof ex));
468      lapply (refl ? bexpr); cases bexpr in ⊢ (???% → %); //;
469      #b cases b; #eb lapply (exec_bool_of_val_sound … eb); #Hb
470      [ @(step_skip_or_continue_dowhile_true … (exec_expr_sound' … Hv))
471        [ %2 ; // | @(bool_of … Hb) ]
472      | @(step_skip_or_continue_dowhile_false … (exec_expr_sound' … Hv))
473        [ %2 ; // | @(bool_of … Hb) ]
474      ]
475    | #ex #s1 #s2 #k' whd; @step_skip_or_continue_for2 %2 ; //
476    | #k' whd; (* XXX //;*) @step_continue_switch
477    ]
478  | #r whd in ⊢ (?????%); cases r;
479    [ whd; lapply (refl ? (fn_return f)); cases (fn_return f) in ⊢ (???% → %); //; #H
480        @step_return_0 @H
481    | #ex cases (type_eq_dec (fn_return f) Tvoid); //; whd in ⊢ (% → ?????%); #Hnotvoid
482        @res_bindIO2_OK #v #tr #Hv
483        whd; @(step_return_1 … Hnotvoid (exec_expr_sound' … Hv))
484    ]
485  | #ex #ls @res_bindIO2_OK #v cases v; //; #n #tr #Hv
486    @step_switch @(exec_expr_sound' … Hv)
487  | #l #s' whd; @step_label (* XXX //; *)
488  | #l whd in ⊢ (?????%); lapply (refl ? (find_label l (fn_body f) (call_cont k)));
489      cases (find_label l (fn_body f) (call_cont k)) in ⊢ (???% → %); //;
490      #sk cases sk; #s' #k' #H
491      @(step_goto … H)
492  | #l #s' whd; (* XXX //; *) @step_cost
493  ]
494| #f0 #vargs #k #m whd in ⊢ (?????%); cases f0;
495  [ #fn whd in ⊢ (?????%)
496    lapply (refl ? (exec_alloc_variables empty_env m (fn_params fn@fn_vars fn)))
497    cases (exec_alloc_variables empty_env m (fn_params fn@fn_vars fn)) in ⊢ (???% → %)
498    #en' #m' #ALLOC whd in ⊢ (?????%)
499    @res_bindIO_OK #m2 #BIND
500    whd; @(step_internal_function … (exec_alloc_variables_sound … ALLOC))
501    @(P_res_to_P … (exec_bind_parameters_sound …) BIND)
502  | #id #argtys #rty @res_bindIO_OK #evs #Hevs
503    @bindIO_OK #eres whd;
504    @step_external_function % [ @(P_res_to_P … (check_eventval_list_sound …) Hevs)
505                              | @mk_val_correct ]
506  ] 
507| #v #k' #m' whd in ⊢ (?????%); cases k'; //;
508    #r #f #e #k whd in ⊢ (?????%); cases r;
509  [ whd; @step_returnstate_0
510  | #x cases x; #y cases y; #z cases z; #pcl #b #ofs #ty
511    @opt_bindIO_OK #m' #em' @step_returnstate_1 whd in em':(??%?); //;
512  ]
513]
514qed.
515
516lemma make_initial_state_sound : ∀p. P_res ? (λgs.globalenv Genv ?? p = OK ? (\fst gs) ∧ initial_state p (\snd gs)) (make_initial_state p).
517#p cases p; #fns #main #vars
518whd in ⊢ (???%);
519@bind_OK #ge #Ege
520@bind_OK #m #Em
521@opt_bind_OK #x cases x; #sp #b #esb
522@opt_bind_OK #f #ef
523whd; % [ whd in ⊢ (???(??%)) // | @(initial_state_intro … Ege Em esb ef) ]
524qed.
525
526theorem exec_steps_sound: ∀ge,n,st.
527 P_io ??? (λts:trace×state. star (mk_transrel ?? step) ge st (\fst ts) (\snd ts))
528 (exec_steps n ge st).
529#ge #n elim n;
530[ #st whd in ⊢ (?????%); elim (is_final_state st); #H whd; %
531| #n' #IH #st whd in ⊢ (?????%); elim (is_final_state st); #H
532  [ whd; %
533  | @(P_bindIO2_OK ????????? (exec_step_sound …)) #t #s' cases s';
534      [ #f #s #k #e #m | #fd #args #k #m | #r #k #m ]
535      whd in ⊢ (? → ?????(??????%?));
536      cases m; #mc #mn #mp #Hstep
537      whd in ⊢ (?????(??????%?));
538      @(P_bindIO2_OK ????????? (IH …)) #t' #s'' #Hsteps
539      whd; @(star_step ????????? Hsteps) [ 2,5,8: @Hstep | 3,6,9: // ]
540  ]
541qed.
542
543lemma is_final_sound: ∀s,r. is_final s = Some ? r → final_state s r.
544* [ 3: #v * [ #m #r cases v [ 2: #r' #E normalize in E; destruct %
545                            | *: normalize #x1 try #x2 try #x3 try #x4 try #x5 destruct
546                            ]
547            | *: normalize #x1 try #x2 try #x3 try #x4 try #x5 try #x6 try #x7 destruct
548            ]
549  | *: normalize #x1 #x2 #x3 #x4 #x5 #x6 try #x7 destruct
550  ] qed.
Note: See TracBrowser for help on using the repository browser.