2012-06-27 18:09:30 +02:00
|
|
|
(***********************************************************************)
|
|
|
|
(* *)
|
|
|
|
(* Heptagon *)
|
|
|
|
(* *)
|
|
|
|
(* Gwenael Delaval, LIG/INRIA, UJF *)
|
|
|
|
(* Leonard Gerard, Parkas, ENS *)
|
|
|
|
(* Adrien Guatto, Parkas, ENS *)
|
|
|
|
(* Cedric Pasteur, Parkas, ENS *)
|
2012-06-29 01:43:15 +02:00
|
|
|
(* Marc Pouzet, Parkas, ENS *)
|
2012-06-27 18:09:30 +02:00
|
|
|
(* *)
|
|
|
|
(* Copyright 2012 ENS, INRIA, UJF *)
|
|
|
|
(* *)
|
|
|
|
(* This file is part of the Heptagon compiler. *)
|
|
|
|
(* *)
|
|
|
|
(* Heptagon is free software: you can redistribute it and/or modify it *)
|
|
|
|
(* under the terms of the GNU General Public License as published by *)
|
|
|
|
(* the Free Software Foundation, either version 3 of the License, or *)
|
|
|
|
(* (at your option) any later version. *)
|
|
|
|
(* *)
|
|
|
|
(* Heptagon is distributed in the hope that it will be useful, *)
|
|
|
|
(* but WITHOUT ANY WARRANTY; without even the implied warranty of *)
|
|
|
|
(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *)
|
|
|
|
(* GNU General Public License for more details. *)
|
|
|
|
(* *)
|
|
|
|
(* You should have received a copy of the GNU General Public License *)
|
|
|
|
(* along with Heptagon. If not, see <http://www.gnu.org/licenses/> *)
|
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
2010-06-15 10:49:03 +02:00
|
|
|
(* dependences between equations *)
|
|
|
|
|
2011-04-20 14:10:10 +02:00
|
|
|
open Sgraph
|
2010-07-23 19:45:19 +02:00
|
|
|
open Idents
|
2010-06-15 10:49:03 +02:00
|
|
|
|
|
|
|
module type READ =
|
|
|
|
sig
|
|
|
|
type equation
|
|
|
|
val read: equation -> ident list
|
2011-09-07 14:14:59 +02:00
|
|
|
val linear_read : equation -> ident list
|
2010-06-15 10:49:03 +02:00
|
|
|
val def: ident list -> equation -> ident list
|
|
|
|
val antidep: equation -> bool
|
|
|
|
end
|
|
|
|
|
|
|
|
module Make (Read:READ) =
|
|
|
|
struct
|
|
|
|
let build eqs =
|
|
|
|
(* associate a graph node for each name declaration *)
|
2013-11-08 18:51:06 +01:00
|
|
|
let nametograph g var_list is_antidep n_to_graph =
|
2010-06-15 10:49:03 +02:00
|
|
|
let add_node env x =
|
2010-06-26 16:53:25 +02:00
|
|
|
if Env.mem x env then
|
|
|
|
let l = Env.find x env in
|
|
|
|
Env.add x ((g, is_antidep)::l) env
|
|
|
|
else
|
|
|
|
Env.add x [(g, is_antidep)] env
|
2010-06-15 10:49:03 +02:00
|
|
|
in
|
2010-06-26 16:53:25 +02:00
|
|
|
List.fold_left add_node n_to_graph var_list in
|
2010-06-15 10:49:03 +02:00
|
|
|
|
2013-11-08 18:51:06 +01:00
|
|
|
let nametograph_env g var_list node_env =
|
2010-06-15 10:49:03 +02:00
|
|
|
List.fold_left (fun env x -> Env.add x g env) node_env var_list in
|
|
|
|
|
2011-09-07 17:27:58 +02:00
|
|
|
let rec init_graph eqs g_list n_to_graph lin_map node_env =
|
2010-06-15 10:49:03 +02:00
|
|
|
match eqs with
|
2011-09-07 17:27:58 +02:00
|
|
|
| [] -> g_list, n_to_graph, lin_map, node_env
|
2010-06-15 10:49:03 +02:00
|
|
|
| eq :: eqs ->
|
|
|
|
let g = make eq in
|
|
|
|
let node_env = nametograph_env g (Read.def [] eq) node_env in
|
2010-06-26 16:53:25 +02:00
|
|
|
let n_to_graph = nametograph g (Read.def [] eq)
|
2010-06-18 11:53:31 +02:00
|
|
|
(Read.antidep eq) n_to_graph in
|
2011-09-07 17:27:58 +02:00
|
|
|
let lin_map = nametograph g (Read.linear_read eq) true lin_map in
|
|
|
|
init_graph eqs (g :: g_list) n_to_graph lin_map node_env
|
2010-06-15 10:49:03 +02:00
|
|
|
in
|
|
|
|
|
2011-09-07 17:27:58 +02:00
|
|
|
let rec make_graph g_list names_to_graph lin_map =
|
2010-06-15 10:49:03 +02:00
|
|
|
let attach_one node (g, is_antidep) =
|
2010-06-26 16:53:25 +02:00
|
|
|
if is_antidep then
|
|
|
|
add_depends g node
|
|
|
|
else
|
|
|
|
add_depends node g
|
2010-06-15 10:49:03 +02:00
|
|
|
in
|
|
|
|
|
2011-09-07 17:27:58 +02:00
|
|
|
let attach env node n =
|
2010-06-15 10:49:03 +02:00
|
|
|
try
|
2011-09-07 17:27:58 +02:00
|
|
|
let l = Env.find n env in
|
2010-06-26 16:53:25 +02:00
|
|
|
List.iter (attach_one node) l
|
2010-06-15 10:49:03 +02:00
|
|
|
with
|
|
|
|
| Not_found -> () in
|
2010-06-26 16:53:25 +02:00
|
|
|
|
|
|
|
match g_list with
|
|
|
|
| [] -> ()
|
|
|
|
| node :: g_list ->
|
|
|
|
let names = Read.read (containt node) in
|
2011-09-07 17:27:58 +02:00
|
|
|
List.iter (attach names_to_graph node) names;
|
|
|
|
let reads = Misc.list_diff names (Read.linear_read (containt node)) in
|
2011-10-17 15:25:52 +02:00
|
|
|
List.iter (attach lin_map node) reads;
|
2011-09-07 17:27:58 +02:00
|
|
|
make_graph g_list names_to_graph lin_map
|
|
|
|
in
|
2010-06-26 16:53:25 +02:00
|
|
|
|
2011-09-07 17:27:58 +02:00
|
|
|
let g_list, names_to_graph, lin_map, node_env =
|
|
|
|
init_graph eqs [] Env.empty Env.empty Env.empty in
|
|
|
|
make_graph g_list names_to_graph lin_map;
|
2010-06-26 16:53:25 +02:00
|
|
|
g_list, node_env
|
2010-06-15 10:49:03 +02:00
|
|
|
end
|