source: src/Clight/CexecSound.ma @ 2468

Last change on this file since 2468 was 2468, checked in by garnier, 7 years ago

Floats are gone from the front-end. Some trace amount might remain in RTL/RTLabs, but this should be easily fixable.
Also, work-in-progress in Clight/memoryInjections.ma

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