Definition MATCH (d:CMinSel_core) mu c1 m1 c2 m2:Prop :=
match_states (restrict (as_inj mu) (vis mu)) c1 m1 c2 m2 /\
REACH_closed m1 (vis mu) /\
meminj_preserves_globals ge (as_inj mu) /\
globalfunction_ptr_inject (as_inj mu) /\
(forall b, isGlobalBlock ge b = true -> frgnBlocksSrc mu b = true) /\
sm_valid mu m1 m2 /\ SM_wd mu /\ Mem.inject (as_inj mu) m1 m2.

(* Specifications: *)
Lemma MATCH_wd: forall d mu c1 m1 c2 m2
(MC: MATCH d mu c1 m1 c2 m2), SM_wd mu.
Lemma MATCH_valid: forall d mu c1 m1 c2 m2
(MC: MATCH d mu c1 m1 c2 m2), sm_valid mu m1 m2.
Lemma MATCH_initial: forall v1 v2 sig entrypoints
(EP: In (v1, v2, sig) entrypoints)
(entry_points_ok : forall (v1 v2 : val) (sig : signature),
In (v1, v2, sig) entrypoints ->
exists b f1 f2,
v1 = Vptr b Int.zero /\
v2 = Vptr b Int.zero /\
Genv.find_funct_ptr ge b = Some f1 /\
Genv.find_funct_ptr tge b = Some f2)
vals1 c1 m1 j vals2 m2 (DomS DomT : block -> bool)
(Ini: initial_core cminsel_eff_sem ge v1 vals1 = Some c1)
(Inj: Mem.inject j m1 m2)
(VInj: Forall2 (val_inject j) vals1 vals2)
(PG:meminj_preserves_globals ge j)
(R : list_norepet (map fst (prog_defs prog)))
(J: forall b1 b2 delta, j b1 = Some (b2, delta) ->
(DomS b1 = true /\ DomT b2 = true))
(RCH: forall b, REACH m2
(fun b' : block => isGlobalBlock tge b' || getBlocks vals2 b') b = true ->
DomT b = true)
(InitMem : exists m0 : mem, Genv.init_mem prog = Some m0
/\ Ple (Mem.nextblock m0) (Mem.nextblock m1)
/\ Ple (Mem.nextblock m0) (Mem.nextblock m2))
(GDE: genvs_domain_eq ge tge)
(HDomS: forall b : block, DomS b = true -> Mem.valid_block m1 b)
(HDomT: forall b : block, DomT b = true -> Mem.valid_block m2 b),
exists c2,
initial_core rtl_eff_sem tge v2 vals2 = Some c2 /\
MATCH c1
(initial_SM DomS DomT
(REACH m1 (fun b : block => isGlobalBlock ge b || getBlocks vals1 b))
(REACH m2 (fun b : block => isGlobalBlock tge b || getBlocks vals2 b))
j) c1 m1 c2 m2.
Lemma MATCH_afterExternal: forall
(GDE : genvs_domain_eq ge tge)
mu st1 st2 m1 e vals1 m2 ef_sig vals2 e' ef_sig'
(MemInjMu : Mem.inject (as_inj mu) m1 m2)
(MatchMu: MATCH st1 mu st1 m1 st2 m2)
(AtExtSrc : at_external cminsel_eff_sem st1 = Some (e, ef_sig, vals1))
(AtExtTgt : at_external rtl_eff_sem st2 = Some (e', ef_sig', vals2))
(ValInjMu : Forall2 (val_inject (restrict (as_inj mu) (vis mu))) vals1 vals2)
(pubSrc' : block -> bool)
(pubSrcHyp : pubSrc' =
(fun b : block =>
locBlocksSrc mu b && REACH m1 (exportedSrc mu vals1) b))
(pubTgt' : block -> bool)
(pubTgtHyp: pubTgt' =
(fun b : block =>
locBlocksTgt mu b && REACH m2 (exportedTgt mu vals2) b))
nu (NuHyp: nu = replace_locals mu pubSrc' pubTgt')
nu' ret1 m1' ret2 m2'
(INC: extern_incr nu nu')
(SEP: sm_inject_separated nu nu' m1 m2)
(WDnu': SM_wd nu')
(SMvalNu': sm_valid nu' m1' m2')
(MemInjNu': Mem.inject (as_inj nu') m1' m2')
(RValInjNu': val_inject (as_inj nu') ret1 ret2)
(FwdSrc: mem_forward m1 m1')
(FwdTgt: mem_forward m2 m2')
(frgnSrc' : block -> bool)
(frgnSrcHyp: frgnSrc' =
(fun b : block => DomSrc nu' b &&
(negb (locBlocksSrc nu' b) && REACH m1' (exportedSrc nu' (ret1 :: nil)) b)))
(frgnTgt' : block -> bool)
(frgnTgtHyp: frgnTgt' =
(fun b : block => DomTgt nu' b &&
(negb (locBlocksTgt nu' b) && REACH m2' (exportedTgt nu' (ret2 :: nil)) b)))
mu' (Mu'Hyp: mu' = replace_externs nu' frgnSrc' frgnTgt')
(UnchPrivSrc: Mem.unchanged_on
(fun b z => locBlocksSrc nu b = true /\ pubBlocksSrc nu b = false) m1 m1')
(UnchLOOR: Mem.unchanged_on (local_out_of_reach nu m1) m2 m2'),
exists st1' st2',
after_external cminsel_eff_sem (Some ret1) st1 =Some st1' /\
after_external rtl_eff_sem (Some ret2) st2 = Some st2' /\
MATCH st1' mu' st1' m1' st2' m2'.
Lemma MATCH_corestep: forall
st1 m1 st1' m1'
(CS: corestep cminsel_eff_sem ge st1 m1 st1' m1')
st2 mu m2 (MTCH: MATCH st1 mu st1 m1 st2 m2),
exists st2' m2' mu',
(corestep_plus rtl_eff_sem tge st2 m2 st2' m2' \/
(corestep_star rtl_eff_sem tge st2 m2 st2' m2' /\ lt_state st1' st1))
/\ intern_incr mu mu'
/\ sm_inject_separated mu mu' m1 m2
/\ sm_locally_allocated mu mu' m1 m2 m1' m2'
/\ MATCH st1' mu' st1' m1' st2' m2'
/\ SM_wd mu' /\ sm_valid mu' m1' m2'.
Lemma MATCH_effcore_diagram: forall
st1 m1 st1' m1' (U1 : block -> Z -> bool)
(CS: effstep cminsel_eff_sem ge U1 st1 m1 st1' m1')
st2 mu m2
(UHyp: forall b z, U1 b z = true ->
Mem.valid_block m1 b -> vis mu b = true)
(MTCH: MATCH st1 mu st1 m1 st2 m2),
exists st2' m2' mu', exists U2 : block -> Z -> bool,
(effstep_plus rtl_eff_sem tge U2 st2 m2 st2' m2' \/
effstep_star rtl_eff_sem tge U2 st2 m2 st2' m2' /\ lt_state st1' st1)
/\ intern_incr mu mu' /\
sm_inject_separated mu mu' m1 m2 /\
sm_locally_allocated mu mu' m1 m2 m1' m2' /\
MATCH st1' mu' st1' m1' st2' m2' /\
(forall (b : block) (ofs : Z),
U2 b ofs = true ->
Mem.valid_block m2 b /\
(locBlocksTgt mu b = false ->
exists (b1 : block) (delta1 : Z),
foreign_of mu b1 = Some (b, delta1) /\
U1 b1 (ofs - delta1)%Z = true /\
Mem.perm m1 b1 (ofs - delta1) Max Nonempty)).
(** The simulation proof *)
Theorem transl_program_correct:
forall (R: list_norepet (map fst (prog_defs prog)))
entrypoints
(entry_points_ok :
forall v1 v2 sig,
In (v1, v2, sig) entrypoints ->
exists b f1 f2,
v1 = Vptr b Int.zero
/\ v2 = Vptr b Int.zero
/\ Genv.find_funct_ptr ge b = Some f1
/\ Genv.find_funct_ptr tge b = Some f2)
(init_mem: exists m0, Genv.init_mem prog = Some m0),
SM_simulation.SM_simulation_inject cminsel_eff_sem
rtl_eff_sem ge tge entrypoints.