lustrec / src / sortProg.ml @ 3340aff0
History | View | Annotate | Download (2.23 KB)
1 | a2d97a3e | 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 | 8446bf03 | ploc | open Lustre_types |
13 | 22fe1c93 | ploc | open Corelang |
14 | |||
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 |
||
17 | |||
18 | let check_external_defs x not_nodes = true (* TODO, check whether a node, a function or an include defines this node *) |
||
19 | |||
20 | let sort prog = |
||
21 | let not_nodes, nodes = |
||
22 | List.partition (fun top -> match top.top_decl_desc with Node _ -> false | _ -> true) prog |
||
23 | in |
||
24 | let sorted = |
||
25 | try |
||
26 | let g = Causality.NodeDep.dependence_graph nodes in |
||
27 | Causality.CycleDetection.check_cycles g; |
||
28 | |||
29 | ( |
||
30 | 70466917 | ploc | Causality.TopologicalDepGraph.fold |
31 | 22fe1c93 | ploc | (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 | eb837d74 | xthirioux | with (Causality.Error err) as exc -> |
44 | Causality.pp_error Format.err_formatter err; |
||
45 | 22fe1c93 | ploc | raise exc |
46 | in |
||
47 | Log.report ~level:3 |
||
48 | (fun fmt -> Format.fprintf fmt "Ordered list of declarations:@.%a@.@?" (Utils.fprintf_list ~sep:"@." Printers.pp_short_decl) sorted); |
||
49 | not_nodes@sorted |
||
50 | |||
51 | 70466917 | ploc | |
52 | let sort_node_locals nd = |
||
53 | { nd with node_locals = Causality.VarClockDep.sort nd.node_locals} |
||
54 | |||
55 | let sort_nodes_locals prog = |
||
56 | List.map |
||
57 | (fun top -> |
||
58 | match top.top_decl_desc with |
||
59 | | Node nd -> {top with top_decl_desc = Node (sort_node_locals nd)} |
||
60 | | _ -> top |
||
61 | ) |
||
62 | prog |
||
63 | |||
64 | 22fe1c93 | ploc | (* Local Variables: *) |
65 | (* compile-command:"make -C .." *) |
||
66 | (* End: *) |