(** * Semantic preservation *)

(** We now prove that the whole CompCert compiler (as characterized by the
  [match_prog] relation) preserves semantics by constructing
  the following simulations:
- Forward simulations from [Cstrategy] to [Asm]
  (composition of the forward simulations for each pass).
- Backward simulations for the same languages
  (derived from the forward simulation, using receptiveness of the source
  language and determinacy of [Asm]).
- Backward simulation from [Csem] to [Asm]
  (composition of two backward simulations).
*)

Remark forward_simulation_identity:
  forall sem, forward_simulation sem sem.

(* Specifications: *)
Lemma match_if_simulation: forall (A: Type) (sem: A -> semantics) (flag: unit -> bool) (transf: A -> A -> Prop) (prog tprog: A), match_if flag transf prog tprog -> (forall p tp, transf p tp -> forward_simulation (sem p) (sem tp)) -> forward_simulation (sem prog) (sem tprog).
Theorem cstrategy_semantic_preservation: forall p tp, match_prog p tp -> forward_simulation (Cstrategy.semantics p) (Asm.semantics tp) /\ backward_simulation (atomic (Cstrategy.semantics p)) (Asm.semantics tp).