Library Rustre.Dataflow.Syntax

Require Import Rustre.Common.
Require Import PArith.
Require Import Rustre.Nelist.

Import List.ListNotations.
Open Scope list_scope.

The CoreDF dataflow language

Clocks


Inductive clock : Set :=
| Cbase : clock
| Con : clockidentboolclock.
Implicit Type ck : clock.

Expressions


Inductive lexp : Set :=
  | Econst : constlexp
  | Evar : identlexp
  | Ewhen : lexpidentboollexp
  | Eop : operatornelist lexplexp.

Definition lexps := nelist lexp.

Implicit Type le: lexp.
Implicit Type les: lexps.

Control expressions


Inductive cexp : Set :=
  | Emerge : identcexpcexpcexp
  | Eexp : lexpcexp.

Implicit Type ce: cexp.

Equations


Inductive equation : Type :=
  | EqDef : identclockcexpequation
  | EqApp : identclockidentlexpsequation
  | EqFby : identclockconstlexpequation.

Implicit Type eqn: equation.

Node


Record node : Set := mk_node {
  n_name : ident;
  n_input : nelist ident;
  n_output : ident;
  n_eqs : list equation }.

Implicit Type N: node.

Program


Definition global := list node.

Implicit Type G: global.

Definition find_node (f : ident) : globaloption node :=
  List.find (fun nident_eqb n.(n_name) f).

Properties

Stronger induction scheme for lexp
Definition lexp_ind2 : P : lexpProp,
  ( c, P (Econst c)) →
  ( i, P (Evar i)) →
  ( le, P le i b, P (Ewhen le i b)) →
  ( op les, Nelist.Forall P lesP (Eop op les)) →
   le, P le.
Proof.
intros P Hconst Hvar Hwhen Hop. fix 1.
intro le.
destruct le as [c | i | le | op les].
+ apply Hconst.
+ apply Hvar.
+ apply Hwhen. apply lexp_ind2.
+ apply Hop. induction les; constructor.
  - apply lexp_ind2.
  - apply lexp_ind2.
  - apply IHles.
Defined.