Revision ca7ff3f7
Added by Lélio Brun over 1 year ago
src/sortProg.ml | ||
---|---|---|
11 | 11 |
|
12 | 12 |
open Lustre_types |
13 | 13 |
open Utils |
14 |
|
|
14 |
|
|
15 | 15 |
let get_node nid prog = |
16 |
List.find (fun t -> match t.top_decl_desc with Node n -> n.node_id = nid | _ -> false) prog |
|
16 |
List.find |
|
17 |
(fun t -> |
|
18 |
match t.top_decl_desc with Node n -> n.node_id = nid | _ -> false) |
|
19 |
prog |
|
17 | 20 |
|
18 |
let check_external_defs x not_nodes = true (* TODO, check whether a node, a function or an include defines this node *) |
|
21 |
let check_external_defs x not_nodes = true |
|
22 |
(* TODO, check whether a node, a function or an include defines this node *) |
|
19 | 23 |
|
20 | 24 |
let sort prog = |
21 |
let not_nodes, nodes = |
|
22 |
List.partition (fun top -> match top.top_decl_desc with Node _ -> false | _ -> true) prog |
|
25 |
let not_nodes, nodes = |
|
26 |
List.partition |
|
27 |
(fun top -> match top.top_decl_desc with Node _ -> false | _ -> true) |
|
28 |
prog |
|
23 | 29 |
in |
24 |
let sorted =
|
|
30 |
let sorted = |
|
25 | 31 |
try |
26 | 32 |
let g = Causality.NodeDep.dependence_graph nodes in |
27 | 33 |
Causality.CycleDetection.check_cycles g; |
28 |
|
|
29 |
( |
|
30 |
TopologicalDepGraph.fold |
|
31 |
(fun x accu -> |
|
32 |
try |
|
33 |
(get_node x nodes)::accu |
|
34 |
with Not_found -> |
|
35 |
(* check whether it is an imported node, a function or in the includes *) |
|
36 |
if check_external_defs x not_nodes then |
|
37 |
accu |
|
38 |
else |
|
39 |
(Format.eprintf "Impossible to find node %s@.@?" x; failwith x) |
|
40 |
) |
|
41 |
g [] |
|
42 |
) |
|
43 |
with (Causality.Error err) as exc -> |
|
44 |
Causality.pp_error Format.err_formatter err; |
|
45 |
raise exc |
|
34 |
|
|
35 |
TopologicalDepGraph.fold |
|
36 |
(fun x accu -> |
|
37 |
try get_node x nodes :: accu |
|
38 |
with Not_found -> |
|
39 |
(* check whether it is an imported node, a function or in the |
|
40 |
includes *) |
|
41 |
if check_external_defs x not_nodes then accu |
|
42 |
else ( |
|
43 |
Format.eprintf "Impossible to find node %s@.@?" x; |
|
44 |
failwith x)) |
|
45 |
g [] |
|
46 |
with Causality.Error err as exc -> |
|
47 |
Causality.pp_error Format.err_formatter err; |
|
48 |
raise exc |
|
46 | 49 |
in |
47 |
|
|
48 |
Log.report ~level:3 |
|
49 |
(fun fmt -> Format.fprintf fmt "@ @[<v 2>.. ordered list of declarations:@ %a@]@ " |
|
50 |
(Utils.fprintf_list ~sep:"@ " Printers.pp_short_decl) sorted); |
|
51 |
not_nodes@sorted |
|
52 | 50 |
|
51 |
Log.report ~level:3 (fun fmt -> |
|
52 |
Format.fprintf fmt "@ @[<v 2>.. ordered list of declarations:@ %a@]@ " |
|
53 |
(Utils.fprintf_list ~sep:"@ " Printers.pp_short_decl) |
|
54 |
sorted); |
|
55 |
not_nodes @ sorted |
|
53 | 56 |
|
54 | 57 |
let sort_node_locals nd = |
55 |
{ nd with node_locals = Causality.VarClockDep.sort nd.node_locals} |
|
56 |
|
|
58 |
{ nd with node_locals = Causality.VarClockDep.sort nd.node_locals }
|
|
59 |
|
|
57 | 60 |
let sort_nodes_locals prog = |
58 | 61 |
List.map |
59 | 62 |
(fun top -> |
60 | 63 |
match top.top_decl_desc with |
61 |
| Node nd -> {top with top_decl_desc = Node (sort_node_locals nd)} |
|
62 |
| _ -> top |
|
63 |
) |
|
64 |
| Node nd -> |
|
65 |
{ top with top_decl_desc = Node (sort_node_locals nd) } |
|
66 |
| _ -> |
|
67 |
top) |
|
64 | 68 |
prog |
65 |
|
|
69 |
|
|
66 | 70 |
(* Local Variables: *) |
67 | 71 |
(* compile-command:"make -C .." *) |
68 | 72 |
(* End: *) |
Also available in: Unified diff
reformatting