Project

General

Profile

« Previous | Next » 

Revision 70466917

Added by Pierre-Loïc Garoche over 5 years ago

[main] node locals are now sorted according to their dependencies wrt clocks. The produced lustre node with types shall now be compilable

View differences:

src/causality.ml
29 29

  
30 30

  
31 31
module IdentDepGraph = Graph.Imperative.Digraph.ConcreteBidirectional (IdentModule)
32
module TopologicalDepGraph = Topological.Make(IdentDepGraph)
33

  
32 34
(*module DotGraph = Graphviz.Dot (IdentDepGraph)*)
33 35
module Bfs = Traverse.Bfs (IdentDepGraph)
34 36
  
......
652 654
      raise (Error (exc))
653 655
  )
654 656

  
657
(* A module to sort dependencies among local variables when relying on clocked declarations *)
658
module VarClockDep =
659
struct
660
  let rec get_clock_dep ck =
661
    match ck.Clocks.cdesc with
662
    | Clocks.Con (ck ,c ,l) -> l::(get_clock_dep ck)
663
    | Clocks.Clink ck' 
664
    | Clocks.Ccarrying (_, ck') -> get_clock_dep ck'
665
    | _ -> []
666
      
667
  let sort locals =
668
    let g = new_graph () in
669
    let g = List.fold_left (
670
      fun g var_decl ->
671
	let deps = get_clock_dep var_decl.var_clock in
672
	add_edges [var_decl.var_id] deps g
673
    ) g locals
674
    in
675
    let sorted, no_deps =
676
      TopologicalDepGraph.fold (fun vid (accu, remaining) -> (
677
	let select v = v.var_id = vid in
678
	let selected, not_selected = List.partition select remaining in
679
	selected@accu, not_selected
680
      )) g ([],locals)
681
    in
682
    no_deps @ sorted
683
    
684
end
685
  
655 686
(* Local Variables: *)
656 687
(* compile-command:"make -C .." *)
657 688
(* End: *)
src/compiler_stages.ml
187 187
      Access.check_prog prog;
188 188
    end;
189 189

  
190
  let prog = SortProg.sort_nodes_locals prog in
191
  
190 192
  prog, dependencies
src/sortProg.ml
9 9
(*                                                                  *)
10 10
(********************************************************************)
11 11

  
12
open Graph
13 12
open LustreSpec
14 13
open Corelang
15
module TopologicalDepGraph = Topological.Make(Causality.IdentDepGraph)
16 14

  
17 15
let get_node nid prog =
18 16
  List.find (fun t -> match t.top_decl_desc with Node n -> n.node_id = nid | _ -> false) prog
......
29 27
      Causality.CycleDetection.check_cycles g;
30 28
    
31 29
      (
32
	TopologicalDepGraph.fold 
30
	Causality.TopologicalDepGraph.fold 
33 31
	  (fun x accu -> 
34 32
	    try 
35 33
	      (get_node x nodes)::accu
......
50 48
    (fun fmt -> Format.fprintf fmt "Ordered list of declarations:@.%a@.@?" (Utils.fprintf_list ~sep:"@." Printers.pp_short_decl) sorted);
51 49
  	  not_nodes@sorted
52 50

  
51

  
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
    
53 64
(* Local Variables: *)
54 65
(* compile-command:"make -C .." *)
55 66
(* End: *)

Also available in: Unified diff