(* *********************************************************************)
(*                                                                     *)
(*              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.     *)
(*                                                                     *)
(* *********************************************************************)
(** Correctness proof for Asm generation: machine-independent framework *)
Require Intv.
(** * Processor registers and register states *)
Hint Extern 2 (_ <> _) => congruence: asmgen.
Hint Resolve preg_of_data: asmgen.
Hint Resolve data_diff: asmgen.
Hint Resolve preg_of_not_SP preg_of_not_PC: asmgen.
Fixpoint preg_notin (r: preg) (rl: list mreg) : Prop :=
match rl with
| nil => True
| r1 :: nil => r <> preg_of r1
| r1 :: rl => r <> preg_of r1 /\ preg_notin r rl
end.
Remark preg_notin_charact:
forall r rl,
preg_notin r rl <-> (forall mr, In mr rl -> r <> preg_of mr).
(** * Agreement between Mach registers and processor registers *)
Record agree (ms: Mach.regset) (sp: val) (rs: Asm.regset) : Prop := mkagree {
agree_sp: rs#SP = sp;
agree_sp_def: sp <> Vundef;
agree_mregs: forall r: mreg, Val.lessdef (ms r) (rs#(preg_of r))
}.
(** Preservation of register agreement under various assignments. *)
(** Connection between Mach and Asm calling conventions for external functions. *)
(** Translation of arguments and results to builtins. *)
Remark builtin_arg_match:
forall ge (rs: regset) sp m a v,
eval_builtin_arg ge (fun r => rs (preg_of r)) sp m a v ->
eval_builtin_arg ge rs sp m (map_builtin_arg preg_of a) v.

Lemma builtin_args_match:
forall ge ms sp rs m m', agree ms sp rs -> Mem.extends m m' ->
forall al vl, eval_builtin_args ge ms sp m al vl ->
exists vl', eval_builtin_args ge rs sp m' (map (map_builtin_arg preg_of) al) vl'
/\ Val.lessdef_list vl vl'.