(* *********************************************************************)
(*                                                                     *)
(*              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 GNU General Public License as published by  *)
(*  the Free Software Foundation, either version 2 of the License, or  *)
(*  (at your option) any later version.  This file is also distributed *)
(*  under the terms of the INRIA Non-Commercial License Agreement.     *)
(*                                                                     *)
(* *********************************************************************)
(** Tools for small-step operational semantics *)
(** This module defines generic operations and theorems over the one-step transition relations that are used to specify operational semantics in small-step style. *)
Set Implicit Arguments.
(** * Transition semantics *)
(** The general form of a transition semantics. *)
Section ExposingMemory.
Variables L1 L2: semantics.
Variable get_mem1: state L1 -> mem.
Variable get_mem2: state L2 -> mem.
(** *Equality Phases*)
Section Equality.
Record fsim_properties_eq: Type :=
{
Eqindex: Type;
Eqorder: Eqindex -> Eqindex -> Prop;
Eqmatch_states: Eqindex -> state L1 -> state L2 -> Prop;
Eqfsim_order_wf: well_founded Eqorder;
Eqfsim_match_meminj: forall i s1 s2, Eqmatch_states i s1 s2 ->  (get_mem1 s1) = (get_mem2 s2);
(*    fsim_match_initial_states: forall s1 m1 f m2, initial_state L1 (s1,m1) -> Mem.inject f m1 m2 -> exists i, exists s2, initial_state L2 (s2,m2) /\ match_states i f (s1,m1) (s2,m2);*)
Eqfsim_match_initial_states:
forall s1, initial_state L1 s1 ->
exists i s2, initial_state L2 s2 /\ Eqmatch_states i s1 s2;
Eqfsim_match_final_states:
forall i s1 s2 r ,
Eqmatch_states i s1 s2 -> final_state L1 s1 r -> (final_state L2 s2 r);
Eqfsim_simulation:
forall s1 t s1', Step L1 s1 t s1' ->
forall i s2, Eqmatch_states i s1 s2 ->
exists i', exists s2',
(Plus L2 s2 t s2' \/ (Star L2 s2 t s2' /\ Eqorder i' i))
/\ Eqmatch_states i' s1' s2';
Eqfsim_public_preserved:
forall id, Senv.public_symbol (symbolenv L2) id = Senv.public_symbol (symbolenv L1) id
}.

Lemma sim_eqSim':
forall index order (match_states:index -> state L1 -> state L2 -> Prop),
(forall i s1 s2, match_states i s1 s2 ->  (get_mem1 s1) = (get_mem2 s2)) ->
fsim_properties L1 L2 index order match_states ->
fsim_properties_eq.