Project

General

Profile

Download (2.24 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 Corelang
14
open Utils
15
   
16
let get_node nid prog =
17
  List.find (fun t -> match t.top_decl_desc with Node n -> n.node_id = nid | _ -> false) prog
18

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

    
21
let sort prog =
22
  let not_nodes, nodes = 
23
    List.partition (fun top -> match top.top_decl_desc with Node _ -> false | _ -> true) prog 
24
  in
25
  let sorted = 
26
    try
27
      let g = Causality.NodeDep.dependence_graph nodes in
28
      Causality.CycleDetection.check_cycles g;
29
    
30
      (
31
	TopologicalDepGraph.fold 
32
	  (fun x accu -> 
33
	    try 
34
	      (get_node x nodes)::accu
35
	    with Not_found -> 
36
	      (* check whether it is an imported node, a function or in the includes *)
37
	      if check_external_defs x not_nodes then
38
		accu 
39
	      else 
40
		(Format.eprintf "Impossible to find node %s@.@?" x; failwith x)
41
	  )
42
	  g []
43
      )
44
  with (Causality.Error err) as exc ->
45
    Causality.pp_error Format.err_formatter err;
46
    raise exc
47
  in
48
  Log.report ~level:3 
49
    (fun fmt -> Format.fprintf fmt "Ordered list of declarations:@.%a@.@?" (Utils.fprintf_list ~sep:"@." Printers.pp_short_decl) sorted);
50
  	  not_nodes@sorted
51

    
52

    
53
let sort_node_locals nd =
54
  { nd with node_locals = Causality.VarClockDep.sort nd.node_locals}
55
    
56
let sort_nodes_locals prog =
57
  List.map
58
    (fun top ->
59
      match top.top_decl_desc with
60
      | Node nd -> {top with top_decl_desc = Node (sort_node_locals nd)}
61
      | _ -> top
62
    )
63
    prog
64
    
65
(* Local Variables: *)
66
(* compile-command:"make -C .." *)
67
(* End: *)
(66-66/77)