Skip to content
Snippets Groups Projects
astCore.ml 5.71 KiB
Newer Older
(* Time-stamp: <modified the 29/08/2019 (at 14:41) by Erwan Jahier> *)
Erwan Jahier's avatar
Erwan Jahier committed


(** (Raw) Abstract syntax tree of source Lustre Core programs. *)
Erwan Jahier's avatar
Erwan Jahier committed

open Lxm


(**********************************************************************************)
type clock_exp =
  | NamedClock of Lv6Id.clk srcflagged
Erwan Jahier's avatar
Erwan Jahier committed
(**********************************************************************************)
(** [type_exp] is used to type flow, parameters, constants. *)
Erwan Jahier's avatar
Erwan Jahier committed
type type_exp = type_exp_core srcflagged
Erwan Jahier's avatar
Erwan Jahier committed
and
  type_exp_core =
  | Bool_type_exp
  | Int_type_exp
  | Real_type_exp
Erwan Jahier's avatar
Erwan Jahier committed
  | Array_type_exp of (type_exp * val_exp)
Erwan Jahier's avatar
Erwan Jahier committed
  static_params : static_param srcflagged list;
  vars    : node_vars option;  (* aliased node may have no i/o decl *)
  (* consts  : ICI A FAIRE *)
  loc_consts : (Lxm.t * const_info) list;
  is_safe : bool; (* safe <=> no side-effect are performed *)
Erwan Jahier's avatar
Erwan Jahier committed
and static_param =
  | StaticParamType  of Lv6Id.t
  | StaticParamConst of Lv6Id.t * type_exp
      (Lv6Id.t * var_info srcflagged list * var_info srcflagged list * has_mem_flag * is_safe_flag)
  inlist  : Lv6Id.t list;
  outlist : Lv6Id.t list;
  loclist : Lv6Id.t list option; (* abstract/ext node have no body *)
Erwan Jahier's avatar
Erwan Jahier committed
}
and var_info_table = (Lv6Id.t, var_info srcflagged) Hashtbl.t
Erwan Jahier's avatar
Erwan Jahier committed
and var_info = {
  var_type   : type_exp;
  var_clock  : clock_exp 
Erwan Jahier's avatar
Erwan Jahier committed
}
and var_nature =
  | VarInput
  | VarOutput
  | VarLocal

and node_def = 
  | Extern
  | Abstract
  | Body of node_body
  | Alias of by_pos_op srcflagged
and node_body = {
  asserts : (val_exp srcflagged) list;
  eqs     : (eq_info srcflagged) list;
}
and has_mem_flag = bool
and is_safe_flag = bool
Erwan Jahier's avatar
Erwan Jahier committed
and eq_info = (left_part list * val_exp)

Erwan Jahier's avatar
Erwan Jahier committed
and left_part = 
  | LeftVar of (Lv6Id.t srcflagged)
  | LeftField of (left_part * (Lv6Id.t srcflagged))
Erwan Jahier's avatar
Erwan Jahier committed
  | LeftArray of (left_part * (val_exp srcflagged))  
  | LeftSlice of (left_part * (slice_info srcflagged))
Erwan Jahier's avatar
Erwan Jahier committed
and slice_info = {
  si_first : val_exp ;
  si_last  : val_exp ;
  si_step  : val_exp option ;
}

Erwan Jahier's avatar
Erwan Jahier committed
(* zeroaire *)
  | Predef_n of AstPredef.op srcflagged
  | CALL_n of node_exp srcflagged (* e.g., a_node<<xx>> *)
  | IDENT_n  of Lv6Id.idref (* constant or variable *)
Erwan Jahier's avatar
Erwan Jahier committed
  | TUPLE_n
  | WITH_n of val_exp * val_exp * val_exp
Erwan Jahier's avatar
Erwan Jahier committed

  | ARRAY_SLICE_n of slice_info   
Erwan Jahier's avatar
Erwan Jahier committed

