Project

General

Profile

Download (2.25 KB) Statistics
| Branch: | Tag: | Revision:
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 365d1b07 ploc
open Utils
14
   
15 22fe1c93 ploc
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 365d1b07 ploc
	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 861f327f ploc
  
48 22fe1c93 ploc
  Log.report ~level:3 
49 7ee5f69e LĂ©lio Brun
    (fun fmt -> Format.fprintf fmt "@ @[<v 2>.. ordered list of declarations:@ %a@]@ "
50
        (Utils.fprintf_list ~sep:"@ " Printers.pp_short_decl) sorted);
51 22fe1c93 ploc
  	  not_nodes@sorted
52
53 70466917 ploc
54
let sort_node_locals nd =
55
  { nd with node_locals = Causality.VarClockDep.sort nd.node_locals}
56
    
57
let sort_nodes_locals prog =
58
  List.map
59
    (fun top ->
60
      match top.top_decl_desc with
61
      | Node nd -> {top with top_decl_desc = Node (sort_node_locals nd)}
62
      | _ -> top
63
    )
64
    prog
65
    
66 22fe1c93 ploc
(* Local Variables: *)
67
(* compile-command:"make -C .." *)
68
(* End: *)