@@ -356,32 +356,18 @@ Qed.
356356
357357(** ** Relating global environments *)
358358
359- Inductive match_globalenvs (F: meminj) (bound: block): Prop :=
360- | mk_match_globalenvs
361- (DOMAIN: forall b, Plt b bound -> F b = Some(b, 0))
362- (IMAGE: forall b1 b2 delta, F b1 = Some(b2, delta) -> Plt b2 bound -> b1 = b2)
363- (SYMBOLS: forall id b, Genv.find_symbol ge id = Some b -> Plt b bound)
364- (FUNCTIONS: forall b fd, Genv.find_funct_ptr ge b = Some fd -> Plt b bound)
365- (VARINFOS: forall b gv, Genv.find_var_info ge b = Some gv -> Plt b bound).
366-
367359Lemma find_function_agree:
368- forall ros rs fd F ctx rs' bound ,
360+ forall ros rs fd F ctx rs',
369361 find_function ge ros rs = Some fd ->
370362 agree_regs F ctx rs rs' ->
371- match_globalenvs F bound ->
363+ Genv.inject F ge ->
372364 exists cu fd',
373365 find_function tge (sros ctx ros) rs' = Some fd' /\ transf_fundef (funenv_program cu) fd = OK fd' /\ linkorder cu prog.
374366Proof .
375367 intros. destruct ros as [r | id]; simpl in *.
376368- (* register *)
377369 assert (EQ: rs'#(sreg ctx r) = rs#r).
378- { exploit Genv.find_funct_inv; eauto. intros [b EQ].
379- assert (A: Val.inject F rs#r rs'#(sreg ctx r)). eapply agree_val_reg; eauto.
380- rewrite EQ in A; inv A.
381- inv H1. rewrite DOMAIN in H5. inv H5. auto.
382- apply FUNCTIONS with fd.
383- rewrite EQ in H; rewrite Genv.find_funct_find_funct_ptr in H. auto.
384- }
370+ { eapply Genv.find_funct_inject; eauto using agree_val_reg. }
385371 rewrite EQ. eapply functions_translated; eauto.
386372- (* symbol *)
387373 rewrite symbols_preserved. destruct (Genv.find_symbol ge id); try discriminate.
405391(** Translation of builtin arguments. *)
406392
407393Lemma tr_builtin_arg:
408- forall F bound ctx rs rs' sp sp' m m',
409- match_globalenvs F bound ->
394+ forall F ctx rs rs' sp sp' m m',
395+ Genv.inject F ge ->
410396 agree_regs F ctx rs rs' ->
411397 F sp = Some(sp', ctx.(dstk)) ->
412398 Mem.inject F m m' ->
@@ -415,7 +401,12 @@ Lemma tr_builtin_arg:
415401 exists v', eval_builtin_arg tge (fun r => rs'#r) (Vptr sp' Ptrofs.zero) m' (sbuiltinarg ctx a) v'
416402 /\ Val.inject F v v'.
417403Proof .
418- intros until m'; intros MG AG SP MI. induction 1; simpl.
404+ intros until m'; intros MG AG SP MI.
405+ assert (SYMB: forall id ofs, Val.inject F (Senv.symbol_address ge id ofs) (Senv.symbol_address tge id ofs)).
406+ { intros. unfold Senv.symbol_address; simpl. rewrite symbols_preserved.
407+ destruct (Genv.find_symbol ge id) as [b|] eqn:FS; auto.
408+ eauto using Val.inject_ptr_flat, Genv.find_symbol_inject. }
409+ induction 1; simpl.
419410- exists rs'#(sreg ctx x); split. constructor. eapply agree_val_reg; eauto.
420411- econstructor; eauto with barg.
421412- econstructor; eauto with barg.
@@ -426,16 +417,8 @@ Proof.
426417 simpl. econstructor; eauto. rewrite Ptrofs.add_zero_l; auto.
427418 intros (v' & A & B). exists v'; split; auto. constructor. simpl. rewrite Ptrofs.add_zero_l; auto.
428419- econstructor; split. constructor. simpl. econstructor; eauto. rewrite ! Ptrofs.add_zero_l; auto.
429- - assert (Val.inject F (Senv.symbol_address ge id ofs) (Senv.symbol_address tge id ofs)).
430- { unfold Senv.symbol_address; simpl; unfold Genv.symbol_address.
431- rewrite symbols_preserved. destruct (Genv.find_symbol ge id) as [b|] eqn:FS; auto.
432- inv MG. econstructor. eauto. rewrite Ptrofs.add_zero; auto. }
433- exploit Mem.loadv_inject; eauto. intros (v' & A & B).
434- exists v'; eauto with barg.
435- - econstructor; split. constructor.
436- unfold Senv.symbol_address; simpl; unfold Genv.symbol_address.
437- rewrite symbols_preserved. destruct (Genv.find_symbol ge id) as [b|] eqn:FS; auto.
438- inv MG. econstructor. eauto. rewrite Ptrofs.add_zero; auto.
420+ - exploit Mem.loadv_inject; eauto. intros (v' & A & B). exists v'; eauto with barg.
421+ - econstructor; split. constructor. auto.
439422- destruct IHeval_builtin_arg1 as (v1' & A1 & B1).
440423 destruct IHeval_builtin_arg2 as (v2' & A2 & B2).
441424 econstructor; split. eauto with barg. apply Val.longofwords_inject; auto.
@@ -446,8 +429,8 @@ Proof.
446429Qed .
447430
448431Lemma tr_builtin_args:
449- forall F bound ctx rs rs' sp sp' m m',
450- match_globalenvs F bound ->
432+ forall F ctx rs rs' sp sp' m m',
433+ Genv.inject F ge ->
451434 agree_regs F ctx rs rs' ->
452435 F sp = Some(sp', ctx.(dstk)) ->
453436 Mem.inject F m m' ->
467450
468451Inductive match_stacks (F: meminj) (m m': mem):
469452 list stackframe -> list stackframe -> block -> Prop :=
470- | match_stacks_nil: forall bound1 bound
471- (MG: match_globalenvs F bound1 )
472- (BELOW: Ple bound1 bound),
453+ | match_stacks_nil: forall bound
454+ (GINJ: Genv.inject F ge )
455+ (BELOW: Ple (Genv.genv_next ge) bound),
473456 match_stacks F m m' nil nil bound
474457 | match_stacks_cons: forall res f sp pc rs stk f' sp' rs' stk' bound fenv ctx
475458 (MS: match_stacks_inside F m m' stk stk' f' ctx sp' rs')
@@ -528,38 +511,23 @@ Variables m m': mem.
528511
529512Lemma match_stacks_globalenvs:
530513 forall stk stk' bound,
531- match_stacks F m m' stk stk' bound -> exists b, match_globalenvs F b
514+ match_stacks F m m' stk stk' bound -> Genv.inject F ge
532515with match_stacks_inside_globalenvs:
533516 forall stk stk' f ctx sp rs',
534- match_stacks_inside F m m' stk stk' f ctx sp rs' -> exists b, match_globalenvs F b .
517+ match_stacks_inside F m m' stk stk' f ctx sp rs' -> Genv.inject F ge .
535518Proof .
536519 induction 1; eauto.
537520 induction 1; eauto.
538521Qed .
539522
540- Lemma match_globalenvs_preserves_globals:
541- forall b, match_globalenvs F b -> meminj_preserves_globals ge F.
542- Proof .
543- intros. inv H. red. split. eauto. split. eauto.
544- intros. symmetry. eapply IMAGE; eauto.
545- Qed .
546-
547- Lemma match_stacks_inside_globals:
548- forall stk stk' f ctx sp rs',
549- match_stacks_inside F m m' stk stk' f ctx sp rs' -> meminj_preserves_globals ge F.
550- Proof .
551- intros. exploit match_stacks_inside_globalenvs; eauto. intros [b A].
552- eapply match_globalenvs_preserves_globals; eauto.
553- Qed .
554-
555523Lemma match_stacks_bound:
556524 forall stk stk' bound bound1,
557525 match_stacks F m m' stk stk' bound ->
558526 Ple bound bound1 ->
559527 match_stacks F m m' stk stk' bound1.
560528Proof .
561529 intros. inv H.
562- apply match_stacks_nil with bound0 . auto. eapply Ple_trans; eauto.
530+ apply match_stacks_nil. auto. eapply Ple_trans; eauto.
563531 eapply match_stacks_cons; eauto. eapply Pos.lt_le_trans; eauto.
564532 eapply match_stacks_untailcall; eauto. eapply Pos.lt_le_trans; eauto.
565533Qed .
@@ -600,10 +568,10 @@ with match_stacks_inside_invariant:
600568Proof .
601569 induction 1; intros.
602570 (* nil *)
603- apply match_stacks_nil with (bound1 := bound1) .
604- inv MG. constructor; auto .
605- intros. apply IMAGE with delta. eapply INJ; eauto. eapply Pos.lt_le_trans; eauto .
606- auto. auto.
571+ apply match_stacks_nil; auto .
572+ destruct GINJ as [A B]. split; intros .
573+ apply INCR. apply A. extlia .
574+ apply B; auto. apply INJ; auto. extlia .
607575 (* cons *)
608576 apply match_stacks_cons with (fenv := fenv) (ctx := ctx); auto.
609577 eapply match_stacks_inside_invariant; eauto.
@@ -773,10 +741,10 @@ with match_stacks_inside_extcall:
773741 match_stacks_inside F2 m2 m2' stk stk' f' ctx sp' rs'.
774742Proof .
775743 induction 1; intros.
776- apply match_stacks_nil with bound1 ; auto.
777- inv MG. constructor ; intros; eauto.
778- destruct (F1 b1 ) as [[b2' delta' ]|] eqn:?.
779- exploit INCR; eauto. intros EQ; rewrite H0 in EQ; inv EQ. eapply IMAGE; eauto.
744+ apply match_stacks_nil; auto.
745+ destruct GINJ as [P Q]. split ; intros; eauto.
746+ destruct (F1 b ) as [[b0 delta0 ]|] eqn:?.
747+ exploit INCR; eauto. intros EQ; rewrite H0 in EQ; inv EQ. eauto.
780748 exploit SEP; eauto. intros [A B]. elim B. red. extlia.
781749 eapply match_stacks_cons; eauto.
782750 eapply match_stacks_inside_extcall; eauto. extlia.
@@ -921,7 +889,7 @@ Proof.
921889- (* op *)
922890 exploit tr_funbody_inv; eauto. intros TR; inv TR.
923891 exploit eval_operation_inject.
924- eapply match_stacks_inside_globals ; eauto.
892+ eapply match_stacks_inside_globalenvs ; eauto.
925893 eexact SP.
926894 instantiate (2 := rs##args). instantiate (1 := rs'##(sregs ctx args)). eapply agree_val_regs; eauto.
927895 eexact MINJ. eauto.
@@ -936,7 +904,7 @@ Proof.
936904- (* load *)
937905 exploit tr_funbody_inv; eauto. intros TR; inv TR.
938906 exploit eval_addressing_inject.
939- eapply match_stacks_inside_globals ; eauto.
907+ eapply match_stacks_inside_globalenvs ; eauto.
940908 eexact SP.
941909 instantiate (2 := rs##args). instantiate (1 := rs'##(sregs ctx args)). eapply agree_val_regs; eauto.
942910 eauto.
@@ -953,7 +921,7 @@ Proof.
953921- (* store *)
954922 exploit tr_funbody_inv; eauto. intros TR; inv TR.
955923 exploit eval_addressing_inject.
956- eapply match_stacks_inside_globals ; eauto.
924+ eapply match_stacks_inside_globalenvs ; eauto.
957925 eexact SP.
958926 instantiate (2 := rs##args). instantiate (1 := rs'##(sregs ctx args)). eapply agree_val_regs; eauto.
959927 eauto.
@@ -973,8 +941,7 @@ Proof.
973941 intros. eapply SSZ2. eapply Mem.perm_store_2; eauto with mem.
974942
975943- (* call *)
976- exploit match_stacks_inside_globalenvs; eauto. intros [bound G].
977- exploit find_function_agree; eauto. intros (cu & fd' & A & B & C).
944+ exploit find_function_agree; eauto using match_stacks_inside_globalenvs. intros (cu & fd' & A & B & C).
978945 exploit tr_funbody_inv; eauto. intros TR; inv TR.
979946+ (* not inlined *)
980947 left; econstructor; split.
@@ -994,8 +961,7 @@ Proof.
994961 red; intros; apply PRIV. destruct H16. lia.
995962
996963- (* tailcall *)
997- exploit match_stacks_inside_globalenvs; eauto. intros [bound G].
998- exploit find_function_agree; eauto. intros (cu & fd' & A & B & C).
964+ exploit find_function_agree; eauto using match_stacks_inside_globalenvs. intros (cu & fd' & A & B & C).
999965 assert (PRIV': range_private F m' m'0 sp' (dstk ctx) f'.(fn_stacksize)).
1000966 { eapply range_private_free_left; eauto. inv FB. rewrite <- H4. auto. }
1001967 exploit tr_funbody_inv; eauto. intros TR; inv TR.
@@ -1050,10 +1016,8 @@ Proof.
10501016
10511017- (* builtin *)
10521018 exploit tr_funbody_inv; eauto. intros TR; inv TR.
1053- exploit match_stacks_inside_globalenvs; eauto. intros [bound MG].
1054- exploit tr_builtin_args; eauto. intros (vargs' & P & Q).
1055- exploit external_call_mem_inject; eauto.
1056- eapply match_stacks_inside_globals; eauto.
1019+ exploit tr_builtin_args; eauto using match_stacks_inside_globalenvs. intros (vargs' & P & Q).
1020+ exploit external_call_mem_inject; eauto using match_stacks_inside_globalenvs.
10571021 intros [F1 [v1 [m1' [A [B [C [D [E [J K]]]]]]]]].
10581022 left; econstructor; split.
10591023 eapply plus_one. eapply exec_Ibuiltin; eauto.
@@ -1207,9 +1171,7 @@ Proof.
12071171 auto. auto.
12081172
12091173- (* external function *)
1210- exploit match_stacks_globalenvs; eauto. intros [bound MG].
1211- exploit external_call_mem_inject; eauto.
1212- eapply match_globalenvs_preserves_globals; eauto.
1174+ exploit external_call_mem_inject; eauto using match_stacks_globalenvs.
12131175 intros [F1 [v1 [m1' [A [B [C [D [E [J K]]]]]]]]].
12141176 simpl in FD. inv FD.
12151177 left; econstructor; split.
@@ -1274,14 +1236,8 @@ Proof.
12741236 rewrite <- H3. eapply sig_function_translated; eauto.
12751237 econstructor; eauto.
12761238 instantiate (1 := Mem.flat_inj (Mem.nextblock m0)).
1277- apply match_stacks_nil with (Mem.nextblock m0).
1278- constructor; intros.
1279- unfold Mem.flat_inj. apply pred_dec_true; auto.
1280- unfold Mem.flat_inj in H. destruct (plt b1 (Mem.nextblock m0)); congruence.
1281- eapply Genv.find_symbol_not_fresh; eauto.
1282- eapply Genv.find_funct_ptr_not_fresh; eauto.
1283- eapply Genv.find_var_info_not_fresh; eauto.
1284- apply Ple_refl.
1239+ erewrite <- Genv.init_mem_genv_next by eauto.
1240+ apply match_stacks_nil. apply Genv.init_inject. apply Ple_refl.
12851241 eapply Genv.initmem_inject; eauto.
12861242Qed .
12871243
0 commit comments