(************************************************)
(* Info associes aux expressions               *)
(************************************************)
(* Vision "fonctionnelle" des val_exp :         *)
(* Une exp. est une application d'operation :   *)
(* - avec passage par position, auquel cas les  *)
(* oprandes sont des val_exp                   *)
(* - avec passage par nom, auquel cas les       *)
(* oprandes sont des Lv6Id.t * val_exp         *)
Erwan Jahier's avatar
Erwan Jahier committed
(************************************************)
(* and val_exp = by_pos_op srcflagged * operands *)
Erwan Jahier's avatar
Erwan Jahier committed

and val_exp = 
  | CallByPos  of (by_pos_op  srcflagged  * operands) 
  | CallByName of (by_name_op srcflagged  * (Lv6Id.t srcflagged * val_exp) list)
  | Merge_n of val_exp srcflagged * (Lv6Id.idref srcflagged * val_exp) list
  | Merge_bool_n of val_exp srcflagged * val_exp * val_exp
Erwan Jahier's avatar
Erwan Jahier committed
   
and operands = Oper of val_exp list
(* Virer cet Oper ? Non, sinon ca boucle... *)
Erwan Jahier's avatar
Erwan Jahier committed

and by_name_op =
  | STRUCT_n of Lv6Id.idref
  | STRUCT_WITH_n of Lv6Id.idref * Lv6Id.idref
Erwan Jahier's avatar
Erwan Jahier committed
  | STRUCT_anonymous_n
      (* for backward compatibility with lv4 *)
Erwan Jahier's avatar
Erwan Jahier committed

Erwan Jahier's avatar
Erwan Jahier committed
and node_exp = 
      (Lv6Id.idref * (static_arg srcflagged list))
	
(** Params statiques effectifs :
    - val_exp (pour les constantes)
    - type_exp (pour les types)
    - node_exp (pour les node)
    - ident : a rsoudre, peut etre const, type ou node 
*)
Erwan Jahier's avatar
Erwan Jahier committed
and static_arg =
Erwan Jahier's avatar
Erwan Jahier committed
  | StaticArgConst of val_exp
  | StaticArgType  of type_exp
(*   | StaticArgFunc  of node_exp *)
Erwan Jahier's avatar
Erwan Jahier committed


(**********************************************************************************)

(** constant *)

and const_info = 
  | ExternalConst  of (Lv6Id.t * type_exp * val_exp option)
  | EnumConst      of (Lv6Id.t * type_exp)
  | DefinedConst   of (Lv6Id.t * type_exp option * val_exp)
Erwan Jahier's avatar
Erwan Jahier committed

(** Type *)

type field_info = {
Erwan Jahier's avatar
Erwan Jahier committed
  fd_type  : type_exp ;
  fd_value : val_exp option
}
type struct_type_info = {
  st_name    : Lv6Id.t ;
  st_flist   : Lv6Id.t list; (* field name list *)
  st_ftable  : (Lv6Id.t, field_info srcflagged)  Hashtbl.t 
Erwan Jahier's avatar
Erwan Jahier committed
}
type type_info =
  | ExternalType of (Lv6Id.t)
  | AliasedType  of (Lv6Id.t * type_exp)
  | EnumType     of (Lv6Id.t * Lv6Id.t srcflagged list)
Erwan Jahier's avatar
Erwan Jahier committed
  | StructType   of struct_type_info
  | ArrayType    of (Lv6Id.t * type_exp * val_exp)
Erwan Jahier's avatar
Erwan Jahier committed

(** Operator *)

type item_ident =
  | ConstItem of Lv6Id.t
  | TypeItem  of Lv6Id.t
  | NodeItem  of Lv6Id.t * static_param srcflagged list
Erwan Jahier's avatar
Erwan Jahier committed
      
type item_info =
    ConstInfo of const_info
  | TypeInfo  of type_info
Erwan Jahier's avatar
Erwan Jahier committed
  | NodeInfo  of node_info
Erwan Jahier's avatar
Erwan Jahier committed

(* to be used for error msgs only...*)
let rec string_of_type_exp x = 
  match x.it with
    | Bool_type_exp -> "bool"
    | Int_type_exp  -> "int"
    | Real_type_exp -> "real"
    | Named_type_exp id -> (Lv6Id.string_of_idref false id)
    | Array_type_exp (te, _sz) -> (string_of_type_exp te) ^ "^ ..."
let string_of_var_nature = function
  | VarInput -> "input"
  | VarOutput -> "output"
  | VarLocal -> "local"


let lxm_of_val_exp = function
  | CallByPos(op,_)  -> op.src
  | CallByName(op,_) -> op.src
  | Merge_n(ve,_)  -> ve.src
  | Merge_bool_n(id,_,_) -> id.src