Definition cl_halted (c: CC_core) : option val := None.
Definition empty_function : function := mkfunction Tvoid cc_default nil nil nil Sskip.
Fixpoint temp_bindings (i: positive) (vl: list val) :=
match vl with
| nil => PTree.empty val
| v::vl' => PTree.set i v (temp_bindings (i+1)%positive vl')
end.
Fixpoint params_of_types (i: positive) (l : list type) : list (ident * type) :=
match l with
| nil => nil
| t :: l => (i, t) :: params_of_types (i+1)%positive l
end.
Fixpoint typelist2list (tl: typelist) : list type :=
match tl with
| Tcons t r => t::typelist2list r
| Tnil => nil
end.
Definition params_of_fundef (f: fundef) : list type :=
match f with
| Internal {| fn_params := fn_params |} => map snd fn_params
| External _ t _ _ => typelist2list t
end.
Definition cl_initial_core (ge: genv) (v: val) (args: list val) : option CC_core :=
match v with
Vptr b i =>
if Ptrofs.eq_dec i Ptrofs.zero then
match Genv.find_funct_ptr ge b with
Some f =>
Some (CC_core_State empty_function
(Scall None
(Etempvar 1%positive (type_of_fundef f))
(map (fun x => Etempvar (fst x) (snd x))
(params_of_types 2%positive
(params_of_fundef f))))
(Kseq (Sloop Sskip Sskip) Kstop)
empty_env
(temp_bindings 1%positive (v::args)))
| _ => None end
else None
| _ => None
end.
Definition stuck_signature : signature := mksignature nil None cc_default.
Definition cl_at_external (c: CC_core) : option (external_function * list val) :=
match c with
| CC_core_Callstate (External ef _ _ _) args _ => Some (ef, args)
| CC_core_State _ (Sbuiltin _ ef _ args) _ _ _ => Some (EF_external "stuck" stuck_signature, nil)
| _ => None
end.
Definition cl_after_external (vret: option val) (c: CC_core) : option CC_core :=
match c with
| CC_core_Callstate (External ef _ _ _) _ k =>
Some (CC_core_Returnstate (match vret with Some v => v | _ => Vundef end) k)
| _ => None
end.
Definition cl_step ge (q: CC_core) (m: mem) (q': CC_core) (m': mem) : Prop :=
cl_at_external q = None /\
Clight.step ge (Clight.function_entry2 ge)
(CC_core_to_CC_state q m) Events.E0 (CC_core_to_CC_state q' m').

(* Specifications: *)
Lemma cl_corestep_not_at_external:
forall ge m q m' q',
cl_step ge q m q' m' -> cl_at_external q = None.
Lemma cl_corestep_not_halted :
forall ge m q m' q', cl_step ge q m q' m' -> cl_halted q = None.
Lemma cl_after_at_external_excl :
forall retv q q', cl_after_external retv q = Some q' -> cl_at_external q' = None.