diff options
author | Sylvain Henry <sylvain@haskus.fr> | 2020-03-01 16:37:59 +0100 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2020-03-15 10:57:10 -0400 |
commit | 2e82465fff5851f00449131fdc8bacd3ca95f90f (patch) | |
tree | cb8c8f57b1c1bf9950c514d91286b3a5463778f4 /compiler/GHC/CmmToAsm/Ppr.hs | |
parent | dd6ffe6be742cf3ec98406704fef53ad86cc1560 (diff) | |
download | haskell-2e82465fff5851f00449131fdc8bacd3ca95f90f.tar.gz |
Refactor CmmToAsm (disentangle DynFlags)
This patch disentangles a bit more DynFlags from the native code
generator (CmmToAsm).
In more details:
- add a new NCGConfig datatype in GHC.CmmToAsm.Config which contains the
configuration of a native code generation session
- explicitly pass NCGConfig/Platform arguments when necessary
- as a consequence `sdocWithPlatform` is gone and there are only a few
`sdocWithDynFlags` left
- remove the use of `unsafeGlobalDynFlags` from GHC.CmmToAsm.CFG
- remove `sdocDebugLevel` (now we pass the debug level via NCGConfig)
There are still some places where DynFlags is used, especially because
of pretty-printing (CLabel), because of Cmm helpers (such as
`cmmExprType`) and because of `Outputable` instance for the
instructions. These are left for future refactoring as this patch is
already big.
Diffstat (limited to 'compiler/GHC/CmmToAsm/Ppr.hs')
-rw-r--r-- | compiler/GHC/CmmToAsm/Ppr.hs | 44 |
1 files changed, 23 insertions, 21 deletions
diff --git a/compiler/GHC/CmmToAsm/Ppr.hs b/compiler/GHC/CmmToAsm/Ppr.hs index 636d2e4e3a..324bad63c4 100644 --- a/compiler/GHC/CmmToAsm/Ppr.hs +++ b/compiler/GHC/CmmToAsm/Ppr.hs @@ -25,6 +25,7 @@ import GhcPrelude import AsmUtils import GHC.Cmm.CLabel import GHC.Cmm +import GHC.CmmToAsm.Config import GHC.Driver.Session import FastString import Outputable @@ -203,48 +204,49 @@ string in source code. See #14741 for profiling results. -- identical strings in the linker. With -split-sections each string also gets -- a unique section to allow strings from unused code to be GC'd. -pprSectionHeader :: Platform -> Section -> SDoc -pprSectionHeader platform (Section t suffix) = - case platformOS platform of +pprSectionHeader :: NCGConfig -> Section -> SDoc +pprSectionHeader config (Section t suffix) = + case platformOS (ncgPlatform config) of OSAIX -> pprXcoffSectionHeader t OSDarwin -> pprDarwinSectionHeader t - OSMinGW32 -> pprGNUSectionHeader (char '$') t suffix - _ -> pprGNUSectionHeader (char '.') t suffix - -pprGNUSectionHeader :: SDoc -> SectionType -> CLabel -> SDoc -pprGNUSectionHeader sep t suffix = sdocWithDynFlags $ \dflags -> - let splitSections = gopt Opt_SplitSections dflags - subsection | splitSections = sep <> ppr suffix - | otherwise = empty - in text ".section " <> ptext (header dflags) <> subsection <> - flags dflags + OSMinGW32 -> pprGNUSectionHeader config (char '$') t suffix + _ -> pprGNUSectionHeader config (char '.') t suffix + +pprGNUSectionHeader :: NCGConfig -> SDoc -> SectionType -> CLabel -> SDoc +pprGNUSectionHeader config sep t suffix = + text ".section " <> ptext header <> subsection <> flags where - header dflags = case t of + platform = ncgPlatform config + splitSections = ncgSplitSections config + subsection + | splitSections = sep <> ppr suffix + | otherwise = empty + header = case t of Text -> sLit ".text" Data -> sLit ".data" - ReadOnlyData | OSMinGW32 <- platformOS (targetPlatform dflags) + ReadOnlyData | OSMinGW32 <- platformOS platform -> sLit ".rdata" | otherwise -> sLit ".rodata" - RelocatableReadOnlyData | OSMinGW32 <- platformOS (targetPlatform dflags) + RelocatableReadOnlyData | OSMinGW32 <- platformOS platform -- Concept does not exist on Windows, -- So map these to R/O data. -> sLit ".rdata$rel.ro" | otherwise -> sLit ".data.rel.ro" UninitialisedData -> sLit ".bss" - ReadOnlyData16 | OSMinGW32 <- platformOS (targetPlatform dflags) + ReadOnlyData16 | OSMinGW32 <- platformOS platform -> sLit ".rdata$cst16" | otherwise -> sLit ".rodata.cst16" CString - | OSMinGW32 <- platformOS (targetPlatform dflags) + | OSMinGW32 <- platformOS platform -> sLit ".rdata" | otherwise -> sLit ".rodata.str" OtherSection _ -> panic "PprBase.pprGNUSectionHeader: unknown section type" - flags dflags = case t of + flags = case t of CString - | OSMinGW32 <- platformOS (targetPlatform dflags) + | OSMinGW32 <- platformOS platform -> empty - | otherwise -> text ",\"aMS\"," <> sectionType "progbits" <> text ",1" + | otherwise -> text ",\"aMS\"," <> sectionType platform "progbits" <> text ",1" _ -> empty -- XCOFF doesn't support relocating label-differences, so we place all |