Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

lustrec / src / backends / EMF / EMF_common.ml @ 2475c9e8

History | View | Annotate | Download (1.65 KB)

1
open LustreSpec
2
open Format
3
open Machine_code 
4

    
5
(* Matlab starting counting from 1.
6
   simple function to extract the element id in the list. Starts from 1. *)
7
let rec get_idx x l =
8
  match l with
9
  | hd::tl -> if hd = x then 1 else 1+(get_idx x tl)
10
  | [] -> assert false
11

    
12
let rec get_expr_vars v =
13
  match v.value_desc with
14
  | Cst c -> VSet.empty
15
  | LocalVar v | StateVar v -> VSet.singleton v
16
  | Fun (_, args) -> List.fold_left (fun accu v -> VSet.union accu (get_expr_vars v)) VSet.empty args
17
  | _ -> assert false (* Invalid argument *)
18

    
19
let is_imported_node f m =
20
  let (decl, _) = List.assoc f m.mcalls in
21
  Corelang.is_imported_node decl
22
    
23
(* Basic printing functions *)
24
    
25
let pp_var_string fmt v = fprintf fmt "\"%s\"" v
26
(*let pp_var_name fmt v = fprintf fmt "\"%a\"" Printers.pp_var_name v*)
27
(*let pp_node_args = fprintf_list ~sep:", " pp_var_name*)
28

    
29
let pp_emf_var_decl fmt v =
30
  fprintf fmt "@[{\"name\": \"%a\", \"type\":\"%a\"}@]"
31
    Printers.pp_var_name v
32
    Printers.pp_var_type v
33
    
34
let pp_emf_vars_decl fmt vl =
35
  fprintf fmt "@[";
36
  Utils.fprintf_list ~sep:",@ " pp_emf_var_decl fmt vl;
37
  fprintf fmt "@]"
38
  
39
let reset_name id =
40
  "reset_" ^ id
41
  
42
    
43
let pp_emf_cst_or_var fmt v =
44
  match v.value_desc with
45
  | Cst c ->
46
     fprintf fmt "{@[\"type\": \"constant\",@ \"value\": \"%a\"@ @]}"
47
       Printers.pp_const c
48
  | LocalVar v
49
  | StateVar v ->
50
     fprintf fmt "{@[\"type\": \"variable\",@ \"value\": \"%a\"@ @]}"
51
       Printers.pp_var_name v
52
  | _ -> assert false (* Invalid argument *)
53

    
54

    
55
let pp_emf_cst_or_var_list =
56
  Utils.fprintf_list ~sep:",@ " pp_emf_cst_or_var
57

    
58

    
59
(* Local Variables: *)
60
(* compile-command: "make -C ../.." *)
61
(* End: *)