summaryrefslogtreecommitdiff
path: root/compiler/GHC/Utils
diff options
context:
space:
mode:
authorSylvain Henry <sylvain@haskus.fr>2020-09-18 11:44:44 +0200
committerMarge Bot <ben+marge-bot@smart-cactus.org>2020-09-23 20:43:48 -0400
commit667d63558a694e12974ace723b553950f6080365 (patch)
tree50167bdcff894b1ca9ca96a8ad73fe20a883d245 /compiler/GHC/Utils
parentd7385f7077c6258c2a76ae51b4ea80f6fa9c7015 (diff)
downloadhaskell-667d63558a694e12974ace723b553950f6080365.tar.gz
Refactor CLabel pretty-printing
* Don't depend on the selected backend to know if we print Asm or C labels: we already have PprStyle to determine this. Moreover even when a native backend is used (NCG, LLVM) we may want to C headers containing pretty-printed labels, so it wasn't a good predicate anyway. * Make pretty-printing code clearer and avoid partiality
Diffstat (limited to 'compiler/GHC/Utils')
-rw-r--r--compiler/GHC/Utils/Outputable.hs26
1 files changed, 16 insertions, 10 deletions
diff --git a/compiler/GHC/Utils/Outputable.hs b/compiler/GHC/Utils/Outputable.hs
index abb3e94615..c0537e4dc0 100644
--- a/compiler/GHC/Utils/Outputable.hs
+++ b/compiler/GHC/Utils/Outputable.hs
@@ -51,7 +51,7 @@ module GHC.Utils.Outputable (
-- * Converting 'SDoc' into strings and outputting it
printSDoc, printSDocLn,
bufLeftRenderSDoc,
- pprCode, mkCodeStyle,
+ pprCode,
showSDocOneLine,
renderWithContext,
@@ -68,7 +68,7 @@ module GHC.Utils.Outputable (
-- * Controlling the style in which output is printed
BindingSite(..),
- PprStyle(..), CodeStyle(..), PrintUnqualified(..),
+ PprStyle(..), LabelStyle(..), PrintUnqualified(..),
QueryQualifyName, QueryQualifyModule, QueryQualifyPackage,
reallyAlwaysQualify, reallyAlwaysQualifyNames,
alwaysQualify, alwaysQualifyNames, alwaysQualifyModules,
@@ -150,11 +150,20 @@ data PprStyle
-- Does not assume tidied code: non-external names
-- are printed with uniques.
- | PprCode CodeStyle
- -- Print code; either C or assembler
+ | PprCode LabelStyle -- ^ Print code; either C or assembler
-data CodeStyle = CStyle -- The format of labels differs for C and assembler
- | AsmStyle
+-- | Style of label pretty-printing.
+--
+-- When we produce C sources or headers, we have to take into account that C
+-- compilers transform C labels when they convert them into symbols. For
+-- example, they can add prefixes (e.g., "_" on Darwin) or suffixes (size for
+-- stdcalls on Windows). So we provide two ways to pretty-print CLabels: C style
+-- or Asm style.
+--
+data LabelStyle
+ = CStyle -- ^ C label style (used by C and LLVM backends)
+ | AsmStyle -- ^ Asm label style (used by NCG backend)
+ deriving (Eq,Ord,Show)
data Depth
= AllTheWay
@@ -556,12 +565,9 @@ bufLeftRenderSDoc :: SDocContext -> BufHandle -> SDoc -> IO ()
bufLeftRenderSDoc ctx bufHandle doc =
Pretty.bufLeftRender bufHandle (runSDoc doc ctx)
-pprCode :: CodeStyle -> SDoc -> SDoc
+pprCode :: LabelStyle -> SDoc -> SDoc
pprCode cs d = withPprStyle (PprCode cs) d
-mkCodeStyle :: CodeStyle -> PprStyle
-mkCodeStyle = PprCode
-
renderWithContext :: SDocContext -> SDoc -> String
renderWithContext ctx sdoc
= let s = Pretty.style{ Pretty.mode = PageMode,