21 |
21 |
module OrdVarDecl:Map.OrderedType with type t=var_decl =
|
22 |
22 |
struct type t = var_decl;; let compare = compare end
|
23 |
23 |
|
24 |
|
module ISet = Set.Make(OrdVarDecl)
|
|
24 |
module VSet = Set.Make(OrdVarDecl)
|
25 |
25 |
|
26 |
26 |
let rec pp_val fmt v =
|
27 |
27 |
match v.value_desc with
|
... | ... | |
110 |
110 |
Format.eprintf "Unable to find node %s in list [%a]@.@?"
|
111 |
111 |
id
|
112 |
112 |
(Utils.fprintf_list ~sep:", " (fun fmt (n,_) -> Format.fprintf fmt "%s" n)) m.mcalls
|
113 |
|
; assert false;
|
|
113 |
;
|
114 |
114 |
raise Not_found
|
115 |
115 |
)
|
116 |
116 |
|
... | ... | |
314 |
314 |
(* Format.eprintf "trnaslating ident: %s@." id; *)
|
315 |
315 |
try (* id is a node var *)
|
316 |
316 |
let var_id = get_node_var id node in
|
317 |
|
if ISet.exists (fun v -> v.var_id = id) m
|
|
317 |
if VSet.exists (fun v -> v.var_id = id) m
|
318 |
318 |
then (
|
319 |
319 |
(* Format.eprintf "a STATE VAR@."; *)
|
320 |
320 |
mk_val (StateVar var_id) var_id.var_type
|
... | ... | |
463 |
463 |
Utils.IMap.add o (arrow_top_decl, []) j,
|
464 |
464 |
d,
|
465 |
465 |
(control_on_clock node args eq.eq_rhs.expr_clock (mkinstr ?lustre_eq:(Some eq) (MStep ([var_x], o, [c1;c2])))) :: s)
|
466 |
|
| [x], Expr_pre e1 when ISet.mem (get_node_var x node) d ->
|
|
466 |
| [x], Expr_pre e1 when VSet.mem (get_node_var x node) d ->
|
467 |
467 |
let var_x = get_node_var x node in
|
468 |
|
(ISet.add var_x m,
|
|
468 |
(VSet.add var_x m,
|
469 |
469 |
si,
|
470 |
470 |
j,
|
471 |
471 |
d,
|
472 |
472 |
control_on_clock node args eq.eq_rhs.expr_clock (mkinstr ?lustre_eq:(Some eq) (MStateAssign (var_x, translate_expr node args e1))) :: s)
|
473 |
|
| [x], Expr_fby (e1, e2) when ISet.mem (get_node_var x node) d ->
|
|
473 |
| [x], Expr_fby (e1, e2) when VSet.mem (get_node_var x node) d ->
|
474 |
474 |
let var_x = get_node_var x node in
|
475 |
|
(ISet.add var_x m,
|
|
475 |
(VSet.add var_x m,
|
476 |
476 |
mkinstr ?lustre_eq:(Some eq) (MStateAssign (var_x, translate_expr node args e1)) :: si,
|
477 |
477 |
j,
|
478 |
478 |
d,
|
... | ... | |
631 |
631 |
let locals_list = nd.node_locals @ new_locals in
|
632 |
632 |
|
633 |
633 |
let nd = { nd with node_locals = locals_list } in
|
634 |
|
let init_args = ISet.empty, [], Utils.IMap.empty, List.fold_right (fun l -> ISet.add l) locals_list ISet.empty, [] in
|
|
634 |
let init_args = VSet.empty, [], Utils.IMap.empty, List.fold_right (fun l -> VSet.add l) locals_list VSet.empty, [] in
|
635 |
635 |
(* memories, init instructions, node calls, local variables (including memories), step instrs *)
|
636 |
636 |
let m0, init0, j0, locals0, s0 = translate_eqs nd init_args constant_eqs in
|
637 |
|
assert (ISet.is_empty m0);
|
|
637 |
assert (VSet.is_empty m0);
|
638 |
638 |
assert (init0 = []);
|
639 |
639 |
assert (Utils.IMap.is_empty j0);
|
640 |
640 |
let m, init, j, locals, s as context_with_asserts = translate_eqs nd (m0, init0, j0, locals0, []) (assert_instrs@sorted_eqs) in
|
641 |
641 |
let mmap = Utils.IMap.fold (fun i n res -> (i, n)::res) j [] in
|
642 |
642 |
{
|
643 |
643 |
mname = nd;
|
644 |
|
mmemory = ISet.elements m;
|
|
644 |
mmemory = VSet.elements m;
|
645 |
645 |
mcalls = mmap;
|
646 |
646 |
minstances = List.filter (fun (_, (n,_)) -> not (Stateless.check_node n)) mmap;
|
647 |
647 |
minit = init;
|
... | ... | |
650 |
650 |
mstep = {
|
651 |
651 |
step_inputs = nd.node_inputs;
|
652 |
652 |
step_outputs = nd.node_outputs;
|
653 |
|
step_locals = ISet.elements (ISet.diff locals m);
|
|
653 |
step_locals = VSet.elements (VSet.diff locals m);
|
654 |
654 |
step_checks = List.map (fun d -> d.Dimension.dim_loc, translate_expr nd init_args (expr_of_dimension d)) nd.node_checks;
|
655 |
655 |
step_instrs = (
|
656 |
656 |
(* special treatment depending on the active backend. For horn backend,
|
Renamed ISet of Machine_code to VSet: was sets of variable and was conflicting with ISet from Utils which carries strings.