diff options
Diffstat (limited to 'compiler/nativeGen/PprBase.hs')
-rw-r--r-- | compiler/nativeGen/PprBase.hs | 52 |
1 files changed, 51 insertions, 1 deletions
diff --git a/compiler/nativeGen/PprBase.hs b/compiler/nativeGen/PprBase.hs index 90a3b303f4..b2e574af4c 100644 --- a/compiler/nativeGen/PprBase.hs +++ b/compiler/nativeGen/PprBase.hs @@ -10,11 +10,19 @@ module PprBase ( castFloatToWord8Array, castDoubleToWord8Array, floatToBytes, - doubleToBytes + doubleToBytes, + pprSectionHeader ) where +import CLabel +import Cmm +import DynFlags +import FastString +import Outputable +import Platform + import qualified Data.Array.Unsafe as U ( castSTUArray ) import Data.Array.ST @@ -70,3 +78,45 @@ doubleToBytes d i7 <- readArray arr 7 return (map fromIntegral [i0,i1,i2,i3,i4,i5,i6,i7]) ) + +-- ---------------------------------------------------------------------------- +-- Printing section headers. +-- +-- If -split-section was specified, include the suffix label, otherwise just +-- print the section type. For Darwin, where subsections-for-symbols are +-- used instead, only print section type. + +pprSectionHeader :: Platform -> Section -> SDoc +pprSectionHeader platform (Section t suffix) = + case platformOS platform of + OSDarwin -> pprDarwinSectionHeader t + _ -> pprGNUSectionHeader t suffix + +pprGNUSectionHeader :: SectionType -> CLabel -> SDoc +pprGNUSectionHeader t suffix = sdocWithDynFlags $ \dflags -> + let splitSections = gopt Opt_SplitSections dflags + subsection | splitSections = char '.' <> ppr suffix + | otherwise = empty + in ptext (sLit ".section ") <> ptext header <> subsection + where + header = case t of + Text -> sLit ".text" + Data -> sLit ".data" + ReadOnlyData -> sLit ".rodata" + RelocatableReadOnlyData -> sLit ".data.rel.ro" + UninitialisedData -> sLit ".bss" + ReadOnlyData16 -> sLit ".rodata.cst16" + OtherSection _ -> + panic "PprBase.pprGNUSectionHeader: unknown section type" + +pprDarwinSectionHeader :: SectionType -> SDoc +pprDarwinSectionHeader t = + ptext $ case t of + Text -> sLit ".text" + Data -> sLit ".data" + ReadOnlyData -> sLit ".const" + RelocatableReadOnlyData -> sLit ".const_data" + UninitialisedData -> sLit ".data" + ReadOnlyData16 -> sLit ".const" + OtherSection _ -> + panic "PprBase.pprDarwinSectionHeader: unknown section type" |