Revision 65de9931
Added by Pierre-Loïc Garoche about 5 years ago
include/io_frontend.c | ||
---|---|---|
67 | 67 |
printf("'%i' ", (_V)? 1 : 0); |
68 | 68 |
printf("\n"); |
69 | 69 |
fprintf(file, "%i\n", _V); |
70 |
fflush(file); |
|
70 | 71 |
} |
72 |
|
|
71 | 73 |
void _put_int(FILE* file, char* n, int _V){ |
72 | 74 |
if(ISATTY) { |
73 | 75 |
printf("%s = ", n); |
... | ... | |
77 | 79 |
printf("'%d' ", _V); |
78 | 80 |
printf("\n"); |
79 | 81 |
fprintf(file, "%d\n", _V); |
82 |
fflush(file); |
|
80 | 83 |
} |
81 | 84 |
|
82 |
void _put_float(FILE* file, char* n, float _V){ |
|
85 |
void _put_float(FILE* file, char* n, float _V, int PREC){
|
|
83 | 86 |
if(ISATTY) { |
84 | 87 |
printf("%s = ", n); |
85 | 88 |
} else { |
... | ... | |
88 | 91 |
printf("'%.*f' ", PREC, _V); |
89 | 92 |
printf("\n"); |
90 | 93 |
fprintf(file, "%.*f\n", PREC, _V); |
94 |
fflush(file); |
|
91 | 95 |
} |
92 | 96 |
|
93 |
void _put_double(FILE* file, char* n, double _V){ |
|
97 |
void _put_double(FILE* file, char* n, double _V, int PREC){
|
|
94 | 98 |
if(ISATTY) { |
95 | 99 |
printf("%s = ", n); |
96 | 100 |
} else { |
... | ... | |
99 | 103 |
printf("'%.*f' ", PREC, _V); |
100 | 104 |
printf("\n"); |
101 | 105 |
fprintf(file, "%.*f\n", PREC, _V); |
106 |
fflush(file); |
|
102 | 107 |
} |
include/io_frontend.h | ||
---|---|---|
23 | 23 |
extern void _put_int(FILE* file, char* n, int _V); |
24 | 24 |
|
25 | 25 |
/*@ assigns \nothing; */ |
26 |
extern void _put_float(FILE* file, char* n, float _V); |
|
26 |
extern void _put_float(FILE* file, char* n, float _V, int PREC);
|
|
27 | 27 |
|
28 | 28 |
/*@ assigns \nothing; */ |
29 |
extern void _put_double(FILE* file, char* n, double _V); |
|
29 |
extern void _put_double(FILE* file, char* n, double _V, int PREC);
|
|
30 | 30 |
|
31 | 31 |
#endif |
include/io_frontend.hpp | ||
---|---|---|
69 | 69 |
printf("'%i' ", (_V)? 1 : 0); |
70 | 70 |
printf("\n"); |
71 | 71 |
fprintf(file, "%i\n", _V); |
72 |
fflush(file); |
|
72 | 73 |
} |
73 | 74 |
|
74 | 75 |
void _put_int(FILE* file, char* n, int _V){ |
... | ... | |
80 | 81 |
printf("'%d' ", _V); |
81 | 82 |
printf("\n"); |
82 | 83 |
fprintf(file, "%d\n", _V); |
84 |
fflush(file); |
|
83 | 85 |
} |
84 | 86 |
|
85 |
void _put_float(FILE* file, char* n, float _V){ |
|
87 |
void _put_float(FILE* file, char* n, float _V, int PREC){
|
|
86 | 88 |
if(ISATTY) { |
87 | 89 |
printf("%s = ", n); |
88 | 90 |
} else { |
... | ... | |
91 | 93 |
printf("'%.*f' ", PREC, _V); |
92 | 94 |
printf("\n"); |
93 | 95 |
fprintf(file, "%.*f\n", PREC, _V); |
96 |
fflush(file); |
|
94 | 97 |
} |
95 | 98 |
|
96 |
void _put_double(FILE* file, char* n, double _V){ |
|
99 |
void _put_double(FILE* file, char* n, double _V, int PREC){
|
|
97 | 100 |
if(ISATTY) { |
98 | 101 |
printf("%s = ", n); |
99 | 102 |
} else { |
... | ... | |
102 | 105 |
printf("'%.*f' ", PREC, _V); |
103 | 106 |
printf("\n"); |
104 | 107 |
fprintf(file, "%.*f\n", PREC, _V); |
108 |
fflush(file); |
|
105 | 109 |
} |
106 | 110 |
|
111 |
|
|
107 | 112 |
#endif |
src/backends/C/c_backend_common.ml | ||
---|---|---|
646 | 646 |
aux [] fmt (List.hd inputs).value_type |
647 | 647 |
end |
648 | 648 |
|
649 |
|
|
650 |
(*** Common functions for main ***) |
|
651 |
|
|
652 |
let print_put_var fmt file_suffix name var_type var_id = |
|
653 |
match (Types.unclock_type var_type).Types.tdesc with |
|
654 |
| Types.Tint -> fprintf fmt "_put_int(f_out%s, \"%s\", %s)" file_suffix name var_id |
|
655 |
| Types.Tbool -> fprintf fmt "_put_bool(f_out%s, \"%s\", %s)" file_suffix name var_id |
|
656 |
| Types.Treal when !Options.mpfr -> fprintf fmt "_put_double(f_out%s, \"%s\", mpfr_get_d(%s, %s), %i)" file_suffix name var_id (Mpfr.mpfr_rnd ()) !Options.print_prec_double |
|
657 |
| Types.Treal -> fprintf fmt "_put_double(f_out%s, \"%s\", %s, %i)" file_suffix name var_id !Options.print_prec_double |
|
658 |
| _ -> Format.eprintf "Impossible to print the _put_xx for type %a@.@?" Types.print_ty var_type; assert false |
|
659 |
|
|
649 | 660 |
(* Local Variables: *) |
650 | 661 |
(* compile-command:"make -C ../../.." *) |
651 | 662 |
(* End: *) |
src/backends/C/c_backend_main.ml | ||
---|---|---|
51 | 51 |
fprintf fmt "@ %a;" pi ((idx+1), v', v); |
52 | 52 |
) m.mname.node_inputs m.mstep.step_inputs |
53 | 53 |
|
54 |
|
|
54 | 55 |
let print_put_outputs fmt m = |
55 | 56 |
let po fmt (id, o', o) = |
56 |
match (Types.unclock_type o.var_type).Types.tdesc with |
|
57 |
| Types.Tint -> fprintf fmt "_put_int(f_out%i, \"%s\", %s)" id o'.var_id o.var_id |
|
58 |
| Types.Tbool -> fprintf fmt "_put_bool(f_out%i, \"%s\", %s)" id o'.var_id o.var_id |
|
59 |
| Types.Treal when !Options.mpfr -> fprintf fmt "_put_double(f_out%i, \"%s\", mpfr_get_d(%s, %s))" id o'.var_id o.var_id (Mpfr.mpfr_rnd ()) |
|
60 |
| Types.Treal -> fprintf fmt "_put_double(f_out%i, \"%s\", %s)" id o'.var_id o.var_id |
|
61 |
| _ -> assert false |
|
57 |
let suff = string_of_int id in |
|
58 |
print_put_var fmt suff o'.var_id o.var_type o.var_id |
|
62 | 59 |
in |
63 | 60 |
Utils.List.iteri2 (fun idx v' v -> fprintf fmt "@ %a;" po ((idx+1), v', v)) m.mname.node_outputs m.mstep.step_outputs |
64 | 61 |
|
... | ... | |
142 | 139 |
fprintf fmt "@ /* Infinite loop */@ "; |
143 | 140 |
fprintf fmt "@[<v 2>while(1){@ "; |
144 | 141 |
fprintf fmt "fflush(stdout);@ "; |
145 |
List.iteri (fun idx _ -> fprintf fmt "fflush(f_in%i);@ " (idx+1)) m.mstep.step_inputs; |
|
146 |
List.iteri (fun idx _ -> fprintf fmt "fflush(f_out%i);@ " (idx+1)) m.mstep.step_outputs; |
|
147 | 142 |
fprintf fmt "%a@ %t%a" |
148 | 143 |
print_get_inputs m |
149 | 144 |
(fun fmt -> pp_main_call mname main_mem fmt m input_values m.mstep.step_outputs) |
... | ... | |
158 | 153 |
else "main_mem" in |
159 | 154 |
fprintf fmt "@[<v 2>int main (int argc, char *argv[]) {@ "; |
160 | 155 |
print_main_inout_declaration basename fmt m; |
156 |
Plugins.c_backend_main_loop_body_prefix basename mname fmt (); |
|
161 | 157 |
print_main_memory_allocation mname main_mem fmt m; |
162 | 158 |
if !Options.mpfr then |
163 | 159 |
begin |
src/options.ml | ||
---|---|---|
52 | 52 |
let cpp = ref false |
53 | 53 |
let int_type = ref "int" |
54 | 54 |
let real_type = ref "double" |
55 |
let print_prec_double = ref 15 |
|
56 |
let print_prec_float = ref 10 |
|
55 | 57 |
|
56 | 58 |
let sfunction = ref "" |
57 | 59 |
|
... | ... | |
61 | 63 |
let gen_mcdc = ref false |
62 | 64 |
let no_mutation_suffix = ref false |
63 | 65 |
|
66 |
|
|
67 |
|
|
68 |
|
|
64 | 69 |
let set_mpfr prec = |
65 | 70 |
if prec > 0 then ( |
66 | 71 |
mpfr := true; |
... | ... | |
107 | 112 |
"-c++" , Arg.Set cpp , "c++ backend"; |
108 | 113 |
"-int" , Arg.Set_string int_type , "specifies the integer type (default=\"int\")"; |
109 | 114 |
"-real", Arg.Set_string real_type, "specifies the real type (default=\"double\" without mpfr option)"; |
115 |
"-real-print-prec", Arg.Set_int print_prec_double, "specifies the number of digits to be printed for real values (default=15)"; |
|
110 | 116 |
|
111 | 117 |
"-mauve", Arg.String (fun node -> mauve := node; cpp := true; static_mem := false), "generates the mauve code"; |
112 | 118 |
] |
src/pluginType.ml | ||
---|---|---|
6 | 6 |
val check_force_stateful : unit -> bool |
7 | 7 |
val refine_machine_code: LustreSpec.top_decl list -> |
8 | 8 |
Machine_code.machine_t list -> Machine_code.machine_t list |
9 |
val c_backend_main_loop_body_prefix : string -> string -> Format.formatter -> unit -> unit |
|
9 | 10 |
val c_backend_main_loop_body_suffix : Format.formatter -> unit -> unit |
10 | 11 |
end |
11 | 12 |
|
... | ... | |
13 | 14 |
struct |
14 | 15 |
let check_force_stateful () = false |
15 | 16 |
let refine_machine_code prog machines = machines |
17 |
let c_backend_main_loop_body_prefix basename mname fmt () = () |
|
16 | 18 |
let c_backend_main_loop_body_suffix fmt () = () |
17 | 19 |
end |
src/plugins.ml | ||
---|---|---|
25 | 25 |
) machine_code plugins |
26 | 26 |
|
27 | 27 |
|
28 |
let c_backend_main_loop_body_prefix basename mname fmt () = |
|
29 |
List.iter (fun (m: (module PluginType.PluginType)) -> |
|
30 |
let module M = (val m : PluginType.PluginType) in |
|
31 |
M.c_backend_main_loop_body_prefix basename mname fmt ()) plugins |
|
32 |
|
|
28 | 33 |
let c_backend_main_loop_body_suffix fmt () = |
29 | 34 |
List.iter (fun (m: (module PluginType.PluginType)) -> |
30 | 35 |
let module M = (val m : PluginType.PluginType) in |
src/plugins/scopes/scopes.ml | ||
---|---|---|
169 | 169 |
let scopes_map : (LustreSpec.ident list * scope_t) list ref = ref [] |
170 | 170 |
|
171 | 171 |
let register_scopes s = |
172 |
option_scopes := true; |
|
172 | 173 |
option_all_scopes:=false; |
173 | 174 |
let scope_list = Str.split (Str.regexp ", *") s in |
174 | 175 |
let scope_list = List.map (fun scope -> Str.split (Str.regexp "\\.") scope) scope_list in |
175 | 176 |
scopes_def := scope_list |
176 | 177 |
|
177 | 178 |
let register_inputs s = |
179 |
option_scopes := true; |
|
178 | 180 |
let input_list = Str.split (Str.regexp "[;]") s in |
179 | 181 |
let input_list = List.map (fun s -> match Str.split (Str.regexp "=") s with | [v;e] -> v, e | _ -> raise (Invalid_argument ("Input list error: " ^ s))) input_list in |
180 | 182 |
let input_list = List.map (fun (v, e) -> v, Str.split (Str.regexp "[;]") e) input_list in |
... | ... | |
185 | 187 |
iterer sur path pour construire la suite des xx_mem._reg.yy_mem._reg......flow |
186 | 188 |
par ex main_mem->n8->n9->_reg.flow |
187 | 189 |
*) |
188 |
let pp_scopes fmt scopes =
|
|
190 |
let extract_scopes_defs scopes =
|
|
189 | 191 |
let rec scope_path (path, flow) accu = |
190 | 192 |
match path with |
191 |
| [] -> accu ^ "_reg." ^ flow.var_id, flow.var_type
|
|
192 |
| (_, _, Some instance_id)::tl -> scope_path (tl, flow) ( accu ^ instance_id ^ "->" )
|
|
193 |
| _ -> assert false
|
|
193 |
| [] -> accu ^ "_reg." ^ flow.var_id, flow.var_type |
|
194 |
| (_, _, Some instance_id)::tl -> scope_path (tl, flow) ( accu ^ instance_id ^ "->" ) |
|
195 |
| _ -> assert false |
|
194 | 196 |
in |
195 | 197 |
let scopes_vars = |
196 | 198 |
List.map |
... | ... | |
198 | 200 |
String.concat "." sl, scope_path scope "main_mem.") |
199 | 201 |
scopes |
200 | 202 |
in |
201 |
List.iter (fun (id, (var, typ)) -> |
|
202 |
match (Types.repr typ).Types.tdesc with |
|
203 |
| Types.Tint -> Format.fprintf fmt "_put_int(\"%s\", %s);@ " id var |
|
204 |
| Types.Tbool -> Format.fprintf fmt "_put_bool(\"%s\", %s);@ " id var |
|
205 |
| Types.Treal when !Options.mpfr -> |
|
206 |
Format.fprintf fmt "_put_double(\"%s\", mpfr_get_d(%s, %s));@ " id var (Mpfr.mpfr_rnd ()) |
|
207 |
| Types.Treal -> Format.fprintf fmt "_put_double(\"%s\", %s);@ " id var |
|
208 |
| _ -> Format.eprintf "Impossible to print the _put_xx for type %a@.@?" Types.print_ty typ; assert false |
|
203 |
scopes_vars |
|
204 |
|
|
205 |
let pp_scopes_files basename mname fmt scopes = |
|
206 |
let scopes_vars = extract_scopes_defs scopes in |
|
207 |
List.iteri (fun idx _ (* (id, (var, typ)) *) -> |
|
208 |
Format.fprintf fmt "FILE *f_out_scopes_%i;@ " (idx+1); (* we start from 1: in1, in2, ... *) |
|
209 |
Format.fprintf fmt "f_out_scopes_%i = fopen(\"%s_%s_simu.scope%i\", \"w\");@ " (idx+1) basename mname (idx+1); |
|
210 |
) scopes_vars |
|
211 |
|
|
212 |
|
|
213 |
let pp_scopes fmt scopes = |
|
214 |
let scopes_vars = extract_scopes_defs scopes in |
|
215 |
List.iteri (fun idx (id, (var, typ)) -> |
|
216 |
Format.fprintf fmt "@ %t;" |
|
217 |
(fun fmt -> C_backend_common.print_put_var fmt ("_scopes_" ^ string_of_int (idx+1)) var typ var) |
|
209 | 218 |
) scopes_vars |
210 | 219 |
|
211 | 220 |
let update_machine machine = |
... | ... | |
235 | 244 |
struct |
236 | 245 |
let name = "scopes" |
237 | 246 |
let is_active () = |
238 |
!option_scopes |
|
247 |
!option_scopes || !option_show_scopes || !option_all_scopes || !option_mem_scopes || !option_input_scopes
|
|
239 | 248 |
|
240 | 249 |
let show_scopes () = |
241 | 250 |
!option_show_scopes && ( |
... | ... | |
250 | 259 |
"-select-mem", Arg.Set option_mem_scopes, "select all memory variables to log"; |
251 | 260 |
"-select-inputs", Arg.Set option_input_scopes, "select all input variables to log"; |
252 | 261 |
] |
253 |
|
|
262 |
|
|
254 | 263 |
let activate () = |
255 | 264 |
option_scopes := true; |
256 | 265 |
Options.optimization := 0; (* no optimization *) |
... | ... | |
315 | 324 |
let machines = List.map update_machine machines in |
316 | 325 |
machines |
317 | 326 |
|
318 |
let pp fmt = pp_scopes fmt !scopes_map
|
|
327 |
(* let pp fmt = pp_scopes fmt !scopes_map *)
|
|
319 | 328 |
|
320 |
let check_force_stateful () = !option_scopes
|
|
329 |
let check_force_stateful () = is_active()
|
|
321 | 330 |
|
322 | 331 |
let refine_machine_code prog machine_code = |
323 | 332 |
if show_scopes () then |
... | ... | |
339 | 348 |
let c_backend_main_loop_body_suffix fmt () = |
340 | 349 |
if is_active () then |
341 | 350 |
begin |
342 |
Format.fprintf fmt "@ %t" pp |
|
343 |
end; |
|
344 |
|
|
351 |
Format.fprintf fmt "@ %a" pp_scopes !scopes_map |
|
352 |
end |
|
353 |
|
|
354 |
let c_backend_main_loop_body_prefix basename mname fmt () = |
|
355 |
if is_active () then |
|
356 |
begin |
|
357 |
Format.fprintf fmt "@ %a" (pp_scopes_files basename mname) !scopes_map |
|
358 |
end |
|
359 |
|
|
360 |
|
|
345 | 361 |
end |
346 | 362 |
|
347 | 363 |
(* Local Variables: *) |
Also available in: Unified diff
New feature to specify the number of digits to be printed