[700] | 1 | include "Clight/Cexec.ma". |
---|
[2019] | 2 | include "Clight/CexecInd.ma". |
---|
[399] | 3 | |
---|
[487] | 4 | lemma exec_bool_of_val_sound: ∀v,ty,r. |
---|
[399] | 5 | exec_bool_of_val v ty = OK ? r → bool_of_val v ty (of_bool r). |
---|
[487] | 6 | #v #ty #r |
---|
[2176] | 7 | cases v; [ | #sz #i | #f | | #ptr ] |
---|
| 8 | cases 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 ] |
---|
[1516] | 9 | whd in ⊢ (??%? → ?); |
---|
[961] | 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 |
---|
[1410] | 14 | | #E1 #E2 destruct @bool_of_val_true @is_true_int_int @E1 |
---|
[961] | 15 | ] |
---|
[487] | 16 | ] |
---|
[961] | 17 | | 8: #H cases (eq_dec f Fzero) |
---|
[1516] | 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 |
---|
[487] | 20 | ] |
---|
[1410] | 21 | | 14: #H destruct @bool_of_val_false @is_false_pointer |
---|
| 22 | | 15: #H destruct @bool_of_val_true @is_true_pointer_pointer |
---|
[961] | 23 | | *: #H destruct |
---|
[487] | 24 | ] qed. |
---|
[399] | 25 | |
---|
[487] | 26 | lemma bool_val_distinct: Vtrue ≠ Vfalse. |
---|
[1410] | 27 | % normalize #H destruct |
---|
[487] | 28 | qed. |
---|
[399] | 29 | |
---|
[487] | 30 | lemma bool_of: ∀v,ty,b. bool_of_val v ty (of_bool b) → |
---|
[399] | 31 | if b then is_true v ty else is_false v ty. |
---|
[1336] | 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' |
---|
[487] | 34 | qed. |
---|
[399] | 35 | |
---|
[961] | 36 | lemma 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' |
---|
[1516] | 38 | whd in ⊢ (??%? → ?); |
---|
[961] | 39 | @eq_bv_elim |
---|
[487] | 40 | [ #e >e |
---|
[2176] | 41 | cases ty; [ | #sz' #sg | #fs | (*#sp*) #ty | (*#sp*) #ty #n | #args #rty | #id #fs | #id #fs | (*#r*) #id ] |
---|
[961] | 42 | whd in ⊢ (??%? → ?); #H [ 2: | *: destruct ] |
---|
[2176] | 43 | cases ty' in H ⊢ %; [ | #sz'' #sg | #fs | (*#sp*) #ty | (*#sp*) #ty #n | #args #rty | #id #fs | #id #fs | (*#r*) #id ] |
---|
[961] | 44 | try (@eq_intsize_elim #E) whd in ⊢ (??%? → ?); #H destruct @cast_ip_z // |
---|
[487] | 45 | | #_ whd in ⊢ (??%? → ?); #H destruct |
---|
| 46 | ] |
---|
| 47 | qed. |
---|
[399] | 48 | |
---|
[1410] | 49 | lemma 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' |
---|
[487] | 51 | cases v; |
---|
| 52 | [ #H whd in H:(??%?); destruct; |
---|
[961] | 53 | | #sz #i cases ty; |
---|
[487] | 54 | [ #H whd in H:(??%?); destruct; |
---|
| 55 | | 3: #a #H whd in H:(??%?); destruct; |
---|
[2176] | 56 | | 7,8,9: #a [ 1,2: #b ] #H whd in H:(??%?); destruct; |
---|
[487] | 57 | | #sz1 #si1 cases ty'; |
---|
[1516] | 58 | [ whd in ⊢ (??%? → ?); @intsize_eq_elim_elim |
---|
[961] | 59 | [ #NE #H destruct |
---|
| 60 | | *; whd #H whd in H:(??%?); destruct; |
---|
| 61 | ] |
---|
[1516] | 62 | | 3: #a whd in ⊢ (??%? → ?); @intsize_eq_elim_elim |
---|
[961] | 63 | [ #E #H whd in H:(??%?); destruct |
---|
| 64 | | *; whd #H whd in H:(??%?); destruct; @cast_if |
---|
| 65 | ] |
---|
[2176] | 66 | | 2,7,8,9: #a [1,2,3: #b] whd in ⊢ (??%? → ?); @intsize_eq_elim_elim |
---|
[961] | 67 | [ 1,3,5,7: #NE #H destruct |
---|
| 68 | | *: *; whd #H whd in H:(??%?); destruct; // |
---|
| 69 | ] |
---|
[2176] | 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) ] |
---|
[1516] | 73 | whd in ⊢ (??%? → ?); @intsize_eq_elim_elim |
---|
[961] | 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 | ] |
---|
[487] | 81 | ] |
---|
| 82 | ] |
---|
[2176] | 83 | | *: [ #ty'' letin t ≝ (Tpointer ty'') |
---|
| 84 | | #ty'' #n letin t ≝ (Tarray ty'' n) |
---|
| 85 | | #args #rty letin t ≝ (Tfunction args rty) ] |
---|
[487] | 86 | whd in ⊢ (??%? → ?); |
---|
[961] | 87 | lapply (try_cast_null_sound m sz i t ty' v'); |
---|
| 88 | cases (try_cast_null m sz i t ty'); |
---|
[487] | 89 | [ 1,3,5: #v'' #H' #e @H' @e |
---|
[797] | 90 | | *: #m #_ whd in ⊢ (??%? → ?); #H destruct (H); |
---|
[487] | 91 | ] |
---|
| 92 | ] |
---|
[2176] | 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 ] |
---|
[487] | 95 | whd in e:(??%?); destruct; //; |
---|
| 96 | | *: #e whd in e:(??%?); destruct |
---|
| 97 | ] |
---|
[2176] | 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; |
---|
[487] | 101 | @cast_pp_z //; |
---|
[2176] | 102 | (* |
---|
[1545] | 103 | | #ptr whd in ⊢ (??%? → ?); #e |
---|
[500] | 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''; |
---|
[487] | 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 ] |
---|
[1647] | 109 | whd in e:(??%%); destruct; //; |
---|
[487] | 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 ] |
---|
[1647] | 113 | whd in e:(??%%); destruct; //; |
---|
[487] | 114 | | #Hty' |
---|
[1545] | 115 | cut (s = ptype ptr). elim (eq_region_dec (ptype ptr) s) in eu; //; normalize; #_ #e destruct. |
---|
[1516] | 116 | #e >e in Hty; #Hty |
---|
[1545] | 117 | cases (pointer_compat_dec (pblock ptr) s') in e'''; |
---|
[1647] | 118 | #Hcompat #e''' whd in e''':(??%%); destruct /2 by cast_pp/ |
---|
[487] | 119 | ] |
---|
| 120 | ] |
---|
[2176] | 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/ |
---|
[1410] | 126 | ] qed. |
---|
[399] | 127 | |
---|
| 128 | |
---|
[487] | 129 | theorem exec_expr_sound: ∀ge:genv. ∀en:env. ∀m:mem. ∀e:expr. |
---|
[399] | 130 | (P_res ? (λx.eval_expr ge en m e (\fst x) (\snd x)) (exec_expr ge en m e)). |
---|
[498] | 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) |
---|
[1516] | 132 | [ #sz #ty #c whd in ⊢ (???%); cases ty try #sz' try #sg try #x try @I whd in ⊢ (???%); |
---|
[961] | 133 | @eq_intsize_elim #E try @I <E whd % |
---|
[1410] | 134 | | #ty #c whd // |
---|
[399] | 135 | (* expressions that are lvalues *) |
---|
[487] | 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) |
---|
[1516] | 139 | >H in He'; #He' @He' |
---|
[487] | 140 | | #v #ty |
---|
| 141 | whd in ⊢ (???%); |
---|
[1058] | 142 | lapply (refl ? (lookup SymbolTag block en v)) |
---|
[1516] | 143 | cases (lookup SymbolTag block en v) in ⊢ (???% → %); |
---|
[487] | 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 | ] |
---|
[1516] | 148 | | #ty #e #He whd in ⊢ (???%); |
---|
[2176] | 149 | @bind2_OK #v cases v / by / * #l #ofs #tr #Hv whd |
---|
[1516] | 150 | >Hv in He; #He |
---|
[2176] | 151 | @eval_Ederef @He |
---|
[891] | 152 | | #ty #e'' #ty'' #He'' @bind2_OK * #loc #ofs #tr #H |
---|
[2176] | 153 | cases ty try (try #a try #b try #c @I) |
---|
| 154 | #ty' whd |
---|
[1516] | 155 | @eval_Eaddrof whd in H:(??%?); >H in He''; #He'' @He'' |
---|
[487] | 156 | | #ty #op #e1 #He1 @bind2_OK #v1 #tr #Hv1 |
---|
| 157 | @opt_bind_OK #v #ev |
---|
| 158 | @(eval_Eunop … ev) |
---|
[1516] | 159 | >Hv1 in He1; #He1 @He1 |
---|
[487] | 160 | | #ty #op #e1 #e2 #He1 #He2 |
---|
[1516] | 161 | @bind2_OK #v1 #tr1 #ev1 >ev1 in He1; #He1 |
---|
| 162 | @bind2_OK #v2 #tr2 #ev2 >ev2 in He2; #He2 |
---|
[487] | 163 | @opt_bind_OK #v #ev whd in He1 He2; whd; |
---|
| 164 | @(eval_Ebinop … He1 He2 ev) |
---|
| 165 | | #ty #ty' #e' #He' |
---|
[1516] | 166 | @bind2_OK #v #tr #Hv >Hv in He'; #He' |
---|
[487] | 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 |
---|
[1516] | 172 | @bind2_OK #vb #tr1 #Hvb >Hvb in He1; #He1 |
---|
[487] | 173 | @bind_OK #b |
---|
| 174 | cases b; #eb lapply (exec_bool_of_val_sound … eb); #Hb |
---|
[1516] | 175 | @bind2_OK #v #tr #Hv whd in Hv:(??%?); |
---|
| 176 | [ >Hv in He2; #He2 whd in He2 Hv:(??%?) ⊢%; |
---|
[487] | 177 | @(eval_Econdition_true … He1 ? He2) @(bool_of ??? Hb) |
---|
[1516] | 178 | | >Hv in He3; #He3 whd in He3 Hv:(??%?) ⊢%; |
---|
[487] | 179 | @(eval_Econdition_false … He1 ? He3) @(bool_of ??? Hb) |
---|
| 180 | ] |
---|
| 181 | | #ty #e1 #e2 #He1 #He2 |
---|
[1516] | 182 | @bind2_OK #v1 #tr1 #Hv1 >Hv1 in He1; #He1 |
---|
[487] | 183 | @bind_OK #b1 cases b1; #eb1 lapply (exec_bool_of_val_sound … eb1); #Hb1 |
---|
[1516] | 184 | [ @bind2_OK #v2 #tr2 #Hv2 >Hv2 in He2; #He2 |
---|
[487] | 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 |
---|
[1516] | 191 | @bind2_OK #v1 #tr1 #Hv1 >Hv1 in He1; #He1 |
---|
[487] | 192 | @bind_OK #b1 cases b1; #eb1 lapply (exec_bool_of_val_sound … eb1); #Hb1 |
---|
| 193 | [ @(eval_Eorbool_1 … He1) @(bool_of … Hb1) |
---|
[1516] | 194 | | @bind2_OK #v2 #tr2 #Hv2 >Hv2 in He2; #He2 |
---|
[487] | 195 | @bind_OK #b2 #eb2 |
---|
| 196 | @(eval_Eorbool_2 … He1 … He2) |
---|
| 197 | [ @(bool_of … Hb1) | @(exec_bool_of_val_sound … eb2) ] |
---|
| 198 | ] |
---|
[1410] | 199 | | #ty #ty' cases ty try #sz try #sg try #x // |
---|
[487] | 200 | | #ty #e' #ty' #i cases ty'; //; |
---|
| 201 | [ #id #fs #He' @bind2_OK #x cases x; #sp #l #ofs #H |
---|
[1516] | 202 | @bind_OK #delta #Hdelta whd in H:(??%?); >H in He'; #He' |
---|
[487] | 203 | @(eval_Efield_struct … He' (refl ??) Hdelta) |
---|
[1516] | 204 | | #id #fs #He' @bind2_OK #x cases x; #sp #l #ofs #H whd in H:(??%?); |
---|
| 205 | >H in He'; #He' |
---|
[487] | 206 | @(eval_Efield_union … He' (refl ??)) |
---|
| 207 | ] |
---|
[1516] | 208 | | #ty #l #e' #He' @bind2_OK #v #tr1 #H >H in He'; #He' |
---|
[487] | 209 | @(eval_Ecost … He') |
---|
[399] | 210 | (* exec_lvalue fails on non-lvalues. *) |
---|
[487] | 211 | | #e' #ty cases e'; |
---|
[961] | 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 ] |
---|
[487] | 213 | @I |
---|
| 214 | ] qed. |
---|
[399] | 215 | |
---|
[2176] | 216 | lemma addrof_eval_lvalue: ∀ge,en,m,e,loc,off,tr,ty. |
---|
| 217 | eval_expr ge en m (Expr (Eaddrof e) ty) (Vptr (mk_pointer loc off)) tr → |
---|
[498] | 218 | eval_lvalue ge en m e loc off tr. |
---|
[2176] | 219 | #ge #en #m #e #loc #off #tr #ty #H inversion H; |
---|
[961] | 220 | [ 1,2,5: #a #b #c #H @False_ind destruct (H); |
---|
[1516] | 221 | | #a #b #c #d #e #f #H1 #g #H2 #E1 #E2 #E3 <H2 in H1; #H1 @False_ind |
---|
[487] | 222 | @(eval_lvalue_inv_ind … H1) |
---|
| 223 | [ #a #b #c #d #bad destruct (bad); |
---|
[498] | 224 | | #a #b #c #d #e #bad destruct (bad); |
---|
[2176] | 225 | | #a #b #c #d #e #f #bad destruct (bad); |
---|
[1672] | 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); |
---|
[487] | 228 | ] |
---|
[2176] | 229 | | #e' #ty' #loc' #ofs' #tr' #H' #e1 #e2 #e3 destruct (e1 e2 e3); #E @H' |
---|
[487] | 230 | | #a #b #c #d #e #f #g #h #bad destruct (bad); |
---|
[1672] | 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); |
---|
[487] | 238 | | #a #b #c #d #e #f #g #h #bad destruct (bad); |
---|
[1672] | 239 | | #a #b #c #d #e #f #bad destruct (bad); |
---|
[487] | 240 | ] qed. |
---|
[399] | 241 | |
---|
[500] | 242 | lemma addrof_exec_lvalue: ∀ge,en,m,e,r,loc,off,tr. |
---|
| 243 | exec_lvalue ge en m e = OK ? 〈〈mk_block r loc,off〉,tr〉 → |
---|
[2176] | 244 | exec_expr ge en m (Expr (Eaddrof e) (Tpointer Tvoid)) = OK ? 〈Vptr (mk_pointer (mk_block r loc) off), tr〉. |
---|
[1516] | 245 | #ge #en #m #e #r #loc #off #tr #H whd in ⊢ (??%?); |
---|
| 246 | >H whd in ⊢ (??%?); cases r @refl |
---|
[487] | 247 | qed. |
---|
[399] | 248 | |
---|
[487] | 249 | theorem exec_lvalue_sound: ∀ge,en,m,e. |
---|
[498] | 250 | P_res ? (λr.eval_lvalue ge en m e (\fst (\fst r)) (\snd (\fst r)) (\snd r)) (exec_lvalue ge en m e). |
---|
[487] | 251 | #ge #en #m #e lapply (refl ? (exec_lvalue ge en m e)); |
---|
| 252 | cases (exec_lvalue ge en m e) in ⊢ (???% → %); |
---|
[1516] | 253 | [ #x cases x #y cases y #loc #off #tr #H whd cases loc in H ⊢ %; #locr #loci #H |
---|
[2176] | 254 | @(addrof_eval_lvalue … (Tpointer Tvoid)) |
---|
[500] | 255 | lapply (addrof_exec_lvalue … H) #H' |
---|
[2176] | 256 | lapply (exec_expr_sound ge en m (Expr (Eaddrof e) (Tpointer Tvoid))) |
---|
[487] | 257 | >H' #H'' @H'' |
---|
[797] | 258 | | #msg #_ whd @I |
---|
[487] | 259 | ] qed. |
---|
[399] | 260 | |
---|
| 261 | (* Plain equality versions of the above *) |
---|
| 262 | |
---|
[487] | 263 | definition exec_expr_sound' ≝ λge,en,m,e,v. |
---|
[399] | 264 | λH:exec_expr ge en m e = OK ? v. |
---|
| 265 | P_res_to_P ???? (exec_expr_sound ge en m e) H. |
---|
| 266 | |
---|
[498] | 267 | definition exec_lvalue_sound' ≝ λge,en,m,e,loc,off,tr. |
---|
| 268 | λH:exec_lvalue ge en m e = OK ? 〈〈loc,off〉,tr〉. |
---|
[399] | 269 | P_res_to_P ???? (exec_lvalue_sound ge en m e) H. |
---|
| 270 | |
---|
[487] | 271 | lemma 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; |
---|
[1410] | 273 | whd |
---|
[487] | 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. |
---|
[399] | 283 | |
---|
[487] | 284 | lemma 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' |
---|
[2176] | 290 | lapply (refl ? (alloc m O (sizeof ty) XData)) whd in ⊢ (? → ??%? → ?); |
---|
[2106] | 291 | cases (alloc ????) in ⊢ (???% → %); #m'' #b #ALLOC #EXEC |
---|
[487] | 292 | @(alloc_variables_cons … ALLOC) |
---|
| 293 | @IH @EXEC |
---|
| 294 | qed. |
---|
| 295 | |
---|
| 296 | lemma 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)) |
---|
[1516] | 306 | cases (exec_bind_parameters en m' ps' vs) in ⊢ (???% → %); [2: #msg #_ %] |
---|
[487] | 307 | #m'' #BIND |
---|
| 308 | @(bind_parameters_cons … GET STORE) |
---|
[1516] | 309 | lapply (IH vs en m') whd in ⊢ (% → ?); >BIND // |
---|
[487] | 310 | ] |
---|
| 311 | ] qed. |
---|
| 312 | |
---|
| 313 | lemma 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 | [ // |
---|
[1516] | 319 | | #ty #tys whd in ⊢ (???%); |
---|
[2176] | 320 | cases ty [ #sz #sg | | #sz ] cases v // |
---|
[1516] | 321 | [ #sz' #v @bind_OK #ev whd in ⊢ (??%? → ?); |
---|
[961] | 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 | // |
---|
[487] | 326 | ] |
---|
| 327 | ] qed. |
---|
| 328 | |
---|
| 329 | theorem exec_step_sound: ∀ge,st. |
---|
[399] | 330 | P_io ??? (λr. step ge st (\fst r) (\snd r)) (exec_step ge st). |
---|
[487] | 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 //; |
---|
[1410] | 338 | | #s' #k' whd; // |
---|
[487] | 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 | ] |
---|
[797] | 352 | | #msg #_ //; |
---|
[487] | 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 | ] |
---|
[1410] | 378 | | #s1 #s2 // |
---|
[487] | 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 | ] |
---|
[1410] | 395 | | #ex #s' // |
---|
[487] | 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 | ] |
---|
[1342] | 407 | | whd in ⊢ (?????%); cases k; // #k' @step_skip_break_switch %2 // |
---|
[487] | 408 | | whd in ⊢ (?????%); cases k; //; |
---|
[1342] | 409 | [ #ex #s' #k' whd; @step_skip_or_continue_while %2 ; //; |
---|
[487] | 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 | ] |
---|
[961] | 429 | | #ex #ls @res_bindIO2_OK * // #sz #n #tr #Hv |
---|
[487] | 430 | @step_switch @(exec_expr_sound' … Hv) |
---|
[1410] | 431 | | #l #s' // |
---|
[487] | 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) |
---|
[1410] | 436 | | #l #s' // |
---|
[487] | 437 | ] |
---|
| 438 | | #f0 #vargs #k #m whd in ⊢ (?????%); cases f0; |
---|
[1516] | 439 | [ #fn whd in ⊢ (?????%); |
---|
[487] | 440 | lapply (refl ? (exec_alloc_variables empty_env m (fn_params fn@fn_vars fn))) |
---|
[1516] | 441 | cases (exec_alloc_variables empty_env m (fn_params fn@fn_vars fn)) in ⊢ (???% → %); |
---|
| 442 | #en' #m' #ALLOC whd in ⊢ (?????%); |
---|
[487] | 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) |
---|
[1647] | 446 | | #id #argtys #rty @res_bindIO_OK #evs #Hevs #v' |
---|
| 447 | @bindIO_OK #eres whd |
---|
[487] | 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'; //; |
---|
[1713] | 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 | | // |
---|
[487] | 458 | ] |
---|
| 459 | qed. |
---|
[399] | 460 | |
---|
[1244] | 461 | lemma make_initial_state_sound : ∀p. P_res ? (initial_state p) (make_initial_state p). |
---|
[487] | 462 | #p cases p; #fns #main #vars |
---|
| 463 | whd in ⊢ (???%); |
---|
| 464 | @bind_OK #m #Em |
---|
| 465 | @opt_bind_OK #x cases x; #sp #b #esb |
---|
| 466 | @opt_bind_OK #f #ef |
---|
[1244] | 467 | @(initial_state_intro … Em esb ef) @refl |
---|
[487] | 468 | qed. |
---|
[399] | 469 | |
---|
[487] | 470 | theorem exec_steps_sound: ∀ge,n,st. |
---|
[399] | 471 | P_io ??? (λts:trace×state. star (mk_transrel ?? step) ge st (\fst ts) (\snd ts)) |
---|
| 472 | (exec_steps n ge st). |
---|
[487] | 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'; |
---|
[1713] | 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 |
---|
[487] | 480 | @(P_bindIO2_OK ????????? (IH …)) #t' #s'' #Hsteps |
---|
[1713] | 481 | whd; @(star_step ????????? Hsteps) [ 2,5,8,11: @Hstep | 3,6,9,12: // ] |
---|
[487] | 482 | ] |
---|
| 483 | qed. |
---|
[708] | 484 | |
---|
| 485 | lemma is_final_sound: ∀s,r. is_final s = Some ? r → final_state s r. |
---|
[1713] | 486 | * [ 4: #r #r' normalize #E destruct % |
---|
| 487 | | *: normalize #x1 #x2 #x3 #x4 #x5 try #x6 try #x7 destruct |
---|
[1350] | 488 | ] qed. |
---|