X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Fcompiler%2Futils%2FDigraph.lhs;h=1544c7b93386c90f15fd4ae646a73bbe99ea8215;hb=d923f167d8a1120c0e918330b44740f8f12b7f45;hp=f09d465bc259cdb65a0d5d40e0365d4e821b8db4;hpb=6c393867f02f2f7482a0431d4abb8d998ef88dc5;p=ghc-hetmet.git diff --git a/ghc/compiler/utils/Digraph.lhs b/ghc/compiler/utils/Digraph.lhs index f09d465..1544c7b 100644 --- a/ghc/compiler/utils/Digraph.lhs +++ b/ghc/compiler/utils/Digraph.lhs @@ -2,7 +2,7 @@ module Digraph( -- At present the only one with a "nice" external interface - stronglyConnComp, stronglyConnCompR, SCC(..), + stronglyConnComp, stronglyConnCompR, SCC(..), flattenSCC, flattenSCCs, Graph, Vertex, graphFromEdges, buildG, transposeG, reverseE, outdegree, indegree, @@ -43,6 +43,7 @@ import ST import Maybe import Array import List +import Outputable \end{code} @@ -56,6 +57,18 @@ import List data SCC vertex = AcyclicSCC vertex | CyclicSCC [vertex] +flattenSCCs :: [SCC a] -> [a] +flattenSCCs = concatMap flattenSCC + +flattenSCC (AcyclicSCC v) = [v] +flattenSCC (CyclicSCC vs) = vs + +instance Outputable a => Outputable (SCC a) where + ppr (AcyclicSCC v) = text "NONREC" $$ (nest 3 (ppr v)) + ppr (CyclicSCC vs) = text "REC" $$ (nest 3 (vcat (map ppr vs))) +\end{code} + +\begin{code} stronglyConnComp :: Ord key => [(node, key, [key])] -- The graph; its ok for the