Skip to content
Snippets Groups Projects
soc.ml 3 KiB
Newer Older
(* Time-stamp: <modified the 21/03/2013 (at 09:55) by Erwan Jahier> *)
(** Synchronous Object Component *)

(* Just a string because :
   - it's more ocamldebug-friendly  
   - Name clashing issues ougth to have been fixed before
 *)
type ident = string

type var_type =
  | Bool | Int | Real
  | Extern of ident
  | Enum   of (ident * ident list)
  | Struct of ident * (ident * var_type) list
  | Array  of (var_type * int)
  | Alpha of int

type var = ident * var_type

    ident * 
    var_type list *  (* I/O type list *)
    (int * int * int) option (* to deal with slices (useful?) *)


(* Variable denotation *)
type var_expr =
  | Var   of var
  | Const of var (* useful? *)
  | Field of var_expr * ident * var_type
  | Index of var_expr * int * var_type

let (var_type_of_var_expr : var_expr -> var_type) =
  function
  | Var(_,vt)
  | Const(_,vt)
  | Index(_,_,vt) -> vt


type atomic_operation =
  | Assign (* Wire *)
  | Method    of instance * ident (* node step call ; the ident is the step name *)
  | Procedure of key (* memoryless method made explicit (a good idea?) *)


(* Guarded Atomic Operation *)
type gao =
  | Case of ident  (* enum var *) * (ident  (* enum value *) * gao list) list
  | Call of var_expr list * atomic_operation * var_expr list
         (* outputs       * op               * inputs *)

type step_method = {
  name    : ident;
  lxm     : Lxm.t;
(* XXX c'est laid ces histoires d'index. y'a qu'a recopier les
   variables nécessaires et puis c'est marre !!! *)
  idx_ins  : int list; (* input  index in the profile *)
  idx_outs : int list; (* output index in the profile *)
  impl    : (var list * gao list) option; (* local vars + body ; None for predef op *)
(* XXX à quoi sert cette liste de variables ??? (Parce que dans
   SocPredef, je ne sais pas trop quoi y mettre...)  *)
}

type precedence = ident * ident list   
(* Partial order over step members. Maps a step method name with
   the list of step methods that should be called _before_.
   
   nb : steps in step are already ordered ; this partial order
   can be useful to find another (better) total order w.r.t. test
   opening.
*)
  (* les memoires de l'objet sont calculées par l'interpreteur (ou l'objet C)  *)
  key      : key;
  profile  : var list * var list;
  instances : instance list;
(*   init     : step_method option; *)
  step     : step_method list; (* the order in the list is a valid w.r.t. 
                                  the partial order defined in precedences *)
  precedences : precedence list; (* partial order over step methods *)
  have_mem : (var_type * var_expr option) option; 
    (* Do this soc have a memory (pre, fby, arrow) + its type + default value *)
module SocMap = Map.Make(
  struct
    type t = key
    let compare = compare
  end
)

type tbl = t SocMap.t

let cpt = ref 0
let (make: key -> instance) = 
  fun sk -> 
    let (id,_,_) = sk in
    let instance = Printf.sprintf "%s%03d" id !cpt in
    incr cpt;
    instance,sk