-- | Various utilities used in generating assembler.
--
-- These are used not only by the native code generator, but also by the
-- "GHC.Driver.Pipeline"
module GHC.Utils.Asm
    ( sectionType
    ) where

import GHC.Prelude

import GHC.Platform
import GHC.Utils.Outputable

-- | Generate a section type (e.g. @\@progbits@). See #13937.
sectionType :: IsLine doc
            => Platform -- ^ Target platform
            -> String   -- ^ section type
            -> doc      -- ^ pretty assembler fragment
sectionType :: forall doc. IsLine doc => Platform -> String -> doc
sectionType Platform
platform String
ty =
    case Platform -> Arch
platformArch Platform
platform of
      ArchARM{} -> Char -> doc
forall doc. IsLine doc => Char -> doc
char Char
'%' doc -> doc -> doc
forall doc. IsLine doc => doc -> doc -> doc
<> String -> doc
forall doc. IsLine doc => String -> doc
text String
ty
      Arch
_         -> Char -> doc
forall doc. IsLine doc => Char -> doc
char Char
'@' doc -> doc -> doc
forall doc. IsLine doc => doc -> doc -> doc
<> String -> doc
forall doc. IsLine doc => String -> doc
text String
ty