source:
etc/campbell/dev-notes/2012-10-09-cost-labels-in-syntax.patch
Last change on this file was 2394, checked in by , 7 years ago | |
---|---|
File size: 114.7 KB |
-
Deliverables/D2.2/8051-matita-out/src/clight/clightPrintMatita.ml
Abandoned work on push cost labels into loop syntax. This was meant to avoid putting extra skips in Cminor/RTLabs code to make the cost labelling properties nicer, but the Cminor skips are eliminated in the translation to RTLabs, so it wasn't necessary in the end. This was against r2385. If applying you might need to undo the reversion of changeset 2353. commit b4bfef8bef285f11e41cff3829d5eaed9ef127a8 Author: Brian Campbell <Brian.Campbell@ed.ac.uk> Date: Tue Oct 9 14:58:31 2012 +0100 Version of Csyntax with all loop cost labels embedded in syntax. diff --git a/Deliverables/D2.2/8051-matita-out/src/clight/clightPrintMatita.ml b/Deliverables/D2.2/8051-matita-out/src/clight/clightPrintMatita.ml index d3fc026..4e19f18 100644
a b let rec print_stmt p s = 265 265 print_stmt s1 266 266 print_stmt s2 267 267 | Swhile(_, e, s) -> 268 fprintf p "@[<v 2>(Swhile %a@ %a)@]"268 fprintf p "@[<v 2>(Swhile %a@ (None ?)@ %a@ (None ?))@]" 269 269 print_expr e 270 270 print_stmt s 271 271 | Sdowhile(_, e, s) -> 272 fprintf p "@[<v 2>S(dowhile %a@ %a)@]"272 fprintf p "@[<v 2>S(dowhile %a@ (None ?)@ %a@ (None ?))@]" 273 273 print_expr e 274 274 print_stmt s 275 275 | Sfor(_, s_init, e, s_iter, s_body) -> 276 fprintf p "@[<v 2>(Sfor %a@ %a@ %a@ \n%a@;<0 -2>)@]"276 fprintf p "@[<v 2>(Sfor %a@ %a@ %a@ (None ?)@\n%a@;<0 -2>(None ?))@]" 277 277 print_stmt s_init 278 278 print_expr e 279 279 print_stmt s_iter -
src/CHANGES
diff --git a/src/CHANGES b/src/CHANGES index f451b84..e8007f7 100644
a b 87 87 to be used in is_final. In Matita, they don't. For RTL the information was 88 88 duplicated in the internal function record. I have done the same for ERTL too. 89 89 To be double checked with the OCaml semantics. 90 91 02/10/2012: 92 Cost labels following loops and for the body of each loop have been 93 incorporated into the syntax of Swhile, etc. This keeps them closely 94 associated with the loop, allowing us to avoid placing skips before cost 95 labels which breaks our labelling invariant. The Cminor to RTLabs translation 96 is also careful to avoid introducing skips at goto labels for the same reason, 97 by backpatching the gotos after the rest of the code is generated. -
src/Clight/Cexec.ma
diff --git a/src/Clight/Cexec.ma b/src/Clight/Cexec.ma index 5b8cbc3..d509fa9 100644
a b definition is_Sskip : ∀s:statement. (s = Sskip) ⊎ (s ≠ Sskip) ≝ 330 330 λs.match s return λs'.(s' = Sskip) ⊎ (s' ≠ Sskip) with 331 331 [ Sskip ⇒ inl ?? (refl ??) 332 332 | _ ⇒ inr ?? (nmk ? (λH.?)) 333 ]. destruct333 ]. lapply (eq_to_jmeq ??? H) -H #H destruct 334 334 qed. 335 335 336 336 … … match st with 389 389 [ Tvoid ⇒ ret ? 〈E0, Returnstate Vundef k (free_list m (blocks_of_env e))〉 390 390 | _ ⇒ Wrong ??? (msg NonsenseState) 391 391 ] 392 | Kwhile a s' cl k' ⇒ ret ? 〈E0, State f (Swhile a s' cl) k' e m〉393 | Kdowhile a s'k' ⇒392 | Kwhile a lb s' lp k' ⇒ ret ? 〈E0, State f (Swhile a lb s' lp) k' e m〉 393 | Kdowhile a lb s' lp k' ⇒ 394 394 ! 〈v,tr〉 ← exec_expr ge e m a : IO ???; 395 395 ! b ← err_to_io … (exec_bool_of_val v (typeof a)); 396 396 match b with 397 [ true ⇒ ret ? 〈tr, State f (Sdowhile a s') k' e m〉398 | false ⇒ ret ? 〈tr, State f Sskipk' e m〉397 [ true ⇒ ret ? 〈tr, State f (Sdowhile a lb s' lp) k' e m〉 398 | false ⇒ ret ? 〈tr, State f (optional_cost lp Sskip) k' e m〉 399 399 ] 400 | Kfor2 a2 a3 s' k' ⇒ ret ? 〈E0, State f a3 (Kfor3 a2 a3 s'k') e m〉401 | Kfor3 a2 a3 s' k' ⇒ ret ? 〈E0, State f (Sfor Sskip a2 a3 s') k' e m〉400 | Kfor2 a2 a3 lb s' lp k' ⇒ ret ? 〈E0, State f a3 (Kfor3 a2 a3 lb s' lp k') e m〉 401 | Kfor3 a2 a3 lb s' lp k' ⇒ ret ? 〈E0, State f (Sfor Sskip a2 a3 lb s' lp) k' e m〉 402 402 | Kswitch k' ⇒ ret ? 〈E0, State f Sskip k' e m〉 403 403 | _ ⇒ Wrong ??? (msg NonsenseState) 404 404 ] 405 405 | Scontinue ⇒ 406 406 match k with 407 407 [ Kseq s' k' ⇒ ret ? 〈E0, State f Scontinue k' e m〉 408 | Kwhile a s' cl k' ⇒ ret ? 〈E0, State f (Swhile a s' cl) k' e m〉409 | Kdowhile a s'k' ⇒408 | Kwhile a lb s' lp k' ⇒ ret ? 〈E0, State f (Swhile a lb s' lp) k' e m〉 409 | Kdowhile a lb s' lp k' ⇒ 410 410 ! 〈v,tr〉 ← exec_expr ge e m a : IO ???; 411 411 ! b ← err_to_io … (exec_bool_of_val v (typeof a)); 412 412 match b with 413 [ true ⇒ ret ? 〈tr, State f (Sdowhile a s') k' e m〉414 | false ⇒ ret ? 〈tr, State f Sskipk' e m〉413 [ true ⇒ ret ? 〈tr, State f (Sdowhile a lb s' lp) k' e m〉 414 | false ⇒ ret ? 〈tr, State f (optional_cost lp Sskip) k' e m〉 415 415 ] 416 | Kfor2 a2 a3 s' k' ⇒ ret ? 〈E0, State f a3 (Kfor3 a2 a3 s'k') e m〉416 | Kfor2 a2 a3 lb s' lp k' ⇒ ret ? 〈E0, State f a3 (Kfor3 a2 a3 lb s' lp k') e m〉 417 417 | Kswitch k' ⇒ ret ? 〈E0, State f Scontinue k' e m〉 418 418 | _ ⇒ Wrong ??? (msg NonsenseState) 419 419 ] 420 420 | Sbreak ⇒ 421 421 match k with 422 422 [ Kseq s' k' ⇒ ret ? 〈E0, State f Sbreak k' e m〉 423 | Kwhile a s' cl k' ⇒ ret ? 〈E0, State f (optional_cost clSskip) k' e m〉424 | Kdowhile a s' k' ⇒ ret ? 〈E0, State f Sskipk' e m〉425 | Kfor2 a2 a3 s' k' ⇒ ret ? 〈E0, State f Sskipk' e m〉423 | Kwhile a lb s' lp k' ⇒ ret ? 〈E0, State f (optional_cost lp Sskip) k' e m〉 424 | Kdowhile a lb s' lp k' ⇒ ret ? 〈E0, State f (optional_cost lp Sskip) k' e m〉 425 | Kfor2 a2 a3 lb s' lp k' ⇒ ret ? 〈E0, State f (optional_cost lp Sskip) k' e m〉 426 426 | Kswitch k' ⇒ ret ? 〈E0, State f Sskip k' e m〉 427 427 | _ ⇒ Wrong ??? (msg NonsenseState) 428 428 ] … … match st with 430 430 ! 〈v,tr〉 ← exec_expr ge e m a : IO ???; 431 431 ! b ← err_to_io … (exec_bool_of_val v (typeof a)); 432 432 ret ? 〈tr, State f (if b then s1 else s2) k e m〉 433 | Swhile a s' cl⇒433 | Swhile a lb s' lp ⇒ 434 434 ! 〈v,tr〉 ← exec_expr ge e m a : IO ???; 435 435 ! b ← err_to_io … (exec_bool_of_val v (typeof a)); 436 ret ? 〈tr, if b then State f s' (Kwhile a s' clk) e m437 else State f (optional_cost clSskip) k e m〉438 | Sdowhile a s' ⇒ ret ? 〈E0, State f s' (Kdowhile a s'k) e m〉439 | Sfor a1 a2 a3 s'⇒436 ret ? 〈tr, if b then State f (optional_cost lb s') (Kwhile a lb s' lp k) e m 437 else State f (optional_cost lp Sskip) k e m〉 438 | Sdowhile a lb s' lp ⇒ ret ? 〈E0, State f (optional_cost lb s') (Kdowhile a lb s' lp k) e m〉 439 | Sfor a1 a2 a3 lb s' lp ⇒ 440 440 match is_Sskip a1 with 441 441 [ inl _ ⇒ 442 442 ! 〈v,tr〉 ← exec_expr ge e m a2 : IO ???; 443 443 ! b ← err_to_io … (exec_bool_of_val v (typeof a2)); 444 ret ? 〈tr, State f (if b then s' else Sskip) (if b then (Kfor2 a2 a3 s'k) else k) e m〉445 | inr _ ⇒ ret ? 〈E0, State f a1 (Kseq (Sfor Sskip a2 a3 s') k) e m〉444 ret ? 〈tr, State f (if b then optional_cost lb s' else optional_cost lp Sskip) (if b then (Kfor2 a2 a3 lb s' lp k) else k) e m〉 445 | inr _ ⇒ ret ? 〈E0, State f a1 (Kseq (Sfor Sskip a2 a3 lb s' lp) k) e m〉 446 446 ] 447 447 | Sreturn a_opt ⇒ 448 448 match a_opt with -
src/Clight/CexecComplete.ma
diff --git a/src/Clight/CexecComplete.ma b/src/Clight/CexecComplete.ma index 337877b..38fcc98 100644
a b theorem step_complete: ∀ge,s,tr,s'. 382 382 >(yields_eq ??? (expr_complete … H1)) whd in ⊢ (??%?); 383 383 >(yields_eq ??? (bool_of_false ?? H2)) 384 384 @refl 385 | #f #e # s #cl#k #env #m #v #tr #H1 #H2 whd in ⊢ (??%?);385 | #f #e #lb #s #lp #k #env #m #v #tr #H1 #H2 whd in ⊢ (??%?); 386 386 >(yields_eq ??? (expr_complete … H1)) whd in ⊢ (??%?); 387 387 >(yields_eq ??? (bool_of_false ?? H2)) 388 388 @refl 389 | #f #e # s #cl#k #env #m #v #tr #H1 #H2 whd in ⊢ (??%?);389 | #f #e #lb #s #lp #k #env #m #v #tr #H1 #H2 whd in ⊢ (??%?); 390 390 >(yields_eq ??? (expr_complete … H1)) whd in ⊢ (??%?); 391 391 >(yields_eq ??? (bool_of_true ?? H2)) 392 392 @refl 393 | #f #s1 #e # s2 #cl#k #env #m #H cases H; #es1 >es1 @refl394 | 13,14: #f #e # s [#cl]#k #env #m @refl395 | #f #s1 #e # s2#k #env #m #v #tr *; #es1 >es1 #H1 #H2 whd in ⊢ (??%?);393 | #f #s1 #e #lb #s2 #lp #k #env #m #H cases H; #es1 >es1 @refl 394 | 13,14: #f #e #lb #s #lp #k #env #m @refl 395 | #f #s1 #e #lb #s2 #lp #k #env #m #v #tr *; #es1 >es1 #H1 #H2 whd in ⊢ (??%?); 396 396 >(yields_eq ??? (expr_complete … H1)) whd in ⊢ (??%?); 397 397 >(yields_eq ??? (bool_of_false ?? H2)) 398 398 @refl 399 | #f #s1 #e # s2#k #env #m #v #tr *; #es1 >es1 #H1 #H2 whd in ⊢ (??%?);399 | #f #s1 #e #lb #s2 #lp #k #env #m #v #tr *; #es1 >es1 #H1 #H2 whd in ⊢ (??%?); 400 400 >(yields_eq ??? (expr_complete … H1)) whd in ⊢ (??%?); 401 401 >(yields_eq ??? (bool_of_true ?? H2)) 402 402 @refl 403 | #f #e # s#k #env #m @refl404 | #f #s1 #e #s2 # s3#k #env #m #nskip whd in ⊢ (??%?); cases (is_Sskip s1);403 | #f #e #lb #s #lp #k #env #m @refl 404 | #f #s1 #e #s2 #lb #s3 #lp #k #env #m #nskip whd in ⊢ (??%?); cases (is_Sskip s1); 405 405 [ #H @False_ind @(absurd ? H nskip) 406 406 | #H whd in ⊢ (??%?); @refl ] 407 | #f #e #s1 # s2#k #env #m #v #tr #H1 #H2 whd in ⊢ (??%?);407 | #f #e #s1 #lb #s2 #lp #k #env #m #v #tr #H1 #H2 whd in ⊢ (??%?); 408 408 >(yields_eq ??? (expr_complete … H1)) whd in ⊢ (??%?); 409 409 >(yields_eq ??? (bool_of_false ?? H2)) 410 410 @refl 411 | #f #e #s1 # s2#k #env #m #v #tr #H1 #H2 whd in ⊢ (??%?);411 | #f #e #s1 #lb #s2 #lp #k #env #m #v #tr #H1 #H2 whd in ⊢ (??%?); 412 412 >(yields_eq ??? (expr_complete … H1)) whd in ⊢ (??%?); 413 413 >(yields_eq ??? (bool_of_true ?? H2)) 414 414 @refl 415 | #f #s1 #e #s2 # s3#k #env #m *; #es1 >es1 @refl416 | 22,23: #f #e #s1 # s2#k #env #m @refl415 | #f #s1 #e #s2 #lb #s3 #lp #k #env #m *; #es1 >es1 @refl 416 | 22,23: #f #e #s1 #lb #s2 #lp #k #env #m @refl 417 417 | #f #k #env #m #H whd in ⊢ (??%?); >H @refl 418 418 | #f #e #k #env #m #v #tr #H1 #H2 whd in ⊢ (??%?); 419 419 @(dec_false ? (type_eq_dec (fn_return f) Tvoid) H1) #pf' … … theorem step_complete: ∀ge,s,tr,s'. 423 423 | #f #k #env #m cases k; 424 424 [ #H1 #H2 whd in ⊢ (??%?); >H2 @refl 425 425 | #s' #k' whd in ⊢ (% → ?); *; 426 | 3,4: #e' # s' [#cl]#k' whd in ⊢ (% → ?); *;427 | 5,6: #e' #s1' # s2'#k' whd in ⊢ (% → ?); *;426 | 3,4: #e' #lb #s' #lp #k' whd in ⊢ (% → ?); *; 427 | 5,6: #e' #s1' #lb #s2' #lp #k' whd in ⊢ (% → ?); *; 428 428 | #k' whd in ⊢ (% → ?); *; 429 429 | #r #f' #env' #k' #H1 #H2 whd in ⊢ (??%?); >H2 @refl 430 430 ] -
src/Clight/CexecEquiv.ma
diff --git a/src/Clight/CexecEquiv.ma b/src/Clight/CexecEquiv.ma index 725ebc1..501de00 100644
a b lemma exec_step_interaction: 513 513 ∀ge,s. interact_prop ? (λo,k. ∀i.∃tr.∃s'. k i = Value ??? 〈tr,s'〉 ∧ tr ≠ E0) (exec_step ge s). 514 514 #ge #s cases s; 515 515 [ #f #st #kk #e #m cases st; 516 [ 11,14: #a | 2,4, 7,12,13,15: #a #b | 3,5,6: #a #b #c | 8: #a #b #c #d]517 [ 4,5,7,8: @I ]516 [ 11,14: #a | 2,4,12,13,15: #a #b | 3,5: #a #b #c | 6,7: #a #b #c #d | 8: #a #b #c #d #e #f ] 517 try @I 518 518 whd in ⊢ (???%); 519 519 [ cases a; [ cases (fn_return f); //; | #e whd nodelta in ⊢ (???%); 520 520 cases (type_eq_dec (fn_return f) Tvoid); #x //; @err2_does_not_interact // ] … … lemma exec_step_interaction: 527 527 | cases (is_Sskip a); #H [ @err2_does_not_interact #x1 #x2 @err_does_not_interact #x3 @I 528 528 | @I ] 529 529 | cases kk; [ 1,8: cases (fn_return f); //; | 2,3,5,6,7: //; 530 | #z1 #z2 #z3 @err2_does_not_interact #x1 #x2 @err_does_not_interact #x3 cases x3; @I ]530 | #z1 #z2 #z3 #z4 #z5 @err2_does_not_interact #x1 #x2 @err_does_not_interact #x3 cases x3; @I ] 531 531 | cases kk; //; 532 | cases kk; [ 4: #z1 #z2 #z3 @err2_does_not_interact #x1 #x2 @err_does_not_interact #x3 cases x3; @I532 | cases kk; [ 4: #z1 #z2 #z3 #z4 #z5 @err2_does_not_interact #x1 #x2 @err_does_not_interact #x3 cases x3; @I 533 533 | *: // ] 534 534 ] 535 535 | #f #args #kk #m cases f; -
src/Clight/CexecSound.ma
diff --git a/src/Clight/CexecSound.ma b/src/Clight/CexecSound.ma index dc7fce3..88ef64b 100644
a b theorem exec_step_sound: ∀ge,st. 336 336 //; #H whd; 337 337 @step_skip_call //; 338 338 | #s' #k' whd; // 339 | #ex # s' #cl#k' @step_skip_or_continue_while % //;340 | #ex # s'#k'339 | #ex #lb #s' #lp #k' @step_skip_or_continue_while % //; 340 | #ex #lb #s' #lp #k' 341 341 @res_bindIO2_OK #v #tr #Hv 342 342 letin bexpr ≝ (exec_bool_of_val v (typeof ex)); 343 343 lapply (refl ? bexpr); … … theorem exec_step_sound: ∀ge,st. 351 351 ] 352 352 | #msg #_ //; 353 353 ] 354 | #ex #s1 # s2#k' @step_skip_or_continue_for2 % //;355 | #ex #s1 # s2#k' @step_skip_for3354 | #ex #s1 #lb #s2 #lp #k' @step_skip_or_continue_for2 % //; 355 | #ex #s1 #lb #s2 #lp #k' @step_skip_for3 356 356 | #k' @step_skip_break_switch % //; 357 357 | #r #f' #e' #k' whd in ⊢ (?????%); 358 358 lapply (refl ? (fn_return f)); cases (fn_return f) in ⊢ (???% → %); … … theorem exec_step_sound: ∀ge,st. 384 384 [ @(step_ifthenelse_true … (exec_expr_sound' … Hv)) @(bool_of … Hb) 385 385 | @(step_ifthenelse_false … (exec_expr_sound' … Hv)) @(bool_of … Hb) 386 386 ] 387 | #ex # s' #cl387 | #ex #lb #s' #lp 388 388 @res_bindIO2_OK #v #tr #Hv 389 389 letin bexpr ≝ (exec_bool_of_val v (typeof ex)); 390 390 lapply (refl ? bexpr); cases bexpr in ⊢ (???% → %); //; … … theorem exec_step_sound: ∀ge,st. 392 392 [ @(step_while_true … (exec_expr_sound' … Hv)) @(bool_of … Hb) 393 393 | @(step_while_false … (exec_expr_sound' … Hv)) @(bool_of … Hb) 394 394 ] 395 | #ex # s'//396 | #s1 #ex #s2 # s3whd in ⊢ (?????%); elim (is_Sskip s1); #Hs1 whd in ⊢ (?????%);395 | #ex #lb #s' #lp // 396 | #s1 #ex #s2 #lb #s3 #lp whd in ⊢ (?????%); elim (is_Sskip s1); #Hs1 whd in ⊢ (?????%); 397 397 [ >Hs1 398 398 @res_bindIO2_OK #v #tr #Hv 399 399 letin bexpr ≝ (exec_bool_of_val v (typeof ex)); … … theorem exec_step_sound: ∀ge,st. 406 406 ] 407 407 | whd in ⊢ (?????%); cases k; // #k' @step_skip_break_switch %2 // 408 408 | whd in ⊢ (?????%); cases k; //; 409 [ #ex # s' #cl#k' whd; @step_skip_or_continue_while %2 ; //;410 | #ex # s'#k' whd;409 [ #ex #lb #s' #lp #k' whd; @step_skip_or_continue_while %2 ; //; 410 | #ex #lb #s' #lp #k' whd; 411 411 @res_bindIO2_OK #v #tr #Hv 412 412 letin bexpr ≝ (exec_bool_of_val v (typeof ex)); 413 413 lapply (refl ? bexpr); cases bexpr in ⊢ (???% → %); //; … … theorem exec_step_sound: ∀ge,st. 417 417 | @(step_skip_or_continue_dowhile_false … (exec_expr_sound' … Hv)) 418 418 [ %2 ; // | @(bool_of … Hb) ] 419 419 ] 420 | #ex #s1 # s2#k' whd; @step_skip_or_continue_for2 %2 ; //420 | #ex #s1 #lb #s2 #lp #k' whd; @step_skip_or_continue_for2 %2 ; // 421 421 ] 422 422 | #r whd in ⊢ (?????%); cases r; 423 423 [ whd; lapply (refl ? (fn_return f)); cases (fn_return f) in ⊢ (???% → %); //; #H -
src/Clight/Csem.ma
diff --git a/src/Clight/Csem.ma b/src/Clight/Csem.ma index 344de75..9685b53 100644
a b inductive eval_exprlist (ge:genv) (e:env) (m:mem) : list expr → list val → t 907 907 908 908 inductive cont: Type[0] := 909 909 | Kstop: cont 910 | Kseq: statement -> cont ->cont910 | Kseq: statement → cont → cont 911 911 (**r [Kseq s2 k] = after [s1] in [s1;s2] *) 912 | Kwhile: expr -> statement → option costlabel -> cont ->cont913 (**r [Kwhile e sk] = after [s] in [while (e) s] *)914 | Kdowhile: expr -> statement -> cont ->cont915 (**r [Kdowhile e sk] = after [s] in [do s while (e)] *)916 | Kfor2: expr -> statement -> statement -> cont ->cont917 (**r [Kfor2 e2 e3 sk] = after [s] in [for(e1;e2;e3) s] *)918 | Kfor3: expr -> statement -> statement -> cont ->cont919 (**r [Kfor3 e2 e3 sk] = after [e3] in [for(e1;e2;e3) s] *)920 | Kswitch: cont ->cont912 | Kwhile: expr → option costlabel → statement → option costlabel → cont → cont 913 (**r [Kwhile e lb s lp k] = after [s] in [while (e) s] *) 914 | Kdowhile: expr → option costlabel → statement → option costlabel → cont → cont 915 (**r [Kdowhile e lb s lp k] = after [s] in [do s while (e)] *) 916 | Kfor2: expr → statement → option costlabel → statement → option costlabel → cont → cont 917 (**r [Kfor2 e2 e3 lb s lp k] = after [s] in [for(e1;e2;e3) s] *) 918 | Kfor3: expr → statement → option costlabel → statement → option costlabel → cont → cont 919 (**r [Kfor3 e2 e3 lb s lp k] = after [e3] in [for(e1;e2;e3) s] *) 920 | Kswitch: cont → cont 921 921 (**r catches [break] statements arising out of [switch] *) 922 | Kcall: option (block × offset × type) ->(**r where to store result *)923 function ->(**r calling function *)924 env ->(**r local env of calling function *)925 cont ->cont.922 | Kcall: option (block × offset × type) → (**r where to store result *) 923 function → (**r calling function *) 924 env → (**r local env of calling function *) 925 cont → cont. 926 926 927 927 (* * Pop continuation until a call or stop *) 928 928 929 929 let rec call_cont (k: cont) : cont := 930 930 match k with 931 931 [ Kseq s k => call_cont k 932 | Kwhile e s lk => call_cont k933 | Kdowhile e sk => call_cont k934 | Kfor2 e2 e3 sk => call_cont k935 | Kfor3 e2 e3 sk => call_cont k932 | Kwhile e _ s _ k => call_cont k 933 | Kdowhile e _ s _ k => call_cont k 934 | Kfor2 e2 e3 _ s _ k => call_cont k 935 | Kfor3 e2 e3 _ s _ k => call_cont k 936 936 | Kswitch k => call_cont k 937 937 | _ => k 938 938 ]. … … let rec find_label (lbl: label) (s: statement) (k: cont) 982 982 [ Some sk => Some ? sk 983 983 | None => find_label lbl s2 k 984 984 ] 985 | Swhile a s1 l=>986 find_label lbl s1 (Kwhile a s1 lk)987 | Sdowhile a s1=>988 find_label lbl s1 (Kdowhile a s1k)989 | Sfor a1 a2 a3 s1=>990 match find_label lbl a1 (Kseq (Sfor Sskip a2 a3 s1) k) with985 | Swhile a lb s1 lp => 986 find_label lbl s1 (Kwhile a lb s1 lp k) 987 | Sdowhile a lb s1 lp => 988 find_label lbl s1 (Kdowhile a lb s1 lp k) 989 | Sfor a1 a2 a3 lb s1 lp => 990 match find_label lbl a1 (Kseq (Sfor Sskip a2 a3 lb s1 lp) k) with 991 991 [ Some sk => Some ? sk 992 992 | None => 993 match find_label lbl s1 (Kfor2 a2 a3 s1k) with993 match find_label lbl s1 (Kfor2 a2 a3 lb s1 lp k) with 994 994 [ Some sk => Some ? sk 995 | None => find_label lbl a3 (Kfor3 a2 a3 s1k)995 | None => find_label lbl a3 (Kfor3 a2 a3 lb s1 lp k) 996 996 ] 997 997 ] 998 998 | Sswitch e sl => … … definition fun_typeof ≝ 1034 1034 | Tcomp_ptr a ⇒ Tcomp_ptr a 1035 1035 ]. 1036 1036 1037 (* For loops we may generate a cost label statement for the body / following 1038 code if there's one present in the loop statement. *) 1039 1037 1040 definition optional_cost : option costlabel → statement → statement ≝ 1038 1041 λo,s. match o with [ Some cl ⇒ Scost cl s | None ⇒ s ]. 1039 1042 … … inductive step (ge:genv) : state → trace → state → Prop ≝ 1089 1092 step ge (State f (Sifthenelse a s1 s2) k e m) 1090 1093 tr (State f s2 k e m) 1091 1094 1092 | step_while_false: ∀f,a, s,cl,k,e,m,v,tr.1095 | step_while_false: ∀f,a,lb,s,lp,k,e,m,v,tr. 1093 1096 eval_expr ge e m a v tr → 1094 1097 is_false v (typeof a) → 1095 step ge (State f (Swhile a s cl) k e m)1096 tr (State f (optional_cost clSskip) k e m)1097 | step_while_true: ∀f,a, s,cl,k,e,m,v,tr.1098 step ge (State f (Swhile a lb s lp) k e m) 1099 tr (State f (optional_cost lp Sskip) k e m) 1100 | step_while_true: ∀f,a,lb,s,lp,k,e,m,v,tr. 1098 1101 eval_expr ge e m a v tr → 1099 1102 is_true v (typeof a) → 1100 step ge (State f (Swhile a s cl) k e m)1101 tr (State f s (Kwhile a s clk) e m)1102 | step_skip_or_continue_while: ∀f,x,a, s,cl,k,e,m.1103 step ge (State f (Swhile a lb s lp) k e m) 1104 tr (State f (optional_cost lb s) (Kwhile a lb s lp k) e m) 1105 | step_skip_or_continue_while: ∀f,x,a,lb,s,lp,k,e,m. 1103 1106 x = Sskip ∨ x = Scontinue → 1104 step ge (State f x (Kwhile a s clk) e m)1105 E0 (State f (Swhile a s cl) k e m)1106 | step_break_while: ∀f,a, s,cl,k,e,m.1107 step ge (State f Sbreak (Kwhile a s clk) e m)1108 E0 (State f (optional_cost clSskip) k e m)1109 1110 | step_dowhile: ∀f,a, s,k,e,m.1111 step ge (State f (Sdowhile a s) k e m)1112 E0 (State f s (Kdowhile a sk) e m)1113 | step_skip_or_continue_dowhile_false: ∀f,x,a, s,k,e,m,v,tr.1107 step ge (State f x (Kwhile a lb s lp k) e m) 1108 E0 (State f (Swhile a lb s lp) k e m) 1109 | step_break_while: ∀f,a,lb,s,lp,k,e,m. 1110 step ge (State f Sbreak (Kwhile a lb s lp k) e m) 1111 E0 (State f (optional_cost lp Sskip) k e m) 1112 1113 | step_dowhile: ∀f,a,lb,s,lp,k,e,m. 1114 step ge (State f (Sdowhile a lb s lp) k e m) 1115 E0 (State f (optional_cost lb s) (Kdowhile a lb s lp k) e m) 1116 | step_skip_or_continue_dowhile_false: ∀f,x,a,lb,s,lp,k,e,m,v,tr. 1114 1117 x = Sskip ∨ x = Scontinue → 1115 1118 eval_expr ge e m a v tr → 1116 1119 is_false v (typeof a) → 1117 step ge (State f x (Kdowhile a sk) e m)1118 tr (State f Sskipk e m)1119 | step_skip_or_continue_dowhile_true: ∀f,x,a, s,k,e,m,v,tr.1120 step ge (State f x (Kdowhile a lb s lp k) e m) 1121 tr (State f (optional_cost lp Sskip) k e m) 1122 | step_skip_or_continue_dowhile_true: ∀f,x,a,lb,s,lp,k,e,m,v,tr. 1120 1123 x = Sskip ∨ x = Scontinue → 1121 1124 eval_expr ge e m a v tr → 1122 1125 is_true v (typeof a) → 1123 step ge (State f x (Kdowhile a sk) e m)1124 tr (State f (Sdowhile a s) k e m)1125 | step_break_dowhile: ∀f,a, s,k,e,m.1126 step ge (State f Sbreak (Kdowhile a sk) e m)1127 E0 (State f Sskipk e m)1126 step ge (State f x (Kdowhile a lb s lp k) e m) 1127 tr (State f (Sdowhile a lb s lp) k e m) 1128 | step_break_dowhile: ∀f,a,lb,s,lp,k,e,m. 1129 step ge (State f Sbreak (Kdowhile a lb s lp k) e m) 1130 E0 (State f (optional_cost lp Sskip) k e m) 1128 1131 1129 | step_for_start: ∀f,a1,a2,a3, s,k,e,m.1132 | step_for_start: ∀f,a1,a2,a3,lb,s,lp,k,e,m. 1130 1133 a1 ≠ Sskip → 1131 step ge (State f (Sfor a1 a2 a3 s) k e m)1132 E0 (State f a1 (Kseq (Sfor Sskip a2 a3 s) k) e m)1133 | step_for_false: ∀f,a2,a3, s,k,e,m,v,tr.1134 step ge (State f (Sfor a1 a2 a3 lb s lp) k e m) 1135 E0 (State f a1 (Kseq (Sfor Sskip a2 a3 lb s lp) k) e m) 1136 | step_for_false: ∀f,a2,a3,lb,s,lp,k,e,m,v,tr. 1134 1137 eval_expr ge e m a2 v tr → 1135 1138 is_false v (typeof a2) → 1136 step ge (State f (Sfor Sskip a2 a3 s) k e m)1137 tr (State f Sskipk e m)1138 | step_for_true: ∀f,a2,a3, s,k,e,m,v,tr.1139 step ge (State f (Sfor Sskip a2 a3 lb s lp) k e m) 1140 tr (State f (optional_cost lp Sskip) k e m) 1141 | step_for_true: ∀f,a2,a3,lb,s,lp,k,e,m,v,tr. 1139 1142 eval_expr ge e m a2 v tr → 1140 1143 is_true v (typeof a2) → 1141 step ge (State f (Sfor Sskip a2 a3 s) k e m)1142 tr (State f s (Kfor2 a2 a3 sk) e m)1143 | step_skip_or_continue_for2: ∀f,x,a2,a3, s,k,e,m.1144 step ge (State f (Sfor Sskip a2 a3 lb s lp) k e m) 1145 tr (State f (optional_cost lb s) (Kfor2 a2 a3 lb s lp k) e m) 1146 | step_skip_or_continue_for2: ∀f,x,a2,a3,lb,s,lp,k,e,m. 1144 1147 x = Sskip ∨ x = Scontinue → 1145 step ge (State f x (Kfor2 a2 a3 sk) e m)1146 E0 (State f a3 (Kfor3 a2 a3 sk) e m)1147 | step_break_for2: ∀f,a2,a3, s,k,e,m.1148 step ge (State f Sbreak (Kfor2 a2 a3 sk) e m)1149 E0 (State f Sskipk e m)1150 | step_skip_for3: ∀f,a2,a3, s,k,e,m.1151 step ge (State f Sskip (Kfor3 a2 a3 sk) e m)1152 E0 (State f (Sfor Sskip a2 a3 s) k e m)1148 step ge (State f x (Kfor2 a2 a3 lb s lp k) e m) 1149 E0 (State f a3 (Kfor3 a2 a3 lb s lp k) e m) 1150 | step_break_for2: ∀f,a2,a3,lb,s,lp,k,e,m. 1151 step ge (State f Sbreak (Kfor2 a2 a3 lb s lp k) e m) 1152 E0 (State f (optional_cost lp Sskip) k e m) 1153 | step_skip_for3: ∀f,a2,a3,lb,s,lp,k,e,m. 1154 step ge (State f Sskip (Kfor3 a2 a3 lb s lp k) e m) 1155 E0 (State f (Sfor Sskip a2 a3 lb s lp) k e m) 1153 1156 1154 1157 | step_return_0: ∀f,k,e,m. 1155 1158 fn_return f = Tvoid → -
src/Clight/Csyntax.ma
diff --git a/src/Clight/Csyntax.ma b/src/Clight/Csyntax.ma index a96a722..4bc2925 100644
a b definition typeof : expr → type ≝ λe. 183 183 (* * Clight statements include all C statements. 184 184 Only structured forms of [switch] are supported; moreover, 185 185 the [default] case must occur last. Blocks and block-scoped declarations 186 are not supported. *) 186 are not supported. 187 188 The loops have optional cost labels for the body of the loop and for after 189 the loop is complete (usually denoted lb and lp respectively in definitions). 190 By closely associating the cost labels with the syntax it is easier to write 191 the code to compile loops without introducing extraneous statements between 192 control flow and cost labels. 193 *) 187 194 188 195 definition label ≝ ident. 189 196 … … inductive statement : Type[0] ≝ 193 200 | Scall: option expr → expr → list expr → statement (**r function call *) 194 201 | Ssequence : statement → statement → statement (**r sequence *) 195 202 | Sifthenelse : expr → statement → statement → statement (**r conditional *) 196 | Swhile : expr → statement → option costlabel → statement (**r [while] loop *)197 | Sdowhile : expr → statement→ statement (**r [do] loop *)198 | Sfor: statement → expr → statement → statement→ statement (**r [for] loop *)203 | Swhile : expr → option costlabel → statement → option costlabel → statement (**r [while] loop *) 204 | Sdowhile : expr → option costlabel → statement → option costlabel → statement (**r [do] loop *) 205 | Sfor: statement → expr → statement → option costlabel → statement → option costlabel → statement (**r [for] loop *) 199 206 | Sbreak : statement (**r [break] statement *) 200 207 | Scontinue : statement (**r [continue] statement *) 201 208 | Sreturn : option expr → statement (**r [return] statement *) … … let rec statement_ind2 225 232 (Sca:∀eo,e,args. P (Scall eo e args)) 226 233 (Ssq:∀s1,s2. P s1 → P s2 → P (Ssequence s1 s2)) 227 234 (Sif:∀e,s1,s2. P s1 → P s2 → P (Sifthenelse e s1 s2)) 228 (Swh:∀e,s,l . P s → P (Swhile e s l))229 (Sdo:∀e,s . P s → P (Sdowhile e s))230 (Sfo:∀s1,e,s2,s3 . P s1 → P s2 → P s3 → P (Sfor s1 e s2 s3))235 (Swh:∀e,s,lb,lp. P s → P (Swhile e lb s lp)) 236 (Sdo:∀e,s,lb,lp. P s → P (Sdowhile e lb s lp)) 237 (Sfo:∀s1,e,s2,s3,lb,lp. P s1 → P s2 → P s3 → P (Sfor s1 e s2 lb s3 lp)) 231 238 (Sbr:P Sbreak) 232 239 (Sco:P Scontinue) 233 240 (Sre:∀eo. P (Sreturn eo)) … … match s with 248 255 | Sifthenelse e s1 s2 ⇒ Sif e s1 s2 249 256 (statement_ind2 P Q Ssk Sas Sca Ssq Sif Swh Sdo Sfo Sbr Sco Sre Ssw Sla Sgo Scs LSd LSc s1) 250 257 (statement_ind2 P Q Ssk Sas Sca Ssq Sif Swh Sdo Sfo Sbr Sco Sre Ssw Sla Sgo Scs LSd LSc s2) 251 | Swhile e s cl ⇒ Swh e s cl258 | Swhile e lb s lp ⇒ Swh e s lb lp 252 259 (statement_ind2 P Q Ssk Sas Sca Ssq Sif Swh Sdo Sfo Sbr Sco Sre Ssw Sla Sgo Scs LSd LSc s) 253 | Sdowhile e s ⇒ Sdo e s260 | Sdowhile e lb s lp ⇒ Sdo e s lb lp 254 261 (statement_ind2 P Q Ssk Sas Sca Ssq Sif Swh Sdo Sfo Sbr Sco Sre Ssw Sla Sgo Scs LSd LSc s) 255 | Sfor s1 e s2 s3 ⇒ Sfo s1 e s2 s3262 | Sfor s1 e s2 lb s3 lp ⇒ Sfo s1 e s2 s3 lb lp 256 263 (statement_ind2 P Q Ssk Sas Sca Ssq Sif Swh Sdo Sfo Sbr Sco Sre Ssw Sla Sgo Scs LSd LSc s1) 257 264 (statement_ind2 P Q Ssk Sas Sca Ssq Sif Swh Sdo Sfo Sbr Sco Sre Ssw Sla Sgo Scs LSd LSc s2) 258 265 (statement_ind2 P Q Ssk Sas Sca Ssq Sif Swh Sdo Sfo Sbr Sco Sre Ssw Sla Sgo Scs LSd LSc s3) … … and labeled_statements_ind2 274 281 (Sca:∀eo,e,args. P (Scall eo e args)) 275 282 (Ssq:∀s1,s2. P s1 → P s2 → P (Ssequence s1 s2)) 276 283 (Sif:∀e,s1,s2. P s1 → P s2 → P (Sifthenelse e s1 s2)) 277 (Swh:∀e,s,l . P s → P (Swhile e s l))278 (Sdo:∀e,s . P s → P (Sdowhile e s))279 (Sfo:∀s1,e,s2,s3 . P s1 → P s2 → P s3 → P (Sfor s1 e s2 s3))284 (Swh:∀e,s,lb,lp. P s → P (Swhile e lb s lp)) 285 (Sdo:∀e,s,lb,lp. P s → P (Sdowhile e lb s lp)) 286 (Sfo:∀s1,e,s2,s3,lb,lp. P s1 → P s2 → P s3 → P (Sfor s1 e s2 lb s3 lp)) 280 287 (Sbr:P Sbreak) 281 288 (Sco:P Scontinue) 282 289 (Sre:∀eo. P (Sreturn eo)) -
src/Clight/SimplifyCasts.ma
diff --git a/src/Clight/SimplifyCasts.ma b/src/Clight/SimplifyCasts.ma index 16aff67..d9b69fc 100644
a b match s with 1981 1981 | Scall eo e es ⇒ Scall (option_map ?? simplify_e eo) (simplify_e e) (map ?? simplify_e es) 1982 1982 | Ssequence s1 s2 ⇒ Ssequence (simplify_statement s1) (simplify_statement s2) 1983 1983 | Sifthenelse e s1 s2 ⇒ Sifthenelse (simplify_e e) (simplify_statement s1) (simplify_statement s2) (* TODO: try to reduce size of e *) 1984 | Swhile e s1 cl ⇒ Swhile (simplify_e e) (simplify_statement s1) cl(* TODO: try to reduce size of e *)1985 | Sdowhile e s1 ⇒ Sdowhile (simplify_e e) (simplify_statement s1)(* TODO: try to reduce size of e *)1986 | Sfor s1 e s2 s3 ⇒ Sfor (simplify_statement s1) (simplify_e e) (simplify_statement s2) (simplify_statement s3)(* TODO: reduce size of e *)1984 | Swhile e lb s1 lp ⇒ Swhile (simplify_e e) lb (simplify_statement s1) lp (* TODO: try to reduce size of e *) 1985 | Sdowhile e lb s1 lp ⇒ Sdowhile (simplify_e e) lb (simplify_statement s1) lp (* TODO: try to reduce size of e *) 1986 | Sfor s1 e s2 lb s3 lp ⇒ Sfor (simplify_statement s1) (simplify_e e) (simplify_statement s2) lb (simplify_statement s3) lp (* TODO: reduce size of e *) 1987 1987 | Sbreak ⇒ Sbreak 1988 1988 | Scontinue ⇒ Scontinue 1989 1989 | Sreturn eo ⇒ Sreturn (option_map ?? simplify_e eo) … … definition simplify_program : clight_program → clight_program ≝ 2014 2014 inductive cont_cast : cont → cont → Prop ≝ 2015 2015 | cc_stop : cont_cast Kstop Kstop 2016 2016 | cc_seq : ∀s,k,k'. cont_cast k k' → cont_cast (Kseq s k) (Kseq (simplify_statement s) k') 2017 | cc_while : ∀e, s,cl,k,k'.2017 | cc_while : ∀e,lb,s,lp,k,k'. 2018 2018 cont_cast k k' → 2019 cont_cast (Kwhile e s cl k) (Kwhile (simplify_e e) (simplify_statement s) clk')2020 | cc_dowhile : ∀e, s,k,k'.2019 cont_cast (Kwhile e lb s lp k) (Kwhile (simplify_e e) lb (simplify_statement s) lp k') 2020 | cc_dowhile : ∀e,lb,s,lp,k,k'. 2021 2021 cont_cast k k' → 2022 cont_cast (Kdowhile e s k) (Kdowhile (simplify_e e) (simplify_statement s)k')2023 | cc_for1 : ∀e,s1, s2,k,k'.2022 cont_cast (Kdowhile e lb s lp k) (Kdowhile (simplify_e e) lb (simplify_statement s) lp k') 2023 | cc_for1 : ∀e,s1,lb,s2,lp,k,k'. 2024 2024 cont_cast k k' → 2025 cont_cast (Kseq (Sfor Sskip e s1 s2) k) (Kseq (Sfor Sskip (simplify_e e) (simplify_statement s1) (simplify_statement s2)) k')2026 | cc_for2 : ∀e,s1, s2,k,k'.2025 cont_cast (Kseq (Sfor Sskip e s1 lb s2 lp) k) (Kseq (Sfor Sskip (simplify_e e) (simplify_statement s1) lb (simplify_statement s2) lp) k') 2026 | cc_for2 : ∀e,s1,lb,s2,lp,k,k'. 2027 2027 cont_cast k k' → 2028 cont_cast (Kfor2 e s1 s2 k) (Kfor2 (simplify_e e) (simplify_statement s1) (simplify_statement s2)k')2029 | cc_for3 : ∀e,s1, s2,k,k'.2028 cont_cast (Kfor2 e s1 lb s2 lp k) (Kfor2 (simplify_e e) (simplify_statement s1) lb (simplify_statement s2) lp k') 2029 | cc_for3 : ∀e,s1,lb,s2,lp,k,k'. 2030 2030 cont_cast k k' → 2031 cont_cast (Kfor3 e s1 s2 k) (Kfor3 (simplify_e e) (simplify_statement s1) (simplify_statement s2)k')2031 cont_cast (Kfor3 e s1 lb s2 lp k) (Kfor3 (simplify_e e) (simplify_statement s1) lb (simplify_statement s2) lp k') 2032 2032 | cc_switch : ∀k,k'. 2033 2033 cont_cast k k' → cont_cast (Kswitch k) (Kswitch k') 2034 2034 | cc_call : ∀r,f,en,k,k'. … … lemma cast_find_label : ∀lab,s,k,k'. 2423 2423 normalize nodelta %{kst'} /2/ 2424 2424 | 1: * #Hrewrite >Hrewrite #Hrewrite1 >Hrewrite1 normalize nodelta // 2425 2425 ] ] 2426 | 6: #e #s # cl#Hind_s #k #k' #Hcont_cast2426 | 6: #e #s #lb #lp #Hind_s #k #k' #Hcont_cast 2427 2427 whd in match (find_label ???); 2428 2428 whd in match (find_label ? (simplify_statement ?) ?); 2429 elim (elim_IH_aux lab s (Kwhile e s cl k) (Kwhile (simplify_e e) (simplify_statement s) clk') ? Hind_s)2429 elim (elim_IH_aux lab s (Kwhile e lb s lp k) (Kwhile (simplify_e e) lb (simplify_statement s) lp k') ? Hind_s) 2430 2430 [ 2: * #st * #kst * #kst' * * #Hrewrite >Hrewrite #Hrewrite1 >Hrewrite1 #Hcont_cast' 2431 2431 normalize nodelta %{kst'} /2/ 2432 2432 | 1: * #Hrewrite >Hrewrite #Hrewrite1 >Hrewrite1 normalize nodelta // 2433 2433 | 3: @cc_while // ] 2434 | 7: #e #s # Hind_s #k #k' #Hcont_cast2434 | 7: #e #s #lb #lp #Hind_s #k #k' #Hcont_cast 2435 2435 whd in match (find_label ???); 2436 2436 whd in match (find_label ? (simplify_statement ?) ?); 2437 elim (elim_IH_aux lab s (Kdowhile e s k) (Kdowhile (simplify_e e) (simplify_statement s)k') ? Hind_s)2437 elim (elim_IH_aux lab s (Kdowhile e lb s lp k) (Kdowhile (simplify_e e) lb (simplify_statement s) lp k') ? Hind_s) 2438 2438 [ 2: * #st * #kst * #kst' * * #Hrewrite >Hrewrite #Hrewrite1 >Hrewrite1 #Hcont_cast' 2439 2439 normalize nodelta %{kst'} /2/ 2440 2440 | 1: * #Hrewrite >Hrewrite #Hrewrite1 >Hrewrite1 normalize nodelta // 2441 2441 | 3: @cc_dowhile // ] 2442 | 8: #s1 #cond #s2 #s3 # Hind_s1 #Hind_s2 #Hind_s3 #k #k' #Hcont_cast2442 | 8: #s1 #cond #s2 #s3 #lb #lp #Hind_s1 #Hind_s2 #Hind_s3 #k #k' #Hcont_cast 2443 2443 whd in match (find_label ???); 2444 2444 whd in match (find_label ? (simplify_statement ?) ?); 2445 2445 elim (elim_IH_aux lab s1 2446 (Kseq (Sfor Sskip cond s2 s3) k)2447 (Kseq (Sfor Sskip (simplify_e cond) (simplify_statement s2) (simplify_statement s3)) k')2446 (Kseq (Sfor Sskip cond s2 lb s3 lp) k) 2447 (Kseq (Sfor Sskip (simplify_e cond) (simplify_statement s2) lb (simplify_statement s3) lp) k') 2448 2448 ? Hind_s1) 2449 2449 [ 2: * #st * #kst * #kst' * * #Hrewrite >Hrewrite #Hrewrite1 >Hrewrite1 #Hcont_cast' 2450 2450 normalize nodelta %{kst'} /2/ 2451 2451 | 3: @cc_for1 // 2452 2452 | 1: * #Hrewrite >Hrewrite #Hrewrite1 >Hrewrite1 normalize nodelta 2453 2453 elim (elim_IH_aux lab s3 2454 (Kfor2 cond s2 s3k)2455 (Kfor2 (simplify_e cond) (simplify_statement s2) (simplify_statement s3)k')2454 (Kfor2 cond s2 lb s3 lp k) 2455 (Kfor2 (simplify_e cond) (simplify_statement s2) lb (simplify_statement s3) lp k') 2456 2456 ? Hind_s3) 2457 2457 [ 2: * #st * #kst * #kst' * * #Hrewrite >Hrewrite #Hrewrite1 >Hrewrite1 #Hcont_cast' 2458 2458 normalize nodelta %{kst'} /2/ 2459 2459 | 3: @cc_for2 // 2460 2460 | 1: * #Hrewrite >Hrewrite #Hrewrite1 >Hrewrite1 normalize nodelta 2461 2461 elim (elim_IH_aux lab s2 2462 (Kfor3 cond s2 s3k)2463 (Kfor3 (simplify_e cond) (simplify_statement s2) (simplify_statement s3)k')2462 (Kfor3 cond s2 lb s3 lp k) 2463 (Kfor3 (simplify_e cond) (simplify_statement s2) lb (simplify_statement s3) lp k') 2464 2464 ? Hind_s2) 2465 2465 [ 2: * #st * #kst * #kst' * * #Hrewrite >Hrewrite #Hrewrite1 >Hrewrite1 #Hcont_cast' 2466 2466 normalize nodelta %{kst'} /2/ … … inversion Hs1_sim_s1' 2590 2590 lapply (related_globals_lvalue_simulation ge ge' en m Hrelated) #Hsim_lvalue_related 2591 2591 cases stm 2592 2592 (* Perform the intros for the statements*) 2593 [ 1: | 2: #lhs #rhs | 3: #ret #func #args | 4: #stm1 #stm2 | 5: #cond #iftrue #iffalse | 6: #cond # body2594 | 7: #cond # body | 8: #init #cond #step #body| 9,10: | 11: #retval | 12: #cond #switchcases | 13: #lab #body2593 [ 1: | 2: #lhs #rhs | 3: #ret #func #args | 4: #stm1 #stm2 | 5: #cond #iftrue #iffalse | 6: #cond #lb #body #lp 2594 | 7: #cond #lb #body #lp | 8: #init #cond #step #lb #body #lp | 9,10: | 11: #retval | 12: #cond #switchcases | 13: #lab #body 2595 2595 | 14: #lab | 15: #cost #body ] 2596 2596 [ 1: (* Skip *) 2597 2597 #Heq_s1 #Heq_s1' #_ lapply Houtcome >Heq_s1 … … inversion Hs1_sim_s1' 2615 2615 %{(State (simplify_function f) (simplify_statement stm') k0' en m)} @conj 2616 2616 [ 1: // | 2: %1 // ] 2617 2617 | 3: (* Kwhile *) 2618 #cond # body #cl#k0 #k0' #Hconst_cast0 #Hind #Hk #Hk' #_ normalize nodelta #Eq2618 #cond #lb #body #lp #k0 #k0' #Hconst_cast0 #Hind #Hk #Hk' #_ normalize nodelta #Eq 2619 2619 whd in match (ret ??) in Eq; destruct (Eq) 2620 %{(State (simplify_function f) (Swhile (simplify_e cond) (simplify_statement body) cl) k0' en m)} @conj2620 %{(State (simplify_function f) (Swhile (simplify_e cond) lb (simplify_statement body) lp) k0' en m)} @conj 2621 2621 [ 1: // | 2: %1 // ] 2622 2622 | 4: (* Kdowhile *) 2623 #cond # body#k0 #k0' #Hcont_cast0 #Hind #Hk #Hk' #_ normalize nodelta #Eq2623 #cond #lb #body #lp #k0 #k0' #Hcont_cast0 #Hind #Hk #Hk' #_ normalize nodelta #Eq 2624 2624 elim (Hsim_related cond) #Hsim_cond #Htype_cond_eq cases Hsim_cond 2625 2625 [ 2: * #error #Hfail >Hfail in Eq; #Habsurd normalize in Habsurd; destruct 2626 2626 | 1: cases (exec_expr ge en m cond) in Eq; … … inversion Hs1_sim_s1' 2635 2635 | 1: * whd in match (bindIO ??????); 2636 2636 whd in match (bindIO ??????); 2637 2637 #Eq destruct (Eq) 2638 [ 1: %{(State (simplify_function f) (Sdowhile (simplify_e cond) (simplify_statement body)) k0' en m)} 2639 @conj [ 1: // | 2: %1 // ] 2640 | 2: %{(State (simplify_function f) Sskip k0' en m)} 2638 [ 1: %{(State (simplify_function f) (Sdowhile (simplify_e cond) lb (simplify_statement body) lp) k0' en m)} 2641 2639 @conj [ 1: // | 2: %1 // ] 2640 | 2: %{(State (simplify_function f) (optional_cost lp Sskip) k0' en m)} 2641 @conj [ 1: // | 2: cases lp [2:#lp'] %1 // ] 2642 2642 ] 2643 2643 ] 2644 2644 ] 2645 2645 ] 2646 2646 | 5,6,7: 2647 #cond #step # body#k0 #k0' #Hcont_cast0 #Hind #Hk #Hk' #_ normalize nodelta #Eq2647 #cond #step #lb #body #lp #k0 #k0' #Hcont_cast0 #Hind #Hk #Hk' #_ normalize nodelta #Eq 2648 2648 whd in match (ret ??) in Eq ⊢ %; destruct (Eq) 2649 2649 [ 1: %{(State (simplify_function f) 2650 (Sfor Sskip (simplify_e cond) (simplify_statement step) (simplify_statement body))2650 (Sfor Sskip (simplify_e cond) (simplify_statement step) lb (simplify_statement body) lp) 2651 2651 k0' en m)} @conj 2652 2652 [ 1: // | 2: %1 // ] 2653 2653 | 2: %{(State (simplify_function f) 2654 2654 (simplify_statement step) 2655 (Kfor3 (simplify_e cond) (simplify_statement step) (simplify_statement body)k0')2655 (Kfor3 (simplify_e cond) (simplify_statement step) lb (simplify_statement body) lp k0') 2656 2656 en m)} @conj 2657 2657 [ 1: // | 2: %1 @cc_for3 // ] 2658 2658 | 3: %{(State (simplify_function f) 2659 2659 (Sfor Sskip (simplify_e cond) (simplify_statement step) 2660 (simplify_statement body))2660 lb (simplify_statement body) lp) 2661 2661 k0' en m)} @conj 2662 2662 [ 1: // | 2: %1 // ] 2663 2663 ] … … inversion Hs1_sim_s1' 2782 2782 %{(State (simplify_function f) (simplify_statement iffalse) k' en m)} @conj 2783 2783 [ 1: // | 2: <e0 %1 // ] 2784 2784 ] ] ] ] 2785 | 6: # cl #Heq_s1 #Heq_s1' #_ >Heq_s1 in Houtcome;2785 | 6: #Heq_s1 #Heq_s1' #_ >Heq_s1 in Houtcome; 2786 2786 whd in match (simplify_statement ?) in Heq ⊢ %; #Heq 2787 2787 whd in match (exec_step ??) in Heq ⊢ %; 2788 2788 elim (Hsim_related cond) in Heq; * … … inversion Hs1_sim_s1' 2797 2797 [ 2: #error #Habsurd normalize in Habsurd; destruct (Habsurd) 2798 2798 | 1: * whd in match (bindIO ??????) in ⊢ (% → %); #Heq normalize nodelta in Heq ⊢ %; 2799 2799 [ 1: destruct skip (condtrace) 2800 %{(State (simplify_function f) ( simplify_statement body) (Kwhile (simplify_e cond) (simplify_statement body) clk') en m)}2800 %{(State (simplify_function f) (optional_cost lb (simplify_statement body)) (Kwhile (simplify_e cond) lb (simplify_statement body) lp k') en m)} 2801 2801 @conj 2802 [ 1: // | 2: <e0 %1 @cc_while // ]2802 [ 1: // | 2: <e0 cases lb [2: #lb'] %1 @cc_while // ] 2803 2803 | 2: destruct skip (condtrace) 2804 %{(State (simplify_function f) (optional_cost clSskip) k' en m)} @conj2805 [ 1: // | 2: <e0 cases cl [2:#cl'] %1 // ]2804 %{(State (simplify_function f) (optional_cost lp Sskip) k' en m)} @conj 2805 [ 1: // | 2: <e0 cases lp [2:#lp'] %1 // ] 2806 2806 ] ] ] ] 2807 2807 | 7: #Heq_s1 #Heq_s1' #_ >Heq_s1 in Houtcome; 2808 2808 whd in match (simplify_statement ?) in Heq ⊢ %; #Heq 2809 2809 whd in match (exec_step ??) in Heq ⊢ %; 2810 2810 destruct (Heq) 2811 %{(State (simplify_function f) ( simplify_statement body)2812 (Kdowhile (simplify_e cond) (simplify_statement body)k') en m)} @conj2813 [ 1: // | 2: %1 @cc_dowhile // ]2811 %{(State (simplify_function f) (optional_cost lb (simplify_statement body)) 2812 (Kdowhile (simplify_e cond) lb (simplify_statement body) lp k') en m)} @conj 2813 [ 1: // | 2: cases lb [2:#lb'] %1 @cc_dowhile // ] 2814 2814 | 8: #Heq_s1 #Heq_s1' #_ >Heq_s1 in Houtcome; 2815 2815 whd in match (simplify_statement ?) in Heq ⊢ %; #Heq 2816 2816 whd in match (exec_step ??) in Heq ⊢ %; … … inversion Hs1_sim_s1' 2820 2820 whd in match (ret ??) in ⊢ (% → %); 2821 2821 #Eq destruct (Eq) 2822 2822 %{(State (simplify_function f) (simplify_statement init) 2823 (Kseq (Sfor Sskip (simplify_e cond) (simplify_statement step) (simplify_statement body)) k') en m)} @conj2823 (Kseq (Sfor Sskip (simplify_e cond) (simplify_statement step) lb (simplify_statement body) lp) k') en m)} @conj 2824 2824 [ 1: // | 2: %1 @cc_for1 // ] 2825 2825 | 1: #Hinit_eq_Sskip >Hinit_eq_Sskip 2826 2826 whd in match (simplify_statement ?); … … inversion Hs1_sim_s1' 2837 2837 [ 2: #error #Habsurd normalize in Habsurd; destruct (Habsurd) 2838 2838 | 1: * whd in match (bindIO ??????); whd in match (bindIO ??????); 2839 2839 normalize nodelta #Heq destruct (Heq) 2840 [ 1: %{(State (simplify_function f) ( simplify_statement body)2841 (Kfor2 (simplify_e cond) (simplify_statement step) (simplify_statement body)k') en m)}2842 @conj [ 1: // | 2: %1 @cc_for2 // ]2843 | 2: %{(State (simplify_function f) Sskipk' en m)} @conj2844 [ 1: // | 2: %1 // ]2840 [ 1: %{(State (simplify_function f) (optional_cost lb (simplify_statement body)) 2841 (Kfor2 (simplify_e cond) (simplify_statement step) lb (simplify_statement body) lp k') en m)} 2842 @conj [ 1: // | 2: cases lb [2:#lb'] %1 @cc_for2 // ] 2843 | 2: %{(State (simplify_function f) (optional_cost lp Sskip) k' en m)} @conj 2844 [ 1: // | 2: cases lp [2:#lp'] %1 // ] 2845 2845 ] ] ] ] ] 2846 2846 | 9: #Heq_s1 #Heq_s1' #_ >Heq_s1 in Houtcome; 2847 2847 whd in match (simplify_statement ?) in Heq ⊢ %; #Heq … … inversion Hs1_sim_s1' 2849 2849 inversion Hcont_cast in Heq; normalize nodelta 2850 2850 [ 1: #Hk #Hk' #_ 2851 2851 | 2: #stm' #k0 #k0' #Hconst_cast0 #Hind #Hk #Hk' #_ 2852 | 3: #cond # body #cl#k0 #k0' #Hconst_cast0 #Hind #Hk #Hk' #_2853 | 4: #cond # body#k0 #k0' #Hcont_cast0 #Hind #Hk #Hk' #_2854 | 5,6,7: #cond #step # body#k0 #k0' #Hcont_cast0 #Hind #Hk #Hk' #_2852 | 3: #cond #lb #body #lp #k0 #k0' #Hconst_cast0 #Hind #Hk #Hk' #_ 2853 | 4: #cond #lb #body #lp #k0 #k0' #Hcont_cast0 #Hind #Hk #Hk' #_ 2854 | 5,6,7: #cond #step #lb #body #lp #k0 #k0' #Hcont_cast0 #Hind #Hk #Hk' #_ 2855 2855 | 8: #k0 #k0' #Hcont_cast0 #Hind #Hk #Hk' #_ 2856 2856 | 9: #r #f0 #en0 #k0 #k0' #Hcont_cast #Hind #Hk #Hk' #_ ] 2857 2857 #H whd in match (ret ??) in H ⊢ %; 2858 2858 destruct (H) 2859 2859 [ 1,4: %{(State (simplify_function f) Sbreak k0' en m)} @conj [ 1,3: // | 2,4: %1 // ] 2860 | %{(State (simplify_function f) (optional_cost cl Sskip) k0' en m)} @conj try // cases cl [2:#cl'] %1 //2861 | 3,5,6: %{(State (simplify_function f) Sskip k0' en m)} @conj try // %1 // ]2860 | 2,3,5: %{(State (simplify_function f) (optional_cost lp Sskip) k0' en m)} @conj try // cases lp [2,4,6:#lp'] %1 // 2861 | 6: %{(State (simplify_function f) Sskip k0' en m)} @conj try // %1 // ] 2862 2862 | 10: #Heq_s1 #Heq_s1' #_ >Heq_s1 in Houtcome; 2863 2863 whd in match (simplify_statement ?) in Heq ⊢ %; #Heq 2864 2864 whd in match (exec_step ??) in Heq ⊢ %; 2865 2865 inversion Hcont_cast in Heq; normalize nodelta 2866 2866 [ 1: #Hk #Hk' #_ 2867 2867 | 2: #stm' #k0 #k0' #Hconst_cast0 #Hind #Hk #Hk' #_ 2868 | 3: #cond # body #cl#k0 #k0' #Hconst_cast0 #Hind #Hk #Hk' #_2869 | 4: #cond # body#k0 #k0' #Hcont_cast0 #Hind #Hk #Hk' #_2870 | 5,6,7: #cond #step # body#k0 #k0' #Hcont_cast0 #Hind #Hk #Hk' #_2868 | 3: #cond #lb #body #lp #k0 #k0' #Hconst_cast0 #Hind #Hk #Hk' #_ 2869 | 4: #cond #lb #body #lp #k0 #k0' #Hcont_cast0 #Hind #Hk #Hk' #_ 2870 | 5,6,7: #cond #step #lb #body #lp #k0 #k0' #Hcont_cast0 #Hind #Hk #Hk' #_ 2871 2871 | 8: #k0 #k0' #Hcont_cast0 #Hind #Hk #Hk' #_ 2872 2872 | 9: #r #f0 #en0 #k0 #k0' #Hcont_cast #Hind #Hk #Hk' #_ ] 2873 2873 #H whd in match (ret ??) in H ⊢ %; 2874 2874 destruct (H) 2875 2875 [ 1,4,6: %{(State (simplify_function f) Scontinue k0' en m)} @conj try // %1 // 2876 | 2: %{(State (simplify_function f) (Swhile (simplify_e cond) (simplify_statement body) cl) k0' en m)}2876 | 2: %{(State (simplify_function f) (Swhile (simplify_e cond) lb (simplify_statement body) lp) k0' en m)} 2877 2877 @conj try // %1 // 2878 2878 | 3: elim (Hsim_related cond) #Hsim_cond #Htype_cond_eq elim Hsim_cond in H; 2879 2879 [ 2: * #error #Hfail >Hfail #Habsurd normalize in Habsurd; destruct (Habsurd) … … inversion Hs1_sim_s1' 2886 2886 [ 2: #error #Habsurd normalize in Habsurd; destruct (Habsurd) 2887 2887 | 1: * whd in match (bindIO ??????); whd in match (bindIO ??????); 2888 2888 normalize nodelta #Heq destruct (Heq) 2889 [ 1: %{(State (simplify_function f) (Sdowhile (simplify_e cond) (simplify_statement body)) k0' en m)} 2890 @conj [ 1: // | 2: %1 // ] 2891 | 2: %{(State (simplify_function f) Sskip k0' en m)} 2889 [ 1: %{(State (simplify_function f) (Sdowhile (simplify_e cond) lb (simplify_statement body) lp) k0' en m)} 2892 2890 @conj [ 1: // | 2: %1 // ] 2891 | 2: %{(State (simplify_function f) (optional_cost lp Sskip) k0' en m)} 2892 @conj [ 1: // | 2: cases lp [2:#lp'] %1 // ] 2893 2893 ] ] ] ] 2894 2894 | 5: %{(State (simplify_function f) (simplify_statement step) 2895 (Kfor3 (simplify_e cond) (simplify_statement step) (simplify_statement body)k0') en m)} @conj2895 (Kfor3 (simplify_e cond) (simplify_statement step) lb (simplify_statement body) lp k0') en m)} @conj 2896 2896 [ 1: // | 2: %1 @cc_for3 // ] 2897 2897 ] 2898 2898 | 11: #Heq_s1 #Heq_s1' #_ >Heq_s1 in Houtcome; … … inversion Hs1_sim_s1' 3007 3007 inversion Hcont_cast 3008 3008 [ 1: #Hk #Hk' #_ 3009 3009 | 2: #stm' #k0 #k0' #Hconst_cast0 #Hind #Hk #Hk' #_ 3010 | 3: #cond # body #cl#k0 #k0' #Hconst_cast0 #Hind #Hk #Hk' #_3011 | 4: #cond # body#k0 #k0' #Hcont_cast0 #Hind #Hk #Hk' #_3012 | 5,6,7: #cond #step # body#k0 #k0' #Hcont_cast0 #Hind #Hk #Hk' #_3010 | 3: #cond #lb #body #lp #k0 #k0' #Hconst_cast0 #Hind #Hk #Hk' #_ 3011 | 4: #cond #lb #body #lp #k0 #k0' #Hcont_cast0 #Hind #Hk #Hk' #_ 3012 | 5,6,7: #cond #step #lb #body #lp #k0 #k0' #Hcont_cast0 #Hind #Hk #Hk' #_ 3013 3013 | 8: #k0 #k0' #Hcont_cast0 #Hind #Hk #Hk' #_ 3014 3014 | 9: #r #f0 #en0 #k0 #k0' #Hcont_cast #Hind #Hk #Hk' #_ ] 3015 3015 normalize nodelta -
src/Clight/addRuntime.ma
diff --git a/src/Clight/addRuntime.ma b/src/Clight/addRuntime.ma index 7c69cb3..bd6f7fc 100644
a b match s with 80 80 match oe with [ Some e ⇒ expr_ops e @ l | None ⇒ l ] 81 81 | Ssequence s1 s2 ⇒ stmt_ops s1 @ stmt_ops s2 82 82 | Sifthenelse e1 s1 s2 ⇒ expr_ops e1 @ stmt_ops s1 @ stmt_ops s2 83 | Swhile e1 s1⇒ expr_ops e1 @ stmt_ops s184 | Sdowhile e1 s1⇒ expr_ops e1 @ stmt_ops s185 | Sfor s1 e1 s2 s3⇒ expr_ops e1 @ stmt_ops s1 @ stmt_ops s2 @ stmt_ops s383 | Swhile e1 _ s1 _ ⇒ expr_ops e1 @ stmt_ops s1 84 | Sdowhile e1 _ s1 _ ⇒ expr_ops e1 @ stmt_ops s1 85 | Sfor s1 e1 s2 _ s3 _ ⇒ expr_ops e1 @ stmt_ops s1 @ stmt_ops s2 @ stmt_ops s3 86 86 | Sreturn oe ⇒ match oe with [ Some e ⇒ expr_ops e | None ⇒ [ ] ] 87 87 | Sswitch e1 ls ⇒ expr_ops e1 @ lstmt_ops ls 88 88 | Slabel _ s1 ⇒ stmt_ops s1 … … match s with 210 210 211 211 (* This is particularly bad - for loops we end up duplicating the code. *) 212 212 213 | Swhile e1 s1⇒213 | Swhile e1 lb s1 lp ⇒ 214 214 let 〈ls1,e1,u〉 ≝ subst_expr e1 rs u in 215 215 let 〈s1,u〉 ≝ subst_stmt s1 rs u in 216 〈rev_prepend_stmts ls1 (Swhile e1 (append_stmts s1 ls1)), u〉217 | Sdowhile e1 s1⇒216 〈rev_prepend_stmts ls1 (Swhile e1 lb (append_stmts s1 ls1) lp), u〉 217 | Sdowhile e1 lb s1 lp ⇒ 218 218 let 〈ls1,e1,u〉 ≝ subst_expr e1 rs u in 219 219 let 〈s1,u〉 ≝ subst_stmt s1 rs u in 220 〈Sdowhile e1 (append_stmts s1 ls1), u〉221 | Sfor s1 e1 s2 s3⇒220 〈Sdowhile e1 lb (append_stmts s1 ls1) lp, u〉 221 | Sfor s1 e1 s2 lb s3 lp ⇒ 222 222 let 〈ls1,e1,u〉 ≝ subst_expr e1 rs u in 223 223 let 〈s1,u〉 ≝ subst_stmt s1 rs u in 224 224 let 〈s2,u〉 ≝ subst_stmt s2 rs u in 225 225 let 〈s3,u〉 ≝ subst_stmt s3 rs u in 226 〈Sfor (append_stmts s1 ls1) e1 s2 (append_stmts s3 ls1), u〉226 〈Sfor (append_stmts s1 ls1) e1 s2 lb (append_stmts s3 ls1) lp, u〉 227 227 | Sreturn oe ⇒ 228 228 match oe with 229 229 [ Some e ⇒ let 〈ls1,e,u〉 ≝ subst_expr e rs u in 〈rev_prepend_stmts ls1 (Sreturn (Some ? e)), u〉 … … definition divu : universe SymbolTag → intsize → replace_op × (universe Sym 291 291 (Ssequence 292 292 (Swhile 293 293 (Expr (Ebinop Oge (Expr (Evar x) uint) (Expr (Evar y) uint)) uint) 294 (None ?) 294 295 (Ssequence 295 296 (Sassign (Expr (Evar x) uint) (Expr (Ebinop Osub (Expr (Evar x) uint) (Expr (Evar y) uint)) uint)) 296 (Sassign (Expr (Evar quo) uint) (Expr (Ebinop Oadd (Expr (Evar quo) uint) (Expr (Econst_int sz (repr sz 1)) uint)) uint)))) 297 (Sassign (Expr (Evar quo) uint) (Expr (Ebinop Oadd (Expr (Evar quo) uint) (Expr (Econst_int sz (repr sz 1)) uint)) uint))) 298 (None ?) ) 297 299 (Sreturn (Some ? (Expr (Evar quo) uint))))))), 298 300 u〉. 299 301 -
src/Clight/label.ma
diff --git a/src/Clight/label.ma b/src/Clight/label.ma index bbadc0e..90c8ebb 100644
a b match e with 20 20 ] 21 21 ]. 22 22 23 definition is_none : ∀A:Type[0]. option A → bool ≝ 24 λA,o. match o with [ None ⇒ true | Some _ ⇒ false ]. 25 23 26 let rec statement_label_free (s:statement) : bool ≝ 24 27 match s with 25 28 [ Sassign e1 e2 ⇒ expr_label_free e1 ∧ expr_label_free e2 26 29 | Scall oe e1 es ⇒ option_map_def … expr_label_free true oe ∧ expr_label_free e1 ∧ all … expr_label_free es 27 30 | Ssequence s1 s2 ⇒ statement_label_free s1 ∧ statement_label_free s2 28 31 | Sifthenelse e1 s1 s2 ⇒ expr_label_free e1 ∧ statement_label_free s1 ∧ statement_label_free s2 29 | Swhile e1 s1 cl ⇒ expr_label_free e1 ∧ statement_label_free s1 ∧ match cl with [ None ⇒ true | _ ⇒ false ]30 | Sdowhile e1 s1 ⇒ expr_label_free e1 ∧ statement_label_free s131 | Sfor s1 e1 s2 s3 ⇒ statement_label_free s1 ∧ expr_label_free e1 ∧ statement_label_free s2 ∧ statement_label_free s332 | Swhile e1 lb s1 lp ⇒ expr_label_free e1 ∧ statement_label_free s1 ∧ is_none … lb ∧ is_none … lp 33 | Sdowhile e1 lb s1 lp ⇒ expr_label_free e1 ∧ statement_label_free s1 ∧ is_none … lb ∧ is_none … lp 34 | Sfor s1 e1 s2 lb s3 lp ⇒ statement_label_free s1 ∧ expr_label_free e1 ∧ statement_label_free s2 ∧ statement_label_free s3 ∧ is_none … lb ∧ is_none … lp 32 35 | Sreturn oe ⇒ option_map_def … expr_label_free true oe 33 36 | Sswitch e1 ls ⇒ expr_label_free e1 ∧ labeled_statements_label_free ls 34 37 | Slabel _ s1 ⇒ statement_label_free s1 … … match s with 177 180 let 〈s2,costgen〉 ≝ label_statement s2 costgen in 178 181 let 〈s2,costgen〉 ≝ add_cost_before s2 costgen in 179 182 〈Sifthenelse e s1 s2, costgen〉 180 | Swhile e s' cl⇒183 | Swhile e lb s' lp ⇒ 181 184 let 〈e,costgen〉 ≝ label_expr e costgen in 185 let 〈body,costgen〉 ≝ ensure_label lb costgen in 182 186 let 〈s',costgen〉 ≝ label_statement s' costgen in 183 let 〈s',costgen〉 ≝ add_cost_before s' costgen in 184 let 〈after,costgen〉 ≝ ensure_label cl costgen in 185 〈Swhile e s' (Some ? after), costgen〉 186 | Sdowhile e s' ⇒ 187 let 〈after,costgen〉 ≝ ensure_label lp costgen in 188 〈Swhile e (Some ? body) s' (Some ? after), costgen〉 189 | Sdowhile e lb s' lp ⇒ 187 190 let 〈e,costgen〉 ≝ label_expr e costgen in 191 let 〈body,costgen〉 ≝ ensure_label lb costgen in 188 192 let 〈s',costgen〉 ≝ label_statement s' costgen in 189 let 〈s',costgen〉 ≝ add_cost_before s' costgen in 190 let 〈s,costgen〉 ≝ add_cost_after (Sdowhile e s') costgen in 191 〈s,costgen〉 192 | Sfor s1 e s2 s3 ⇒ 193 let 〈after,costgen〉 ≝ ensure_label lp costgen in 194 〈Sdowhile e (Some ? body) s' (Some ? after),costgen〉 195 | Sfor s1 e s2 lb s3 lp ⇒ 193 196 let 〈e,costgen〉 ≝ label_expr e costgen in 194 197 let 〈s1,costgen〉 ≝ label_statement s1 costgen in 195 198 let 〈s2,costgen〉 ≝ label_statement s2 costgen in 199 let 〈body,costgen〉 ≝ ensure_label lb costgen in 196 200 let 〈s3,costgen〉 ≝ label_statement s3 costgen in 197 let 〈s3,costgen〉 ≝ add_cost_before s3 costgen in 198 let 〈s,costgen〉 ≝ add_cost_after (Sfor s1 e s2 s3) costgen in 199 〈s,costgen〉 201 let 〈after,costgen〉 ≝ ensure_label lp costgen in 202 〈Sfor s1 e s2 (Some ? body) s3 (Some ? after),costgen〉 200 203 | Sbreak ⇒ 〈Sbreak,costgen〉 201 204 | Scontinue ⇒ 〈Scontinue,costgen〉 202 205 | Sreturn opt_e ⇒ -
src/Clight/labelSimulation.ma
diff --git a/src/Clight/labelSimulation.ma b/src/Clight/labelSimulation.ma index c72ece3..f99db37 100644
a b lemma label_exprs_ok : ∀ge,ge'. 257 257 | /2/ ] | skip ] 258 258 ] qed. 259 259 260 inductive label_le : option costlabel → costlabel → Prop ≝ 261 | ll_none : ∀c. label_le (None ?) c 262 | ll_some : ∀c. label_le (Some ? c) c. 260 263 261 264 (* Now we move on to describe the simulation relation. First, relate the 262 265 continuations. *) 263 266 inductive cont_with_labels : cont → cont → Prop ≝ 264 267 | cwl_stop : cont_with_labels Kstop Kstop 265 268 | cwl_seq : ∀u,s,k,k'. cont_with_labels k k' → cont_with_labels (Kseq s k) (Kseq (\fst (label_statement s u)) k') 266 | cwl_while : ∀ue,e,us, s,cl,cs,cpost,k,k'.269 | cwl_while : ∀ue,e,us,lb,s,lp,cs,cpost,k,k'. 267 270 cont_with_labels k k' → 268 (cl = None ? ∨ cl = Some ? cpost) → 269 cont_with_labels (Kwhile e s cl k) (Kwhile (\fst (label_expr e ue)) (Scost cs (\fst (label_statement s us))) (Some ? cpost) k') 270 | cwl_dowhile : ∀ue,e,us,s,cs,cpost,k,k'. 271 label_le lb cs → 272 label_le lp cpost → 273 cont_with_labels (Kwhile e lb s lp k) (Kwhile (\fst (label_expr e ue)) (Some ? cs) (\fst (label_statement s us)) (Some ? cpost) k') 274 | cwl_dowhile : ∀ue,e,us,lb,s,lp,cs,cpost,k,k'. 271 275 cont_with_labels k k' → 272 cont_with_labels (Kdowhile e s k) (Kdowhile (\fst (label_expr e ue)) (Scost cs (\fst (label_statement s us))) (Kseq (Scost cpost Sskip) k')) 273 | cwl_for1 : ∀ue,e,us1,s1,us2,s2,cs,cpost,k,k'. 276 label_le lb cs → 277 label_le lp cpost → 278 cont_with_labels (Kdowhile e lb s lp k) (Kdowhile (\fst (label_expr e ue)) (Some ? cs) (\fst (label_statement s us)) (Some ? cpost) k') 279 | cwl_for1 : ∀ue,e,us1,s1,us2,lb,s2,lp,cs,cpost,k,k'. 274 280 cont_with_labels k k' → 275 cont_with_labels (Kseq (Sfor Sskip e s1 s2) k) (Kseq (Sfor Sskip (\fst (label_expr e ue)) (\fst (label_statement s1 us1)) (Scost cs (\fst (label_statement s2 us2)))) (Kseq (Scost cpost Sskip) k')) 276 | cwl_for2 : ∀ue,e,us1,s1,us2,s2,cs,cpost,k,k'. cont_with_labels k k' → cont_with_labels (Kfor2 e s1 s2 k) (Kfor2 (\fst (label_expr e ue)) (\fst (label_statement s1 us1)) (Scost cs (\fst (label_statement s2 us2))) (Kseq (Scost cpost Sskip) k')) 277 | cwl_for3 : ∀ue,e,us1,s1,us2,s2,cs,cpost,k,k'. cont_with_labels k k' → cont_with_labels (Kfor3 e s1 s2 k) (Kfor3 (\fst (label_expr e ue)) (\fst (label_statement s1 us1)) (Scost cs (\fst (label_statement s2 us2))) (Kseq (Scost cpost Sskip) k')) 281 label_le lb cs → 282 label_le lp cpost → 283 cont_with_labels (Kseq (Sfor Sskip e s1 lb s2 lp) k) (Kseq (Sfor Sskip (\fst (label_expr e ue)) (\fst (label_statement s1 us1)) (Some ? cs) (\fst (label_statement s2 us2)) (Some ? cpost)) k') 284 | cwl_for2 : ∀ue,e,us1,s1,us2,lb,s2,lp,cs,cpost,k,k'. 285 cont_with_labels k k' → 286 label_le lb cs → 287 label_le lp cpost → 288 cont_with_labels (Kfor2 e s1 lb s2 lp k) (Kfor2 (\fst (label_expr e ue)) (\fst (label_statement s1 us1)) (Some ? cs) (\fst (label_statement s2 us2)) (Some ? cpost) k') 289 | cwl_for3 : ∀ue,e,us1,s1,us2,lb,s2,lp,cs,cpost,k,k'. 290 cont_with_labels k k' → 291 label_le lb cs → 292 label_le lp cpost → 293 cont_with_labels (Kfor3 e s1 lb s2 lp k) (Kfor3 (\fst (label_expr e ue)) (\fst (label_statement s1 us1)) (Some ? cs) (\fst (label_statement s2 us2)) (Some ? cpost) k') 278 294 | cwl_switch : ∀k,k'. cont_with_labels k k' → cont_with_labels (Kswitch k) (Kswitch k') 279 295 | cwl_call : ∀g,r,f,en,k,k'. cont_with_labels k k' → cont_with_labels (Kcall r f en k) (Kcall r (\fst (label_function g f)) en k') 280 296 | cwl_seqls : ∀ls,u,k,k'. cont_with_labels k k' → … … qed. 290 306 inductive state_with_labels_partial : state → state → Prop ≝ 291 307 | swl_state : ∀g,f,us,s,k,k',e,m. cont_with_labels k k' → state_with_labels_partial (State f s k e m) (State (\fst (label_function g f)) (\fst (label_statement s us)) k' e m) 292 308 (* Extra matching states that we can reach that don't quite correspond to the 293 labelling function *) 294 | swl_whilestate : ∀g,f,ua,a,us,s,cl,cs,cpost,k,k',e,m. cont_with_labels k k' → 295 (cl = None ? ∨ cl = Some ? cpost) → 296 state_with_labels_partial (State f (Swhile a s cl) k e m) (State (\fst (label_function g f)) (Swhile (\fst (label_expr a ua)) (Scost cs (\fst (label_statement s us))) (Some ? cpost)) k' e m) 297 | swl_dowhilestate : ∀g,f,ua,a,us,s,cs,cpost,k,k',e,m. cont_with_labels k k' → 298 state_with_labels_partial (State f (Sdowhile a s) k e m) (State (\fst (label_function g f)) (Sdowhile (\fst (label_expr a ua)) (Scost cs (\fst (label_statement s us)))) (Kseq (Scost cpost Sskip) k') e m) 299 | swl_forstate : ∀g,f,ua2,a2,us3,s3,us,s,cs,cpost,k,k',e,m. cont_with_labels k k' → 300 state_with_labels_partial (State f (Sfor Sskip a2 s3 s) k e m) (State (\fst (label_function g f)) (Sfor Sskip (\fst (label_expr a2 ua2)) (\fst (label_statement s3 us3)) (Scost cs (\fst (label_statement s us)))) (Kseq (Scost cpost Sskip) k') e m) 309 labelling function because we've forgotten the relationship between the 310 fresh labels *) 311 | swl_whilestate : ∀g,f,ua,a,us,lb,s,lp,cs,cpost,k,k',e,m. cont_with_labels k k' → 312 label_le lb cs → 313 label_le lp cpost → 314 state_with_labels_partial (State f (Swhile a lb s lp) k e m) (State (\fst (label_function g f)) (Swhile (\fst (label_expr a ua)) (Some ? cs) (\fst (label_statement s us)) (Some ? cpost)) k' e m) 315 | swl_dowhilestate : ∀g,f,ua,a,us,lb,s,lp,cs,cpost,k,k',e,m. cont_with_labels k k' → 316 label_le lb cs → 317 label_le lp cpost → 318 state_with_labels_partial (State f (Sdowhile a lb s lp) k e m) (State (\fst (label_function g f)) (Sdowhile (\fst (label_expr a ua)) (Some ? cs) (\fst (label_statement s us)) (Some ? cpost)) k' e m) 319 | swl_forstate : ∀g,f,ua2,a2,us3,s3,us,lb,s,lp,cs,cpost,k,k',e,m. cont_with_labels k k' → 320 label_le lb cs → 321 label_le lp cpost → 322 state_with_labels_partial (State f (Sfor Sskip a2 s3 lb s lp) k e m) (State (\fst (label_function g f)) (Sfor Sskip (\fst (label_expr a2 ua2)) (\fst (label_statement s3 us3)) (Some ? cs) (\fst (label_statement s us)) (Some ? cpost)) k' e m) 301 323 (* and the rest *) 302 324 | swl_callstate : ∀g,fd,args,k,k',m. cont_with_labels k k' → state_with_labels_partial (Callstate fd args k m) (Callstate (\fst (label_fundef g fd)) args k' m) 303 325 | swl_returnstate : ∀res,k,k',m. cont_with_labels k k' → state_with_labels_partial (Returnstate res k m) (Returnstate res k' m) … … lemma labelled_not_skip : ∀s,u. 373 395 (\fst (label_statement s u)) ≠ Sskip. 374 396 * #u 375 397 [ * #H cases (H (refl ??)) 376 | *: #a try #b try #c try #d try #e 398 | *: #a try #b try #c try #d try #e try #f try #g 377 399 (* Use the state-monad-like structure of the labelling function to break 378 400 it up *) 379 401 whd in match (label_statement ??); 380 402 repeat @(breakup_pair ???? (λx.\fst x ≠ Sskip)) 381 % #E destruct403 % #E lapply (eq_to_jmeq ??? E) -E #E destruct 382 404 ] qed. 383 405 384 406 lemma labelled_is_not_skip : ∀s,u. … … lemma label_select_ls : ∀sz,i,ls,u. 425 447 ] 426 448 ] qed. 427 449 450 lemma ensure_label_elim : ∀c,u. ∀P:costlabel × (universe CostTag) → Type[0]. 451 (∀c',u'. label_le c c' → P 〈c',u'〉) → 452 P (ensure_label c u). 453 * /3/ 454 qed. 455 428 456 (* Break up labelling function in one go for statements. *) 429 457 lemma blindly_label : ∀u,s. ∀P:statement → Prop. 430 458 match s with … … match s with 433 461 | Scall eo e args ⇒ ∀u1,u2,u3. P (Scall (\fst (label_opt_expr eo u1)) (\fst (label_expr e u2)) (\fst (label_exprs args u3))) 434 462 | Ssequence s1 s2 ⇒ ∀u1,u2. P (Ssequence (\fst (label_statement s1 u1)) (\fst (label_statement s2 u2))) 435 463 | Sifthenelse e s1 s2 ⇒ ∀u1,u2,u3,c2,c3. P (Sifthenelse (\fst (label_expr e u1)) (Scost c2 (\fst (label_statement s1 u2))) (Scost c3 (\fst (label_statement s2 u3)))) 436 | Swhile e s1 cl ⇒ ∀u1,u2,cs,cpost. cl = None ? ∨ cl = Some ? cpost → P (Swhile (\fst (label_expr e u1)) (Scost cs (\fst (label_statement s1 u2))) (Some ? cpost)) 437 | Sdowhile e s1 ⇒ ∀u1,u2,cs,cpost. P (Ssequence (Sdowhile (\fst (label_expr e u1)) (Scost cs (\fst (label_statement s1 u2)))) (Scost cpost Sskip)) 438 | Sfor s1 e s2 s3 ⇒ ∀u1,u2,u3,u4,c3,c4. P (Ssequence (Sfor (\fst (label_statement s1 u1)) (\fst (label_expr e u2)) (\fst (label_statement s2 u3)) (Scost c3 (\fst (label_statement s3 u4)))) (Scost c4 Sskip)) 464 | Swhile e lb s1 lp ⇒ ∀u1,u2,cs,cpost. 465 label_le lb cs → 466 label_le lp cpost → 467 P (Swhile (\fst (label_expr e u1)) (Some ? cs) (\fst (label_statement s1 u2)) (Some ? cpost)) 468 | Sdowhile e lb s1 lp ⇒ ∀u1,u2,cs,cpost. 469 label_le lb cs → 470 label_le lp cpost → 471 P (Sdowhile (\fst (label_expr e u1)) (Some ? cs) (\fst (label_statement s1 u2)) (Some ? cpost)) 472 | Sfor s1 e s2 lb s3 lp ⇒ ∀u1,u2,u3,u4,c3,c4. 473 label_le lb c3 → 474 label_le lp c4 → 475 P (Sfor (\fst (label_statement s1 u1)) (\fst (label_expr e u2)) (\fst (label_statement s2 u3)) (Some ? c3) (\fst (label_statement s3 u4)) (Some ? c4)) 439 476 | Sbreak ⇒ P Sbreak 440 477 | Scontinue ⇒ P Scontinue 441 478 | Sreturn eo ⇒ ∀u1. P (Sreturn (\fst (label_opt_expr eo u1))) … … match s with 444 481 | Sgoto l ⇒ P (Sgoto l) 445 482 | Scost c s1 ⇒ ∀u1. P (Scost c (\fst (label_statement s1 u1))) 446 483 ] → P (\fst (label_statement s u)). 447 #u * // #A #B #C try #D try #E try #F whd in match (label_statement ??);484 #u * // #A #B #C try #D try #E try #F try #G try #H whd in match (label_statement ??); 448 485 @label_gen_elim #u1 // 486 [ 5,6: @ensure_label_elim #cA #uA #HA ] 449 487 @label_gen_elim #u2 // 450 [ 6: >shift_fst // 451 | 3: @label_gen_elim #u3 >shift_fst >shift_fst 452 cases C in E ⊢ %; /3/ 453 | *: @label_gen_elim #u3 // 454 @label_gen_elim #u4 455 [ @label_gen_elim #u5 >shift_fst >shift_fst // 456 | >shift_fst >shift_fst // 457 | @label_gen_elim #u5 >shift_fst >shift_fst >shift_fst // 458 ] 488 [ 6: >shift_fst // ] 489 @label_gen_elim #u3 // 490 [ 1,2,4: @ensure_label_elim #cB #uB #HB ] 491 @label_gen_elim #u4 /2/ 492 [ @label_gen_elim #u5 @ensure_label_elim #c6 #u6 #H6 >shift_fst /2/ 493 | @label_gen_elim #u5 >shift_fst >shift_fst /2/ 459 494 ] qed. 460 495 461 496 (* Apply induction hypothesis in label_find_label proof below while getting … … lemma label_find_label : ∀lbl,s,k,k',u. 532 567 whd in ⊢ (??%?); whd in match (find_label ???); >FIND1' in ⊢ (??%?); 533 568 @refl | // ] |skip ]| skip ]| skip ] 534 569 ] 535 | #e #s0 # cl #IH #k #k' #u #K @blindly_label #u1 #u2 #cs #cpost #CL570 | #e #s0 #lb #lp #IH #k #k' #u #K @blindly_label #u1 #u2 #cs #cpost #LB #LP 536 571 whd in match (find_label ?? k); normalize in match (find_label ?? k'); 537 572 @(lfl_IH s0 … IH) [ /2/ ] 538 573 cases (find_label ???) … … lemma label_find_label : ∀lbl,s,k,k',u. 543 578 whd in ⊢ (??%?); whd in match (find_label ???); >FIND1' in ⊢ (??%?); 544 579 @refl | // ]| skip ]| skip ]| skip ] 545 580 ] 546 | #e #s0 # IH #k #k' #u #K @blindly_label #u1 #u2 #cs #cpost581 | #e #s0 #lb #lp #IH #k #k' #u #K @blindly_label #u1 #u2 #cs #cpost #LB #LP 547 582 whd in match (find_label ?? k); normalize in match (find_label ?? k'); 548 583 @(lfl_IH s0 … IH) [ /2/ ] 549 584 cases (find_label ???) … … lemma label_find_label : ∀lbl,s,k,k',u. 554 589 whd in ⊢ (??%?); whd in match (find_label ???); >FIND1' in ⊢ (??%?); 555 590 @refl | // ]| skip ]| skip ]| skip ] 556 591 ] 557 | #s1 #e #s2 #s3 # IH1 #IH2 #IH3 #k #k' #u #K @blindly_label #u1 #u2 #u3 #u4 #c3 #c4592 | #s1 #e #s2 #s3 #lb #lp #IH1 #IH2 #IH3 #k #k' #u #K @blindly_label #u1 #u2 #u3 #u4 #c3 #c4 #LB #LP 558 593 whd in match (find_label ???); normalize in match (find_label ?? k'); 559 594 @(lfl_IH s1 … IH1) [ /2/ ] 560 595 cases (find_label ???) … … lapply (label_find_label lbl s (call_cont k) (call_cont k') g ?) 641 676 >FIND whd in ⊢ (% → ?); // 642 677 qed. 643 678 679 lemma swl_cost_state : 680 ∀g,f,us,s,k,k',e,m,cs. 681 cont_with_labels k k' → 682 state_with_labels_partial (State f (Scost cs s) k e m) (State (\fst (label_function g f)) (Scost cs (\fst (label_statement s us))) k' e m). 683 #g #f #us #s #k #k' #e #m #cs #K 684 cut (Scost cs (\fst (label_statement s us)) = \fst (label_statement (Scost cs s) us)) 685 [ normalize >shift_fst % ] 686 #E >E @swl_state // 687 qed. 688 689 lemma ffs: ∀c. 690 None costlabel = None costlabel ∨ None costlabel = Some costlabel c. 691 /2/ 692 qed. 693 644 694 645 695 (* We show the main simulation in two stages. First, we show it for all states 646 696 in the relation *except* those for labeled_statements, then we'll show the … … lemma step_with_labels_partial : ∀ge,ge'. 674 724 ] 675 725 | #u #s0 #k0 #k0' #K #_ #E1 #E2 #E3 destruct %{0} whd 676 726 whd in EX:(??%%); destruct /4/ 677 | #ue #e0 #us0 # s0 #cl #cs #cpost #k0 #k0' #K #CL#_ #E1 #E2 #E3 destruct %{0}727 | #ue #e0 #us0 #lb #s0 #lp #cs #cpost #k0 #k0' #K #LB #LP #_ #E1 #E2 #E3 destruct %{0} 678 728 whd in EX:(??%%); destruct whd /4/ 679 | #ue #e0 #us0 # s0 #cs #cpost #k0 #k0' #K#_ #E1 #E2 #E3 destruct729 | #ue #e0 #us0 #lb #s0 #lp #cs #cpost #k0 #k0' #K #LB #LP #_ #E1 #E2 #E3 destruct 680 730 cases (bindIO_inversion ??????? EX) -EX * #ve #tre * #EXe #EX 681 731 cases (bindIO_inversion ??????? EX) -EX * * #EXb #EX 682 732 normalize in EX; destruct … … lemma step_with_labels_partial : ∀ge,ge'. 685 735 whd in ⊢ (??%?); >EXe' 686 736 whd in ⊢ (??%?); >label_expr_type >EXb 687 737 whd % /4/ 688 | %{2}whd738 | cases LP #E destruct [ %{1} | %{0} ] whd 689 739 whd in ⊢ (??%?); >EXe' 690 740 whd in ⊢ (??%?); >label_expr_type >EXb 691 whd % [ <(E0_right tr) @twel_app /2/ |/4/ ]741 whd % [ <(E0_right tr) @twel_app /2/ | *: /4/ ] 692 742 ] 693 | #ue #e0 #us1 #st1 #us2 # st2 #cs #cpost #k0 #k0' #K#_ #E1 #E2 #E3 destruct743 | #ue #e0 #us1 #st1 #us2 #lb #st2 #lp #cs #cpost #k0 #k0' #K #LB #LP #_ #E1 #E2 #E3 destruct 694 744 whd in EX:(??%?); destruct 695 745 %{0} whd /4/ 696 | #ue #e0 #us1 #st1 #us2 # st2 #cs #cpost #k0 #k0' #K#_ #E1 #E2 #E3 destruct746 | #ue #e0 #us1 #st1 #us2 #lb #st2 #lp #cs #cpost #k0 #k0' #K #LB #LP #_ #E1 #E2 #E3 destruct 697 747 whd in EX:(??%?); destruct 698 748 %{0} % /4/ 699 | #ue #e0 #us1 #st1 #us2 # st2 #cs #cpost #k0 #k0' #K#_ #E1 #E2 #E3 destruct749 | #ue #e0 #us1 #st1 #us2 #lb #st2 #lp #cs #cpost #k0 #k0' #K #LB #LP #_ #E1 #E2 #E3 destruct 700 750 whd in EX:(??%?); destruct 701 751 %{0} % /4/ 702 752 | #k0 #k0' #K #_ #E1 #E2 #E3 destruct … … lemma step_with_labels_partial : ∀ge,ge'. 764 814 whd in ⊢ (??%?); >EX1' 765 815 whd in ⊢ (??%?); >label_expr_type >EX2 766 816 whd in ⊢ (??%?); % [1,3: <(E0_right tr) ] /4/ 767 | #a # st #cl#EX817 | #a #lb #st #lp #EX 768 818 cases (bindIO_inversion ??????? EX) -EX * #v1 #tr1 * #EX1 #EX 769 819 cases (bindIO_inversion ??????? EX) -EX * * #EX2 #EX 770 820 normalize in EX; destruct 771 @blindly_label #u1 #u2 #cs #cpost * # CLdestruct821 @blindly_label #u1 #u2 #cs #cpost * #LB * #LP destruct 772 822 cases (proj1 ?? (label_expr_ok ge ge' e m RG) ??? EX1 u1) #tr1' * #EX1' #T1 773 [ 1,2, 3: %{1} |%{0} ] whd823 [ 1,2,5,7: %{1} | *: %{0} ] whd 774 824 whd in ⊢ (??%?); >EX1' 775 825 whd in ⊢ (??%?); >label_expr_type >EX2 776 whd in ⊢ (??%?); whd % [ 1,3,5,7: <(E0_right tr) ] /5 by twel_new, swl_partial, swl_state, cwl_while, twel_app, or_introl, or_intror/ 777 | #a #st #EX 826 whd in ⊢ (??%?); whd % [ 1,3,5,7: <(E0_right tr) @twel_app /2/ ] 827 (* faster than /4 by _/ but still not pleasant *) 828 try assumption try @twel_new % 829 try ( @swl_cost_state @cwl_while // ) 830 try ( @swl_state @cwl_while // ) 831 @swl_state /2/ 832 | #a #lb #st #lp #EX 778 833 normalize in EX; destruct 779 whd in match (label_statement ??); @label_gen_elim #u1 780 @label_gen_elim #u2 781 whd in match (add_cost_before ??); cases (fresh ??) #c6 #u6 >shift_fst 782 whd in match (add_cost_after ??); cases (fresh ??) #c7 #u7 >shift_fst 783 %{2} % /4/ 784 | #st1 #a #st2 #st #EX 834 @blindly_label #u1 #u2 #cs #cpost * #LB #LP destruct 835 [ %{1} | %{0} ] whd % /5/ 836 | #st1 #a #st2 #lb #st #lp #EX 785 837 lapply (refl ? (is_Sskip st1)) cases (is_Sskip st1) in ⊢ (???% → ?); #Esk #Eskip 786 838 whd in EX:(??%?); >Eskip in EX; #EX 787 whd in match (label_statement ??); @label_gen_elim #u1 788 @label_gen_elim #u2 @label_gen_elim #u3 @label_gen_elim #u4 789 whd in match (add_cost_before ??); cases (fresh ??) #c5 #u5 >shift_fst 790 whd in match (add_cost_after ??); cases (fresh ??) #c6 #u6 >shift_fst 839 @blindly_label #u1 #u2 #u3 #u4 #c3 #c4 #LB #LP 791 840 [ cases (bindIO_inversion ??????? EX) -EX * #v1 #tr1 * #EX1 #EX 792 841 cases (bindIO_inversion ??????? EX) -EX * * #EX2 #EX 793 842 normalize in EX; destruct 794 cases (proj1 ?? (label_expr_ok ge ge' e m RG) ??? EX1 us) #tr1' * #EX1' #T1 795 [ %{2} | %{3} ] whd 843 cases (proj1 ?? (label_expr_ok ge ge' e m RG) ??? EX1 u2) #tr1' * #EX1' #T1 844 cases LB #LB cases LP #LP destruct 845 [ 1,2,5,7: %{1} | 3,4,6,8: %{0} ] whd 796 846 whd in ⊢ (??%?); >EX1' 797 847 whd in ⊢ (??%?); >label_expr_type >EX2 798 whd in ⊢ (??%?); % [ 1,3: <(E0_right tr) ] /4/ 848 whd in ⊢ (??%?); % [ 1,3,5,7: <(E0_right tr) ] 849 /5 by twel_new, swl_partial, swl_state, cwl_for2, twel_app, or_introl, or_intror, swl_cost_state/ 799 850 | whd in EX:(??%%); destruct 800 %{ 1} whd851 %{0} whd 801 852 whd in ⊢ (??%?); cases (labelled_is_not_skip ? u1 Esk) #Esk' #Eskip' 802 >Eskip' whd in ⊢ (??%?); % /4/853 >Eskip' whd in ⊢ (??%?); whd % /4/ 803 854 ] 804 855 | #EX inversion KL 805 856 [ #E1 #E2 #E3 destruct whd in EX:(??%?); destruct 806 857 |#u #s0 #k0 #k0' #K' #_ #E1 #E2 #E3 destruct whd in EX:(??%?); destruct 807 | #ue #e0 #us0 # s0 #cl #cs #cpost #k0 #k0' #K' * #CL#_ #E1 #E2 #E3 destruct whd in EX:(??%?); destruct808 | #ue #e0 #us0 # s0 #cs #cpost #k0 #k0' #K'#_ #E1 #E2 #E3 destruct whd in EX:(??%?); destruct809 | #ue #e0 #us1 #s1 #us2 # st2 #cs #cpost #k0 #k0' #K'#_ #E1 #E2 #E3 destruct whd in EX:(??%?); destruct810 | #ue #e0 #us1 #s1 #us2 # st2 #cs #cpost #k0 #k0' #K'#_ #E1 #E2 #E3 destruct whd in EX:(??%?); destruct811 | #ue #e0 #us1 #s1 #us2 # st2 #cs #cpost #k0 #k0' #K'#_ #E1 #E2 #E3 destruct whd in EX:(??%?); destruct858 | #ue #e0 #us0 #lb #s0 #lp #cs #cpost #k0 #k0' #K' * #LB * #LP #_ #E1 #E2 #E3 destruct whd in EX:(??%?); destruct 859 | #ue #e0 #us0 #lb #s0 #lp #cs #cpost #k0 #k0' #K' * #LB * #LP #_ #E1 #E2 #E3 destruct whd in EX:(??%?); destruct 860 | #ue #e0 #us1 #s1 #us2 #lb #st2 #lp #cs #cpost #k0 #k0' #K' * #LB * #LP #_ #E1 #E2 #E3 destruct whd in EX:(??%?); destruct 861 | #ue #e0 #us1 #s1 #us2 #lb #st2 #lp #cs #cpost #k0 #k0' #K' * #LB * #LP #_ #E1 #E2 #E3 destruct whd in EX:(??%?); destruct 862 | #ue #e0 #us1 #s1 #us2 #lb #st2 #lp #cs #cpost #k0 #k0' #K' * #LB * #LP #_ #E1 #E2 #E3 destruct whd in EX:(??%?); destruct 812 863 | #k0 #k0' #K' #_ #E1 #E2 #E3 destruct whd in EX:(??%?); destruct 813 864 | #ux #r #f0 #en #k0 #k0' #K' #_ #E1 #E2 #E3 destruct whd in EX:(??%?); destruct 814 865 | #ls #u #k0 #k0' #K #_ #E1 #E2 #E3 destruct whd in EX:(??%?); destruct 815 866 ] 816 867 whd in match (label_statement ??); 817 [ 1,3,7,8: %{0} % /3/ 818 | 2,5: %{1} whd % /3/ 819 | 4,6: %{2} whd % /3/ 868 [ 1,3,5,7,9,10,11,12,13,15,17,18,19: %{0} % /3/ 869 | 2,4,6,8,14,16: %{1} whd % /3/ 820 870 ] 821 871 | #EX inversion KL 822 872 [ #E1 #E2 #E3 destruct whd in EX:(??%?); destruct 823 873 |#u #s0 #k0 #k0' #K' #_ #E1 #E2 #E3 destruct whd in EX:(??%?); destruct 824 | #ue #e0 #us0 # s0 #cl #cs #cpost #k0 #k0' #K' * #CL#_ #E1 #E2 #E3 destruct whd in EX:(??%?); destruct825 | #ue #e0 #us0 # s0 #cs #cpost #k0 #k0' #K'#_ #E1 #E2 #E3 destruct whd in EX:(??%?); destruct826 | #ue #e0 #us1 #s1 #us2 # st2 #cs #cpost #k0 #k0' #K'#_ #E1 #E2 #E3 destruct whd in EX:(??%?); destruct827 | #ue #e0 #us1 #s1 #us2 # st2 #cs #cpost #k0 #k0' #K'#_ #E1 #E2 #E3 destruct whd in EX:(??%?); destruct828 | #ue #e0 #us1 #s1 #us2 # st2 #cs #cpost #k0 #k0' #K'#_ #E1 #E2 #E3 destruct whd in EX:(??%?); destruct874 | #ue #e0 #us0 #lb #s0 #lp #cs #cpost #k0 #k0' #K' * #LB * #LP #_ #E1 #E2 #E3 destruct whd in EX:(??%?); destruct 875 | #ue #e0 #us0 #lb #s0 #lp #cs #cpost #k0 #k0' #K' * #LB * #LP #_ #E1 #E2 #E3 destruct whd in EX:(??%?); destruct 876 | #ue #e0 #us1 #s1 #us2 #lb #st2 #lp #cs #cpost #k0 #k0' #K' * #LB * #LP #_ #E1 #E2 #E3 destruct whd in EX:(??%?); destruct 877 | #ue #e0 #us1 #s1 #us2 #lb #st2 #lp #cs #cpost #k0 #k0' #K' * #LB * #LP #_ #E1 #E2 #E3 destruct whd in EX:(??%?); destruct 878 | #ue #e0 #us1 #s1 #us2 #lb #st2 #lp #cs #cpost #k0 #k0' #K' * #LB * #LP #_ #E1 #E2 #E3 destruct whd in EX:(??%?); destruct 829 879 | #k0 #k0' #K' #_ #E1 #E2 #E3 destruct whd in EX:(??%?); destruct 830 880 | #g #r #f0 #en #k0 #k0' #K' #_ #E1 #E2 #E3 destruct whd in EX:(??%?); destruct 831 881 | #ls #u #k0 #k0' #K #_ #E1 #E2 #E3 destruct whd in EX:(??%?); destruct 832 882 ] 833 883 whd in match (label_statement ??); 834 [ 1,2,3,6,7,8: %{0} % /4/ 835 | 5: %{1} % /4/ 836 | cases (bindIO_inversion ??????? EX) -EX * #v1 #tr1 * #EX1 #EX 884 [ 6,7,8,9: 885 cases (bindIO_inversion ??????? EX) -EX * #v1 #tr1 * #EX1 #EX 837 886 cases (bindIO_inversion ??????? EX) -EX * * #EX2 #EX 838 887 normalize in EX; destruct 839 888 cases (proj1 ?? (label_expr_ok ge ge' e m RG) ??? EX1 ue) #tr1' * #EX1' #T1 840 [ %{0} | %{2} ] whd889 [ 1,3,4,5,7,8: %{0} | *: %{1} ] whd 841 890 whd in ⊢ (??%?); >EX1' 842 891 whd in ⊢ (??%?); >label_expr_type >EX2 843 whd in ⊢ (??%?); % [ 3: <(E0_right tr) ] /3/ 892 whd in ⊢ (??%?); % [ 13,15: <(E0_right tr) ] /4/ 893 | *: %{0} whd % /5 by swl_partial, swl_state, swl_whilestate, cwl_for3, or_introl, or_intror/ 844 894 ] 845 895 | * [2: #a ] #EX 846 896 whd in EX:(??%?); cases (type_eq_dec (fn_return f) Tvoid) in EX; … … lemma step_with_labels_partial : ∀ge,ge'. 867 917 cases (bindIO_inversion ??????? EX) -EX * #v1 #tr1 * #EX1 #EX 868 918 cases v1 in EX1 EX; 869 919 [ 2: #sz #i #EX1 #EX 870 | *: normalize #A #B try #Cdestruct920 | *: [ 2,4: #x ] #EX1 #EX whd in EX:(??%%); destruct 871 921 ] 872 922 whd in EX:(??%%); destruct 873 923 cases (proj1 ?? (label_expr_ok ge ge' e m RG) ??? EX1 us) #tr1' * #EX1' #T1 … … lemma step_with_labels_partial : ∀ge,ge'. 896 946 | #c #st #EX whd in EX:(??%?); destruct @blindly_label #u1 897 947 %{0} % /3/ 898 948 ] 899 | #u0 #f #ua #a #us # s #cl #cs #cpost #k #k' #e #m #K * #CL#EX949 | #u0 #f #ua #a #us #lb #s #lp #cs #cpost #k #k' #e #m #K * #LB * #LP #EX 900 950 cases (bindIO_inversion ??????? EX) -EX * #v1 #tr1 * #EX1 #EX 901 951 cases (bindIO_inversion ??????? EX) -EX * * #EX2 #EX 902 952 whd in EX:(??%%); destruct 903 953 cases (proj1 ?? (label_expr_ok ge ge' e m RG) ??? EX1 ua) #tr1' * #EX1' #T1 904 [ 4 : %{0} | 1,2,3: %{1} ] whd954 [ 4,5,7,8: %{0} | *: %{1} ] whd 905 955 whd in ⊢ (??%?); >EX1' 906 956 whd in ⊢ (??%?); >label_expr_type >EX2 907 whd % [ 1,3,5,7: <(E0_right tr) ] /5/908 | #u0 #f #ua #a #us # s #cs #cpost #k #k' #e #m #K#EX957 whd % [ 9,11,13,15: <(E0_right tr) ] /5/ 958 | #u0 #f #ua #a #us #lb #s #lp #cs #cpost #k #k' #e #m #K * #LB * #LP #EX 909 959 whd in EX:(??%%); destruct 910 %{1} % /4/911 | #u0 #f #ua2 #a2 #us3 #s3 #us # s #cs #cpost #k #k' #e #m #K#EX960 [ 1,2: %{1} | *: %{0} ] % /5/ 961 | #u0 #f #ua2 #a2 #us3 #s3 #us #lb #s #lp #cs #cpost #k #k' #e #m #K * #LB * #LP #EX 912 962 cases (bindIO_inversion ??????? EX) -EX * #v1 #tr1 * #EX1 #EX 913 963 cases (bindIO_inversion ??????? EX) -EX * * #EX2 #EX 914 964 whd in EX:(??%%); destruct 915 965 cases (proj1 ?? (label_expr_ok ge ge' e m RG) ??? EX1 ua2) #tr1' * #EX1' #T1 916 [ %{1} | %{2} ] whd966 [ 1,2,3,6: %{1} | *: %{0} ] whd 917 967 whd in ⊢ (??%?); >EX1' 918 968 whd in ⊢ (??%?); >label_expr_type >EX2 919 % [ 1,3: <(E0_right tr) ] /4/969 % [ 1,3,5,7: <(E0_right tr) ] try @swl_partial /5/ 920 970 | #u0 * 921 971 [ #f #args #k #k' #m #K whd in ⊢ (??%? → ?); @pair_elim #e #m1 #EX1 #EX 922 972 cases (bindIO_inversion ??????? EX) -EX #m2 * #EX2 #EX … … lemma step_with_labels_partial : ∀ge,ge'. 948 998 whd in EX:(??%%); destruct 949 999 %{0} whd whd in ⊢ (??%?); >EX1 % /3/ 950 1000 ] 951 | *: #A #B #C #D #E #F #G try #H try #I try #J try #L try #M try #N try #O 1001 | *: #A #B #C #D #E #F #G try #H try #I try #J try #L try #M try #N try #O try #P try #Q try #R 952 1002 destruct whd in EX:(??%?); destruct 953 1003 ] 954 1004 | #r #EX whd in EX:(??%%); destruct … … lemma exec_step_interaction: 990 1040 ∃f,argtys,retty,vargs,k',m. s = Callstate (CL_External f argtys retty) vargs k' m. 991 1041 #ge #s cases s 992 1042 [ #f #st #kk #e #m #o #k #EX @⊥ cases st in EX ⊢ %; 993 [ 11,14: #a | 2,4, 7,12,13,15: #a #b | 3,5,6: #a #b #c | 8: #a #b #c #d]1043 [ 11,14: #a | 2,4,12,13,15: #a #b | 3,5: #a #b #c | 6,7: #a #b #c #d | 8: #a #b #c #d #e #f ] 994 1044 whd in ⊢ (??%? → ?); 995 [ 4, 5,7,8: #EX destruct ]1045 [ 4,6,7,11: #EX destruct ] 996 1046 [ cases a 997 1047 [ whd in ⊢ (??%? → ?); cases (fn_return f) normalize #A try #B try #C try #D destruct 998 1048 | #a' whd nodelta in ⊢ (??%? → ?); cases (type_eq_dec (fn_return f) Tvoid) … … lemma exec_step_interaction: 1006 1056 | 6,7: @bindIO_res_interact #x1 #x2 @bindIO_res_interact #x3 #x4 #EX whd in EX:(??%?); destruct 1007 1057 | cases (is_Sskip a) #H [ @bindIO_res_interact #vt #Evt @bindIO_res_interact #v #Ev ] #EX whd in EX:(??%?); destruct 1008 1058 | cases kk [ 1,8: cases (fn_return f) normalize #A try #B try #C try #D try #E try #F try #G try #H destruct 1009 | 2,3,5,6,7: normalize #A #B try #C try #D try #E destruct1010 | #z1 #z2 #z3 @bindIO_res_interact #x1 #x2 @bindIO_res_interact #x3 #x4 cases x3 #EX whd in EX:(??%?); destruct ]1011 | cases kk normalize #A try #B try #C try #D try #E destruct1012 | cases kk [ 4: #z1 #z2 #z3 @bindIO_res_interact #x1 #x2 @bindIO_res_interact #x3 #x4 cases x3 #EX whd in EX:(??%?); destruct1013 | *: normalize #A try #B try #C try #D try #E destruct1059 | 2,3,5,6,7: normalize #A #B try #C try #D try #E try #F try #G destruct 1060 | #z1 #z2 #z3 #z4 #z5 @bindIO_res_interact #x1 #x2 @bindIO_res_interact #x3 #x4 cases x3 #EX whd in EX:(??%?); destruct ] 1061 | cases kk normalize #A try #B try #C try #D try #E try #F try #G destruct 1062 | cases kk [ 4: #z1 #z2 #z3 #z4 #z5 @bindIO_res_interact #x1 #x2 @bindIO_res_interact #x3 #x4 cases x3 #EX whd in EX:(??%?); destruct 1063 | *: normalize #A try #B try #C try #D try #E try #F try #G destruct 1014 1064 ] 1015 1065 ] 1016 1066 | #f #args #kk #m #o #k cases f … … lemma exec_step_interaction: 1027 1077 | 8: #x1 #x2 #x3 #x4 cases x1 1028 1078 [ whd in ⊢ (??%? → ?); #EX destruct | #x5 whd in ⊢ (??%? → ?); cases x5 1029 1079 #x6 #x7 @bindIO_opt_interact #m' #Em #EX whd in EX:(??%?); destruct ] 1030 | *: normalize #A try #B try #C try #D try #E destruct ]1080 | *: normalize #A try #B try #C try #D try #E try #F try #G destruct ] 1031 1081 | #r #o #k #EX whd in EX:(??%?); destruct 1032 1082 ] qed. 1033 1083 … … lemma state_with_labels_call : ∀f,a,k,m,s1. 1037 1087 #f #a #k #m #s1 #S inversion S 1038 1088 [ #s #s' #S' #E1 #E2 #E3 destruct inversion S' 1039 1089 [ #H1 #H2 #H3 #H4 #H5 #H6 #H7 #H8 #H9 #H10 #H11 destruct 1040 | #H13 #H14 #H15 #H16 #H17 #H18 #H19 #H20 #H21 #H22 #H23 #H24 #H25 #H26 #H27 #H28 destruct1041 | #H29 #H30 #H31 #H32 #H33 #H34 #H35 #H36 #H37 #H38 #H39 #H40 #H41 #H42 #H43 destruct1042 | #H45 #H46 #H47 #H48 #H49 #H50 #H51 #H52 #H53 #H54 #H55 #H56 #H57 #H58 #H59 #H60 #H61 destruct1090 | #H13 #H14 #H15 #H16 #H17 #H18 #H19 #H20 #H21 #H22 #H23 #H24 #H25 #H26 #H27 #H28 #H29 #H30 destruct 1091 | #H29 #H30 #H31 #H32 #H33 #H34 #H35 #H36 #H37 #H38 #H39 #H40 #H41 #H42 #H43 #H44 #H45 #H46 destruct 1092 | #H45 #H46 #H47 #H48 #H49 #H50 #H51 #H52 #H53 #H54 #H55 #H56 #H57 #H58 #H59 #H60 #H61 #H62 #H66 #H67 destruct 1043 1093 | #u0 #f' #a' #k' #k'' #m' #K #E1 #E2 #E3 destruct %{k''} % /2/ 1044 1094 | #H63 #H64 #H65 #H66 #H67 #H68 #H69 #H70 destruct 1045 1095 | #H72 #H73 #H74 #H75 destruct -
src/Clight/switchRemoval.ma
diff --git a/src/Clight/switchRemoval.ma b/src/Clight/switchRemoval.ma index 89070e4..266949d 100755
a b match st with 76 76 | Scall _ _ _ ⇒ True 77 77 | Ssequence s1 s2 ⇒ switch_free s1 ∧ switch_free s2 78 78 | Sifthenelse e s1 s2 ⇒ switch_free s1 ∧ switch_free s2 79 | Swhile e body _ ⇒ switch_free body80 | Sdowhile e body⇒ switch_free body81 | Sfor s1 _ s2 s3⇒ switch_free s1 ∧ switch_free s2 ∧ switch_free s379 | Swhile e _ body _ ⇒ switch_free body 80 | Sdowhile e _ body _ ⇒ switch_free body 81 | Sfor s1 _ s2 _ s3 _ ⇒ switch_free s1 ∧ switch_free s2 ∧ switch_free s3 82 82 | Sbreak ⇒ True 83 83 | Scontinue ⇒ True 84 84 | Sreturn _ ⇒ True … … match st with 122 122 Ssequence (convert_break_to_goto s1 lab) (convert_break_to_goto s2 lab) 123 123 | Sifthenelse e iftrue iffalse ⇒ 124 124 Sifthenelse e (convert_break_to_goto iftrue lab) (convert_break_to_goto iffalse lab) 125 | Sfor init e update body⇒126 Sfor (convert_break_to_goto init lab) e update body125 | Sfor init e update lb body lp ⇒ 126 Sfor (convert_break_to_goto init lab) e update lb body lp 127 127 | Slabel l body ⇒ 128 128 Slabel l (convert_break_to_goto body lab) 129 129 | Scost cost body ⇒ … … lemma convert_break_lift : ∀s,label . switch_free s → switch_free (convert_b 136 136 #s elim s // 137 137 [ 1: #s1 #s2 #Hind1 #Hind2 #label * #Hsf1 #Hsf2 /3/ 138 138 | 2: #e #s1 #s2 #Hind1 #Hind2 #label * #Hsf1 #Hsf2 /3/ 139 | 3: #s1 #e #s2 # s3#Hind1 #Hind2 #Hind3 #label * * #Hsf1 #Hsf2 #Hsf3 normalize139 | 3: #s1 #e #s2 #lb #s3 #lp #Hind1 #Hind2 #Hind3 #label * * #Hsf1 #Hsf2 #Hsf3 normalize 140 140 try @conj try @conj /3/ 141 141 | 4: #l #s0 #Hind #lab #Hsf whd in Hsf; normalize /2/ 142 142 | 5: #l #s0 #Hind #lab #Hsf whd in Hsf; normalize /3/ … … match st with 247 247 do 〈s1', acc1, fvs', u'〉 ← switch_removal s1 fvs u; 248 248 do 〈s2', acc2, fvs'', u''〉 ← switch_removal s2 fvs' u'; 249 249 ret 〈Sifthenelse e s1' s2', acc1 @ acc2, fvs'', u''〉 250 | Swhile e body cl⇒250 | Swhile e lb body lp ⇒ 251 251 do 〈body', acc, fvs', u'〉 ← switch_removal body fvs u; 252 ret 〈Swhile e body' cl, acc, fvs', u'〉253 | Sdowhile e body⇒252 ret 〈Swhile e lb body' lp, acc, fvs', u'〉 253 | Sdowhile e lb body lp ⇒ 254 254 do 〈body', acc, fvs', u'〉 ← switch_removal body fvs u; 255 ret 〈Sdowhile e body', acc, fvs', u'〉256 | Sfor s1 e s2 s3⇒255 ret 〈Sdowhile e lb body' lp, acc, fvs', u'〉 256 | Sfor s1 e s2 lb s3 lp ⇒ 257 257 do 〈s1', acc1, fvs', u'〉 ← switch_removal s1 fvs u; 258 258 do 〈s2', acc2, fvs'', u''〉 ← switch_removal s2 fvs' u'; 259 259 do 〈s3', acc3, fvs''', u'''〉 ← switch_removal s3 fvs'' u''; 260 ret 〈Sfor s1' e s2' s3', acc1 @ acc2 @ acc3, fvs''', u'''〉260 ret 〈Sfor s1' e s2' lb s3' lp, acc1 @ acc2 @ acc3, fvs''', u'''〉 261 261 | Sbreak ⇒ 262 262 ret 〈st, [ ], fvs, u〉 263 263 | Scontinue ⇒ … … match st with 316 316 let 〈fvs, u'〉 ≝ mk_fresh_variables s1 u in 317 317 let 〈fvs', u''〉 ≝ mk_fresh_variables s2 u' in 318 318 〈fvs @ fvs', u''〉 319 | Swhile e body cl⇒319 | Swhile e _ body _ ⇒ 320 320 mk_fresh_variables body u 321 | Sdowhile e body⇒321 | Sdowhile e _ body _ ⇒ 322 322 mk_fresh_variables body u 323 | Sfor s1 e s2 s3⇒323 | Sfor s1 e s2 _ s3 _ ⇒ 324 324 let 〈fvs, u'〉 ≝ mk_fresh_variables s1 u in 325 325 let 〈fvs', u''〉 ≝ mk_fresh_variables s2 u' in 326 326 let 〈fvs'', u'''〉 ≝ mk_fresh_variables s3 u'' in … … let rec statement_indT 365 365 (Sca:∀eo,e,args. P (Scall eo e args)) 366 366 (Ssq:∀s1,s2. P s1 → P s2 → P (Ssequence s1 s2)) 367 367 (Sif:∀e,s1,s2. P s1 → P s2 → P (Sifthenelse e s1 s2)) 368 (Swh:∀e,s, cl. P s → P (Swhile e s cl))369 (Sdo:∀e,s . P s → P (Sdowhile e s))370 (Sfo:∀s1,e,s2,s3 . P s1 → P s2 → P s3 → P (Sfor s1 e s2 s3))368 (Swh:∀e,s,lb,lp. P s → P (Swhile e lb s lp)) 369 (Sdo:∀e,s,lb,lp. P s → P (Sdowhile e lb s lp)) 370 (Sfo:∀s1,e,s2,s3,lb,lp. P s1 → P s2 → P s3 → P (Sfor s1 e s2 lb s3 lp)) 371 371 (Sbr:P Sbreak) 372 372 (Sco:P Scontinue) 373 373 (Sre:∀eo. P (Sreturn eo)) … … match s with 388 388 | Sifthenelse e s1 s2 ⇒ Sif e s1 s2 389 389 (statement_indT P Q Ssk Sas Sca Ssq Sif Swh Sdo Sfo Sbr Sco Sre Ssw Sla Sgo Scs LSd LSc s1) 390 390 (statement_indT P Q Ssk Sas Sca Ssq Sif Swh Sdo Sfo Sbr Sco Sre Ssw Sla Sgo Scs LSd LSc s2) 391 | Swhile e s cl ⇒ Swh e s cl391 | Swhile e lb s lp ⇒ Swh e s lb lp 392 392 (statement_indT P Q Ssk Sas Sca Ssq Sif Swh Sdo Sfo Sbr Sco Sre Ssw Sla Sgo Scs LSd LSc s) 393 | Sdowhile e s ⇒ Sdo e s393 | Sdowhile e lb s lp ⇒ Sdo e s lb lp 394 394 (statement_indT P Q Ssk Sas Sca Ssq Sif Swh Sdo Sfo Sbr Sco Sre Ssw Sla Sgo Scs LSd LSc s) 395 | Sfor s1 e s2 s3 ⇒ Sfo s1 e s2 s3395 | Sfor s1 e s2 lb s3 lp ⇒ Sfo s1 e s2 s3 lb lp 396 396 (statement_indT P Q Ssk Sas Sca Ssq Sif Swh Sdo Sfo Sbr Sco Sre Ssw Sla Sgo Scs LSd LSc s1) 397 397 (statement_indT P Q Ssk Sas Sca Ssq Sif Swh Sdo Sfo Sbr Sco Sre Ssw Sla Sgo Scs LSd LSc s2) 398 398 (statement_indT P Q Ssk Sas Sca Ssq Sif Swh Sdo Sfo Sbr Sco Sre Ssw Sla Sgo Scs LSd LSc s3) … … and labeled_statements_indT 414 414 (Sca:∀eo,e,args. P (Scall eo e args)) 415 415 (Ssq:∀s1,s2. P s1 → P s2 → P (Ssequence s1 s2)) 416 416 (Sif:∀e,s1,s2. P s1 → P s2 → P (Sifthenelse e s1 s2)) 417 (Swh:∀e,s, cl. P s → P (Swhile e s cl))418 (Sdo:∀e,s . P s → P (Sdowhile e s))419 (Sfo:∀s1,e,s2,s3 . P s1 → P s2 → P s3 → P (Sfor s1 e s2 s3))417 (Swh:∀e,s,lb,lp. P s → P (Swhile e lb s lp)) 418 (Sdo:∀e,s,lb,lp. P s → P (Sdowhile e lb s lp)) 419 (Sfo:∀s1,e,s2,s3,lb,lp. P s1 → P s2 → P s3 → P (Sfor s1 e s2 lb s3 lp)) 420 420 (Sbr:P Sbreak) 421 421 (Sco:P Scontinue) 422 422 (Sre:∀eo. P (Sreturn eo)) … … lemma switch_removal_ok : 470 470 (Sifthenelse e (ret_st statement s1') (ret_st statement s2')) 471 471 (ret_acc statement s1'@ret_acc statement s2') (ret_fvs statement s2') 472 472 (ret_u statement s2')))} % try // 473 | 6: #e #s # cl#H #u0 #u1 #post normalize473 | 6: #e #s #lb #lp #H #u0 #u1 #post normalize 474 474 elim (H u0 u1 post) #s1' * normalize 475 475 cases (mk_fresh_variables s u0) #fvs #u' 476 476 #Heq1 #Heq1_fvs >Heq1 normalize nodelta 477 %{(mk_swret statement (Swhile e (ret_st statement s1') cl) (ret_acc statement s1')477 %{(mk_swret statement (Swhile e lb (ret_st statement s1') lp) (ret_acc statement s1') 478 478 (ret_fvs statement s1') (ret_u statement s1'))} % try // 479 | 7: #e #s # H #u0 #u1 #post normalize479 | 7: #e #s #lb #lp #H #u0 #u1 #post normalize 480 480 elim (H u0 u1 post) #s1' * normalize 481 481 cases (mk_fresh_variables s u0) #fvs #u' 482 482 #Heq1 #Heq1_fvs >Heq1 normalize nodelta 483 %{(mk_swret statement (Sdowhile e (ret_st statement s1')) (ret_acc statement s1')483 %{(mk_swret statement (Sdowhile e lb (ret_st statement s1') lp) (ret_acc statement s1') 484 484 (ret_fvs statement s1') (ret_u statement s1'))} % try // 485 | 8: #s1 #e #s2 #s3 # H1 #H2 #H3 #u0 #u1 #post normalize485 | 8: #s1 #e #s2 #s3 #lb #lp #H1 #H2 #H3 #u0 #u1 #post normalize 486 486 elim (H1 u0 u1 487 487 (\fst (mk_fresh_variables s2 (\snd (mk_fresh_variables s1 u0))) @ 488 488 (\fst (mk_fresh_variables s3 (\snd (mk_fresh_variables s2 (\snd (mk_fresh_variables s1 u0)))))) @ … … lemma switch_removal_ok : 497 497 >associative_append >associative_append >Heq1 normalize >Heq1_fvs 498 498 >Heq2 normalize >Heq2_fvs >Heq3 normalize 499 499 %{(mk_swret statement 500 (Sfor (ret_st statement s1') e (ret_st statement s2') (ret_st statement s3'))500 (Sfor (ret_st statement s1') e (ret_st statement s2') lb (ret_st statement s3') lp) 501 501 (ret_acc statement s1'@ret_acc statement s2'@ret_acc statement s3') 502 502 (ret_fvs statement s3') (ret_u statement s3'))} % try // 503 503 | 9: #u0 #u1 #post normalize %{(mk_swret statement Sbreak [] post u1)} % // … … match s with 626 626 max_id (max_of_statement s1) (max_of_statement s2) 627 627 | Sifthenelse e s1 s2 ⇒ 628 628 max_id (max_of_expr e) (max_id (max_of_statement s1) (max_of_statement s2)) 629 | Swhile e body _ ⇒629 | Swhile e _ body _ ⇒ 630 630 max_id (max_of_expr e) (max_of_statement body) 631 | Sdowhile e body⇒631 | Sdowhile e _ body _ ⇒ 632 632 max_id (max_of_expr e) (max_of_statement body) 633 | Sfor init test incr body⇒633 | Sfor init test incr _ body _ ⇒ 634 634 max_id (max_id (max_of_statement init) (max_of_expr test)) (max_id (max_of_statement incr) (max_of_statement body)) 635 635 | Sbreak ⇒ least_identifier 636 636 | Scontinue ⇒ least_identifier … … match s1 with 710 710 ] 711 711 | Ssequence sub1 sub2 ⇒ P sub1 ∧ P sub2 712 712 | Sifthenelse e sub1 sub2 ⇒ P sub1 ∧ P sub2 713 | Swhile e sub _ ⇒ Q e ∧ P sub714 | Sdowhile e sub⇒ Q e ∧ P sub715 | Sfor sub1 cond sub2 sub3⇒ P sub1 ∧ Q cond ∧ P sub2 ∧ P sub3713 | Swhile e _ sub _ ⇒ Q e ∧ P sub 714 | Sdowhile e _ sub _ ⇒ Q e ∧ P sub 715 | Sfor sub1 cond sub2 _ sub3 _ ⇒ P sub1 ∧ Q cond ∧ P sub2 ∧ P sub3 716 716 | Sbreak ⇒ True 717 717 | Scontinue ⇒ True 718 718 | Sreturn r ⇒ … … inductive switch_cont_sim : (list ident) → cont → cont → Prop ≝ 1414 1414 switch_cont_sim fvs k k' → 1415 1415 switch_removal s fvs u = Some ? result → 1416 1416 switch_cont_sim fvs (Kseq s k) (Kseq (ret_st ? result) k') 1417 | swc_while : ∀fvs,e, s,cl,k,k',u,result.1418 fresh_for_statement (Swhile e s cl) u →1417 | swc_while : ∀fvs,e,lb,s,lp,k,k',u,result. 1418 fresh_for_statement (Swhile e lb s lp) u → 1419 1419 switch_cont_sim fvs k k' → 1420 1420 switch_removal s fvs u = Some ? result → 1421 switch_cont_sim fvs (Kwhile e s cl k) (Kwhile e (ret_st ? result) clk')1422 | swc_dowhile : ∀fvs,e, s,k,k',u,result.1423 fresh_for_statement (Sdowhile e s) u →1421 switch_cont_sim fvs (Kwhile e lb s lp k) (Kwhile e lb (ret_st ? result) lp k') 1422 | swc_dowhile : ∀fvs,e,lb,s,lp,k,k',u,result. 1423 fresh_for_statement (Sdowhile e lb s lp) u → 1424 1424 switch_cont_sim fvs k k' → 1425 1425 switch_removal s fvs u = Some ? result → 1426 switch_cont_sim fvs (Kdowhile e s k) (Kdowhile e (ret_st ? result)k')1427 | swc_for1 : ∀fvs,e,s1, s2,k,k',u,result.1428 fresh_for_statement (Sfor Sskip e s1 s2) u →1426 switch_cont_sim fvs (Kdowhile e lb s lp k) (Kdowhile e lb (ret_st ? result) lp k') 1427 | swc_for1 : ∀fvs,e,s1,lb,s2,lp,k,k',u,result. 1428 fresh_for_statement (Sfor Sskip e s1 lb s2 lp) u → 1429 1429 switch_cont_sim fvs k k' → 1430 switch_removal (Sfor Sskip e s1 s2) fvs u = Some ? result →1431 switch_cont_sim fvs (Kseq (Sfor Sskip e s1 s2) k) (Kseq (ret_st ? result) k')1432 | swc_for2 : ∀fvs,e,s1, s2,k,k',u,result1,result2.1433 fresh_for_statement (Sfor Sskip e s1 s2) u →1430 switch_removal (Sfor Sskip e s1 lb s2 lp) fvs u = Some ? result → 1431 switch_cont_sim fvs (Kseq (Sfor Sskip e s1 lb s2 lp) k) (Kseq (ret_st ? result) k') 1432 | swc_for2 : ∀fvs,e,s1,lb,s2,lp,k,k',u,result1,result2. 1433 fresh_for_statement (Sfor Sskip e s1 lb s2 lp) u → 1434 1434 switch_cont_sim fvs k k' → 1435 1435 switch_removal s1 fvs u = Some ? result1 → 1436 1436 switch_removal s2 fvs (ret_u ? result1) = Some ? result2 → 1437 switch_cont_sim fvs (Kfor2 e s1 s2 k) (Kfor2 e (ret_st ? result1) (ret_st ? result2)k')1438 | swc_for3 : ∀fvs,e,s1, s2,k,k',u,result1,result2.1439 fresh_for_statement (Sfor Sskip e s1 s2) u →1437 switch_cont_sim fvs (Kfor2 e s1 lb s2 lp k) (Kfor2 e (ret_st ? result1) lb (ret_st ? result2) lp k') 1438 | swc_for3 : ∀fvs,e,s1,lb,s2,lp,k,k',u,result1,result2. 1439 fresh_for_statement (Sfor Sskip e s1 lb s2 lp) u → 1440 1440 switch_cont_sim fvs k k' → 1441 1441 switch_removal s1 fvs u = Some ? result1 → 1442 1442 switch_removal s2 fvs (ret_u ? result1) = Some ? result2 -> 1443 switch_cont_sim fvs (Kfor3 e s1 s2 k) (Kfor3 e (ret_st ? result1) (ret_st ? result2)k')1443 switch_cont_sim fvs (Kfor3 e s1 lb s2 lp k) (Kfor3 e (ret_st ? result1) lb (ret_st ? result2) lp k') 1444 1444 | swc_switch : ∀fvs,k,k'. 1445 1445 switch_cont_sim fvs k k' → 1446 1446 switch_cont_sim fvs (Kswitch k) (Kswitch k') -
src/Clight/test/factorial.c.ma
diff --git a/src/Clight/test/factorial.c.ma b/src/Clight/test/factorial.c.ma index fb16992..8a0d78d 100644
a b definition myprog := mk_program (\lambda _. clight_fundef) ((list init_data) × 24 24 (Expr (Evar (ident_of_nat 4)) (Tint I32 Signed )) 25 25 (Expr (Econst_int I32 (repr ? 1)) (Tint I32 Signed ))) 26 26 (Tint I32 Signed ))) 27 (None ?) 27 28 (Sassign (Expr (Evar (ident_of_nat 3)) (Tint I32 Signed )) 28 29 (Expr (Ebinop Omul 29 30 (Expr (Evar (ident_of_nat 3)) (Tint I32 Signed )) 30 31 (Expr (Evar (ident_of_nat 4)) (Tint I32 Signed ))) 31 32 (Tint I32 Signed ))) 32 )33 (None ?)) 33 34 (Sreturn (Some expr (Expr (Evar (ident_of_nat 3)) 34 35 (Tint I32 Signed ))))))) 35 36 -
src/Clight/test/insertsort.c.ma
diff --git a/src/Clight/test/insertsort.c.ma b/src/Clight/test/insertsort.c.ma index 0f0c002..432f65a 100644
a b definition myprog := mk_program (\lambda _. clight_fundef) ((list init_data) × 121 121 (Ssequence 122 122 (Swhile (Expr (Evar (ident_of_nat 2)) 123 123 (Tpointer (Tstruct (ident_of_nat 0) (Fcons (ident_of_nat 1) (Tint I8 Unsigned ) (Fcons (ident_of_nat 2) (Tcomp_ptr (ident_of_nat 0)) Fnil))))) 124 (None ?) 124 125 (Ssequence 125 126 (Sassign (Expr (Evar (ident_of_nat 15)) 126 127 (Tpointer (Tstruct (ident_of_nat 0) (Fcons (ident_of_nat 1) (Tint I8 Unsigned ) (Fcons (ident_of_nat 2) (Tcomp_ptr (ident_of_nat 0)) Fnil))))) … … definition myprog := mk_program (\lambda _. clight_fundef) ((list init_data) × 141 142 (Expr (Eaddrof 142 143 (Expr (Evar (ident_of_nat 16)) 143 144 (Tpointer (Tstruct (ident_of_nat 0) (Fcons (ident_of_nat 1) (Tint I8 Unsigned ) (Fcons (ident_of_nat 2) (Tcomp_ptr (ident_of_nat 0)) Fnil)))))) 144 (Tpointer (Tpointer (Tstruct (ident_of_nat 0) (Fcons (ident_of_nat 1) (Tint I8 Unsigned ) (Fcons (ident_of_nat 2) (Tcomp_ptr (ident_of_nat 0)) Fnil))))))])))) 145 (Tpointer (Tpointer (Tstruct (ident_of_nat 0) (Fcons (ident_of_nat 1) (Tint I8 Unsigned ) (Fcons (ident_of_nat 2) (Tcomp_ptr (ident_of_nat 0)) Fnil))))))]))) 146 (None ?)) 145 147 (Sassign (Expr (Ederef 146 148 (Expr (Evar (ident_of_nat 17)) 147 149 (Tpointer (Tpointer (Tstruct (ident_of_nat 0) (Fcons (ident_of_nat 1) (Tint I8 Unsigned ) (Fcons (ident_of_nat 2) (Tcomp_ptr (ident_of_nat 0)) Fnil))))))) … … definition myprog := mk_program (\lambda _. clight_fundef) ((list init_data) × 172 174 (Ssequence 173 175 (Swhile (Expr (Evar (ident_of_nat 20)) 174 176 (Tpointer (Tstruct (ident_of_nat 0) (Fcons (ident_of_nat 1) (Tint I8 Unsigned ) (Fcons (ident_of_nat 2) (Tcomp_ptr (ident_of_nat 0)) Fnil))))) 177 (None ?) 175 178 (Ssequence 176 179 (Scall (None expr) (Expr (Evar (ident_of_nat 18)) 177 180 (Tfunction (Tcons (Tint I8 Unsigned ) Tnil) Tvoid)) … … definition myprog := mk_program (\lambda _. clight_fundef) ((list init_data) × 186 189 (Expr (Evar (ident_of_nat 20)) 187 190 (Tpointer (Tstruct (ident_of_nat 0) (Fcons (ident_of_nat 1) (Tint I8 Unsigned ) (Fcons (ident_of_nat 2) (Tcomp_ptr (ident_of_nat 0)) Fnil)))))) 188 191 (Tstruct (ident_of_nat 0) (Fcons (ident_of_nat 1) (Tint I8 Unsigned ) (Fcons (ident_of_nat 2) (Tcomp_ptr (ident_of_nat 0)) Fnil)))) (ident_of_nat 2)) 189 (Tpointer (Tstruct (ident_of_nat 0) (Fcons (ident_of_nat 1) (Tint I8 Unsigned ) (Fcons (ident_of_nat 2) (Tcomp_ptr (ident_of_nat 0)) Fnil)))))))) 192 (Tpointer (Tstruct (ident_of_nat 0) (Fcons (ident_of_nat 1) (Tint I8 Unsigned ) (Fcons (ident_of_nat 2) (Tcomp_ptr (ident_of_nat 0)) Fnil))))))) 193 (None ?)) 190 194 (Sreturn (Some expr (Expr (Econst_int I32 (repr ? 0)) 191 195 (Tint I32 Signed ))))))) 192 196 -
src/Clight/test/runtime.c.ma
diff --git a/src/Clight/test/runtime.c.ma b/src/Clight/test/runtime.c.ma index bb2a75e..6485307 100644
a b definition myprog := mk_program (\lambda _. clight_fundef) ((list init_data) × 20 20 (Expr (Ecast (Tint I32 Unsigned) 21 21 (Expr (Econst_int I32 (repr ? 2)) (Tint I32 Signed ))) 22 22 (Tint I32 Unsigned))) (Tint I32 Unsigned)) 23 (None ?) 23 24 (Ssequence 24 25 (Sassign (Expr (Evar (ident_of_nat 1)) (Tint I32 Unsigned)) 25 26 (Expr (Ebinop Osub … … definition myprog := mk_program (\lambda _. clight_fundef) ((list init_data) × 34 35 (Expr (Evar (ident_of_nat 2)) (Tint I8 Unsigned ))) 35 36 (Tint I32 Signed )) 36 37 (Expr (Econst_int I32 (repr ? 1)) (Tint I32 Signed ))) 37 (Tint I32 Signed ))) (Tint I8 Unsigned ))))) 38 (Tint I32 Signed ))) (Tint I8 Unsigned )))) 39 (None ?)) 38 40 (Sreturn (Some expr (Expr (Ecast (Tint I32 Signed ) 39 41 (Expr (Evar (ident_of_nat 2)) 40 42 (Tint I8 Unsigned ))) (Tint I32 Signed ))))))) -
src/Clight/test/search.c.ma
diff --git a/src/Clight/test/search.c.ma b/src/Clight/test/search.c.ma index 6e46252..efb53cc 100644
a b definition myprog := mk_program (\lambda _. clight_fundef) ((list init_data) × 26 26 (Expr (Ecast (Tint I32 Signed ) 27 27 (Expr (Evar (ident_of_nat 1)) (Tint I8 Unsigned ))) 28 28 (Tint I32 Signed ))) (Tint I32 Signed )) 29 (None ?) 29 30 (Ssequence 30 31 (Sassign (Expr (Evar (ident_of_nat 3)) (Tint I8 Unsigned )) 31 32 (Expr (Ecast (Tint I8 Unsigned ) … … definition myprog := mk_program (\lambda _. clight_fundef) ((list init_data) × 103 104 (Tint I32 Signed )) 104 105 (Expr (Econst_int I32 (repr ? 1)) (Tint I32 Signed ))) 105 106 (Tint I32 Signed ))) (Tint I8 Unsigned ))) 106 Sskip))))) 107 Sskip)))) 108 (None ?)) 107 109 (Sreturn (Some expr (Expr (Ecast (Tint I8 Unsigned ) 108 110 (Expr (Eunop Oneg (Expr (Econst_int I32 (repr ? 1)) 109 111 (Tint I32 Signed ))) -
src/Clight/test/sum.c.ma
diff --git a/src/Clight/test/sum.c.ma b/src/Clight/test/sum.c.ma index 5ea484b..e79372b 100644
a b definition myprog := mk_program (\lambda _. clight_fundef) ((list init_data) × 27 27 (Expr (Evar (ident_of_nat 2)) (Tint I32 Signed )) 28 28 (Expr (Econst_int I32 (repr ? 1)) (Tint I32 Signed ))) 29 29 (Tint I32 Signed ))) 30 (None ?) 30 31 (Sassign (Expr (Evar (ident_of_nat 3)) (Tint I8 Unsigned )) 31 32 (Expr (Ecast (Tint I8 Unsigned ) 32 33 (Expr (Ebinop Oadd … … definition myprog := mk_program (\lambda _. clight_fundef) ((list init_data) × 42 43 (Tpointer (Tint I8 Unsigned )))) (Tint I8 Unsigned ))) 43 44 (Tint I32 Signed ))) (Tint I32 Signed ))) 44 45 (Tint I8 Unsigned ))) 45 )46 (None ?)) 46 47 (Sreturn (Some expr (Expr (Ecast (Tint I32 Signed ) 47 48 (Expr (Evar (ident_of_nat 3)) 48 49 (Tint I8 Unsigned ))) (Tint I32 Signed )))))) -
src/Clight/toCminor.ma
diff --git a/src/Clight/toCminor.ma b/src/Clight/toCminor.ma index df4f7b5..8efa403 100644
a b match s with 50 50 | Sifthenelse e1 s1 s2 ⇒ gather_mem_vars_expr e1 ∪ 51 51 gather_mem_vars_stmt s1 ∪ 52 52 gather_mem_vars_stmt s2 53 | Swhile e1 s1 _ ⇒ gather_mem_vars_expr e1 ∪54 gather_mem_vars_stmt s155 | Sdowhile e1 s1⇒ gather_mem_vars_expr e1 ∪56 gather_mem_vars_stmt s157 | Sfor s1 e1 s2 s3⇒ gather_mem_vars_stmt s1 ∪58 gather_mem_vars_expr e1 ∪59 gather_mem_vars_stmt s2 ∪60 gather_mem_vars_stmt s353 | Swhile e1 _ s1 _ ⇒ gather_mem_vars_expr e1 ∪ 54 gather_mem_vars_stmt s1 55 | Sdowhile e1 _ s1 _ ⇒ gather_mem_vars_expr e1 ∪ 56 gather_mem_vars_stmt s1 57 | Sfor s1 e1 s2 _ s3 _ ⇒ gather_mem_vars_stmt s1 ∪ 58 gather_mem_vars_expr e1 ∪ 59 gather_mem_vars_stmt s2 ∪ 60 gather_mem_vars_stmt s3 61 61 | Sbreak ⇒ ∅ 62 62 | Scontinue ⇒ ∅ 63 63 | Sreturn oe1 ⇒ match oe1 with [ None ⇒ ∅ | Some e1 ⇒ gather_mem_vars_expr e1 ] … … let rec labels_defined (s:statement) : list ident ≝ 925 925 match s with 926 926 [ Ssequence s1 s2 ⇒ labels_defined s1 @ labels_defined s2 927 927 | Sifthenelse _ s1 s2 ⇒ labels_defined s1 @ labels_defined s2 928 | Swhile _ s _ ⇒ labels_defined s929 | Sdowhile _ s⇒ labels_defined s930 | Sfor s1 _ s2 s3⇒ labels_defined s1 @ labels_defined s2 @ labels_defined s3928 | Swhile _ _ s _ ⇒ labels_defined s 929 | Sdowhile _ _ s _ ⇒ labels_defined s 930 | Sfor s1 _ s2 _ s3 _ ⇒ labels_defined s1 @ labels_defined s2 @ labels_defined s3 931 931 | Sswitch _ ls ⇒ labels_defined_switch ls 932 932 | Slabel l s ⇒ l::(labels_defined s) 933 933 | Scost _ s ⇒ labels_defined s … … axiom ReturnMismatch : String. 1126 1126 definition optional_cost : option costlabel → stmt → stmt ≝ 1127 1127 λo,s. match o with [ Some l ⇒ St_cost l s | None ⇒ s ]. 1128 1128 1129 lemma optional_cost_P : ∀s,cl,P. 1130 (∀c. P (St_cost c s)) → 1131 stmt_P P s → 1132 stmt_P P (optional_cost cl s). 1133 #s * /2/ 1134 qed. 1135 1129 1136 let rec translate_statement (vars:var_types) (uv:tmpgen vars) (ul:labgen) (lbls:lenv) (flag:convert_flag) (rettyp:option typ) (s:statement) on s 1130 1137 : res (Σsu:(tmpgen vars)×labgen×stmt.trans_inv vars lbls s uv flag rettyp su) ≝ 1131 1138 match s return λs.res (Σsu:(tmpgen vars)×labgen×stmt.trans_inv vars lbls s uv flag rettyp su) with … … match s return λs.res (Σsu:(tmpgen vars)×labgen×stmt.trans_inv vars lbls s u 1168 1175 OK ? «〈fgens2, St_ifthenelse ?? e1' s1' s2'〉, ?» 1169 1176 | _ ⇒ λ_.Error ? (msg TypeMismatch) 1170 1177 ] e1' 1171 | Swhile e1 s1 cl⇒1178 | Swhile e1 lb s1 lp ⇒ 1172 1179 do e1' ← translate_expr vars e1; 1173 1180 match typ_of_type (typeof e1) return λx.(Σe:CMexpr x.expr_vars ? e ?) → ? with 1174 1181 [ ASTint _ _ ⇒ λe1'. … … match s return λs.res (Σsu:(tmpgen vars)×labgen×stmt.trans_inv vars lbls s u 1178 1185 do «fgens2, s1',H1» ← translate_statement vars uv ul1 lbls (ConvertTo entry exit) rettyp s1; 1179 1186 let converted_loop ≝ 1180 1187 St_label entry 1181 (St_ifthenelse ?? e1' (St_seq s1' (St_goto entry)) (St_label exit (optional_cost clSt_skip)))1188 (St_ifthenelse ?? e1' (St_seq (optional_cost lb s1') (St_goto entry)) (St_label exit (optional_cost lp St_skip))) 1182 1189 in 1183 1190 OK ? «〈fgens2, converted_loop〉, ?» 1184 1191 | _ ⇒ λ_.Error ? (msg TypeMismatch) 1185 1192 ] e1' 1186 | Sdowhile e1 s1⇒1193 | Sdowhile e1 lb s1 lp ⇒ 1187 1194 do e1' ← translate_expr vars e1; 1188 1195 match typ_of_type (typeof e1) return λx.(Σe:CMexpr x. expr_vars ? e ?) → ? with 1189 1196 [ ASTint _ _ ⇒ λe1'. … … match s return λs.res (Σsu:(tmpgen vars)×labgen×stmt.trans_inv vars lbls s u 1192 1199 do «fgens2, s1', H1» ← translate_statement vars uv ul1 lbls (ConvertTo entry exit) rettyp s1; 1193 1200 let converted_loop ≝ 1194 1201 St_label entry 1195 ( St_seq1202 (optional_cost lb 1196 1203 (St_seq 1197 1204 s1' 1198 (St_ifthenelse ?? e1' (St_goto entry) St_skip)1205 (St_ifthenelse ?? e1' (St_goto entry) (St_label exit (optional_cost lp St_skip))) 1199 1206 ) 1200 (St_label exit St_skip))1207 ) 1201 1208 in 1202 1209 (* TODO: this is a little different from the prototype and CompCert, is it OK? *) 1203 1210 OK ? «〈fgens2, converted_loop〉, ?» 1204 1211 | _ ⇒ λ_.Error ? (msg TypeMismatch) 1205 1212 ] e1' 1206 | Sfor s1 e1 s2 s3⇒1213 | Sfor s1 e1 s2 lb s3 lp ⇒ 1207 1214 do e1' ← translate_expr vars e1; 1208 1215 match typ_of_type (typeof e1) return λx.(Σe:CMexpr x. expr_vars ? e ?) → ? with 1209 1216 [ ASTint _ _ ⇒ λe1'. … … match s return λs.res (Σsu:(tmpgen vars)×labgen×stmt.trans_inv vars lbls s u 1217 1224 St_seq 1218 1225 s1' 1219 1226 (St_label entry 1220 (St_seq 1221 (St_ifthenelse ?? e1' (St_seq s3' (St_seq s2' (St_goto entry))) St_skip) 1222 (St_label exit St_skip) 1223 )) 1227 (St_ifthenelse ?? e1' (optional_cost lb (St_seq s3' (St_seq s2' (St_goto entry)))) (St_label exit (optional_cost lp St_skip))) 1228 ) 1224 1229 in 1225 1230 OK ? «〈fgens4, converted_loop〉, ?» 1226 1231 | _ ⇒ λ_.Error ? (msg TypeMismatch) … … try @conj try @conj try @conj try @conj try @conj try @conj try (whd @I) try ass 1338 1343 #l * try * [ 1,4: #H %1 %1 normalize in H ⊢ %; try (@Exists_append_l @H); try (@Exists_append_r @H) 1339 1344 | 2,5: #H %1 %2 assumption 1340 1345 | 3,6: #H %2 assumption ] ] 1341 try @conj try @conj try @conj try @conj try @conj try @conj try @conj try @conj try @conj try @conj try @I try assumption 1342 [ 1,10,20: whd elim e1' #e #Hvars @(expr_vars_mp … Hvars) #i #t #Hlocal @(tmp_preserved … Hlocal) 1343 | cases cl normalize /3/ 1346 try @conj try @conj try @conj try @conj try @conj try @conj try @conj try @conj try @conj try @conj try @conj 1347 try ( @optional_cost_P try @(λ_.I) try @conj try @conj try @conj try @conj try @conj 1348 try ( @optional_cost_P try @(λ_.I) try @conj try @conj try @conj try @conj try @conj )) 1349 try @I try assumption 1350 [ 1,7,17: whd elim e1' #e #Hvars @(expr_vars_mp … Hvars) #i #t #Hlocal @(tmp_preserved … Hlocal) 1344 1351 | (*2,8: @(stmt_P_mp … Hstmt_inv1) #s0 #Hstmt_vars @(stmt_vars_mp … Hstmt_vars) // 1345 |*) 3,11: whd #l #H normalize in H;1352 |*) 2,8: whd #l #H normalize in H; 1346 1353 elim (Hlabels_tr1 … H) #label #Hlabel @(ex_intro … label) 1347 1354 @conj 1348 1355 [ 1,3: @(proj1 … Hlabel) 1349 | 2,4: whd @or_intror normalize @Exists_append_l@Exists_append_l try @Exists_append_l1356 | 2,4: whd cases lb [ 2,4: #lb'] @or_intror @Exists_append_l try @Exists_append_l try @Exists_append_l 1350 1357 @(proj2 … Hlabel) ] 1351 | 30: whd %2 %2 whd /2/ 1352 | 31: whd %2 whd /2/ 1353 | cases cl normalize /3/ 1354 | 5,17: whd %1 %1 normalize /2/ 1355 | 6,13: @(stmt_P_mp … Hind) #s0 #Hstmt_labels @(stmt_labels_mp … Hstmt_labels) 1356 #l * try * [ 1,5: #H %1 %1 normalize %2 @Exists_append_l @Exists_append_l try @Exists_append_l @H 1358 | 3,5,9,11,14: whd %1 %1 normalize /2/ 1359 | 4,12: @(stmt_P_mp … Hind) #s0 #Hstmt_labels @(stmt_labels_mp … Hstmt_labels) 1360 #l * try * [ 1,5: #H %1 %1 normalize cases lb [2,4: #lb' ] %2 @Exists_append_l try @Exists_append_l try @Exists_append_l @H 1357 1361 | 2,6: #H %1 %2 assumption 1358 1362 | 3,7: #H <H %1 %1 normalize /2/ 1359 | 4,8: #H normalize in H; elim H [ 1,3: #E <E %1 %1 normalize %21363 | 4,8: #H normalize in H; elim H [ 1,3: #E <E %1 %1 normalize cases lb [ 2,4: #lb' ] %2 1360 1364 @Exists_append_r normalize /2/ 1361 1365 | 2,4: * ] 1362 1366 ] 1363 | 7: normalize %1 %1 %1 // 1364 | 8,15: normalize %1 %1 %2 @Exists_append_r normalize /2/ 1365 | cases cl normalize /3/ 1366 | 12,14: whd %1 %1 normalize /2/ 1367 | 16: whd #label * [ 1: #Eq @(ex_intro … l') @conj [ 1: destruct // | whd /2/ ] 1368 | 2: #H elim (Hlabels_tr1 label H) 1369 #lab * #Hlookup #Hdef @(ex_intro … lab) @conj 1370 [ 1: // | 2: whd %2 assumption ] 1371 ] 1372 | 18: @(stmt_P_mp … Hind) #s0 #Hstmt_labels @(stmt_labels_mp … Hstmt_labels) 1367 | 6,10: normalize %1 %1 %2 cases lb [2,4:#lb'] @Exists_append_r normalize /2/ 1368 | whd #label * [ 1: #Eq @(ex_intro … l') @conj [ 1: destruct // | whd /2/ ] 1369 | 2: #H elim (Hlabels_tr1 label H) 1370 #lab * #Hlookup #Hdef @(ex_intro … lab) @conj 1371 [ 1: // | 2: whd %2 assumption ] 1372 ] 1373 | @(stmt_P_mp … Hind) #s0 #Hstmt_labels @(stmt_labels_mp … Hstmt_labels) 1373 1374 #l * try * [ 1: #H %1 %1 normalize %2 @H 1374 1375 | 2: #H %1 %2 assumption 1375 1376 | 3: #H %2 assumption ] 1376 | 19: @(stmt_P_mp … Hstmt_inv1) #s0 #Hstmt_vars @(stmt_vars_mp … Hstmt_vars) #i #t 1377 #H @(Htmps_pres3 … (Htmps_pres2 … H)) 1378 | 21: @(stmt_P_mp … Hstmt_inv2) #s0 #Hstmt_vars @(stmt_vars_mp … Hstmt_vars) #i #t 1379 #H @(Htmps_pres3 … H) 1380 | 22: whd #l #H normalize in H; 1381 cases (Exists_append … H) #Hcase 1382 [ 1: elim (Hlabels_tr1 l Hcase) #label #Hlabel @(ex_intro … label) @conj 1383 [ 1: @(proj1 … Hlabel) 1384 | 2: normalize @Exists_append_l @(proj2 … Hlabel) 1385 ] 1386 | 2: cases (Exists_append … Hcase) #Hcase2 1387 [ 1: elim (Hlabels_tr2 l Hcase2) #label #Hlabel @(ex_intro … label) @conj 1388 [ 1: @(proj1 … Hlabel) 1389 | 2: normalize >append_nil >append_nil >append_cons 1390 @Exists_append_r @Exists_append_l @Exists_append_r 1391 @(proj2 … Hlabel) 1392 ] 1393 | 2: elim (Hlabels_tr3 l Hcase2) #label #Hlabel @(ex_intro … label) @conj 1394 [ 1: @(proj1 … Hlabel) 1395 | 2: normalize >append_nil >append_nil >append_cons 1396 @Exists_append_r @Exists_append_l @Exists_append_l 1397 @(proj2 … Hlabel) 1398 ] 1399 ] 1377 | @(stmt_P_mp … Hstmt_inv1) #s0 #Hstmt_vars @(stmt_vars_mp … Hstmt_vars) #i #t 1378 #H @(Htmps_pres3 … (Htmps_pres2 … H)) 1379 | @(stmt_P_mp … Hstmt_inv2) #s0 #Hstmt_vars @(stmt_vars_mp … Hstmt_vars) #i #t 1380 #H @(Htmps_pres3 … H) 1381 | whd #l #H normalize in H; 1382 cases (Exists_append … H) #Hcase 1383 [ elim (Hlabels_tr1 l Hcase) #label #Hlabel @(ex_intro … label) @conj 1384 [ @(proj1 … Hlabel) 1385 | normalize @Exists_append_l @(proj2 … Hlabel) 1386 ] 1387 | cases (Exists_append … Hcase) #Hcase2 1388 [ elim (Hlabels_tr2 l Hcase2) #label #Hlabel %{label} % 1389 [ @(proj1 … Hlabel) 1390 | normalize cases lb [2:#lb'] normalize >append_nil >append_cons 1391 @Exists_append_r @Exists_append_l @Exists_append_r 1392 @(proj2 … Hlabel) 1400 1393 ] 1401 | 23: #id #ty #H @(Htmps_pres3 … (Htmps_pres2 … (Htmps_pres1 … H))) 1402 | 24: @(stmt_P_mp … Hind3) #s0 #Hstmt_labels @(stmt_labels_mp … Hstmt_labels) 1394 | 2: elim (Hlabels_tr3 l Hcase2) #label #Hlabel @(ex_intro … label) @conj 1395 [ 1: @(proj1 … Hlabel) 1396 | 2: normalize cases lb [2:#lb'] normalize >append_nil >append_cons 1397 @Exists_append_r @Exists_append_l @Exists_append_l 1398 @(proj2 … Hlabel) 1399 ] 1400 ] 1401 ] 1402 | #id #ty #H @(Htmps_pres3 … (Htmps_pres2 … (Htmps_pres1 … H))) 1403 | @(stmt_P_mp … Hind3) #s0 #Hstmt_labels @(stmt_labels_mp … Hstmt_labels) 1403 1404 #l * try * [ 1: #H %1 %1 normalize @Exists_append_l @H 1404 1405 | 2: #H %1 %2 assumption 1405 1406 | 3: #H %2 assumption ] 1406 | 2 5: whd %1 %1 normalize /2/1407 | 26: @(stmt_P_mp … Hind1) #s0 #Hstmt_labels @(stmt_labels_mp … Hstmt_labels)1408 #l * try * [ 1: #H %1 %1 normalize @Exists_append_r @(Exists_add ?? (nil ?))1409 @Exists_append_r @Exists_append_l @Exists_append_ l1407 | 22,23: whd %1 %1 normalize /2/ 1408 | @(stmt_P_mp … Hind2) #s0 #Hstmt_labels @(stmt_labels_mp … Hstmt_labels) 1409 #l * try * [ 1: #H %1 %1 normalize cases lb [2:#lb'] normalize @Exists_append_r @(Exists_add ?? (nil ?)) 1410 @Exists_append_r @Exists_append_l @Exists_append_r 1410 1411 @Exists_append_l assumption 1411 1412 | 2: #H %1 %2 assumption 1412 1413 | 3: #H <H %1 %1 normalize 1413 1414 @Exists_append_r whd %1 // 1414 | 4: * [ 1: #H <H %1 %1 normalize 1415 @Exists_append_r @(Exists_add ?? (nil ?)) 1416 @Exists_append_r @Exists_append_r 1417 whd %1 // 1415 | 4: * [ 1: #Eq <Eq %1 %1 whd normalize 1416 @Exists_append_r @(Exists_add ?? (nil ?)) @Exists_append_r 1417 @Exists_append_r whd %1 // 1418 1418 | 2: * ] 1419 1419 ] 1420 | 27: @(stmt_P_mp … Hind2) #s0 #Hstmt_labels @(stmt_labels_mp … Hstmt_labels)1421 #l * try * [ 1: #H %1 %1 normalize @Exists_append_r @(Exists_add ?? (nil ?))1422 @Exists_append_r @Exists_append_l @Exists_append_l1423 @Exists_append_ r @Exists_append_l assumption1420 | @(stmt_P_mp … Hind1) #s0 #Hstmt_labels @(stmt_labels_mp … Hstmt_labels) 1421 #l * try * [ 1: #H %1 %1 normalize cases lb [2:#lb'] normalize @Exists_append_r @(Exists_add ?? (nil ?)) 1422 @Exists_append_r @Exists_append_l 1423 @Exists_append_l assumption 1424 1424 | 2: #H %1 %2 assumption 1425 1425 | 3: #H <H %1 %1 normalize 1426 1426 @Exists_append_r whd %1 // 1427 | 4: * [ 1: #Eq <Eq %1 %1 whd normalize 1428 @Exists_append_r @(Exists_add ?? (nil ?)) @Exists_append_r 1429 @Exists_append_r whd %1 // 1427 | 4: * [ 1: #H <H %1 %1 normalize 1428 @Exists_append_r @(Exists_add ?? (nil ?)) 1429 @Exists_append_r @Exists_append_r 1430 whd %1 // 1430 1431 | 2: * ] 1431 1432 ] 1432 | 28: whd %1 %1 normalize /2/ 1433 | 29: whd %1 %1 normalize 1434 @Exists_append_r @(Exists_add ?? (nil ?)) @Exists_append_r @Exists_append_r 1435 whd %1 // 1436 | 32: whd %1 %2 whd @(ex_intro … l) @E 1433 | whd %1 %1 normalize 1434 @Exists_append_r @(Exists_add ?? (nil ?)) @Exists_append_r @Exists_append_r 1435 whd %1 // 1436 | whd %2 %2 whd /2/ 1437 | whd %2 whd /2/ 1438 | whd %1 %2 whd @(ex_intro … l) @E 1437 1439 ] qed. 1438 1440 1439 1441 axiom ParamGlobalMixup : String.
Note: See TracBrowser
for help on using the repository browser.