package lustre-v6

  1. Overview
  2. Docs
The Lustre V6 Verimag compiler

Install

Dune Dependency

Authors

Maintainers

Sources

lustre-v6.v6.107.1.tgz
md5=4b642b106a76e19de3751afb53ccdcf4
sha512=ec6d35f0f4da219490cad7969d86e9128b7c3f03baa507f662b038b1915383581eda697ddb0e734a1a5311ef6b0908b1d0cf375a0be5dbb1aa7e9e79848037cc

doc/src/lustre-v6/astRecognizePredef.ml.html

Source file astRecognizePredef.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
(* Time-stamp: <modified the 22/08/2017 (at 14:57) by Erwan Jahier> *)


let (get_predef : Lv6Id.idref -> AstPredef.op option) =
  fun idref -> 
  let get_op () = (* XXX if a user node is named "plus", this does not work *)
      try Some (AstPredef.string_to_op (Lv6Id.to_string (Lv6Id.name_of_idref idref)))
      with Not_found -> None
    in
    match Lv6Id.pack_of_idref idref with
      | None -> None
(*         get_op () (* The Lustre package is «use»d by default *)  *)
      | Some p -> if (Lv6Id.pack_name_to_string p) = "Lustre" then get_op () else None

open AstV6
open AstCore
open Lxm

let flag f x_flg = Lxm.flagit (f x_flg.it) x_flg.src

let flag2 f x_flg = Lxm.flagit (f x_flg) x_flg.src

let fopt f = function None -> None | Some x -> Some (f x)


(* just a tedious recursive traversal of the syntax tree, replacing idref
   that match predef op with the Predef constructor *)
(* exported *)
let rec (f : AstV6.t -> AstV6.t) = function
  | PRPackBody(sl,pb) -> PRPackBody(sl, r_packbody pb)
  | PRPack_or_models(sl,pml) -> PRPack_or_models(sl,List.map r_pack_or_model pml)

and r_pack_or_model = function   
  | NSPack(pi) -> NSPack(flag r_pack_info pi)
  | NSModel(mi) -> NSModel(flag r_model_info mi)

and r_pack_info pi = { pi with pa_def = r_pack_def pi.pa_def } 

and r_model_info mi = 
  { mi with 
    mo_needs = List.map (flag r_static_param) mi.mo_needs;
    mo_provides = r_item_info_flg_list mi.mo_provides;
    mo_body = r_packbody  mi.mo_body;
  }

and r_pack_def = function
  | PackGiven(pg) -> PackGiven(r_pack_given pg)
  | PackInstance(pi) -> PackInstance(r_pack_instance pi)

and r_pack_given pg = { 
  pg with
    pg_provides = r_item_info_flg_list pg.pg_provides;
    pg_body = r_packbody pg.pg_body;
}

and r_pack_instance pi = { pi with pi_args = List.map r_by_name_static_arg pi.pi_args }

and r_static_param sp = sp 

and r_by_name_static_arg (id,arg) = 
  let arg_it = 
    match arg.it with
      | StaticArgLv6Id(idref) -> (
        match get_predef idref with
	       | None -> StaticArgLv6Id idref
	       | Some predef -> StaticArgNode (Predef_n (flagit predef arg.src))
      )
      | StaticArgConst(ve) -> StaticArgConst(r_val_exp ve)
      | StaticArgType(te) -> StaticArgType(te)
      | StaticArgNode(by_pos_op) -> StaticArgNode(r_by_pos_op (flagit by_pos_op arg.src))
  in
  id, Lxm.flagit arg_it arg.src

and r_static_arg arg = 
  match arg.it with
    | StaticArgLv6Id(idref) -> (
      match get_predef idref with
	     | None -> StaticArgLv6Id idref
	     | Some predef -> StaticArgNode (Predef_n (flagit predef arg.src))
    )
    | StaticArgConst(ve) -> StaticArgConst(r_val_exp ve)
    | StaticArgType(te) -> StaticArgType(te)
    | StaticArgNode(by_pos_op) -> StaticArgNode(r_by_pos_op (flagit by_pos_op arg.src))

