2010-06-15 10:49:03 +02:00
|
|
|
(**************************************************************************)
|
|
|
|
(* *)
|
|
|
|
(* Heptagon *)
|
|
|
|
(* *)
|
|
|
|
(* Author : Marc Pouzet *)
|
|
|
|
(* Organization : Demons, LRI, University of Paris-Sud, Orsay *)
|
|
|
|
(* *)
|
|
|
|
(**************************************************************************)
|
|
|
|
|
|
|
|
(* The internal MiniLustre representation *)
|
|
|
|
|
|
|
|
open Location
|
|
|
|
open Names
|
2010-07-23 19:45:19 +02:00
|
|
|
open Idents
|
2010-06-15 15:08:14 +02:00
|
|
|
open Signature
|
2010-06-15 10:49:03 +02:00
|
|
|
open Static
|
2010-06-16 19:30:37 +02:00
|
|
|
open Types
|
2010-07-23 22:06:06 +02:00
|
|
|
open Clocks
|
2010-06-15 10:49:03 +02:00
|
|
|
|
2010-07-13 14:03:39 +02:00
|
|
|
(** Warning: Whenever Minils ast is modified,
|
|
|
|
minils_format_version should be incremented. *)
|
|
|
|
let minils_format_version = "1"
|
|
|
|
|
2010-06-26 16:53:25 +02:00
|
|
|
type iterator_type =
|
2010-06-15 14:05:26 +02:00
|
|
|
| Imap
|
|
|
|
| Ifold
|
2010-07-26 09:33:22 +02:00
|
|
|
| Ifoldi
|
2010-06-15 14:05:26 +02:00
|
|
|
| Imapfold
|
2010-06-15 10:49:03 +02:00
|
|
|
|
2010-07-07 15:11:32 +02:00
|
|
|
type type_dec = {
|
2010-09-09 00:35:06 +02:00
|
|
|
t_name: qualname;
|
2010-07-07 15:11:32 +02:00
|
|
|
t_desc: tdesc;
|
|
|
|
t_loc: location }
|
2010-06-15 10:49:03 +02:00
|
|
|
|
|
|
|
and tdesc =
|
|
|
|
| Type_abs
|
2010-07-26 17:41:52 +02:00
|
|
|
| Type_alias of ty
|
2010-09-09 00:35:06 +02:00
|
|
|
| Type_enum of constructor_name list
|
2010-06-15 15:08:14 +02:00
|
|
|
| Type_struct of structure
|
2010-06-15 10:49:03 +02:00
|
|
|
|
2010-07-07 15:11:32 +02:00
|
|
|
and exp = {
|
2010-11-23 17:13:33 +01:00
|
|
|
e_desc : edesc;
|
2010-07-07 15:11:32 +02:00
|
|
|
mutable e_ck: ck;
|
|
|
|
mutable e_ty: ty;
|
2010-11-23 17:13:33 +01:00
|
|
|
e_loc : location }
|
2010-06-15 10:49:03 +02:00
|
|
|
|
2010-06-16 19:30:37 +02:00
|
|
|
and edesc =
|
2010-06-30 17:20:56 +02:00
|
|
|
| Econst of static_exp
|
2010-07-07 15:11:32 +02:00
|
|
|
| Evar of var_ident
|
2010-06-30 17:20:56 +02:00
|
|
|
| Efby of static_exp option * exp
|
2010-07-01 19:35:24 +02:00
|
|
|
(** static_exp fby exp *)
|
2010-07-07 15:11:32 +02:00
|
|
|
| Eapp of app * exp list * var_ident option
|
2010-07-01 19:35:24 +02:00
|
|
|
(** app ~args=(exp,exp...) reset ~r=ident *)
|
2010-07-07 15:11:32 +02:00
|
|
|
| Ewhen of exp * constructor_name * var_ident
|
2010-07-01 19:35:24 +02:00
|
|
|
(** exp when Constructor(ident) *)
|
2010-07-07 15:11:32 +02:00
|
|
|
| Emerge of var_ident * (constructor_name * exp) list
|
2010-07-01 19:35:24 +02:00
|
|
|
(** merge ident (Constructor -> exp)+ *)
|
2010-07-07 15:11:32 +02:00
|
|
|
| Estruct of (field_name * exp) list
|
2010-07-01 19:35:24 +02:00
|
|
|
(** { field=exp; ... } *)
|
2010-07-07 15:11:32 +02:00
|
|
|
| Eiterator of iterator_type * app * static_exp * exp list * var_ident option
|
2010-09-09 00:35:06 +02:00
|
|
|
(** map f <<n>> (exp, exp...) reset ident *)
|
2010-06-30 17:20:56 +02:00
|
|
|
|
2010-07-01 19:35:24 +02:00
|
|
|
and app = { a_op: op; a_params: static_exp list; a_unsafe: bool }
|
|
|
|
(** Unsafe applications could have side effects
|
|
|
|
and be delicate about optimizations, !be careful! *)
|
2010-06-30 17:20:56 +02:00
|
|
|
|
|
|
|
and op =
|
2010-07-27 17:16:35 +02:00
|
|
|
| Eequal (** arg1 = arg2 *)
|
2010-07-01 19:35:24 +02:00
|
|
|
| Etuple (** (args) *)
|
2010-07-07 15:11:32 +02:00
|
|
|
| Efun of fun_name (** "Stateless" longname <<a_params>> (args) reset r *)
|
|
|
|
| Enode of fun_name (** "Stateful" longname <<a_params>> (args) reset r *)
|
2010-07-01 19:35:24 +02:00
|
|
|
| Eifthenelse (** if arg1 then arg2 else arg3 *)
|
2010-07-05 12:13:57 +02:00
|
|
|
| Efield (** arg1.a_param1 *)
|
|
|
|
| Efield_update (** { arg1 with a_param1 = arg2 } *)
|
2010-07-01 19:35:24 +02:00
|
|
|
| Earray (** [ args ] *)
|
2010-07-13 14:03:39 +02:00
|
|
|
| Earray_fill (** [arg1^a_param1] *)
|
2010-07-01 19:35:24 +02:00
|
|
|
| Eselect (** arg1[a_params] *)
|
|
|
|
| Eselect_slice (** arg1[a_param1..a_param2] *)
|
|
|
|
| Eselect_dyn (** arg1.[arg3...] default arg2 *)
|
2010-08-19 11:47:22 +02:00
|
|
|
| Eupdate (** [ arg1 with arg3..arg_n = arg2 ] *)
|
2010-07-01 19:35:24 +02:00
|
|
|
| Econcat (** arg1@@arg2 *)
|
2010-09-09 00:35:06 +02:00
|
|
|
|
2010-06-30 17:20:56 +02:00
|
|
|
|
2010-09-06 14:03:47 +02:00
|
|
|
type pat =
|
2010-06-15 10:49:03 +02:00
|
|
|
| Etuplepat of pat list
|
2010-07-07 15:11:32 +02:00
|
|
|
| Evarpat of var_ident
|
|
|
|
|
2010-09-06 14:03:47 +02:00
|
|
|
type eq = {
|
2010-07-07 15:11:32 +02:00
|
|
|
eq_lhs : pat;
|
|
|
|
eq_rhs : exp;
|
|
|
|
eq_loc : location }
|
|
|
|
|
2010-09-06 14:03:47 +02:00
|
|
|
type var_dec = {
|
2010-07-07 15:11:32 +02:00
|
|
|
v_ident : var_ident;
|
|
|
|
v_type : ty;
|
2010-07-15 10:02:42 +02:00
|
|
|
v_clock : ck;
|
|
|
|
v_loc : location }
|
2010-07-07 15:11:32 +02:00
|
|
|
|
|
|
|
type contract = {
|
|
|
|
c_assume : exp;
|
|
|
|
c_enforce : exp;
|
2010-12-06 18:13:15 +01:00
|
|
|
c_controllables : var_dec list;
|
2010-07-07 15:11:32 +02:00
|
|
|
c_local : var_dec list;
|
|
|
|
c_eq : eq list }
|
|
|
|
|
|
|
|
type node_dec = {
|
2010-09-09 00:35:06 +02:00
|
|
|
n_name : qualname;
|
2010-07-07 15:11:32 +02:00
|
|
|
n_input : var_dec list;
|
|
|
|
n_output : var_dec list;
|
|
|
|
n_contract : contract option;
|
2010-12-06 18:13:15 +01:00
|
|
|
(* GD: inglorious hack for controller call *)
|
|
|
|
mutable n_controller_call : var_ident list * var_ident list;
|
2010-07-07 15:11:32 +02:00
|
|
|
n_local : var_dec list;
|
|
|
|
n_equs : eq list;
|
|
|
|
n_loc : location;
|
2010-08-26 13:55:29 +02:00
|
|
|
n_params : param list;
|
|
|
|
n_params_constraints : size_constraint list }
|
2010-07-07 15:11:32 +02:00
|
|
|
|
|
|
|
type const_dec = {
|
2010-09-09 00:35:06 +02:00
|
|
|
c_name : qualname;
|
2010-07-09 11:33:17 +02:00
|
|
|
c_type : ty;
|
2010-07-07 15:11:32 +02:00
|
|
|
c_value : static_exp;
|
|
|
|
c_loc : location }
|
|
|
|
|
|
|
|
type program = {
|
2010-07-13 14:03:39 +02:00
|
|
|
p_modname : name;
|
|
|
|
p_format_version : string;
|
2010-07-07 15:11:32 +02:00
|
|
|
p_opened : name list;
|
|
|
|
p_types : type_dec list;
|
|
|
|
p_nodes : node_dec list;
|
|
|
|
p_consts : const_dec list }
|
2010-06-16 19:31:51 +02:00
|
|
|
|
2010-06-15 10:49:03 +02:00
|
|
|
(*Helper functions to build the AST*)
|
|
|
|
|
2010-11-04 18:08:40 +01:00
|
|
|
let mk_exp ?(ty = invalid_type)
|
|
|
|
?(clock = fresh_clock()) ?(loc = no_location) desc =
|
2010-09-14 17:14:27 +02:00
|
|
|
{ e_desc = desc; e_ty = ty; e_ck = clock; e_loc = loc }
|
2010-06-16 19:30:37 +02:00
|
|
|
|
2010-11-04 18:08:40 +01:00
|
|
|
let mk_var_dec ?(loc = no_location) ?(clock = fresh_clock()) ident ty =
|
2010-07-15 10:02:42 +02:00
|
|
|
{ v_ident = ident; v_type = ty; v_clock = clock; v_loc = loc }
|
2010-06-18 11:46:57 +02:00
|
|
|
|
2010-06-18 14:59:10 +02:00
|
|
|
let mk_equation ?(loc = no_location) pat exp =
|
|
|
|
{ eq_lhs = pat; eq_rhs = exp; eq_loc = loc }
|
2010-06-26 16:53:25 +02:00
|
|
|
|
2010-06-21 18:19:58 +02:00
|
|
|
let mk_node
|
2010-06-29 11:18:50 +02:00
|
|
|
?(input = []) ?(output = []) ?(contract = None) ?(local = []) ?(eq = [])
|
2010-12-08 17:32:24 +01:00
|
|
|
?(loc = no_location) ?(param = []) ?(constraints = [])
|
|
|
|
?(pinst = ([],[])) name =
|
2010-06-29 11:18:50 +02:00
|
|
|
{ n_name = name;
|
|
|
|
n_input = input;
|
|
|
|
n_output = output;
|
|
|
|
n_contract = contract;
|
2010-12-08 17:32:24 +01:00
|
|
|
n_controller_call = pinst;
|
2010-06-29 11:18:50 +02:00
|
|
|
n_local = local;
|
|
|
|
n_equs = eq;
|
|
|
|
n_loc = loc;
|
|
|
|
n_params = param;
|
2010-08-26 13:55:29 +02:00
|
|
|
n_params_constraints = constraints }
|
2010-06-21 18:19:58 +02:00
|
|
|
|
2010-08-17 15:04:16 +02:00
|
|
|
let mk_type_dec type_desc name loc =
|
2010-07-08 14:56:49 +02:00
|
|
|
{ t_name = name; t_desc = type_desc; t_loc = loc }
|
2010-06-21 18:19:58 +02:00
|
|
|
|
2010-08-17 15:04:16 +02:00
|
|
|
let mk_const_dec id ty e loc =
|
|
|
|
{ c_name = id; c_type = ty; c_value = e; c_loc = loc }
|
|
|
|
|
2010-07-08 14:56:49 +02:00
|
|
|
let mk_app ?(params=[]) ?(unsafe=false) op =
|
|
|
|
{ a_op = op; a_params = params; a_unsafe = unsafe }
|
2010-06-29 11:18:50 +02:00
|
|
|
|
2010-08-17 15:04:16 +02:00
|
|
|
(** The modname field has to be set when known, TODO LG : format_version *)
|
|
|
|
let mk_program o n t c =
|
|
|
|
{ p_modname = ""; p_format_version = "";
|
|
|
|
p_opened = o; p_nodes = n; p_types = t; p_consts = c }
|
|
|
|
|
2010-07-08 14:56:49 +02:00
|
|
|
let void = mk_exp (Eapp (mk_app Etuple, [], None))
|
2010-06-15 10:49:03 +02:00
|
|
|
|