[project @ 2002-10-02 09:36:00 by wolfgang]
[ghc-hetmet.git] / ghc / compiler / utils / Digraph.lhs
index df34dde..d8f6220 100644 (file)
@@ -37,12 +37,19 @@ module Digraph(
 import Util    ( sortLt )
 
 -- Extensions
-import ST
+import MONAD_ST
 
 -- std interfaces
 import Maybe
 import Array
 import List
+import Outputable
+
+#if __GLASGOW_HASKELL__ >= 504
+import Data.Array.ST  hiding ( indices, bounds )
+#else
+import ST
+#endif
 \end{code}
 
 
@@ -61,6 +68,10 @@ 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}
@@ -84,7 +95,7 @@ stronglyConnCompR
        => [(node, key, [key])]         -- The graph; its ok for the
                                        -- out-list to contain keys which arent
                                        -- a vertex key, they are ignored
-       -> [SCC (node, key, [key])]
+       -> [SCC (node, key, [key])]     -- Topologically sorted
 
 stronglyConnCompR [] = []  -- added to avoid creating empty array in graphFromEdges -- SOF
 stronglyConnCompR edges
@@ -206,7 +217,7 @@ drawTree         = unlines . draw
 draw (Node x ts) = grp this (space (length this)) (stLoop ts)
  where this          = s1 ++ x ++ " "
 
-       space n       = take n (repeat ' ')
+       space n       = replicate n ' '
 
        stLoop []     = [""]
        stLoop [t]    = grp s2 "  " (draw t)
@@ -228,6 +239,17 @@ draw (Node x ts) = grp this (space (length this)) (stLoop ts)
 %************************************************************************
 
 \begin{code}
+#if __GLASGOW_HASKELL__ >= 504
+newSTArray :: Ix i => (i,i) -> e -> ST s (STArray s i e)
+newSTArray = newArray
+
+readSTArray :: Ix i => STArray s i e -> i -> ST s e
+readSTArray = readArray
+
+writeSTArray :: Ix i => STArray s i e -> i -> e -> ST s ()
+writeSTArray = writeArray
+#endif
+
 type Set s    = STArray s Vertex Bool
 
 mkEmpty      :: Bounds -> ST s (Set s)