and r_by_pos_op arg =
  match arg.it with
    | CALL_n { src=lxm;it=(idref,sargs) } -> (
      match get_predef idref with
	     | None -> CALL_n { src=lxm;it= r_node_exp (idref,sargs) }
	     | Some op -> assert (sargs=[]); Predef_n (flagit op arg.src)
    )
    | IDENT_n(idref) -> (
      match get_predef idref with
	     | None -> IDENT_n(idref)
	     | Some op -> Predef_n (flagit op arg.src)
    )
    | ARRAY_ACCES_n(val_exp) -> ARRAY_ACCES_n(r_val_exp val_exp)
    | ARRAY_SLICE_n(slice_info) -> ARRAY_SLICE_n(r_slice_info slice_info)

    | x -> x

and r_node_exp (idref, sargs) =
  (idref, List.map (flag2 r_static_arg) sargs)

    
and r_slice_info si = {
  si_first = r_val_exp si.si_first;
  si_last  = r_val_exp si.si_last;
  si_step  = fopt r_val_exp si.si_step;
}

and r_val_exp = function
  | CallByPos (by_pos_op, Oper vel) -> 
    CallByPos(flag2 r_by_pos_op by_pos_op, Oper (List.map r_val_exp vel))
  | CallByName(by_name_op, args) -> 
    CallByName(by_name_op, List.map (fun (id, ve) -> id, r_val_exp ve) args)
  | Merge_n (ec,cl) -> 
    let cl = List.map (fun (id,ve) ->  (id, r_val_exp ve)) cl in
    Merge_n (ec,cl) 
  | Merge_bool_n(id, t, f) -> Merge_bool_n(id, r_val_exp t, r_val_exp f) 
    
and r_item_info_flg_list = function
  | None -> None
  | Some iil -> Some (List.map (flag r_item_info) iil)

and r_item_info = function
  | ConstInfo ci -> ConstInfo(r_const_info ci)
  | TypeInfo  ti -> TypeInfo (r_type_info ti)
  | NodeInfo  ni -> NodeInfo (r_node_info ni)

and r_const_info = function
  | ExternalConst(id,te,ve_opt) -> ExternalConst(id,te, fopt r_val_exp ve_opt)
  | EnumConst(id,te) -> EnumConst(id,te)
  | DefinedConst(id,te,ve) -> DefinedConst(id,te, r_val_exp ve)

and r_type_info = function 
  | ExternalType(id) -> ExternalType(id)
  | AliasedType(id,te) -> AliasedType(id,te)
  | EnumType(id,te) -> EnumType(id,te)
  | StructType(sti) -> StructType(r_struct_type_info sti)
  | ArrayType(id,te,ve) -> ArrayType(id,te, r_val_exp ve)

and r_node_info ni = {
  ni with
    static_params = List.map (flag r_static_param) ni.static_params;
    def = r_node_def ni.def;
}
and r_struct_type_info sti =
  Hashtbl.iter 
    (fun id fi -> Hashtbl.replace sti.st_ftable id (flag r_field_info fi)) 
    sti.st_ftable;
  sti

and r_field_info fi = { fi with fd_value = fopt r_val_exp fi.fd_value }

and r_node_def = function
  | Extern -> Extern
  | Abstract -> Abstract
  | Body(node_body) -> Body(r_node_body node_body)
  | Alias(by_pos_op) -> Alias(flag2 r_by_pos_op by_pos_op)

and r_packbody pb = 
  Hashtbl.iter 
    (fun id i -> Hashtbl.replace pb.pk_const_table id (flag r_const_info i))
    pb.pk_const_table;
  Hashtbl.iter
    (fun id i -> Hashtbl.replace pb.pk_type_table id (flag r_type_info i)) 
    pb.pk_type_table;
  Hashtbl.iter 
    (fun id i -> Hashtbl.replace pb.pk_node_table id (flag r_node_info i)) 
    pb.pk_node_table;
  pb

and r_node_body nb = {
  asserts = List.map (flag r_val_exp) nb.asserts;
  eqs     = List.map (flag r_eq_info) nb.eqs;
}
and r_eq_info (lpl,ve) = (List.map r_left_part lpl, r_val_exp ve)

and r_left_part = function 
  | LeftVar(id) -> LeftVar(id)
  | LeftField(lp,id) -> LeftField(r_left_part lp,id)
  | LeftArray(lp,ve) -> LeftArray(r_left_part lp, flag r_val_exp ve)  
  | LeftSlice(lp,si) -> LeftSlice(r_left_part lp, flag r_slice_info si)
OCaml

Innovation. Community. Security.