(** Predictor for return addresses in generated Asm code.  The [return_address_offset] predicate defined here is used in the semantics for Mach to determine the return addresses that are stored in activation records. *)
(** Consider a Mach function [f] and a sequence [c] of Mach instructions representing the Mach code that remains to be executed after a function call returns.  The predicate [return_address_offset f c ofs] holds if [ofs] is the integer offset of the PPC instruction following the call in the Asm code obtained by translating the code of [f]. Graphically: << Mach function f    |--------- Mcall ---------| Mach code c    |                |--------| |                 \        \ |                  \        \ |                   \        \ Asm code           |                    |--------| Asm function       |------------- Pcall ---------|  <-------- ofs -------> >> *)
Definition return_address_offset (f: Mach.function) (c: Mach.code) (ofs: ptrofs) : Prop :=
forall tf tc,
transf_function f = OK tf ->
transl_code f c false = OK tc ->
code_tail (Ptrofs.unsigned ofs) (fn_code tf) tc.
(** We now show that such an offset always exists if the Mach code [c] is a suffix of [f.(fn_code)].  This holds because the translation from Mach to PPC is compositional: each Mach instruction becomes zero, one or several PPC instructions, but the order of instructions is preserved. *)

Lemma is_tail_code_tail:
forall c1 c2, is_tail c1 c2 -> exists ofs, code_tail ofs c2 c1.