Variable sp: val.
Variable e: env.
Variable m: mem.
Definition Efftransl_expr_prop
(le: letenv) (a: expr) (v: val) : Prop :=
forall j tm cs f map pr ns nd rd rs dst
(*NEW:*)(PG: meminj_preserves_globals ge j) sp' (SP: sp_preserved j sp sp')  (MWF: map_wf map) (TE: tr_expr f.(fn_code) map pr a ns nd rd dst) (ME: match_env j map e le rs) (EXT: Mem.inject j m tm), exists rs', exists tm', effstep_star rtl_eff_sem tge EmptyEffect (RTL_State cs f sp' ns rs) tm (RTL_State cs f sp' nd rs') tm' /\ match_env j map (set_optvar dst v e) le rs' /\ val_inject j v rs'#rd /\ (forall r, In r pr -> rs'#r = rs#r) /\ Mem.inject j m tm' /\ tm=tm'.  Definition Efftransl_exprlist_prop (le: letenv) (al: exprlist) (vl: list val) : Prop := forall j tm cs f map pr ns nd rl rs (*NEW:*)(PG: meminj_preserves_globals ge j) sp' (SP: sp_preserved j sp sp')  (MWF: map_wf map) (TE: tr_exprlist f.(fn_code) map pr al ns nd rl) (ME: match_env j map e le rs) (EXT: Mem.inject j m tm), exists rs', exists tm', effstep_star rtl_eff_sem tge EmptyEffect (RTL_State cs f sp' ns rs) tm (RTL_State cs f sp' nd rs') tm' /\ match_env j map e le rs' /\ val_list_inject j vl rs'##rl /\ (forall r, In r pr -> rs'#r = rs#r) /\ Mem.inject j m tm' /\ tm=tm'.  Definition Efftransl_condexpr_prop (le: letenv) (a: condexpr) (v: bool) : Prop := forall j tm cs f map pr ns ntrue nfalse rs (*NEW:*)(PG: meminj_preserves_globals ge j) sp' (SP: sp_preserved j sp sp')  (MWF: map_wf map) (TE: tr_condition f.(fn_code) map pr a ns ntrue nfalse) (ME: match_env j map e le rs) (EXT: Mem.inject j m tm), exists rs', exists tm', effstep_plus rtl_eff_sem tge EmptyEffect (RTL_State cs f sp' ns rs) tm (RTL_State cs f sp' (if v then ntrue else nfalse) rs') tm' /\ match_env j map e le rs' /\ (forall r, In r pr -> rs'#r = rs#r) /\ Mem.inject j m tm' /\ tm=tm'.  (** The correctness of the translation is a huge induction over the Cminor evaluation derivation for the source program.  To keep the proof manageable, we put each case of the proof in a separate lemma.  There is one lemma for each Cminor evaluation rule. It takes as hypotheses the premises of the Cminor evaluation rule, plus the induction hypotheses, that is, the [transl_expr_prop], etc, corresponding to the evaluations of sub-expressions or sub-statements. *)

(* Specifications: *)
Lemma Efftransl_expr_Evar_correct:
forall (le : letenv) (id : positive) (v: val),
e ! id = Some v ->
Efftransl_expr_prop le (Evar id) v.
Lemma Efftransl_expr_Eop_correct:
forall (le : letenv) (op : operation) (args : exprlist)
(vargs : list val) (v : val),
eval_exprlist ge sp e m le args vargs ->
Efftransl_exprlist_prop le args vargs ->
eval_operation ge sp op vargs m = Some v ->
Efftransl_expr_prop le (Eop op args) v.
Lemma Efftransl_expr_Eload_correct:
forall (le : letenv) (chunk : memory_chunk) (addr : Op.addressing)
(args : exprlist) (vargs : list val) (vaddr v : val),
eval_exprlist ge sp e m le args vargs ->
Efftransl_exprlist_prop le args vargs ->
Op.eval_addressing ge sp addr vargs = Some vaddr ->
Mem.loadv chunk m vaddr = Some v ->
Efftransl_expr_prop le (Eload chunk addr args) v.
Lemma Efftransl_expr_Econdition_correct:
forall (le : letenv) (a: condexpr) (ifso ifnot : expr)
(va : bool) (v : val),
eval_condexpr ge sp e m le a va ->
Efftransl_condexpr_prop le a va ->
eval_expr ge sp e m le (if va then ifso else ifnot) v ->
Efftransl_expr_prop le (if va then ifso else ifnot) v ->
Efftransl_expr_prop le (Econdition a ifso ifnot) v.
Lemma Efftransl_expr_Elet_correct:
forall (le : letenv) (a1 a2 : expr) (v1 v2 : val),
eval_expr ge sp e m le a1 v1 ->
Efftransl_expr_prop le a1 v1 ->
eval_expr ge sp e m (v1 :: le) a2 v2 ->
Efftransl_expr_prop (v1 :: le) a2 v2 ->
Efftransl_expr_prop le (Elet a1 a2) v2.
Lemma Efftransl_expr_Eletvar_correct:
forall (le : list val) (n : nat) (v : val),
nth_error le n = Some v ->
Efftransl_expr_prop le (Eletvar n) v.
(*LENB: TODO: builtin: Lemma doesn;'t quite hold -nned to extend j -> j'. But maye we won't need this case, if builtin-expressions can be eliminated from CminorSel.expressions*)
Lemma Efftransl_expr_Ebuiltin_correct:
forall le ef al vl v,
eval_exprlist ge sp e m le al vl ->
Efftransl_exprlist_prop le al vl ->
external_call ef ge vl m E0 v m ->
Efftransl_expr_prop le (Ebuiltin ef al) v.