1 |
a2d97a3e
|
ploc
|
(********************************************************************)
|
2 |
|
|
(* *)
|
3 |
|
|
(* The LustreC compiler toolset / The LustreC Development Team *)
|
4 |
|
|
(* Copyright 2012 - -- ONERA - CNRS - INPT *)
|
5 |
|
|
(* *)
|
6 |
|
|
(* LustreC is free software, distributed WITHOUT ANY WARRANTY *)
|
7 |
|
|
(* under the terms of the GNU Lesser General Public License *)
|
8 |
|
|
(* version 2.1. *)
|
9 |
|
|
(* *)
|
10 |
|
|
(********************************************************************)
|
11 |
|
|
|
12 |
cd670fe1
|
ploc
|
open Format
|
13 |
8446bf03
|
ploc
|
open Lustre_types
|
14 |
cd670fe1
|
ploc
|
open Corelang
|
15 |
089f94be
|
ploc
|
open Machine_code_types
|
16 |
2863281f
|
ploc
|
open Machine_code_common
|
17 |
cd670fe1
|
ploc
|
open C_backend_common
|
18 |
|
|
|
19 |
|
|
(********************************************************************************************)
|
20 |
|
|
(* Header Printing functions *)
|
21 |
|
|
(********************************************************************************************)
|
22 |
|
|
|
23 |
|
|
|
24 |
cefc3744
|
ploc
|
module type MODIFIERS_HDR =
|
25 |
|
|
sig
|
26 |
2863281f
|
ploc
|
val print_machine_decl_prefix: Format.formatter -> machine_t -> unit
|
27 |
cefc3744
|
ploc
|
end
|
28 |
|
|
|
29 |
|
|
module EmptyMod =
|
30 |
|
|
struct
|
31 |
ca7e8027
|
Lélio Brun
|
let print_machine_decl_prefix = fun _ _ -> ()
|
32 |
cefc3744
|
ploc
|
end
|
33 |
|
|
|
34 |
|
|
module Main = functor (Mod: MODIFIERS_HDR) ->
|
35 |
|
|
struct
|
36 |
|
|
|
37 |
cd670fe1
|
ploc
|
let print_import_standard fmt =
|
38 |
04a63d25
|
xthirioux
|
begin
|
39 |
66359a5e
|
ploc
|
(* if Machine_types.has_machine_type () then *)
|
40 |
|
|
(* begin *)
|
41 |
|
|
fprintf fmt "#include <stdint.h>@.";
|
42 |
|
|
(* end; *)
|
43 |
04a63d25
|
xthirioux
|
if !Options.mpfr then
|
44 |
|
|
begin
|
45 |
|
|
fprintf fmt "#include <mpfr.h>@."
|
46 |
|
|
end;
|
47 |
66359a5e
|
ploc
|
if !Options.cpp then
|
48 |
719ae9fd
|
Lélio Brun
|
fprintf fmt "#include \"%s/arrow.hpp\"@.@." (Arrow.arrow_top_decl ()).top_decl_owner
|
49 |
66359a5e
|
ploc
|
else
|
50 |
719ae9fd
|
Lélio Brun
|
fprintf fmt "#include \"%s/arrow.h\"@.@." (Arrow.arrow_top_decl ()).top_decl_owner
|
51 |
66359a5e
|
ploc
|
|
52 |
04a63d25
|
xthirioux
|
end
|
53 |
cd670fe1
|
ploc
|
|
54 |
ec433d69
|
xthirioux
|
let rec print_static_val pp_var fmt v =
|
55 |
04a63d25
|
xthirioux
|
match v.value_desc with
|
56 |
ec433d69
|
xthirioux
|
| Cst c -> pp_c_const fmt c
|
57 |
c35de73b
|
ploc
|
| Var v -> pp_var fmt v
|
58 |
5318ad88
|
xthirioux
|
| Fun (n, vl) -> pp_basic_lib_fun (Types.is_int_type v.value_type) n (print_static_val pp_var) fmt vl
|
59 |
ec433d69
|
xthirioux
|
| _ -> (Format.eprintf "Internal error: C_backend_header.print_static_val"; assert false)
|
60 |
|
|
|
61 |
14c56a07
|
xthirioux
|
let print_constant_decl (m, attr, inst) pp_var fmt v =
|
62 |
|
|
Format.fprintf fmt "%s %a = %a"
|
63 |
|
|
attr
|
64 |
|
|
(pp_c_type (Format.sprintf "%s ## %s" inst v.var_id)) v.var_type
|
65 |
2863281f
|
ploc
|
(print_static_val pp_var) (get_const_assign m v)
|
66 |
ec433d69
|
xthirioux
|
|
67 |
14c56a07
|
xthirioux
|
let print_static_constant_decl (m, attr, inst) fmt const_locals =
|
68 |
ec433d69
|
xthirioux
|
let pp_var fmt v =
|
69 |
|
|
if List.mem v const_locals
|
70 |
|
|
then
|
71 |
|
|
Format.fprintf fmt "%s ## %s" inst v.var_id
|
72 |
|
|
else
|
73 |
|
|
Format.fprintf fmt "%s" v.var_id in
|
74 |
|
|
Format.fprintf fmt "%a%t"
|
75 |
14c56a07
|
xthirioux
|
(Utils.fprintf_list ~sep:";\\@," (print_constant_decl (m, attr, inst) pp_var)) const_locals
|
76 |
ec433d69
|
xthirioux
|
(Utils.pp_final_char_if_non_empty ";\\@," const_locals)
|
77 |
|
|
|
78 |
|
|
let print_static_declare_instance (m, attr, inst) const_locals fmt (i, (n, static)) =
|
79 |
|
|
let pp_var fmt v =
|
80 |
|
|
if List.mem v const_locals
|
81 |
|
|
then
|
82 |
|
|
Format.fprintf fmt "%s ## %s" inst v.var_id
|
83 |
|
|
else
|
84 |
|
|
Format.fprintf fmt "%s" v.var_id in
|
85 |
2863281f
|
ploc
|
let values = List.map (value_of_dimension m) static in
|
86 |
cd670fe1
|
ploc
|
fprintf fmt "%a(%s, %a%t%s)"
|
87 |
ec433d69
|
xthirioux
|
pp_machine_static_declare_name (node_name n)
|
88 |
cd670fe1
|
ploc
|
attr
|
89 |
ec433d69
|
xthirioux
|
(Utils.fprintf_list ~sep:", " (print_static_val pp_var)) values
|
90 |
cd670fe1
|
ploc
|
(Utils.pp_final_char_if_non_empty ", " static)
|
91 |
|
|
i
|
92 |
|
|
|
93 |
ec433d69
|
xthirioux
|
let print_static_declare_macro fmt (m, attr, inst) =
|
94 |
|
|
let const_locals = List.filter (fun vdecl -> vdecl.var_dec_const) m.mstep.step_locals in
|
95 |
cd670fe1
|
ploc
|
let array_mem = List.filter (fun v -> Types.is_array_type v.var_type) m.mmemory in
|
96 |
ec433d69
|
xthirioux
|
fprintf fmt "@[<v 2>#define %a(%s, %a%t%s)\\@,%a%s %a %s;\\@,%a%t%a;@,@]"
|
97 |
cd670fe1
|
ploc
|
pp_machine_static_declare_name m.mname.node_id
|
98 |
|
|
attr
|
99 |
|
|
(Utils.fprintf_list ~sep:", " (pp_c_var_read m)) m.mstatic
|
100 |
|
|
(Utils.pp_final_char_if_non_empty ", " m.mstatic)
|
101 |
|
|
inst
|
102 |
ec433d69
|
xthirioux
|
(* constants *)
|
103 |
14c56a07
|
xthirioux
|
(print_static_constant_decl (m, attr, inst)) const_locals
|
104 |
cd670fe1
|
ploc
|
attr
|
105 |
|
|
pp_machine_memtype_name m.mname.node_id
|
106 |
|
|
inst
|
107 |
ec433d69
|
xthirioux
|
(Utils.fprintf_list ~sep:";\\@," (pp_c_decl_local_var m)) array_mem
|
108 |
cd670fe1
|
ploc
|
(Utils.pp_final_char_if_non_empty ";\\@," array_mem)
|
109 |
|
|
(Utils.fprintf_list ~sep:";\\@,"
|
110 |
|
|
(fun fmt (i',m') ->
|
111 |
ec433d69
|
xthirioux
|
let path = sprintf "%s ## _%s" inst i' in
|
112 |
cd670fe1
|
ploc
|
fprintf fmt "%a"
|
113 |
ec433d69
|
xthirioux
|
(print_static_declare_instance (m, attr, inst) const_locals) (path, m')
|
114 |
cd670fe1
|
ploc
|
)) m.minstances
|
115 |
|
|
|
116 |
|
|
|
117 |
|
|
let print_static_link_instance fmt (i, (m, _)) =
|
118 |
|
|
fprintf fmt "%a(%s)" pp_machine_static_link_name (node_name m) i
|
119 |
|
|
|
120 |
|
|
(* Allocation of a node struct:
|
121 |
|
|
- if node memory is an array/matrix/etc, we cast it to a pointer (see pp_registers_struct)
|
122 |
|
|
*)
|
123 |
ca7e8027
|
Lélio Brun
|
let print_static_link_macro fmt (m, _, inst) =
|
124 |
cd670fe1
|
ploc
|
let array_mem = List.filter (fun v -> Types.is_array_type v.var_type) m.mmemory in
|
125 |
ec433d69
|
xthirioux
|
fprintf fmt "@[<v>@[<v 2>#define %a(%s) do {\\@,%a%t%a;\\@]@,} while (0)@.@]"
|
126 |
cd670fe1
|
ploc
|
pp_machine_static_link_name m.mname.node_id
|
127 |
ec433d69
|
xthirioux
|
inst
|
128 |
cd670fe1
|
ploc
|
(Utils.fprintf_list ~sep:";\\@,"
|
129 |
|
|
(fun fmt v ->
|
130 |
ec433d69
|
xthirioux
|
fprintf fmt "%s._reg.%s = (%a*) &%s"
|
131 |
|
|
inst
|
132 |
cd670fe1
|
ploc
|
v.var_id
|
133 |
|
|
(fun fmt v -> pp_c_type "" fmt (Types.array_base_type v.var_type)) v
|
134 |
|
|
v.var_id
|
135 |
|
|
)) array_mem
|
136 |
|
|
(Utils.pp_final_char_if_non_empty ";\\@," array_mem)
|
137 |
|
|
(Utils.fprintf_list ~sep:";\\@,"
|
138 |
|
|
(fun fmt (i',m') ->
|
139 |
ec433d69
|
xthirioux
|
let path = sprintf "%s ## _%s" inst i' in
|
140 |
|
|
fprintf fmt "%a;\\@,%s.%s = &%s"
|
141 |
cd670fe1
|
ploc
|
print_static_link_instance (path,m')
|
142 |
ec433d69
|
xthirioux
|
inst
|
143 |
cd670fe1
|
ploc
|
i'
|
144 |
|
|
path
|
145 |
|
|
)) m.minstances
|
146 |
ec433d69
|
xthirioux
|
|
147 |
|
|
let print_static_alloc_macro fmt (m, attr, inst) =
|
148 |
|
|
fprintf fmt "@[<v>@[<v 2>#define %a(%s, %a%t%s)\\@,%a(%s, %a%t%s);\\@,%a(%s);@]@,@]@."
|
149 |
cd670fe1
|
ploc
|
pp_machine_static_alloc_name m.mname.node_id
|
150 |
ec433d69
|
xthirioux
|
attr
|
151 |
cd670fe1
|
ploc
|
(Utils.fprintf_list ~sep:", " (pp_c_var_read m)) m.mstatic
|
152 |
|
|
(Utils.pp_final_char_if_non_empty ", " m.mstatic)
|
153 |
ec433d69
|
xthirioux
|
inst
|
154 |
cd670fe1
|
ploc
|
pp_machine_static_declare_name m.mname.node_id
|
155 |
ec433d69
|
xthirioux
|
attr
|
156 |
cd670fe1
|
ploc
|
(Utils.fprintf_list ~sep:", " (pp_c_var_read m)) m.mstatic
|
157 |
|
|
(Utils.pp_final_char_if_non_empty ", " m.mstatic)
|
158 |
ec433d69
|
xthirioux
|
inst
|
159 |
cd670fe1
|
ploc
|
pp_machine_static_link_name m.mname.node_id
|
160 |
ec433d69
|
xthirioux
|
inst
|
161 |
cd670fe1
|
ploc
|
|
162 |
71999483
|
ploc
|
(* TODO: ACSL
|
163 |
|
|
we do multiple things:
|
164 |
|
|
- provide the semantics of the node as a predicate: function step and reset are associated to ACSL predicate
|
165 |
|
|
- the node is associated to a refinement contract, wrt its ACSL sem
|
166 |
|
|
- if the node is a regular node associated to a contract, print the contract as function contract.
|
167 |
|
|
- do not print anything if this is a contract node
|
168 |
|
|
*)
|
169 |
ca7e8027
|
Lélio Brun
|
let print_machine_alloc_decl fmt m =
|
170 |
ef34b4ae
|
xthirioux
|
Mod.print_machine_decl_prefix fmt m;
|
171 |
2863281f
|
ploc
|
if fst (get_stateless_status m) then
|
172 |
ef34b4ae
|
xthirioux
|
begin
|
173 |
|
|
end
|
174 |
|
|
else
|
175 |
|
|
begin
|
176 |
|
|
if !Options.static_mem
|
177 |
|
|
then
|
178 |
|
|
begin
|
179 |
|
|
(* Static allocation *)
|
180 |
ec433d69
|
xthirioux
|
let inst = mk_instance m in
|
181 |
|
|
let attr = mk_attribute m in
|
182 |
ef34b4ae
|
xthirioux
|
fprintf fmt "%a@.%a@.%a@."
|
183 |
ec433d69
|
xthirioux
|
print_static_declare_macro (m, attr, inst)
|
184 |
|
|
print_static_link_macro (m, attr, inst)
|
185 |
|
|
print_static_alloc_macro (m, attr, inst)
|
186 |
ef34b4ae
|
xthirioux
|
end
|
187 |
|
|
else
|
188 |
|
|
begin
|
189 |
|
|
(* Dynamic allocation *)
|
190 |
80f93e0a
|
xavier.thirioux
|
fprintf fmt "extern %a;@.@."
|
191 |
|
|
print_alloc_prototype (m.mname.node_id, m.mstatic);
|
192 |
|
|
|
193 |
|
|
fprintf fmt "extern %a;@.@."
|
194 |
|
|
print_dealloc_prototype m.mname.node_id
|
195 |
ef34b4ae
|
xthirioux
|
end
|
196 |
|
|
end
|
197 |
|
|
|
198 |
|
|
let print_machine_decl_from_header fmt inode =
|
199 |
|
|
(*Mod.print_machine_decl_prefix fmt m;*)
|
200 |
1e48ef45
|
ploc
|
if inode.nodei_prototype = Some "C" then
|
201 |
|
|
if inode.nodei_stateless then
|
202 |
|
|
begin
|
203 |
|
|
fprintf fmt "extern %a;@.@."
|
204 |
|
|
print_stateless_C_prototype
|
205 |
|
|
(inode.nodei_id, inode.nodei_inputs, inode.nodei_outputs)
|
206 |
|
|
end
|
207 |
04a63d25
|
xthirioux
|
else (Format.eprintf "internal error: print_machine_decl_from_header"; assert false)
|
208 |
ef34b4ae
|
xthirioux
|
else
|
209 |
1e48ef45
|
ploc
|
if inode.nodei_stateless then
|
210 |
ef34b4ae
|
xthirioux
|
begin
|
211 |
|
|
fprintf fmt "extern %a;@.@."
|
212 |
1e48ef45
|
ploc
|
print_stateless_prototype
|
213 |
ef34b4ae
|
xthirioux
|
(inode.nodei_id, inode.nodei_inputs, inode.nodei_outputs)
|
214 |
|
|
end
|
215 |
1e48ef45
|
ploc
|
else
|
216 |
|
|
begin
|
217 |
|
|
let static_inputs = List.filter (fun v -> v.var_dec_const) inode.nodei_inputs in
|
218 |
|
|
let used name =
|
219 |
|
|
(List.exists (fun v -> v.var_id = name) inode.nodei_inputs)
|
220 |
|
|
|| (List.exists (fun v -> v.var_id = name) inode.nodei_outputs) in
|
221 |
|
|
let self = mk_new_name used "self" in
|
222 |
|
|
fprintf fmt "extern %a;@.@."
|
223 |
|
|
(print_reset_prototype self) (inode.nodei_id, static_inputs);
|
224 |
04a63d25
|
xthirioux
|
|
225 |
|
|
fprintf fmt "extern %a;@.@."
|
226 |
|
|
(print_init_prototype self) (inode.nodei_id, static_inputs);
|
227 |
|
|
|
228 |
|
|
fprintf fmt "extern %a;@.@."
|
229 |
|
|
(print_clear_prototype self) (inode.nodei_id, static_inputs);
|
230 |
|
|
|
231 |
1e48ef45
|
ploc
|
fprintf fmt "extern %a;@.@."
|
232 |
|
|
(print_step_prototype self)
|
233 |
|
|
(inode.nodei_id, inode.nodei_inputs, inode.nodei_outputs)
|
234 |
|
|
end
|
235 |
ef34b4ae
|
xthirioux
|
|
236 |
cd670fe1
|
ploc
|
let print_const_decl fmt cdecl =
|
237 |
04a63d25
|
xthirioux
|
if !Options.mpfr && Types.is_real_type (Types.array_base_type cdecl.const_type)
|
238 |
|
|
then
|
239 |
|
|
fprintf fmt "extern %a;@."
|
240 |
|
|
(pp_c_type cdecl.const_id) (Types.dynamic_type cdecl.const_type)
|
241 |
|
|
else
|
242 |
|
|
fprintf fmt "extern %a;@."
|
243 |
|
|
(pp_c_type cdecl.const_id) cdecl.const_type
|
244 |
cd670fe1
|
ploc
|
|
245 |
|
|
let rec pp_c_struct_type_field filename cpt fmt (label, tdesc) =
|
246 |
13aec2da
|
ploc
|
fprintf fmt "%a;" (pp_c_type_decl filename cpt label) tdesc
|
247 |
cd670fe1
|
ploc
|
and pp_c_type_decl filename cpt var fmt tdecl =
|
248 |
|
|
match tdecl with
|
249 |
|
|
| Tydec_any -> assert false
|
250 |
|
|
| Tydec_int -> fprintf fmt "int %s" var
|
251 |
04a63d25
|
xthirioux
|
| Tydec_real when !Options.mpfr
|
252 |
|
|
-> fprintf fmt "%s %s" Mpfr.mpfr_t var
|
253 |
cd670fe1
|
ploc
|
| Tydec_real -> fprintf fmt "double %s" var
|
254 |
04a63d25
|
xthirioux
|
(* | Tydec_float -> fprintf fmt "float %s" var *)
|
255 |
cd670fe1
|
ploc
|
| Tydec_bool -> fprintf fmt "_Bool %s" var
|
256 |
|
|
| Tydec_clock ty -> pp_c_type_decl filename cpt var fmt ty
|
257 |
|
|
| Tydec_const c -> fprintf fmt "%s %s" c var
|
258 |
|
|
| Tydec_array (d, ty) -> fprintf fmt "%a[%a]" (pp_c_type_decl filename cpt var) ty pp_c_dimension d
|
259 |
|
|
| Tydec_enum tl ->
|
260 |
|
|
begin
|
261 |
|
|
incr cpt;
|
262 |
13aec2da
|
ploc
|
fprintf fmt "enum _enum_%s_%d { %a } %s" (protect_filename filename) !cpt (Utils.fprintf_list ~sep:", " pp_print_string) tl var
|
263 |
cd670fe1
|
ploc
|
end
|
264 |
|
|
| Tydec_struct fl ->
|
265 |
|
|
begin
|
266 |
|
|
incr cpt;
|
267 |
13aec2da
|
ploc
|
fprintf fmt "struct _struct_%s_%d { %a } %s" (protect_filename filename) !cpt (Utils.fprintf_list ~sep:" " (pp_c_struct_type_field filename cpt)) fl var
|
268 |
cd670fe1
|
ploc
|
end
|
269 |
|
|
|
270 |
|
|
let print_type_definitions fmt filename =
|
271 |
|
|
let cpt_type = ref 0 in
|
272 |
ef34b4ae
|
xthirioux
|
Hashtbl.iter (fun typ decl ->
|
273 |
|
|
match typ with
|
274 |
|
|
| Tydec_const var ->
|
275 |
|
|
(match decl.top_decl_desc with
|
276 |
|
|
| TypeDef tdef ->
|
277 |
|
|
fprintf fmt "typedef %a;@.@."
|
278 |
|
|
(pp_c_type_decl filename cpt_type var) tdef.tydef_desc
|
279 |
|
|
| _ -> assert false)
|
280 |
|
|
| _ -> ()) type_table
|
281 |
|
|
|
282 |
|
|
let reset_type_definitions, print_type_definition_from_header =
|
283 |
57c96fb7
|
Lélio Brun
|
let cpt_type = ref 0 in
|
284 |
|
|
(fun () -> cpt_type := 0),
|
285 |
|
|
(fun fmt typ filename ->
|
286 |
|
|
fprintf fmt "typedef %a;@.@."
|
287 |
|
|
(pp_c_type_decl filename cpt_type typ.tydef_id) typ.tydef_desc)
|
288 |
cd670fe1
|
ploc
|
|
289 |
|
|
(********************************************************************************************)
|
290 |
|
|
(* MAIN Header Printing functions *)
|
291 |
|
|
(********************************************************************************************)
|
292 |
71999483
|
ploc
|
(* Seems not used
|
293 |
|
|
|
294 |
ef34b4ae
|
xthirioux
|
let print_header header_fmt basename prog machines dependencies =
|
295 |
cd670fe1
|
ploc
|
(* Include once: start *)
|
296 |
04a63d25
|
xthirioux
|
let baseNAME = file_to_module_name basename in
|
297 |
ef34b4ae
|
xthirioux
|
begin
|
298 |
04a63d25
|
xthirioux
|
(* Print the version number and the supported C standard (C90 or C99) *)
|
299 |
ef34b4ae
|
xthirioux
|
print_version header_fmt;
|
300 |
|
|
fprintf header_fmt "#ifndef _%s@.#define _%s@." baseNAME baseNAME;
|
301 |
|
|
pp_print_newline header_fmt ();
|
302 |
|
|
fprintf header_fmt "/* Imports standard library */@.";
|
303 |
|
|
(* imports standard library definitions (arrow) *)
|
304 |
|
|
print_import_standard header_fmt;
|
305 |
|
|
pp_print_newline header_fmt ();
|
306 |
|
|
(* imports dependencies *)
|
307 |
04a63d25
|
xthirioux
|
fprintf header_fmt "/* Import dependencies */@.";
|
308 |
ef34b4ae
|
xthirioux
|
fprintf header_fmt "@[<v>";
|
309 |
|
|
List.iter (print_import_prototype header_fmt) dependencies;
|
310 |
|
|
fprintf header_fmt "@]@.";
|
311 |
|
|
fprintf header_fmt "/* Types definitions */@.";
|
312 |
|
|
(* Print the type definitions from the type table *)
|
313 |
|
|
print_type_definitions header_fmt basename;
|
314 |
|
|
pp_print_newline header_fmt ();
|
315 |
|
|
(* Print the global constant declarations. *)
|
316 |
|
|
fprintf header_fmt "/* Global constant (declarations, definitions are in C file) */@.";
|
317 |
|
|
List.iter (fun c -> print_const_decl header_fmt (const_of_top c)) (get_consts prog);
|
318 |
|
|
pp_print_newline header_fmt ();
|
319 |
04a63d25
|
xthirioux
|
if !Options.mpfr then
|
320 |
|
|
begin
|
321 |
|
|
fprintf header_fmt "/* Global initialization declaration */@.";
|
322 |
|
|
fprintf header_fmt "extern %a;@.@."
|
323 |
|
|
print_global_init_prototype baseNAME;
|
324 |
|
|
|
325 |
|
|
fprintf header_fmt "/* Global clear declaration */@.";
|
326 |
|
|
fprintf header_fmt "extern %a;@.@."
|
327 |
|
|
print_global_clear_prototype baseNAME;
|
328 |
|
|
end;
|
329 |
ef34b4ae
|
xthirioux
|
(* Print the struct declarations of all machines. *)
|
330 |
04a63d25
|
xthirioux
|
fprintf header_fmt "/* Structs declarations */@.";
|
331 |
71999483
|
ploc
|
List.iter (print_machine_struct machines header_fmt) machines;
|
332 |
ef34b4ae
|
xthirioux
|
pp_print_newline header_fmt ();
|
333 |
|
|
(* Print the prototypes of all machines *)
|
334 |
|
|
fprintf header_fmt "/* Nodes declarations */@.";
|
335 |
|
|
List.iter (print_machine_decl header_fmt) machines;
|
336 |
|
|
pp_print_newline header_fmt ();
|
337 |
|
|
(* Include once: end *)
|
338 |
|
|
fprintf header_fmt "#endif@.";
|
339 |
|
|
pp_print_newline header_fmt ()
|
340 |
|
|
end
|
341 |
71999483
|
ploc
|
*)
|
342 |
ca7e8027
|
Lélio Brun
|
let print_alloc_header header_fmt basename _prog machines dependencies spec =
|
343 |
ef34b4ae
|
xthirioux
|
(* Include once: start *)
|
344 |
04a63d25
|
xthirioux
|
let baseNAME = file_to_module_name basename in
|
345 |
ef34b4ae
|
xthirioux
|
begin
|
346 |
|
|
(* Print the svn version number and the supported C standard (C90 or C99) *)
|
347 |
|
|
print_version header_fmt;
|
348 |
|
|
fprintf header_fmt "#ifndef _%s_alloc@.#define _%s_alloc@." baseNAME baseNAME;
|
349 |
|
|
pp_print_newline header_fmt ();
|
350 |
|
|
(* Import the header *)
|
351 |
|
|
fprintf header_fmt "/* Import header from %s */@." basename;
|
352 |
|
|
fprintf header_fmt "@[<v>";
|
353 |
5fccce23
|
ploc
|
print_import_prototype header_fmt {local=true; name=basename; content=[]; is_stateful=true} (* assuming it is staful *);
|
354 |
ef34b4ae
|
xthirioux
|
fprintf header_fmt "@]@.";
|
355 |
|
|
fprintf header_fmt "/* Import dependencies */@.";
|
356 |
|
|
fprintf header_fmt "@[<v>";
|
357 |
|
|
List.iter (print_import_alloc_prototype header_fmt) dependencies;
|
358 |
|
|
fprintf header_fmt "@]@.";
|
359 |
|
|
(* Print the struct definitions of all machines. *)
|
360 |
|
|
fprintf header_fmt "/* Struct definitions */@.";
|
361 |
ca7e8027
|
Lélio Brun
|
List.iter (print_machine_struct header_fmt) machines;
|
362 |
ef34b4ae
|
xthirioux
|
pp_print_newline header_fmt ();
|
363 |
71999483
|
ploc
|
fprintf header_fmt "/* Specification */@.%a@." C_backend_spec.pp_acsl_preamble spec;
|
364 |
ef34b4ae
|
xthirioux
|
(* Print the prototypes of all machines *)
|
365 |
|
|
fprintf header_fmt "/* Node allocation function/macro prototypes */@.";
|
366 |
ca7e8027
|
Lélio Brun
|
List.iter (print_machine_alloc_decl header_fmt) machines;
|
367 |
ef34b4ae
|
xthirioux
|
pp_print_newline header_fmt ();
|
368 |
|
|
(* Include once: end *)
|
369 |
|
|
fprintf header_fmt "#endif@.";
|
370 |
|
|
pp_print_newline header_fmt ()
|
371 |
|
|
end
|
372 |
cd670fe1
|
ploc
|
|
373 |
1e48ef45
|
ploc
|
(* Function called when compiling a lusi file and generating the associated C
|
374 |
|
|
header. *)
|
375 |
ef34b4ae
|
xthirioux
|
let print_header_from_header header_fmt basename header =
|
376 |
|
|
(* Include once: start *)
|
377 |
04a63d25
|
xthirioux
|
let baseNAME = file_to_module_name basename in
|
378 |
ef34b4ae
|
xthirioux
|
let types = get_typedefs header in
|
379 |
|
|
let consts = get_consts header in
|
380 |
|
|
let nodes = get_imported_nodes header in
|
381 |
|
|
let dependencies = get_dependencies header in
|
382 |
|
|
begin
|
383 |
04a63d25
|
xthirioux
|
(* Print the version number and the supported C standard (C90 or C99) *)
|
384 |
ef34b4ae
|
xthirioux
|
print_version header_fmt;
|
385 |
|
|
fprintf header_fmt "#ifndef _%s@.#define _%s@." baseNAME baseNAME;
|
386 |
|
|
pp_print_newline header_fmt ();
|
387 |
|
|
fprintf header_fmt "/* Imports standard library */@.";
|
388 |
|
|
(* imports standard library definitions (arrow) *)
|
389 |
|
|
print_import_standard header_fmt;
|
390 |
|
|
pp_print_newline header_fmt ();
|
391 |
|
|
(* imports dependencies *)
|
392 |
|
|
fprintf header_fmt "/* Import dependencies */@.";
|
393 |
|
|
fprintf header_fmt "@[<v>";
|
394 |
|
|
List.iter
|
395 |
58a463e7
|
ploc
|
(fun dep ->
|
396 |
|
|
let (local, s) = dependency_of_top dep in
|
397 |
5fccce23
|
ploc
|
print_import_prototype header_fmt {local=local; name=s; content=[]; is_stateful=true} (* assuming it is stateful *))
|
398 |
ef34b4ae
|
xthirioux
|
dependencies;
|
399 |
|
|
fprintf header_fmt "@]@.";
|
400 |
|
|
fprintf header_fmt "/* Types definitions */@.";
|
401 |
|
|
(* Print the type definitions from the type table *)
|
402 |
|
|
reset_type_definitions ();
|
403 |
|
|
List.iter (fun typ -> print_type_definition_from_header header_fmt (typedef_of_top typ) basename) types;
|
404 |
|
|
pp_print_newline header_fmt ();
|
405 |
|
|
(* Print the global constant declarations. *)
|
406 |
|
|
fprintf header_fmt "/* Global constant (declarations, definitions are in C file) */@.";
|
407 |
|
|
List.iter (fun c -> print_const_decl header_fmt (const_of_top c)) consts;
|
408 |
|
|
pp_print_newline header_fmt ();
|
409 |
04a63d25
|
xthirioux
|
if !Options.mpfr then
|
410 |
|
|
begin
|
411 |
|
|
fprintf header_fmt "/* Global initialization declaration */@.";
|
412 |
|
|
fprintf header_fmt "extern %a;@.@."
|
413 |
|
|
print_global_init_prototype baseNAME;
|
414 |
|
|
|
415 |
|
|
fprintf header_fmt "/* Global clear declaration */@.";
|
416 |
|
|
fprintf header_fmt "extern %a;@.@."
|
417 |
|
|
print_global_clear_prototype baseNAME;
|
418 |
|
|
end;
|
419 |
ef34b4ae
|
xthirioux
|
(* Print the struct declarations of all machines. *)
|
420 |
04a63d25
|
xthirioux
|
fprintf header_fmt "/* Structs declarations */@.";
|
421 |
ef34b4ae
|
xthirioux
|
List.iter (fun node -> print_machine_struct_from_header header_fmt (imported_node_of_top node)) nodes;
|
422 |
|
|
pp_print_newline header_fmt ();
|
423 |
|
|
(* Print the prototypes of all machines *)
|
424 |
|
|
fprintf header_fmt "/* Nodes declarations */@.";
|
425 |
|
|
List.iter (fun node -> print_machine_decl_from_header header_fmt (imported_node_of_top node)) nodes;
|
426 |
|
|
pp_print_newline header_fmt ();
|
427 |
|
|
(* Include once: end *)
|
428 |
|
|
fprintf header_fmt "#endif@.";
|
429 |
|
|
pp_print_newline header_fmt ()
|
430 |
|
|
end
|
431 |
|
|
|
432 |
|
|
end
|
433 |
cd670fe1
|
ploc
|
(* Local Variables: *)
|
434 |
|
|
(* compile-command:"make -C ../../.." *)
|
435 |
|
|
(* End: *)
|