(** * Soundness of the compile-time evaluator *)

(** A global environment [ge] induces a memory injection mapping
  our symbolic pointers [Vptr id ofs] to run-time pointers
  [Vptr b ofs] where [Genv.find_symbol ge id = Some b]. *)

Definition inj (b: block) :=
  match Genv.find_symbol ge b with
  | Some b' => Some (b', 0)
  | None => None
  end.

(* Specifications: *)
Lemma mem_empty_not_valid_pointer: forall b ofs, Mem.valid_pointer Mem.empty b ofs = false.
Lemma mem_empty_not_weak_valid_pointer: forall b ofs, Mem.weak_valid_pointer Mem.empty b ofs = false.
Lemma sem_cast_match: forall v1 ty1 ty2 m v2 v1' v2', sem_cast v1 ty1 ty2 m = Some v2 -> do_cast v1' ty1 ty2 = OK v2' -> Val.inject inj v1' v1 -> Val.inject inj v2' v2.
Lemma bool_val_match: forall v ty b v' m, bool_val v ty Mem.empty = Some b -> Val.inject inj v v' -> bool_val v' ty m = Some b.
Lemma constval_rvalue: forall m a v, eval_simple_rvalue empty_env m a v -> forall v', constval ge a = OK v' -> Val.inject inj v' v with constval_lvalue: forall m a b ofs, eval_simple_lvalue empty_env m a b ofs -> forall v', constval ge a = OK v' -> Val.inject inj v' (Vptr b ofs).
Lemma constval_simple: forall a v, constval ge a = OK v -> simple a.
Theorem constval_steps: forall f r m v v' ty m', star step ge (ExprState f r Kstop empty_env m) E0 (ExprState f (Eval v' ty) Kstop empty_env m') -> constval ge r = OK v -> m' = m /\ ty = typeof r /\ Val.inject inj v v'.