source: src/Clight/CexecSound.ma @ 2176

Last change on this file since 2176 was 2176, checked in by campbell, 6 years ago

Remove memory spaces other than XData and Code; simplify pointers as a
result.

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