summaryrefslogtreecommitdiff
path: root/compiler/utils
diff options
context:
space:
mode:
authorIan Lynagh <igloo@earth.li>2011-07-15 02:26:24 +0100
committerIan Lynagh <igloo@earth.li>2011-07-15 02:29:34 +0100
commitf07af788f1d8009034332a5c0b659486fa9b4d26 (patch)
tree767f69e46f5bd58ce2822cd815f97c91d0959ba4 /compiler/utils
parent58cc5ed228adce6529eb1e0a849e5d9ca6175524 (diff)
downloadhaskell-f07af788f1d8009034332a5c0b659486fa9b4d26.tar.gz
More work towards cross-compilation
There's now a variant of the Outputable class that knows what platform we're targetting: class PlatformOutputable a where pprPlatform :: Platform -> a -> SDoc pprPlatformPrec :: Platform -> Rational -> a -> SDoc and various instances have had to be converted to use that class, and we pass Platform around accordingly.
Diffstat (limited to 'compiler/utils')
-rw-r--r--compiler/utils/Digraph.lhs3
-rw-r--r--compiler/utils/Outputable.lhs18
2 files changed, 21 insertions, 0 deletions
diff --git a/compiler/utils/Digraph.lhs b/compiler/utils/Digraph.lhs
index a341bdecbc..ec65cded94 100644
--- a/compiler/utils/Digraph.lhs
+++ b/compiler/utils/Digraph.lhs
@@ -164,6 +164,9 @@ 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)))
+instance PlatformOutputable a => PlatformOutputable (SCC a) where
+ pprPlatform platform (AcyclicSCC v) = text "NONREC" $$ (nest 3 (pprPlatform platform v))
+ pprPlatform platform (CyclicSCC vs) = text "REC" $$ (nest 3 (vcat (map (pprPlatform platform) vs)))
\end{code}
%************************************************************************
diff --git a/compiler/utils/Outputable.lhs b/compiler/utils/Outputable.lhs
index 8a0c62a2ed..7f8a3a67ff 100644
--- a/compiler/utils/Outputable.lhs
+++ b/compiler/utils/Outputable.lhs
@@ -13,6 +13,7 @@
module Outputable (
-- * Type classes
Outputable(..), OutputableBndr(..),
+ PlatformOutputable(..),
-- * Pretty printing combinators
SDoc, runSDoc, initSDocContext,
@@ -74,6 +75,7 @@ import {-# SOURCE #-} OccName( OccName )
import StaticFlags
import FastString
import FastTypes
+import Platform
import qualified Pretty
import Pretty ( Doc, Mode(..) )
import Panic
@@ -600,6 +602,13 @@ class Outputable a where
ppr = pprPrec 0
pprPrec _ = ppr
+
+class PlatformOutputable a where
+ pprPlatform :: Platform -> a -> SDoc
+ pprPlatformPrec :: Platform -> Rational -> a -> SDoc
+
+ pprPlatform platform = pprPlatformPrec platform 0
+ pprPlatformPrec platform _ = pprPlatform platform
\end{code}
\begin{code}
@@ -621,12 +630,19 @@ instance Outputable Word where
instance Outputable () where
ppr _ = text "()"
+instance PlatformOutputable () where
+ pprPlatform _ _ = text "()"
instance (Outputable a) => Outputable [a] where
ppr xs = brackets (fsep (punctuate comma (map ppr xs)))
+instance (PlatformOutputable a) => PlatformOutputable [a] where
+ pprPlatform platform xs = brackets (fsep (punctuate comma (map (pprPlatform platform) xs)))
instance (Outputable a, Outputable b) => Outputable (a, b) where
ppr (x,y) = parens (sep [ppr x <> comma, ppr y])
+instance (PlatformOutputable a, PlatformOutputable b) => PlatformOutputable (a, b) where
+ pprPlatform platform (x,y)
+ = parens (sep [pprPlatform platform x <> comma, pprPlatform platform y])
instance Outputable a => Outputable (Maybe a) where
ppr Nothing = ptext (sLit "Nothing")
@@ -687,6 +703,8 @@ instance Outputable FastString where
instance (Outputable key, Outputable elt) => Outputable (M.Map key elt) where
ppr m = ppr (M.toList m)
+instance (PlatformOutputable key, PlatformOutputable elt) => PlatformOutputable (M.Map key elt) where
+ pprPlatform platform m = pprPlatform platform (M.toList m)
instance (Outputable elt) => Outputable (IM.IntMap elt) where
ppr m = ppr (IM.toList m)
\end{code}