1 |
b38ffff3
|
ploc
|
(********************************************************************)
|
2 |
|
|
(* *)
|
3 |
|
|
(* The LustreC compiler toolset / The LustreC Development Team *)
|
4 |
|
|
(* Copyright 2012 - -- ONERA - CNRS - INPT *)
|
5 |
|
|
(* *)
|
6 |
|
|
(* LustreC is free software, distributed WITHOUT ANY WARRANTY *)
|
7 |
|
|
(* under the terms of the GNU Lesser General Public License *)
|
8 |
|
|
(* version 2.1. *)
|
9 |
|
|
(* *)
|
10 |
|
|
(********************************************************************)
|
11 |
|
|
|
12 |
0cbf0839
|
ploc
|
open Graph
|
13 |
0038002e
|
ploc
|
open LustreSpec
|
14 |
0cbf0839
|
ploc
|
open Corelang
|
15 |
ae78dfee
|
enoulard
|
module TopologicalDepGraph = Topological.Make(Causality.IdentDepGraph)
|
16 |
0cbf0839
|
ploc
|
|
17 |
|
|
let get_node nid prog =
|
18 |
|
|
List.find (fun t -> match t.top_decl_desc with Node n -> n.node_id = nid | _ -> false) prog
|
19 |
|
|
|
20 |
|
|
let check_external_defs x not_nodes = true (* TODO, check whether a node, a function or an include defines this node *)
|
21 |
|
|
|
22 |
|
|
let sort prog =
|
23 |
|
|
let not_nodes, nodes =
|
24 |
|
|
List.partition (fun top -> match top.top_decl_desc with Node _ -> false | _ -> true) prog
|
25 |
|
|
in
|
26 |
|
|
let sorted =
|
27 |
|
|
try
|
28 |
|
|
let g = Causality.NodeDep.dependence_graph nodes in
|
29 |
|
|
Causality.CycleDetection.check_cycles g;
|
30 |
|
|
|
31 |
|
|
(
|
32 |
|
|
TopologicalDepGraph.fold
|
33 |
|
|
(fun x accu ->
|
34 |
|
|
try
|
35 |
|
|
(get_node x nodes)::accu
|
36 |
|
|
with Not_found ->
|
37 |
|
|
(* check whether it is an imported node, a function or in the includes *)
|
38 |
|
|
if check_external_defs x not_nodes then
|
39 |
|
|
accu
|
40 |
|
|
else
|
41 |
|
|
(Format.eprintf "Impossible to find node %s@.@?" x; failwith x)
|
42 |
|
|
)
|
43 |
|
|
g []
|
44 |
|
|
)
|
45 |
|
|
with (Causality.Cycle v) as exc ->
|
46 |
|
|
Causality.pp_error Format.err_formatter v;
|
47 |
|
|
raise exc
|
48 |
|
|
in
|
49 |
|
|
Log.report ~level:3
|
50 |
|
|
(fun fmt -> Format.fprintf fmt "Ordered list of declarations:@.%a@.@?" (Utils.fprintf_list ~sep:"@." Printers.pp_short_decl) sorted);
|
51 |
|
|
not_nodes@sorted
|
52 |
|
|
|
53 |
|
|
(* Local Variables: *)
|
54 |
|
|
(* compile-command:"make -C .." *)
|
55 |
|
|
(* End: *)
|