Project

General

Profile

Download (2.32 KB) Statistics
| Branch: | Tag: | Revision:
1
(********************************************************************)
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
open Lustre_types
13
open Utils
14

    
15
let get_node nid prog =
16
  List.find
17
    (fun t ->
18
      match t.top_decl_desc with Node n -> n.node_id = nid | _ -> false)
19
    prog
20

    
21
let check_external_defs x not_nodes = true
22
(* TODO, check whether a node, a function or an include defines this node *)
23

    
24
let sort prog =
25
  let not_nodes, nodes =
26
    List.partition
27
      (fun top -> match top.top_decl_desc with Node _ -> false | _ -> true)
28
      prog
29
  in
30
  let sorted =
31
    try
32
      let g = Causality.NodeDep.dependence_graph nodes in
33
      Causality.CycleDetection.check_cycles g;
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
49
  in
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
56

    
57
let sort_node_locals nd =
58
  { nd with node_locals = Causality.VarClockDep.sort nd.node_locals }
59

    
60
let sort_nodes_locals prog =
61
  List.map
62
    (fun top ->
63
      match top.top_decl_desc with
64
      | Node nd ->
65
        { top with top_decl_desc = Node (sort_node_locals nd) }
66
      | _ ->
67
        top)
68
    prog
69

    
70
(* Local Variables: *)
71
(* compile-command:"make -C .." *)
72
(* End: *)
(55-55/66)