(** * Compatibility of evaluation functions with respect to memory injections. *)

Remark val_inject_val_of_bool:
  forall f b, val_inject f (Val.of_bool b) (Val.of_bool b).Remark val_inject_val_of_optbool:
  forall f ob, val_inject f (Val.of_optbool ob) (Val.of_optbool ob).Ltac TrivialExists :=
  match goal with
  | [ |- exists y, Some ?x = Some y /\ val_inject _ _ _ ] =>
      exists x; split; [auto | try(econstructor; eauto)]
  | [ |- exists y, _ /\ val_inject _ (Vint ?x) _ ] =>
      exists (Vint x); split; [eauto with evalexpr | constructor]
  | [ |- exists y, _ /\ val_inject _ (Vfloat ?x) _ ] =>
      exists (Vfloat x); split; [eauto with evalexpr | constructor]
  | [ |- exists y, _ /\ val_inject _ (Vlong ?x) _ ] =>
      exists (Vlong x); split; [eauto with evalexpr | constructor]
  | _ => idtac
  end.

(* Specifications: *)
Lemma eval_unop_compat: forall f op v1 tv1 v, eval_unop op v1 = Some v -> val_inject f v1 tv1 -> exists tv, eval_unop op tv1 = Some tv /\ val_inject f v tv.
Lemma eval_binop_compat: forall f op v1 tv1 v2 tv2 v m tm, eval_binop op v1 v2 m = Some v -> val_inject f v1 tv1 -> val_inject f v2 tv2 -> Mem.inject f m tm -> exists tv, eval_binop op tv1 tv2 tm = Some tv /\ val_inject f v tv.
Lemma make_stackaddr_correct: forall sp te tm ofs, eval_expr tge (Vptr sp Int.zero) te tm (make_stackaddr ofs) (Vptr sp (Int.repr ofs)).
Lemma make_globaladdr_correct: forall sp te tm id b, Genv.find_symbol tge id = Some b -> eval_expr tge (Vptr sp Int.zero) te tm (make_globaladdr id) (Vptr b Int.zero).
Lemma eval_unop_compat: forall f op v1 tv1 v, eval_unop op v1 = Some v -> val_inject f v1 tv1 -> exists tv, eval_unop op tv1 = Some tv /\ val_inject f v tv.
Lemma eval_binop_compat: forall f op v1 tv1 v2 tv2 v m tm, eval_binop op v1 v2 m = Some v -> val_inject f v1 tv1 -> val_inject f v2 tv2 -> Mem.inject f m tm -> exists tv, eval_binop op tv1 tv2 tm = Some tv /\ val_inject f v tv.
Lemma make_stackaddr_correct: forall sp te tm ofs, eval_expr tge (Vptr sp Int.zero) te tm (make_stackaddr ofs) (Vptr sp (Int.repr ofs)).
Lemma make_globaladdr_correct: forall sp te tm id b, Genv.find_symbol tge id = Some b -> eval_expr tge (Vptr sp Int.zero) te tm (make_globaladdr id) (Vptr b Int.zero).