Library comp

Require Export proc.
Set Implicit Arguments.
Unset Strict Implicit.

CPP 2015 submission: Section IV. Compositional semantics

Section Semworld.

Variable sw: semworld.

Let funcname := funcname sw.
Let event := event sw.
Let heap := heap sw.
Let args := args sw.
Let ret := ret sw.

Let trace := list event.
Let traceinf := Stream event.

Let behavior := behavior event (heap * ret).

CPP 2015 submission: Definition 8. Extended events, extended behaviors


Inductive xevent: Type :=
| Event (e: event)
| External (f: funcname) (a: args) (h: heap) (r: ret) (h': heap)
.
Let cbehavior := smallstep.behavior xevent (heap * ret).

Function cbehavior_of_behavior (b: behavior): cbehavior :=
  match b with
    | Terminates l (hr) => Terminates (map Event l) (hr)
    | Stuck l => Stuck _ (map Event l)
    | Diverges l => Diverges _ (map Event l)
    | Reacts f => Reacts _ (fmapinf Event f)
  end.

Definition lift_behset (b: behavior -> Prop) : cbehavior -> Prop :=
  fun beh => exists beh', beh = cbehavior_of_behavior beh' /\ b beh'.

Definition lift_sem (o: funcname -> args -> heap -> behavior -> Prop) f a h :=
  lift_behset (o f a h).

CPP 2015 submission: Definition 10. Compositional semantics


Variable lang: language sw.

Let config := config lang.
Let local := local lang.
Let frame := frame lang.

Variable m: module lang.

Let step := step m.

Transition relation
Inductive cstep : config -> list xevent -> config -> Prop :=
| cstep_step tr c c'
  (Hstep: step c tr c')
  tr' (Htr': tr' = map Event tr) :
  cstep c tr' c'
| cstep_call_external l f a (Hcmd: local_kind l = Some (Call f a))
  (Hf: ~ in_dom m f)
  h h1 fr
  (Hfr: caller_call a h l = (h1, fr))
  h2 (Hh2_le: heap_le h1 h2) r
  h' l' (Hl': caller_return r h2 fr = (h', l'))
  s:
  cstep (Config h l s) (External f a h1 r h2 :: nil) (Config h' l' s)
.

Big-step semantics
Inductive csemantics (f: funcname) (ar: args) (h: heap) : cbehavior -> Prop :=
| csemantics_intro cmd (Hcmd: lookup m f cmd)
  h' l'
  (Hinit: callee_init ar h cmd = (h', l'))
  beh
  (Hbeh: config_behaviors cstep (@config_final _ _) (Config h' l' nil) beh) :
  csemantics f ar h beh
  .

End Semworld.