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 e1 m1 vars e2 m2, Clight.alloc_variables e1 m1 vars e2 m2 -> forall te1, match_env e1 te1 -> exists te2, Csharpminor.alloc_variables te1 m1 (map transl_var vars) te2 m2 /\ match_env e2 te2.  Definition match_tempenv (j:meminj) (le: temp_env) (tle: Csharpminor.temp_env) := forall id v, le!id = Some v -> exists tv, val_inject j v tv /\ tle!id = Some tv.  Lemma match_tempenv_inject_incr: forall j e te (TENV : match_tempenv j e te) j' (INC: inject_incr j j'), match_tempenv j' e te.  Lemma match_tempenv_set: forall j le tle (TENV : match_tempenv j le tle) v tv (Inj : val_inject j v tv) x, match_tempenv j (PTree.set x v le) (PTree.set x tv tle).  Lemma create_undef_temps_match: forall temps, create_undef_temps (map fst temps) = Clight.create_undef_temps temps. Lemma create_undef_temps_match_inject: forall temps j, match_tempenv j (Clight.create_undef_temps temps) (create_undef_temps (map fst temps)).  Lemma bind_parameter_temps_match_inject: forall vars vals le1 le2 (BP: Clight.bind_parameter_temps vars vals le1 = Some le2) j tle1 (TENV: match_tempenv j le1 tle1) tvals (Inj: val_list_inject j vals tvals), exists tle2, bind_parameters (map fst vars) tvals tle1 = Some tle2 /\ match_tempenv j le2 tle2. (* Lemma bind_parameter_temps_match: forall vars vals le1 le2, Clight.bind_parameter_temps vars vals le1 = Some le2 -> bind_parameters (map fst vars) vals le1 = Some le2. *)
(** * Proof of semantic preservation *)
(** ** Semantic preservation for expressions *)
(** The proof of semantic preservation for the translation of expressions relies on simulation diagrams of the following form: << e, le, m, a ------------------- te, le, m, ta |                                | |                                | |                                | v                                v e, le, m, v ------------------- te, le, m, v >> Left: evaluation of r-value expression [a] in Clight. Right: evaluation of its translation [ta] in Csharpminor. Top (precondition): matching between environments [e], [te], plus well-typedness of expression [a]. Bottom (postcondition): the result values [v] are identical in both evaluations.  We state these diagrams as the following properties, parameterized by the Clight evaluation. *)

Lemma unary_op_inject: forall op v ty u
(SUO:sem_unary_operation op v ty = Some u)
j tv (V: val_inject j v tv),
val_inject j u u /\ sem_unary_operation op tv ty = Some u.