Revision a7062da6
Added by LĂ©lio Brun over 3 years ago
src/backends/EMF/EMF_backend.ml | ||
---|---|---|
98 | 98 |
|
99 | 99 |
*) |
100 | 100 |
|
101 |
open Utils |
|
101 | 102 |
open Lustre_types |
103 |
open Corelang |
|
102 | 104 |
open Machine_code_types |
103 | 105 |
open Machine_code_common |
104 | 106 |
open Format |
... | ... | |
108 | 110 |
|
109 | 111 |
module ISet = Utils.ISet |
110 | 112 |
|
111 |
let fprintf_list = Utils.fprintf_list |
|
112 |
|
|
113 | 113 |
(**********************************************) |
114 | 114 |
(* Utility functions: arrow and lustre expr *) |
115 | 115 |
(**********************************************) |
... | ... | |
170 | 170 |
fprintf fmt "branch_%i" !branch_cpt |
171 | 171 |
| MStep (outs, id, _) -> |
172 | 172 |
print_protect fmt (fun fmt -> |
173 |
fprintf fmt "%a_%s" (fprintf_list ~sep:"_" pp_var_name) outs id) |
|
173 |
fprintf fmt "%a_%s" (pp_print_list ~pp_sep:(fun fmt () -> pp_print_string fmt "_") |
|
174 |
pp_var_name) outs id) |
|
174 | 175 |
| _ -> () |
175 | 176 |
(* No name *) |
176 | 177 |
|
... | ... | |
212 | 213 |
lhs, |
213 | 214 |
if is_stateful && is_resetable_fun i.lustre_eq then |
214 | 215 |
let reset_var = |
215 |
let loc = Location.dummy_loc in
|
|
216 |
let loc = Location.dummy in |
|
216 | 217 |
Corelang.mkvar_decl loc |
217 | 218 |
( reset_name f, |
218 | 219 |
Corelang.mktyp loc Tydec_bool, |
... | ... | |
334 | 335 |
fprintf fmt "\"guard\": %a,@ " (pp_emf_cst_or_var m) g; |
335 | 336 |
(* it has to be a variable or a constant *) |
336 | 337 |
fprintf fmt "\"outputs\": [%a],@ " |
337 |
(fprintf_list ~sep:", " pp_var_string)
|
|
338 |
(pp_comma_list pp_var_string)
|
|
338 | 339 |
(ISet.elements outputs); |
339 | 340 |
fprintf fmt "\"inputs\": [%a],@ " pp_emf_vars_decl |
340 | 341 |
(* |
... | ... | |
343 | 344 |
remove guard's variable from inputs *) |
344 | 345 |
(VSet.elements inputs); |
345 | 346 |
fprintf fmt "@[<v 2>\"branches\": {@ @[<v 0>%a@]@]@ }" |
346 |
(fprintf_list ~sep:",@ " (fun fmt (tag, instrs_tag) ->
|
|
347 |
(pp_comma_list (fun fmt (tag, instrs_tag) ->
|
|
347 | 348 |
let branch_all_lhs, _, branch_inputs = |
348 | 349 |
branch_block_vars m instrs_tag |
349 | 350 |
in |
... | ... | |
377 | 378 |
(fun fmt -> pp_print_string fmt node_f.node_id) |
378 | 379 |
f; |
379 | 380 |
fprintf fmt "\"lhs\": [@[%a@]],@ \"args\": [@[%a@]]" |
380 |
(fprintf_list ~sep:",@ " (fun fmt v ->
|
|
381 |
(pp_comma_list (fun fmt v ->
|
|
381 | 382 |
fprintf fmt "\"%a\"" pp_var_name v)) |
382 | 383 |
outputs (pp_emf_cst_or_var_list m) inputs; |
383 | 384 |
if is_stateful then |
... | ... | |
398 | 399 |
fprintf fmt "@]@]@ }" |
399 | 400 |
|
400 | 401 |
and pp_emf_instrs m fmt instrs = |
401 |
fprintf_list ~sep:",@ " (pp_emf_instr m) fmt instrs
|
|
402 |
pp_comma_list (pp_emf_instr m) fmt instrs
|
|
402 | 403 |
|
403 | 404 |
let pp_emf_annot cpt fmt (key, ee) = |
404 | 405 |
let _ = |
405 | 406 |
fprintf fmt "\"ann%i\": { @[<hov 0>\"key\": [%a],@ \"eexpr\": %a@] }" !cpt |
406 |
(fprintf_list ~sep:"," (fun fmt s -> fprintf fmt "\"%s\"" s))
|
|
407 |
(pp_comma_list (fun fmt s -> fprintf fmt "\"%s\"" s))
|
|
407 | 408 |
key pp_emf_eexpr ee |
408 | 409 |
in |
409 | 410 |
incr cpt |
... | ... | |
442 | 443 |
fprintf fmt "@] }" |
443 | 444 |
|
444 | 445 |
let pp_emf_annots cpt fmt annots = |
445 |
fprintf_list ~sep:",@ " (pp_emf_annot cpt) fmt annots.annots
|
|
446 |
pp_comma_list (pp_emf_annot cpt) fmt annots.annots
|
|
446 | 447 |
|
447 | 448 |
let pp_emf_annots_list cpt fmt annots_list = |
448 |
fprintf_list ~sep:",@ " (pp_emf_annots cpt) fmt annots_list
|
|
449 |
pp_comma_list (pp_emf_annots cpt) fmt annots_list
|
|
449 | 450 |
|
450 | 451 |
(* let pp_emf_contract fmt nd = |
451 | 452 |
* let c = Printers.node_as_contract nd in |
... | ... | |
523 | 524 |
(****************************************************) |
524 | 525 |
let pp_meta fmt basename = |
525 | 526 |
fprintf fmt "\"meta\": @[<v 0>{@ "; |
526 |
Utils.fprintf_list ~sep:",@ "
|
|
527 |
Format.pp_comma_list
|
|
527 | 528 |
(fun fmt (k, v) -> fprintf fmt "\"%s\": \"%s\"" k v) |
528 | 529 |
fmt |
529 | 530 |
[ |
... | ... | |
550 | 551 |
fprintf fmt "}@],@ "; |
551 | 552 |
fprintf fmt "\"nodes\": @[<v 0>{@ "; |
552 | 553 |
(* Previous alternative: mapping normalized lustre to EMF: |
553 |
fprintf_list ~sep:",@ " pp_decl fmt prog; *)
|
|
554 |
pp_comma_list pp_decl fmt prog; *)
|
|
554 | 555 |
pp_emf_list pp_machine fmt machines; |
555 | 556 |
fprintf fmt "}@]@ }"; |
556 | 557 |
fprintf fmt "@]@ }" |
Also available in: Unified diff
another step towards refactoring