heptagon/compiler/minils/minils.ml

187 lines
5.5 KiB
OCaml
Raw Normal View History

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
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
(** Warning: Whenever Minils ast is modified,
minils_format_version should be incremented. *)
2011-04-18 16:09:07 +02:00
let minils_format_version = "2"
type iterator_type =
| Imap
| Imapi
| Ifold
| Ifoldi
| Imapfold
2010-06-15 10:49:03 +02:00
type type_dec = {
t_name: qualname;
t_desc: tdesc;
t_loc: location }
2010-06-15 10:49:03 +02:00
and tdesc =
| Type_abs
| Type_alias of ty
| 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
2011-04-12 14:07:05 +02:00
and extvalue = {
2011-04-14 18:06:54 +02:00
w_desc : extvalue_desc;
2011-04-12 14:07:05 +02:00
mutable w_ck: ck;
w_ty : ty;
w_loc : location }
and extvalue_desc =
2011-05-09 19:32:12 +02:00
| Wconst of static_exp (*no tuple*)
2011-04-12 14:07:05 +02:00
| Wvar of var_ident
| Wfield of extvalue * field_name
| Wwhen of extvalue * constructor_name * var_ident (** extvalue when Constructor(ident) *)
2011-04-12 14:07:05 +02:00
and exp = {
2011-05-09 19:32:12 +02:00
e_desc : edesc;
e_level_ck : ck; (*when no data dep, execute the exp on this clock (set by [switch] *)
2011-05-09 19:32:12 +02:00
mutable e_base_ck : ck;
mutable e_ct : ct;
e_ty : ty;
e_loc : location }
2010-06-15 10:49:03 +02:00
2010-06-16 19:30:37 +02:00
and edesc =
2011-04-12 14:07:05 +02:00
| Eextvalue of extvalue
| Efby of static_exp option * extvalue
(** static_exp fby extvalue *)
| Eapp of app * extvalue list * var_ident option
(** app ~args=(extvalue,extvalue...) reset ~r=ident *)
| Ewhen of exp * constructor_name * var_ident (** e when C(c) *)
2011-04-12 14:07:05 +02:00
| Emerge of var_ident * (constructor_name * extvalue) list
(** merge ident (Constructor -> extvalue)+ *)
| Estruct of (field_name * extvalue) list
(** { field=extvalue; ... } *)
| Eiterator of iterator_type * app * static_exp
* extvalue list * extvalue list * var_ident option
(** map f <<n>> <(extvalue)> (extvalue) reset ident *)
2010-06-30 17:20:56 +02:00
2011-03-09 00:02:30 +01:00
and app = { a_op: op; a_params: static_exp list; a_unsafe: bool }
2010-07-01 19:35:24 +02:00
(** Unsafe applications could have side effects
and be delicate about optimizations, !be careful! *)
2010-06-30 17:20:56 +02:00
and op =
| Eequal (** arg1 = arg2 *)
| 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 *)
| Efield_update (** { arg1 with a_param1 = arg2 } *)
2010-07-01 19:35:24 +02:00
| Earray (** [ args ] *)
| 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 *)
| Eselect_trunc (** arg1[>arg_2 ...<]*)
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-06-30 17:20:56 +02:00
type pat =
2010-06-15 10:49:03 +02:00
| Etuplepat of pat list
| Evarpat of var_ident
type eq = {
eq_lhs : pat;
eq_rhs : exp;
eq_loc : location }
type var_dec = {
v_ident : var_ident;
v_type : ty;
2010-07-15 10:02:42 +02:00
v_clock : ck;
v_loc : location }
type contract = {
2011-05-09 19:32:12 +02:00
c_assume : extvalue;
c_enforce : extvalue;
c_controllables : var_dec list;
c_local : var_dec list;
c_eq : eq list }
type node_dec = {
n_name : qualname;
2011-03-21 14:30:19 +01:00
n_stateful : bool;
n_input : var_dec list;
n_output : var_dec list;
n_contract : contract option;
n_local : var_dec list;
n_equs : eq list;
n_loc : location;
n_params : param list;
n_params_constraints : size_constraint list }
type const_dec = {
c_name : qualname;
c_type : ty;
c_value : static_exp;
c_loc : location }
type program = {
p_modname : modul;
p_format_version : string;
p_opened : modul list;
2011-04-18 19:20:03 +02:00
p_desc : program_desc list }
and program_desc =
2011-04-19 18:45:56 +02:00
| Pnode of node_dec
| Pconst of const_dec
| Ptype of type_dec
2010-06-15 10:49:03 +02:00
(*Helper functions to build the AST*)
2011-04-12 14:07:05 +02:00
let mk_extvalue ~ty ?(clock = fresh_clock()) ?(loc = no_location) desc =
{ w_desc = desc; w_ty = ty;
w_ck = clock; w_loc = loc }
2011-05-09 19:32:12 +02:00
let mk_exp level_ck ty ?(ck = Cbase) ?(ct = fresh_ct ty) ?(loc = no_location) desc =
{ e_desc = desc; e_ty = ty; e_level_ck = level_ck; e_base_ck = ck; e_ct = ct; e_loc = loc }
2010-06-16 19:30:37 +02:00
2011-05-10 21:55:53 +02:00
let mk_var_dec ?(loc = no_location) ident ty ck =
{ v_ident = ident; v_type = ty; v_clock = ck; 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 }
let mk_node
2010-06-29 11:18:50 +02:00
?(input = []) ?(output = []) ?(contract = None) ?(local = []) ?(eq = [])
2011-03-21 14:30:19 +01:00
?(stateful = true) ?(loc = no_location) ?(param = []) ?(constraints = [])
2011-04-13 15:10:15 +02:00
name =
2010-06-29 11:18:50 +02:00
{ n_name = name;
2011-03-21 14:30:19 +01:00
n_stateful = stateful;
2010-06-29 11:18:50 +02:00
n_input = input;
n_output = output;
n_contract = contract;
n_local = local;
n_equs = eq;
n_loc = loc;
n_params = param;
n_params_constraints = constraints }
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-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 }
2011-03-09 00:02:30 +01: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