(* *********************************************************************)
(*                                                                     *)
(*              The Compcert verified compiler                         *)
(*                                                                     *)
(*          Xavier Leroy, INRIA Paris-Rocquencourt                     *)
(*                                                                     *)
(*  Copyright Institut National de Recherche en Informatique et en     *)
(*  Automatique.  All rights reserved.  This file is distributed       *)
(*  under the terms of the INRIA Non-Commercial License Agreement.     *)
(*                                                                     *)
(* *********************************************************************)
(** Corollaries of the main semantic preservation theorem. *)
(** * Preservation of whole-program behaviors *)
(** From the simulation diagrams proved in file [Compiler]. it follows that whole-program observable behaviors are preserved in the following sense. First, every behavior of the generated assembly code is matched by a behavior of the source C code.  The behavior [beh] of the assembly code is either identical to the behavior [beh'] of the source C code or ``improves upon'' [beh']  by replacing a ``going wrong'' behavior with a more defined behavior. *)
(** As a corollary, if the source C code cannot go wrong, i.e. is free of undefined behaviors, the behavior of the generated assembly code is one of the possible behaviors of the source C code. *)

Theorem transf_c_program_is_refinement:
forall p tp,
transf_c_program p = OK tp ->
(forall beh, program_behaves (Csem.semantics p) beh -> not_wrong beh) ->
(forall beh, program_behaves (Asm.semantics tp) beh -> program_behaves (Csem.semantics p) beh).