Revision 42f91c0b
Added by Pierre-Loïc Garoche over 5 years ago
src/backends/EMF/EMF_backend.ml | ||
---|---|---|
150 | 150 |
| Expr_appl(_,_,reset) -> ( |
151 | 151 |
match reset with None -> false | Some _ -> true |
152 | 152 |
) |
153 |
| _ -> assert false |
|
153 |
| Expr_arrow _ -> true |
|
154 |
| _ -> Format.eprintf "reseting expr %a@.@?" Printers.pp_expr eq.eq_rhs; assert false |
|
154 | 155 |
) |
155 | 156 |
| None -> assert false (* should have been assigned to an original lustre equation *) |
156 | 157 |
|
... | ... | |
179 | 180 |
ISet.union accu_def common_def_vars, |
180 | 181 |
VSet.union accu_read read_vars) |
181 | 182 |
(ISet.empty, ISet.empty, VSet.empty) il |
183 |
|
|
182 | 184 |
and branch_instr_vars m i = |
185 |
(* Returns all_outputs, outputs, inputs of the instruction. It is |
|
186 |
only called on MBranch instructions but evaluate recursively |
|
187 |
instructions appearing in branches. |
|
188 |
|
|
189 |
It is used to gather the global input/output of a switch and |
|
190 |
print it at the begin of the JSON subtree. |
|
191 |
|
|
192 |
The set "All outputs" is used to filter out input variables |
|
193 |
belong to that set. *) |
|
194 |
|
|
183 | 195 |
match Corelang.get_instr_desc i with |
184 | 196 |
| MLocalAssign (var,expr) |
185 |
| MStateAssign (var,expr) -> ISet.singleton var.var_id, ISet.singleton var.var_id, get_expr_vars expr |
|
197 |
| MStateAssign (var,expr) -> ISet.singleton var.var_id, ISet.singleton var.var_id, get_expr_vars expr
|
|
186 | 198 |
| MStep (vars, f, args) -> |
187 | 199 |
let is_stateful = List.mem_assoc f m.minstances in |
188 | 200 |
let lhs = ISet.of_list (List.map (fun v -> v.var_id) vars) in |
... | ... | |
207 | 219 |
) |
208 | 220 |
| MBranch (g,(_,hd_il)::tl) -> (* We focus on variables defined in all branches *) |
209 | 221 |
let read_guard = get_expr_vars g in |
222 |
(* Bootstrapping with first item *) |
|
210 | 223 |
let all_def_vars_hd, def_vars_hd, read_vars_hd = branch_block_vars m hd_il in |
211 | 224 |
let all_def_vars, def_vars, read_vars = |
212 | 225 |
List.fold_left |
... | ... | |
220 | 233 |
(all_def_vars_hd, def_vars_hd, read_vars_hd) |
221 | 234 |
tl |
222 | 235 |
in |
236 |
(* all_def_vars correspond to variables written or defined in one |
|
237 |
of the branch. It may happen that a variable is defined in one |
|
238 |
but not in the other, because of reset for example. |
|
239 |
|
|
240 |
def_vars are variables defined in all branches. *) |
|
241 |
|
|
242 |
|
|
223 | 243 |
all_def_vars, def_vars, VSet.union read_guard read_vars |
224 | 244 |
| MBranch _ -> assert false (* branch instruction should admit at least one case *) |
225 | 245 |
| MReset ni |
226 |
| MNoReset ni -> |
|
246 |
| MNoReset ni ->
|
|
227 | 247 |
let write = ISet.singleton (reset_name ni) in |
228 | 248 |
write, write, VSet.empty |
229 |
| MComment _ -> assert false (* not available for EMF output *) |
|
249 |
| MSpec _ | MComment _ -> assert false (* not available for EMF output *)
|
|
230 | 250 |
|
231 | 251 |
(* A kind of super join_guards: all MBranch are postponed and sorted by |
232 | 252 |
guards so they can be easier merged *) |
... | ... | |
358 | 378 |
| MStep(outputs, f, inputs ) -> (* This is an imported node *) |
359 | 379 |
EMF_library_calls.pp_call fmt m f outputs inputs |
360 | 380 |
|
361 |
| MComment _ |
|
381 |
| MSpec _ | MComment _
|
|
362 | 382 |
-> Format.eprintf "unhandled comment in EMF@.@?"; assert false |
363 | 383 |
(* not available for EMF output *) |
364 | 384 |
in |
... | ... | |
380 | 400 |
fprintf fmt "{@["; |
381 | 401 |
fprintf fmt "\"mode_id\": \"%s\",@ " |
382 | 402 |
m.mode_id; |
383 |
fprintf fmt "\"require\": [%a],@ "
|
|
403 |
fprintf fmt "\"ensure\": [%a],@ "
|
|
384 | 404 |
pp_emf_eexprs m.ensure; |
385 |
fprintf fmt "\"require\": [%a],@ "
|
|
405 |
fprintf fmt "\"require\": [%a]@ " |
|
386 | 406 |
pp_emf_eexprs m.require; |
387 | 407 |
fprintf fmt "@]}" |
388 | 408 |
|
... | ... | |
402 | 422 |
|
403 | 423 |
let pp_emf_spec fmt spec = |
404 | 424 |
fprintf fmt "{ @[<hov 0>"; |
405 |
fprintf fmt "\"consts\": [%a],@ " |
|
406 |
pp_emf_consts spec.consts; |
|
407 |
fprintf fmt "\"locals\": [%a],@ " |
|
408 |
pp_emf_vars_decl spec.locals; |
|
409 |
fprintf fmt "\"stmts\": [%a],@ " |
|
410 |
pp_emf_stmts spec.stmts;
|
|
425 |
(* fprintf fmt "\"consts\": [%a],@ "
|
|
426 |
* pp_emf_consts spec.consts;
|
|
427 |
* fprintf fmt "\"locals\": [%a],@ "
|
|
428 |
* pp_emf_vars_decl spec.locals;
|
|
429 |
* fprintf fmt "\"stmts\": [%a],@ "
|
|
430 |
* pp_emf_stmts spec.stmts; *)
|
|
411 | 431 |
fprintf fmt "\"assume\": [%a],@ " |
412 | 432 |
pp_emf_eexprs spec.assume; |
413 | 433 |
fprintf fmt "\"guarantees\": [%a],@ " |
414 | 434 |
pp_emf_eexprs spec.guarantees; |
415 |
fprintf fmt "\"modes\": [%a],@ "
|
|
435 |
fprintf fmt "\"modes\": [%a]@ " |
|
416 | 436 |
pp_emf_spec_modes spec.modes; |
417 |
fprintf fmt "\"imports\": [%a]@ " |
|
418 |
pp_emf_spec_imports spec.imports;
|
|
437 |
(* fprintf fmt "\"imports\": [%a]@ "
|
|
438 |
* pp_emf_spec_imports spec.imports; *)
|
|
419 | 439 |
fprintf fmt "@] }" |
420 | 440 |
|
421 | 441 |
let pp_emf_annots cpt fmt annots = fprintf_list ~sep:",@ " (pp_emf_annot cpt) fmt annots.annots |
422 | 442 |
let pp_emf_annots_list cpt fmt annots_list = fprintf_list ~sep:",@ " (pp_emf_annots cpt) fmt annots_list |
423 | 443 |
|
424 |
let pp_emf_contract fmt nd = |
|
425 |
let c = Printers.node_as_contract nd in |
|
426 |
fprintf fmt "@[v 2>\"%a\": {@ "
|
|
427 |
print_protect (fun fmt -> pp_print_string fmt nd.node_id); |
|
428 |
fprintf fmt "\"contract\": %a@ " |
|
429 |
pp_emf_spec c; |
|
430 |
fprintf fmt "@]@ }"
|
|
444 |
(* let pp_emf_contract fmt nd =
|
|
445 |
* let c = Printers.node_as_contract nd in
|
|
446 |
* fprintf fmt "@[<v 2>\"%a\": {@ "
|
|
447 |
* print_protect (fun fmt -> pp_print_string fmt nd.node_id);
|
|
448 |
* fprintf fmt "\"contract\": %a@ "
|
|
449 |
* pp_emf_spec c;
|
|
450 |
* fprintf fmt "@]@ }" *)
|
|
431 | 451 |
|
432 | 452 |
let pp_machine fmt m = |
433 | 453 |
let instrs = (*merge_branches*) m.mstep.step_instrs in |
434 | 454 |
try |
435 | 455 |
fprintf fmt "@[<v 2>\"%a\": {@ " |
436 | 456 |
print_protect (fun fmt -> pp_print_string fmt m.mname.node_id); |
457 |
(match m.mspec with Some (Contract _) -> fprintf fmt "\"contract\": \"true\",@ " | _ -> ()); |
|
437 | 458 |
fprintf fmt "\"imported\": \"false\",@ "; |
438 | 459 |
fprintf fmt "\"kind\": %t,@ " |
439 | 460 |
(fun fmt -> if not ( snd (get_stateless_status m) ) |
... | ... | |
452 | 473 |
fprintf fmt "\"instrs\": {@[<v 0> %a@]@ },@ " |
453 | 474 |
(pp_emf_instrs m) instrs; |
454 | 475 |
(match m.mspec with | None -> () |
455 |
| Some (Contract _) -> assert false |
|
456 |
| Some (NodeSpec id) -> fprintf fmt "\"coco_contract\": %s" id |
|
476 |
| Some (Contract c) -> ( |
|
477 |
assert (c.locals = [] && c.consts = [] && c.stmts = [] && c.imports = []); |
|
478 |
fprintf fmt "\"spec\": %a,@ " pp_emf_spec c |
|
479 |
) |
|
480 |
| Some (NodeSpec id) -> fprintf fmt "\"contract\": \"%s\",@ " id |
|
457 | 481 |
); |
458 | 482 |
fprintf fmt "\"annots\": {@[<v 0> %a@]@ }" (pp_emf_annots_list (ref 0)) m.mannot; |
459 | 483 |
fprintf fmt "@]@ }" |
... | ... | |
464 | 488 |
eprintf "node skipped - no output generated@ @]@." |
465 | 489 |
) |
466 | 490 |
|
467 |
let pp_machine fmt m = |
|
491 |
(*let pp_machine fmt m =
|
|
468 | 492 |
match m.mspec with |
469 | 493 |
| None | Some (NodeSpec _) -> pp_machine fmt m |
470 |
| Some (Contract _) -> pp_emf_contract fmt m.mname |
|
471 |
|
|
494 |
| Some (Contract _) -> pp_emf_contract fmt m |
|
495 |
*) |
|
496 |
|
|
472 | 497 |
let pp_emf_imported_node fmt top = |
473 | 498 |
let ind = Corelang.imported_node_of_top top in |
474 | 499 |
try |
Also available in: Unified diff
Better EMF output, solved some invalid JSON produced