Section CORRECTNESS.
Variable prog: Clight.program.
Variable tprog: Csharpminor.program.
Hypothesis TRANSL: transl_program prog = OK tprog.
Let ge : Clight.genv := Genv.globalenv prog.
Let tge : Csharpminor.genv := Genv.globalenv tprog.
Proof (Genv.find_symbol_transf_partial2 transl_fundef transl_globvar _ TRANSL).
Proof (Genv.find_funct_transf_partial2 transl_fundef transl_globvar _ TRANSL).
Proof (Genv.find_funct_ptr_transf_partial2 transl_fundef transl_globvar _ TRANSL).
Proof (Genv.find_var_info_transf_partial2 transl_fundef transl_globvar _ TRANSL).
Proof (Genv.find_var_info_rev_transf_partial2 transl_fundef transl_globvar _ TRANSL).
(*NEW: globalfunction_ptr_inject - just as in SelctionproofEFF.v*)
Definition globalfunction_ptr_inject (j:meminj):=
forall b f, Genv.find_funct_ptr ge b = Some f ->
j b = Some(b,0) /\ isGlobalBlock ge b = true.
(*From Cminorgenproof*)
Remark val_inject_function_pointer:
forall v fd j tv,
Genv.find_funct ge v = Some fd ->
globalfunction_ptr_inject j ->
val_inject j v tv ->
tv = v.
(** * Matching between environments *)
(** In this section, we define a matching relation between a Clight local environment and a Csharpminor local environment. *)
(*LENB: added parameter j - first, let's try an attempt where all offsets are 0*)
Record match_env (j:meminj) (e: Clight.env) (te: Csharpminor.env) : Prop :=
mk_match_env {
me_local:
forall id b ty,
e!id = Some (b, ty) -> exists b',
j b = Some(b',0) /\ te!id = Some(b', sizeof ty);
me_local_inv:
forall id b sz,
te!id = Some (b, sz) -> exists b' ty,
j b' = Some(b,0) /\e!id = Some(b', ty)
}.
(* Lemma match_env_same_blocks: forall j e te, match_env j e te -> blocks_of_env te = Clight.blocks_of_env e. *)
(* Lemma match_env_empty: match_env Clight.empty_env Csharpminor.empty_env. *)
(** The following lemmas establish the [match_env] invariant at the beginning of a function invocation, after allocation of local variables and initialization of the parameters. *)

Lemma match_env_alloc_variables:
forall vars e1 m1 e2 m2,
Clight.alloc_variables e1 m1 vars e2 m2 ->
forall mu te1 tm1,
match_env (restrict (as_inj mu) (vis mu)) e1 te1 ->
Mem.inject (as_inj mu) m1 tm1 ->
SM_wd mu -> sm_valid mu m1 tm1 ->
exists te2 tm2 mu',
Csharpminor.alloc_variables te1 tm1 (map transl_var vars) te2 tm2
/\ match_env (restrict (as_inj mu') (vis mu')) e2 te2 /\ Mem.inject (as_inj mu') m2 tm2
/\ intern_incr mu mu'
/\ sm_inject_separated mu mu' m1 tm1
/\ sm_locally_allocated mu mu' m1 tm1 m2 tm2
/\ SM_wd mu' /\ sm_valid mu' m2 tm2
/\ (REACH_closed m1 (vis mu) -> REACH_closed m2 (vis mu')).