-----------------------------------------------------------------------------
--
-- Object-file symbols (called CLabel for histerical raisins).
--
-- (c) The University of Glasgow 2004-2006
--
-----------------------------------------------------------------------------

{-# LANGUAGE CPP #-}

module CLabel (
        CLabel, -- abstract type
        ForeignLabelSource(..),
        pprDebugCLabel,

        mkClosureLabel,
        mkSRTLabel,
        mkInfoTableLabel,
        mkEntryLabel,
        mkRednCountsLabel,
        mkConInfoTableLabel,
        mkApEntryLabel,
        mkApInfoTableLabel,
        mkClosureTableLabel,
        mkBytesLabel,

        mkLocalBlockLabel,
        mkLocalClosureLabel,
        mkLocalInfoTableLabel,
        mkLocalClosureTableLabel,

        mkBlockInfoTableLabel,

        mkBitmapLabel,
        mkStringLitLabel,

        mkAsmTempLabel,
        mkAsmTempDerivedLabel,
        mkAsmTempEndLabel,
        mkAsmTempDieLabel,

        mkSplitMarkerLabel,
        mkDirty_MUT_VAR_Label,
        mkUpdInfoLabel,
        mkBHUpdInfoLabel,
        mkIndStaticInfoLabel,
        mkMainCapabilityLabel,
        mkMAP_FROZEN_CLEAN_infoLabel,
        mkMAP_FROZEN_DIRTY_infoLabel,
        mkMAP_DIRTY_infoLabel,
        mkSMAP_FROZEN_CLEAN_infoLabel,
        mkSMAP_FROZEN_DIRTY_infoLabel,
        mkSMAP_DIRTY_infoLabel,
        mkBadAlignmentLabel,
        mkArrWords_infoLabel,
        mkSRTInfoLabel,

        mkTopTickyCtrLabel,
        mkCAFBlackHoleInfoTableLabel,
        mkRtsPrimOpLabel,
        mkRtsSlowFastTickyCtrLabel,

        mkSelectorInfoLabel,
        mkSelectorEntryLabel,

        mkCmmInfoLabel,
        mkCmmEntryLabel,
        mkCmmRetInfoLabel,
        mkCmmRetLabel,
        mkCmmCodeLabel,
        mkCmmDataLabel,
        mkCmmClosureLabel,

        mkRtsApFastLabel,

        mkPrimCallLabel,

        mkForeignLabel,
        addLabelSize,

        foreignLabelStdcallInfo,
        isBytesLabel,
        isForeignLabel,
        isSomeRODataLabel,
        isStaticClosureLabel,
        mkCCLabel, mkCCSLabel,

        DynamicLinkerLabelInfo(..),
        mkDynamicLinkerLabel,
        dynamicLinkerLabelInfo,

        mkPicBaseLabel,
        mkDeadStripPreventer,

        mkHpcTicksLabel,

        -- * Predicates
        hasCAF,
        needsCDecl, maybeLocalBlockLabel, externallyVisibleCLabel,
        isMathFun,
        isCFunctionLabel, isGcPtrLabel, labelDynamic,
        isLocalCLabel,

        -- * Conversions
        toClosureLbl, toSlowEntryLbl, toEntryLbl, toInfoLbl, hasHaskellName,

        pprCLabel,
        isInfoTableLabel,
        isConInfoTableLabel
    ) where

#include "HsVersions.h"

import GhcPrelude

import IdInfo
import BasicTypes
import {-# SOURCE #-} BlockId (BlockId, mkBlockId)
import Packages
import Module
import Name
import Unique
import PrimOp
import Config
import CostCentre
import Outputable
import FastString
import DynFlags
import Platform
import UniqSet
import Util
import PprCore ( {- instances -} )

-- -----------------------------------------------------------------------------
-- The CLabel type

{- |
  'CLabel' is an abstract type that supports the following operations:

  - Pretty printing

  - In a C file, does it need to be declared before use?  (i.e. is it
    guaranteed to be already in scope in the places we need to refer to it?)

  - If it needs to be declared, what type (code or data) should it be
    declared to have?

  - Is it visible outside this object file or not?

  - Is it "dynamic" (see details below)

  - Eq and Ord, so that we can make sets of CLabels (currently only
    used in outputting C as far as I can tell, to avoid generating
    more than one declaration for any given label).

  - Converting an info table label into an entry label.

  CLabel usage is a bit messy in GHC as they are used in a number of different
  contexts:

  - By the C-- AST to identify labels

  - By the unregisterised C code generator ("PprC") for naming functions (hence
    the name 'CLabel')

  - By the native and LLVM code generators to identify labels

  For extra fun, each of these uses a slightly different subset of constructors
  (e.g. 'AsmTempLabel' and 'AsmTempDerivedLabel' are used only in the NCG and
  LLVM backends).

  In general, we use 'IdLabel' to represent Haskell things early in the
  pipeline. However, later optimization passes will often represent blocks they
  create with 'LocalBlockLabel' where there is no obvious 'Name' to hang off the
  label.
-}

data CLabel
  = -- | A label related to the definition of a particular Id or Con in a .hs file.
    IdLabel
        Name
        CafInfo
        IdLabelInfo             -- encodes the suffix of the label

  -- | A label from a .cmm file that is not associated with a .hs level Id.
  | CmmLabel
        UnitId               -- what package the label belongs to.
        FastString              -- identifier giving the prefix of the label
        CmmLabelInfo            -- encodes the suffix of the label

  -- | A label with a baked-in \/ algorithmically generated name that definitely
  --    comes from the RTS. The code for it must compile into libHSrts.a \/ libHSrts.so
  --    If it doesn't have an algorithmically generated name then use a CmmLabel
  --    instead and give it an appropriate UnitId argument.
  | RtsLabel
        RtsLabelInfo

  -- | A label associated with a block. These aren't visible outside of the
  -- compilation unit in which they are defined. These are generally used to
  -- name blocks produced by Cmm-to-Cmm passes and the native code generator,
  -- where we don't have a 'Name' to associate the label to and therefore can't
  -- use 'IdLabel'.
  | LocalBlockLabel
        {-# UNPACK #-} !Unique

  -- | A 'C' (or otherwise foreign) label.
  --
  | ForeignLabel
        FastString              -- name of the imported label.

        (Maybe Int)             -- possible '@n' suffix for stdcall functions
                                -- When generating C, the '@n' suffix is omitted, but when
                                -- generating assembler we must add it to the label.

        ForeignLabelSource      -- what package the foreign label is in.

        FunctionOrData

  -- | Local temporary label used for native (or LLVM) code generation; must not
  -- appear outside of these contexts. Use primarily for debug information
  | AsmTempLabel
        {-# UNPACK #-} !Unique

  -- | A label \"derived\" from another 'CLabel' by the addition of a suffix.
  -- Must not occur outside of the NCG or LLVM code generators.
  | AsmTempDerivedLabel
        CLabel
        FastString              -- suffix

  | StringLitLabel
        {-# UNPACK #-} !Unique

  | CC_Label  CostCentre
  | CCS_Label CostCentreStack


  -- | These labels are generated and used inside the NCG only.
  --    They are special variants of a label used for dynamic linking
  --    see module PositionIndependentCode for details.
  | DynamicLinkerLabel DynamicLinkerLabelInfo CLabel

  -- | This label is generated and used inside the NCG only.
  --    It is used as a base for PIC calculations on some platforms.
  --    It takes the form of a local numeric assembler label '1'; and
  --    is pretty-printed as 1b, referring to the previous definition
  --    of 1: in the assembler source file.
  | PicBaseLabel

  -- | A label before an info table to prevent excessive dead-stripping on darwin
  | DeadStripPreventer CLabel


  -- | Per-module table of tick locations
  | HpcTicksLabel Module

  -- | Static reference table
  | SRTLabel
        {-# UNPACK #-} !Unique

  -- | A bitmap (function or case return)
  | LargeBitmapLabel
        {-# UNPACK #-} !Unique

  deriving CLabel -> CLabel -> Bool
(CLabel -> CLabel -> Bool)
-> (CLabel -> CLabel -> Bool) -> Eq CLabel
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CLabel -> CLabel -> Bool
$c/= :: CLabel -> CLabel -> Bool
== :: CLabel -> CLabel -> Bool
$c== :: CLabel -> CLabel -> Bool
Eq

-- This is laborious, but necessary. We can't derive Ord because
-- Unique doesn't have an Ord instance. Note nonDetCmpUnique in the
-- implementation. See Note [No Ord for Unique]
-- This is non-deterministic but we do not currently support deterministic
-- code-generation. See Note [Unique Determinism and code generation]
instance Ord CLabel where
  compare :: CLabel -> CLabel -> Ordering
compare (IdLabel a1 :: Name
a1 b1 :: CafInfo
b1 c1 :: IdLabelInfo
c1) (IdLabel a2 :: Name
a2 b2 :: CafInfo
b2 c2 :: IdLabelInfo
c2) =
    Name -> Name -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Name
a1 Name
a2 Ordering -> Ordering -> Ordering
`thenCmp`
    CafInfo -> CafInfo -> Ordering
forall a. Ord a => a -> a -> Ordering
compare CafInfo
b1 CafInfo
b2 Ordering -> Ordering -> Ordering
`thenCmp`
    IdLabelInfo -> IdLabelInfo -> Ordering
forall a. Ord a => a -> a -> Ordering
compare IdLabelInfo
c1 IdLabelInfo
c2
  compare (CmmLabel a1 :: UnitId
a1 b1 :: FastString
b1 c1 :: CmmLabelInfo
c1) (CmmLabel a2 :: UnitId
a2 b2 :: FastString
b2 c2 :: CmmLabelInfo
c2) =
    UnitId -> UnitId -> Ordering
forall a. Ord a => a -> a -> Ordering
compare UnitId
a1 UnitId
a2 Ordering -> Ordering -> Ordering
`thenCmp`
    FastString -> FastString -> Ordering
forall a. Ord a => a -> a -> Ordering
compare FastString
b1 FastString
b2 Ordering -> Ordering -> Ordering
`thenCmp`
    CmmLabelInfo -> CmmLabelInfo -> Ordering
forall a. Ord a => a -> a -> Ordering
compare CmmLabelInfo
c1 CmmLabelInfo
c2
  compare (RtsLabel a1 :: RtsLabelInfo
a1) (RtsLabel a2 :: RtsLabelInfo
a2) = RtsLabelInfo -> RtsLabelInfo -> Ordering
forall a. Ord a => a -> a -> Ordering
compare RtsLabelInfo
a1 RtsLabelInfo
a2
  compare (LocalBlockLabel u1 :: Unique
u1) (LocalBlockLabel u2 :: Unique
u2) = Unique -> Unique -> Ordering
nonDetCmpUnique Unique
u1 Unique
u2
  compare (ForeignLabel a1 :: FastString
a1 b1 :: Maybe Int
b1 c1 :: ForeignLabelSource
c1 d1 :: FunctionOrData
d1) (ForeignLabel a2 :: FastString
a2 b2 :: Maybe Int
b2 c2 :: ForeignLabelSource
c2 d2 :: FunctionOrData
d2) =
    FastString -> FastString -> Ordering
forall a. Ord a => a -> a -> Ordering
compare FastString
a1 FastString
a2 Ordering -> Ordering -> Ordering
`thenCmp`
    Maybe Int -> Maybe Int -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Maybe Int
b1 Maybe Int
b2 Ordering -> Ordering -> Ordering
`thenCmp`
    ForeignLabelSource -> ForeignLabelSource -> Ordering
forall a. Ord a => a -> a -> Ordering
compare ForeignLabelSource
c1 ForeignLabelSource
c2 Ordering -> Ordering -> Ordering
`thenCmp`
    FunctionOrData -> FunctionOrData -> Ordering
forall a. Ord a => a -> a -> Ordering
compare FunctionOrData
d1 FunctionOrData
d2
  compare (AsmTempLabel u1 :: Unique
u1) (AsmTempLabel u2 :: Unique
u2) = Unique -> Unique -> Ordering
nonDetCmpUnique Unique
u1 Unique
u2
  compare (AsmTempDerivedLabel a1 :: CLabel
a1 b1 :: FastString
b1) (AsmTempDerivedLabel a2 :: CLabel
a2 b2 :: FastString
b2) =
    CLabel -> CLabel -> Ordering
forall a. Ord a => a -> a -> Ordering
compare CLabel
a1 CLabel
a2 Ordering -> Ordering -> Ordering
`thenCmp`
    FastString -> FastString -> Ordering
forall a. Ord a => a -> a -> Ordering
compare FastString
b1 FastString
b2
  compare (StringLitLabel u1 :: Unique
u1) (StringLitLabel u2 :: Unique
u2) =
    Unique -> Unique -> Ordering
nonDetCmpUnique Unique
u1 Unique
u2
  compare (CC_Label a1 :: CostCentre
a1) (CC_Label a2 :: CostCentre
a2) =
    CostCentre -> CostCentre -> Ordering
forall a. Ord a => a -> a -> Ordering
compare CostCentre
a1 CostCentre
a2
  compare (CCS_Label a1 :: CostCentreStack
a1) (CCS_Label a2 :: CostCentreStack
a2) =
    CostCentreStack -> CostCentreStack -> Ordering
forall a. Ord a => a -> a -> Ordering
compare CostCentreStack
a1 CostCentreStack
a2
  compare (DynamicLinkerLabel a1 :: DynamicLinkerLabelInfo
a1 b1 :: CLabel
b1) (DynamicLinkerLabel a2 :: DynamicLinkerLabelInfo
a2 b2 :: CLabel
b2) =
    DynamicLinkerLabelInfo -> DynamicLinkerLabelInfo -> Ordering
forall a. Ord a => a -> a -> Ordering
compare DynamicLinkerLabelInfo
a1 DynamicLinkerLabelInfo
a2 Ordering -> Ordering -> Ordering
`thenCmp`
    CLabel -> CLabel -> Ordering
forall a. Ord a => a -> a -> Ordering
compare CLabel
b1 CLabel
b2
  compare PicBaseLabel PicBaseLabel = Ordering
EQ
  compare (DeadStripPreventer a1 :: CLabel
a1) (DeadStripPreventer a2 :: CLabel
a2) =
    CLabel -> CLabel -> Ordering
forall a. Ord a => a -> a -> Ordering
compare CLabel
a1 CLabel
a2
  compare (HpcTicksLabel a1 :: Module
a1) (HpcTicksLabel a2 :: Module
a2) =
    Module -> Module -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Module
a1 Module
a2
  compare (SRTLabel u1 :: Unique
u1) (SRTLabel u2 :: Unique
u2) =
    Unique -> Unique -> Ordering
nonDetCmpUnique Unique
u1 Unique
u2
  compare (LargeBitmapLabel u1 :: Unique
u1) (LargeBitmapLabel u2 :: Unique
u2) =
    Unique -> Unique -> Ordering
nonDetCmpUnique Unique
u1 Unique
u2
  compare IdLabel{} _ = Ordering
LT
  compare _ IdLabel{} = Ordering
GT
  compare CmmLabel{} _ = Ordering
LT
  compare _ CmmLabel{} = Ordering
GT
  compare RtsLabel{} _ = Ordering
LT
  compare _ RtsLabel{} = Ordering
GT
  compare LocalBlockLabel{} _ = Ordering
LT
  compare _ LocalBlockLabel{} = Ordering
GT
  compare ForeignLabel{} _ = Ordering
LT
  compare _ ForeignLabel{} = Ordering
GT
  compare AsmTempLabel{} _ = Ordering
LT
  compare _ AsmTempLabel{} = Ordering
GT
  compare AsmTempDerivedLabel{} _ = Ordering
LT
  compare _ AsmTempDerivedLabel{} = Ordering
GT
  compare StringLitLabel{} _ = Ordering
LT
  compare _ StringLitLabel{} = Ordering
GT
  compare CC_Label{} _ = Ordering
LT
  compare _ CC_Label{} = Ordering
GT
  compare CCS_Label{} _ = Ordering
LT
  compare _ CCS_Label{} = Ordering
GT
  compare DynamicLinkerLabel{} _ = Ordering
LT
  compare _ DynamicLinkerLabel{} = Ordering
GT
  compare PicBaseLabel{} _ = Ordering
LT
  compare _ PicBaseLabel{} = Ordering
GT
  compare DeadStripPreventer{} _ = Ordering
LT
  compare _ DeadStripPreventer{} = Ordering
GT
  compare HpcTicksLabel{} _ = Ordering
LT
  compare _ HpcTicksLabel{} = Ordering
GT
  compare SRTLabel{} _ = Ordering
LT
  compare _ SRTLabel{} = Ordering
GT

-- | Record where a foreign label is stored.
data ForeignLabelSource

   -- | Label is in a named package
   = ForeignLabelInPackage      UnitId

   -- | Label is in some external, system package that doesn't also
   --   contain compiled Haskell code, and is not associated with any .hi files.
   --   We don't have to worry about Haskell code being inlined from
   --   external packages. It is safe to treat the RTS package as "external".
   | ForeignLabelInExternalPackage

   -- | Label is in the package currenly being compiled.
   --   This is only used for creating hacky tmp labels during code generation.
   --   Don't use it in any code that might be inlined across a package boundary
   --   (ie, core code) else the information will be wrong relative to the
   --   destination module.
   | ForeignLabelInThisPackage

   deriving (ForeignLabelSource -> ForeignLabelSource -> Bool
(ForeignLabelSource -> ForeignLabelSource -> Bool)
-> (ForeignLabelSource -> ForeignLabelSource -> Bool)
-> Eq ForeignLabelSource
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ForeignLabelSource -> ForeignLabelSource -> Bool
$c/= :: ForeignLabelSource -> ForeignLabelSource -> Bool
== :: ForeignLabelSource -> ForeignLabelSource -> Bool
$c== :: ForeignLabelSource -> ForeignLabelSource -> Bool
Eq, Eq ForeignLabelSource
Eq ForeignLabelSource =>
(ForeignLabelSource -> ForeignLabelSource -> Ordering)
-> (ForeignLabelSource -> ForeignLabelSource -> Bool)
-> (ForeignLabelSource -> ForeignLabelSource -> Bool)
-> (ForeignLabelSource -> ForeignLabelSource -> Bool)
-> (ForeignLabelSource -> ForeignLabelSource -> Bool)
-> (ForeignLabelSource -> ForeignLabelSource -> ForeignLabelSource)
-> (ForeignLabelSource -> ForeignLabelSource -> ForeignLabelSource)
-> Ord ForeignLabelSource
ForeignLabelSource -> ForeignLabelSource -> Bool
ForeignLabelSource -> ForeignLabelSource -> Ordering
ForeignLabelSource -> ForeignLabelSource -> ForeignLabelSource
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: ForeignLabelSource -> ForeignLabelSource -> ForeignLabelSource
$cmin :: ForeignLabelSource -> ForeignLabelSource -> ForeignLabelSource
max :: ForeignLabelSource -> ForeignLabelSource -> ForeignLabelSource
$cmax :: ForeignLabelSource -> ForeignLabelSource -> ForeignLabelSource
>= :: ForeignLabelSource -> ForeignLabelSource -> Bool
$c>= :: ForeignLabelSource -> ForeignLabelSource -> Bool
> :: ForeignLabelSource -> ForeignLabelSource -> Bool
$c> :: ForeignLabelSource -> ForeignLabelSource -> Bool
<= :: ForeignLabelSource -> ForeignLabelSource -> Bool
$c<= :: ForeignLabelSource -> ForeignLabelSource -> Bool
< :: ForeignLabelSource -> ForeignLabelSource -> Bool
$c< :: ForeignLabelSource -> ForeignLabelSource -> Bool
compare :: ForeignLabelSource -> ForeignLabelSource -> Ordering
$ccompare :: ForeignLabelSource -> ForeignLabelSource -> Ordering
$cp1Ord :: Eq ForeignLabelSource
Ord)


-- | For debugging problems with the CLabel representation.
--      We can't make a Show instance for CLabel because lots of its components don't have instances.
--      The regular Outputable instance only shows the label name, and not its other info.
--
pprDebugCLabel :: CLabel -> SDoc
pprDebugCLabel :: CLabel -> SDoc
pprDebugCLabel lbl :: CLabel
lbl
 = case CLabel
lbl of
        IdLabel _ _ info :: IdLabelInfo
info-> CLabel -> SDoc
forall a. Outputable a => a -> SDoc
ppr CLabel
lbl SDoc -> SDoc -> SDoc
<> (SDoc -> SDoc
parens (SDoc -> SDoc) -> SDoc -> SDoc
forall a b. (a -> b) -> a -> b
$ String -> SDoc
text "IdLabel"
                                       SDoc -> SDoc -> SDoc
<> SDoc -> SDoc
whenPprDebug (String -> SDoc
text ":" SDoc -> SDoc -> SDoc
<> String -> SDoc
text (IdLabelInfo -> String
forall a. Show a => a -> String
show IdLabelInfo
info)))
        CmmLabel pkg :: UnitId
pkg _name :: FastString
_name _info :: CmmLabelInfo
_info
         -> CLabel -> SDoc
forall a. Outputable a => a -> SDoc
ppr CLabel
lbl SDoc -> SDoc -> SDoc
<> (SDoc -> SDoc
parens (SDoc -> SDoc) -> SDoc -> SDoc
forall a b. (a -> b) -> a -> b
$ String -> SDoc
text "CmmLabel" SDoc -> SDoc -> SDoc
<+> UnitId -> SDoc
forall a. Outputable a => a -> SDoc
ppr UnitId
pkg)

        RtsLabel{}      -> CLabel -> SDoc
forall a. Outputable a => a -> SDoc
ppr CLabel
lbl SDoc -> SDoc -> SDoc
<> (SDoc -> SDoc
parens (SDoc -> SDoc) -> SDoc -> SDoc
forall a b. (a -> b) -> a -> b
$ String -> SDoc
text "RtsLabel")

        ForeignLabel _name :: FastString
_name mSuffix :: Maybe Int
mSuffix src :: ForeignLabelSource
src funOrData :: FunctionOrData
funOrData
            -> CLabel -> SDoc
forall a. Outputable a => a -> SDoc
ppr CLabel
lbl SDoc -> SDoc -> SDoc
<> (SDoc -> SDoc
parens (SDoc -> SDoc) -> SDoc -> SDoc
forall a b. (a -> b) -> a -> b
$ String -> SDoc
text "ForeignLabel"
                                SDoc -> SDoc -> SDoc
<+> Maybe Int -> SDoc
forall a. Outputable a => a -> SDoc
ppr Maybe Int
mSuffix
                                SDoc -> SDoc -> SDoc
<+> ForeignLabelSource -> SDoc
forall a. Outputable a => a -> SDoc
ppr ForeignLabelSource
src
                                SDoc -> SDoc -> SDoc
<+> FunctionOrData -> SDoc
forall a. Outputable a => a -> SDoc
ppr FunctionOrData
funOrData)

        _               -> CLabel -> SDoc
forall a. Outputable a => a -> SDoc
ppr CLabel
lbl SDoc -> SDoc -> SDoc
<> (SDoc -> SDoc
parens (SDoc -> SDoc) -> SDoc -> SDoc
forall a b. (a -> b) -> a -> b
$ String -> SDoc
text "other CLabel")


data IdLabelInfo
  = Closure             -- ^ Label for closure
  | InfoTable           -- ^ Info tables for closures; always read-only
  | Entry               -- ^ Entry point
  | Slow                -- ^ Slow entry point

  | LocalInfoTable      -- ^ Like InfoTable but not externally visible
  | LocalEntry          -- ^ Like Entry but not externally visible

  | RednCounts          -- ^ Label of place to keep Ticky-ticky  info for this Id

  | ConEntry            -- ^ Constructor entry point
  | ConInfoTable        -- ^ Corresponding info table

  | ClosureTable        -- ^ Table of closures for Enum tycons

  | Bytes               -- ^ Content of a string literal. See
                        -- Note [Bytes label].
  | BlockInfoTable      -- ^ Like LocalInfoTable but for a proc-point block
                        -- instead of a closure entry-point.
                        -- See Note [Proc-point local block entry-point].

  deriving (IdLabelInfo -> IdLabelInfo -> Bool
(IdLabelInfo -> IdLabelInfo -> Bool)
-> (IdLabelInfo -> IdLabelInfo -> Bool) -> Eq IdLabelInfo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: IdLabelInfo -> IdLabelInfo -> Bool
$c/= :: IdLabelInfo -> IdLabelInfo -> Bool
== :: IdLabelInfo -> IdLabelInfo -> Bool
$c== :: IdLabelInfo -> IdLabelInfo -> Bool
Eq, Eq IdLabelInfo
Eq IdLabelInfo =>
(IdLabelInfo -> IdLabelInfo -> Ordering)
-> (IdLabelInfo -> IdLabelInfo -> Bool)
-> (IdLabelInfo -> IdLabelInfo -> Bool)
-> (IdLabelInfo -> IdLabelInfo -> Bool)
-> (IdLabelInfo -> IdLabelInfo -> Bool)
-> (IdLabelInfo -> IdLabelInfo -> IdLabelInfo)
-> (IdLabelInfo -> IdLabelInfo -> IdLabelInfo)
-> Ord IdLabelInfo
IdLabelInfo -> IdLabelInfo -> Bool
IdLabelInfo -> IdLabelInfo -> Ordering
IdLabelInfo -> IdLabelInfo -> IdLabelInfo
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: IdLabelInfo -> IdLabelInfo -> IdLabelInfo
$cmin :: IdLabelInfo -> IdLabelInfo -> IdLabelInfo
max :: IdLabelInfo -> IdLabelInfo -> IdLabelInfo
$cmax :: IdLabelInfo -> IdLabelInfo -> IdLabelInfo
>= :: IdLabelInfo -> IdLabelInfo -> Bool
$c>= :: IdLabelInfo -> IdLabelInfo -> Bool
> :: IdLabelInfo -> IdLabelInfo -> Bool
$c> :: IdLabelInfo -> IdLabelInfo -> Bool
<= :: IdLabelInfo -> IdLabelInfo -> Bool
$c<= :: IdLabelInfo -> IdLabelInfo -> Bool
< :: IdLabelInfo -> IdLabelInfo -> Bool
$c< :: IdLabelInfo -> IdLabelInfo -> Bool
compare :: IdLabelInfo -> IdLabelInfo -> Ordering
$ccompare :: IdLabelInfo -> IdLabelInfo -> Ordering
$cp1Ord :: Eq IdLabelInfo
Ord, Int -> IdLabelInfo -> ShowS
[IdLabelInfo] -> ShowS
IdLabelInfo -> String
(Int -> IdLabelInfo -> ShowS)
-> (IdLabelInfo -> String)
-> ([IdLabelInfo] -> ShowS)
-> Show IdLabelInfo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [IdLabelInfo] -> ShowS
$cshowList :: [IdLabelInfo] -> ShowS
show :: IdLabelInfo -> String
$cshow :: IdLabelInfo -> String
showsPrec :: Int -> IdLabelInfo -> ShowS
$cshowsPrec :: Int -> IdLabelInfo -> ShowS
Show)


data RtsLabelInfo
  = RtsSelectorInfoTable Bool{-updatable-} Int{-offset-}  -- ^ Selector thunks
  | RtsSelectorEntry     Bool{-updatable-} Int{-offset-}

  | RtsApInfoTable       Bool{-updatable-} Int{-arity-}    -- ^ AP thunks
  | RtsApEntry           Bool{-updatable-} Int{-arity-}

  | RtsPrimOp PrimOp
  | RtsApFast     FastString    -- ^ _fast versions of generic apply
  | RtsSlowFastTickyCtr String

  deriving (RtsLabelInfo -> RtsLabelInfo -> Bool
(RtsLabelInfo -> RtsLabelInfo -> Bool)
-> (RtsLabelInfo -> RtsLabelInfo -> Bool) -> Eq RtsLabelInfo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RtsLabelInfo -> RtsLabelInfo -> Bool
$c/= :: RtsLabelInfo -> RtsLabelInfo -> Bool
== :: RtsLabelInfo -> RtsLabelInfo -> Bool
$c== :: RtsLabelInfo -> RtsLabelInfo -> Bool
Eq, Eq RtsLabelInfo
Eq RtsLabelInfo =>
(RtsLabelInfo -> RtsLabelInfo -> Ordering)
-> (RtsLabelInfo -> RtsLabelInfo -> Bool)
-> (RtsLabelInfo -> RtsLabelInfo -> Bool)
-> (RtsLabelInfo -> RtsLabelInfo -> Bool)
-> (RtsLabelInfo -> RtsLabelInfo -> Bool)
-> (RtsLabelInfo -> RtsLabelInfo -> RtsLabelInfo)
-> (RtsLabelInfo -> RtsLabelInfo -> RtsLabelInfo)
-> Ord RtsLabelInfo
RtsLabelInfo -> RtsLabelInfo -> Bool
RtsLabelInfo -> RtsLabelInfo -> Ordering
RtsLabelInfo -> RtsLabelInfo -> RtsLabelInfo
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: RtsLabelInfo -> RtsLabelInfo -> RtsLabelInfo
$cmin :: RtsLabelInfo -> RtsLabelInfo -> RtsLabelInfo
max :: RtsLabelInfo -> RtsLabelInfo -> RtsLabelInfo
$cmax :: RtsLabelInfo -> RtsLabelInfo -> RtsLabelInfo
>= :: RtsLabelInfo -> RtsLabelInfo -> Bool
$c>= :: RtsLabelInfo -> RtsLabelInfo -> Bool
> :: RtsLabelInfo -> RtsLabelInfo -> Bool
$c> :: RtsLabelInfo -> RtsLabelInfo -> Bool
<= :: RtsLabelInfo -> RtsLabelInfo -> Bool
$c<= :: RtsLabelInfo -> RtsLabelInfo -> Bool
< :: RtsLabelInfo -> RtsLabelInfo -> Bool
$c< :: RtsLabelInfo -> RtsLabelInfo -> Bool
compare :: RtsLabelInfo -> RtsLabelInfo -> Ordering
$ccompare :: RtsLabelInfo -> RtsLabelInfo -> Ordering
$cp1Ord :: Eq RtsLabelInfo
Ord)
  -- NOTE: Eq on PtrString compares the pointer only, so this isn't
  -- a real equality.


-- | What type of Cmm label we're dealing with.
--      Determines the suffix appended to the name when a CLabel.CmmLabel
--      is pretty printed.
data CmmLabelInfo
  = CmmInfo                     -- ^ misc rts info tables,      suffix _info
  | CmmEntry                    -- ^ misc rts entry points,     suffix _entry
  | CmmRetInfo                  -- ^ misc rts ret info tables,  suffix _info
  | CmmRet                      -- ^ misc rts return points,    suffix _ret
  | CmmData                     -- ^ misc rts data bits, eg CHARLIKE_closure
  | CmmCode                     -- ^ misc rts code
  | CmmClosure                  -- ^ closures eg CHARLIKE_closure
  | CmmPrimCall                 -- ^ a prim call to some hand written Cmm code
  deriving (CmmLabelInfo -> CmmLabelInfo -> Bool
(CmmLabelInfo -> CmmLabelInfo -> Bool)
-> (CmmLabelInfo -> CmmLabelInfo -> Bool) -> Eq CmmLabelInfo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CmmLabelInfo -> CmmLabelInfo -> Bool
$c/= :: CmmLabelInfo -> CmmLabelInfo -> Bool
== :: CmmLabelInfo -> CmmLabelInfo -> Bool
$c== :: CmmLabelInfo -> CmmLabelInfo -> Bool
Eq, Eq CmmLabelInfo
Eq CmmLabelInfo =>
(CmmLabelInfo -> CmmLabelInfo -> Ordering)
-> (CmmLabelInfo -> CmmLabelInfo -> Bool)
-> (CmmLabelInfo -> CmmLabelInfo -> Bool)
-> (CmmLabelInfo -> CmmLabelInfo -> Bool)
-> (CmmLabelInfo -> CmmLabelInfo -> Bool)
-> (CmmLabelInfo -> CmmLabelInfo -> CmmLabelInfo)
-> (CmmLabelInfo -> CmmLabelInfo -> CmmLabelInfo)
-> Ord CmmLabelInfo
CmmLabelInfo -> CmmLabelInfo -> Bool
CmmLabelInfo -> CmmLabelInfo -> Ordering
CmmLabelInfo -> CmmLabelInfo -> CmmLabelInfo
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: CmmLabelInfo -> CmmLabelInfo -> CmmLabelInfo
$cmin :: CmmLabelInfo -> CmmLabelInfo -> CmmLabelInfo
max :: CmmLabelInfo -> CmmLabelInfo -> CmmLabelInfo
$cmax :: CmmLabelInfo -> CmmLabelInfo -> CmmLabelInfo
>= :: CmmLabelInfo -> CmmLabelInfo -> Bool
$c>= :: CmmLabelInfo -> CmmLabelInfo -> Bool
> :: CmmLabelInfo -> CmmLabelInfo -> Bool
$c> :: CmmLabelInfo -> CmmLabelInfo -> Bool
<= :: CmmLabelInfo -> CmmLabelInfo -> Bool
$c<= :: CmmLabelInfo -> CmmLabelInfo -> Bool
< :: CmmLabelInfo -> CmmLabelInfo -> Bool
$c< :: CmmLabelInfo -> CmmLabelInfo -> Bool
compare :: CmmLabelInfo -> CmmLabelInfo -> Ordering
$ccompare :: CmmLabelInfo -> CmmLabelInfo -> Ordering
$cp1Ord :: Eq CmmLabelInfo
Ord)

data DynamicLinkerLabelInfo
  = CodeStub                    -- MachO: Lfoo$stub, ELF: foo@plt
  | SymbolPtr                   -- MachO: Lfoo$non_lazy_ptr, Windows: __imp_foo
  | GotSymbolPtr                -- ELF: foo@got
  | GotSymbolOffset             -- ELF: foo@gotoff

  deriving (DynamicLinkerLabelInfo -> DynamicLinkerLabelInfo -> Bool
(DynamicLinkerLabelInfo -> DynamicLinkerLabelInfo -> Bool)
-> (DynamicLinkerLabelInfo -> DynamicLinkerLabelInfo -> Bool)
-> Eq DynamicLinkerLabelInfo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DynamicLinkerLabelInfo -> DynamicLinkerLabelInfo -> Bool
$c/= :: DynamicLinkerLabelInfo -> DynamicLinkerLabelInfo -> Bool
== :: DynamicLinkerLabelInfo -> DynamicLinkerLabelInfo -> Bool
$c== :: DynamicLinkerLabelInfo -> DynamicLinkerLabelInfo -> Bool
Eq, Eq DynamicLinkerLabelInfo
Eq DynamicLinkerLabelInfo =>
(DynamicLinkerLabelInfo -> DynamicLinkerLabelInfo -> Ordering)
-> (DynamicLinkerLabelInfo -> DynamicLinkerLabelInfo -> Bool)
-> (DynamicLinkerLabelInfo -> DynamicLinkerLabelInfo -> Bool)
-> (DynamicLinkerLabelInfo -> DynamicLinkerLabelInfo -> Bool)
-> (DynamicLinkerLabelInfo -> DynamicLinkerLabelInfo -> Bool)
-> (DynamicLinkerLabelInfo
    -> DynamicLinkerLabelInfo -> DynamicLinkerLabelInfo)
-> (DynamicLinkerLabelInfo
    -> DynamicLinkerLabelInfo -> DynamicLinkerLabelInfo)
-> Ord DynamicLinkerLabelInfo
DynamicLinkerLabelInfo -> DynamicLinkerLabelInfo -> Bool
DynamicLinkerLabelInfo -> DynamicLinkerLabelInfo -> Ordering
DynamicLinkerLabelInfo
-> DynamicLinkerLabelInfo -> DynamicLinkerLabelInfo
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: DynamicLinkerLabelInfo
-> DynamicLinkerLabelInfo -> DynamicLinkerLabelInfo
$cmin :: DynamicLinkerLabelInfo
-> DynamicLinkerLabelInfo -> DynamicLinkerLabelInfo
max :: DynamicLinkerLabelInfo
-> DynamicLinkerLabelInfo -> DynamicLinkerLabelInfo
$cmax :: DynamicLinkerLabelInfo
-> DynamicLinkerLabelInfo -> DynamicLinkerLabelInfo
>= :: DynamicLinkerLabelInfo -> DynamicLinkerLabelInfo -> Bool
$c>= :: DynamicLinkerLabelInfo -> DynamicLinkerLabelInfo -> Bool
> :: DynamicLinkerLabelInfo -> DynamicLinkerLabelInfo -> Bool
$c> :: DynamicLinkerLabelInfo -> DynamicLinkerLabelInfo -> Bool
<= :: DynamicLinkerLabelInfo -> DynamicLinkerLabelInfo -> Bool
$c<= :: DynamicLinkerLabelInfo -> DynamicLinkerLabelInfo -> Bool
< :: DynamicLinkerLabelInfo -> DynamicLinkerLabelInfo -> Bool
$c< :: DynamicLinkerLabelInfo -> DynamicLinkerLabelInfo -> Bool
compare :: DynamicLinkerLabelInfo -> DynamicLinkerLabelInfo -> Ordering
$ccompare :: DynamicLinkerLabelInfo -> DynamicLinkerLabelInfo -> Ordering
$cp1Ord :: Eq DynamicLinkerLabelInfo
Ord)


-- -----------------------------------------------------------------------------
-- Constructing CLabels
-- -----------------------------------------------------------------------------

-- Constructing IdLabels
-- These are always local:

mkSRTLabel     :: Unique -> CLabel
mkSRTLabel :: Unique -> CLabel
mkSRTLabel u :: Unique
u = Unique -> CLabel
SRTLabel Unique
u

mkRednCountsLabel :: Name -> CLabel
mkRednCountsLabel :: Name -> CLabel
mkRednCountsLabel       name :: Name
name    =
  Name -> CafInfo -> IdLabelInfo -> CLabel
IdLabel Name
name CafInfo
NoCafRefs IdLabelInfo
RednCounts  -- Note [ticky for LNE]

-- These have local & (possibly) external variants:
mkLocalClosureLabel      :: Name -> CafInfo -> CLabel
mkLocalInfoTableLabel    :: Name -> CafInfo -> CLabel
mkLocalClosureTableLabel :: Name -> CafInfo -> CLabel
mkLocalClosureLabel :: Name -> CafInfo -> CLabel
mkLocalClosureLabel     name :: Name
name c :: CafInfo
c  = Name -> CafInfo -> IdLabelInfo -> CLabel
IdLabel Name
name  CafInfo
c IdLabelInfo
Closure
mkLocalInfoTableLabel :: Name -> CafInfo -> CLabel
mkLocalInfoTableLabel   name :: Name
name c :: CafInfo
c  = Name -> CafInfo -> IdLabelInfo -> CLabel
IdLabel Name
name  CafInfo
c IdLabelInfo
LocalInfoTable
mkLocalClosureTableLabel :: Name -> CafInfo -> CLabel
mkLocalClosureTableLabel name :: Name
name c :: CafInfo
c = Name -> CafInfo -> IdLabelInfo -> CLabel
IdLabel Name
name  CafInfo
c IdLabelInfo
ClosureTable

mkClosureLabel              :: Name -> CafInfo -> CLabel
mkInfoTableLabel            :: Name -> CafInfo -> CLabel
mkEntryLabel                :: Name -> CafInfo -> CLabel
mkClosureTableLabel         :: Name -> CafInfo -> CLabel
mkConInfoTableLabel         :: Name -> CafInfo -> CLabel
mkBytesLabel                :: Name -> CLabel
mkClosureLabel :: Name -> CafInfo -> CLabel
mkClosureLabel name :: Name
name         c :: CafInfo
c     = Name -> CafInfo -> IdLabelInfo -> CLabel
IdLabel Name
name CafInfo
c IdLabelInfo
Closure
mkInfoTableLabel :: Name -> CafInfo -> CLabel
mkInfoTableLabel name :: Name
name       c :: CafInfo
c     = Name -> CafInfo -> IdLabelInfo -> CLabel
IdLabel Name
name CafInfo
c IdLabelInfo
InfoTable
mkEntryLabel :: Name -> CafInfo -> CLabel
mkEntryLabel name :: Name
name           c :: CafInfo
c     = Name -> CafInfo -> IdLabelInfo -> CLabel
IdLabel Name
name CafInfo
c IdLabelInfo
Entry
mkClosureTableLabel :: Name -> CafInfo -> CLabel
mkClosureTableLabel name :: Name
name    c :: CafInfo
c     = Name -> CafInfo -> IdLabelInfo -> CLabel
IdLabel Name
name CafInfo
c IdLabelInfo
ClosureTable
mkConInfoTableLabel :: Name -> CafInfo -> CLabel
mkConInfoTableLabel name :: Name
name    c :: CafInfo
c     = Name -> CafInfo -> IdLabelInfo -> CLabel
IdLabel Name
name CafInfo
c IdLabelInfo
ConInfoTable
mkBytesLabel :: Name -> CLabel
mkBytesLabel name :: Name
name                 = Name -> CafInfo -> IdLabelInfo -> CLabel
IdLabel Name
name CafInfo
NoCafRefs IdLabelInfo
Bytes

mkBlockInfoTableLabel :: Name -> CafInfo -> CLabel
mkBlockInfoTableLabel :: Name -> CafInfo -> CLabel
mkBlockInfoTableLabel name :: Name
name c :: CafInfo
c = Name -> CafInfo -> IdLabelInfo -> CLabel
IdLabel Name
name CafInfo
c IdLabelInfo
BlockInfoTable
                               -- See Note [Proc-point local block entry-point].

-- Constructing Cmm Labels
mkDirty_MUT_VAR_Label, mkSplitMarkerLabel, mkUpdInfoLabel,
    mkBHUpdInfoLabel, mkIndStaticInfoLabel, mkMainCapabilityLabel,
    mkMAP_FROZEN_CLEAN_infoLabel, mkMAP_FROZEN_DIRTY_infoLabel,
    mkMAP_DIRTY_infoLabel,
    mkArrWords_infoLabel,
    mkTopTickyCtrLabel,
    mkCAFBlackHoleInfoTableLabel,
    mkSMAP_FROZEN_CLEAN_infoLabel, mkSMAP_FROZEN_DIRTY_infoLabel,
    mkSMAP_DIRTY_infoLabel, mkBadAlignmentLabel :: CLabel
mkDirty_MUT_VAR_Label :: CLabel
mkDirty_MUT_VAR_Label           = FastString
-> Maybe Int -> ForeignLabelSource -> FunctionOrData -> CLabel
mkForeignLabel (String -> FastString
fsLit "dirty_MUT_VAR") Maybe Int
forall a. Maybe a
Nothing ForeignLabelSource
ForeignLabelInExternalPackage FunctionOrData
IsFunction
mkSplitMarkerLabel :: CLabel
mkSplitMarkerLabel              = UnitId -> FastString -> CmmLabelInfo -> CLabel
CmmLabel UnitId
rtsUnitId (String -> FastString
fsLit "__stg_split_marker")    CmmLabelInfo
CmmCode
mkUpdInfoLabel :: CLabel
mkUpdInfoLabel                  = UnitId -> FastString -> CmmLabelInfo -> CLabel
CmmLabel UnitId
rtsUnitId (String -> FastString
fsLit "stg_upd_frame")         CmmLabelInfo
CmmInfo
mkBHUpdInfoLabel :: CLabel
mkBHUpdInfoLabel                = UnitId -> FastString -> CmmLabelInfo -> CLabel
CmmLabel UnitId
rtsUnitId (String -> FastString
fsLit "stg_bh_upd_frame" )     CmmLabelInfo
CmmInfo
mkIndStaticInfoLabel :: CLabel
mkIndStaticInfoLabel            = UnitId -> FastString -> CmmLabelInfo -> CLabel
CmmLabel UnitId
rtsUnitId (String -> FastString
fsLit "stg_IND_STATIC")        CmmLabelInfo
CmmInfo
mkMainCapabilityLabel :: CLabel
mkMainCapabilityLabel           = UnitId -> FastString -> CmmLabelInfo -> CLabel
CmmLabel UnitId
rtsUnitId (String -> FastString
fsLit "MainCapability")        CmmLabelInfo
CmmData
mkMAP_FROZEN_CLEAN_infoLabel :: CLabel
mkMAP_FROZEN_CLEAN_infoLabel    = UnitId -> FastString -> CmmLabelInfo -> CLabel
CmmLabel UnitId
rtsUnitId (String -> FastString
fsLit "stg_MUT_ARR_PTRS_FROZEN_CLEAN") CmmLabelInfo
CmmInfo
mkMAP_FROZEN_DIRTY_infoLabel :: CLabel
mkMAP_FROZEN_DIRTY_infoLabel    = UnitId -> FastString -> CmmLabelInfo -> CLabel
CmmLabel UnitId
rtsUnitId (String -> FastString
fsLit "stg_MUT_ARR_PTRS_FROZEN_DIRTY") CmmLabelInfo
CmmInfo
mkMAP_DIRTY_infoLabel :: CLabel
mkMAP_DIRTY_infoLabel           = UnitId -> FastString -> CmmLabelInfo -> CLabel
CmmLabel UnitId
rtsUnitId (String -> FastString
fsLit "stg_MUT_ARR_PTRS_DIRTY") CmmLabelInfo
CmmInfo
mkTopTickyCtrLabel :: CLabel
mkTopTickyCtrLabel              = UnitId -> FastString -> CmmLabelInfo -> CLabel
CmmLabel UnitId
rtsUnitId (String -> FastString
fsLit "top_ct")                CmmLabelInfo
CmmData
mkCAFBlackHoleInfoTableLabel :: CLabel
mkCAFBlackHoleInfoTableLabel    = UnitId -> FastString -> CmmLabelInfo -> CLabel
CmmLabel UnitId
rtsUnitId (String -> FastString
fsLit "stg_CAF_BLACKHOLE")     CmmLabelInfo
CmmInfo
mkArrWords_infoLabel :: CLabel
mkArrWords_infoLabel            = UnitId -> FastString -> CmmLabelInfo -> CLabel
CmmLabel UnitId
rtsUnitId (String -> FastString
fsLit "stg_ARR_WORDS")         CmmLabelInfo
CmmInfo
mkSMAP_FROZEN_CLEAN_infoLabel :: CLabel
mkSMAP_FROZEN_CLEAN_infoLabel   = UnitId -> FastString -> CmmLabelInfo -> CLabel
CmmLabel UnitId
rtsUnitId (String -> FastString
fsLit "stg_SMALL_MUT_ARR_PTRS_FROZEN_CLEAN") CmmLabelInfo
CmmInfo
mkSMAP_FROZEN_DIRTY_infoLabel :: CLabel
mkSMAP_FROZEN_DIRTY_infoLabel   = UnitId -> FastString -> CmmLabelInfo -> CLabel
CmmLabel UnitId
rtsUnitId (String -> FastString
fsLit "stg_SMALL_MUT_ARR_PTRS_FROZEN_DIRTY") CmmLabelInfo
CmmInfo
mkSMAP_DIRTY_infoLabel :: CLabel
mkSMAP_DIRTY_infoLabel          = UnitId -> FastString -> CmmLabelInfo -> CLabel
CmmLabel UnitId
rtsUnitId (String -> FastString
fsLit "stg_SMALL_MUT_ARR_PTRS_DIRTY") CmmLabelInfo
CmmInfo
mkBadAlignmentLabel :: CLabel
mkBadAlignmentLabel             = UnitId -> FastString -> CmmLabelInfo -> CLabel
CmmLabel UnitId
rtsUnitId (String -> FastString
fsLit "stg_badAlignment")      CmmLabelInfo
CmmEntry

mkSRTInfoLabel :: Int -> CLabel
mkSRTInfoLabel :: Int -> CLabel
mkSRTInfoLabel n :: Int
n = UnitId -> FastString -> CmmLabelInfo -> CLabel
CmmLabel UnitId
rtsUnitId FastString
lbl CmmLabelInfo
CmmInfo
 where
   lbl :: FastString
lbl =
     case Int
n of
       1 -> String -> FastString
fsLit "stg_SRT_1"
       2 -> String -> FastString
fsLit "stg_SRT_2"
       3 -> String -> FastString
fsLit "stg_SRT_3"
       4 -> String -> FastString
fsLit "stg_SRT_4"
       5 -> String -> FastString
fsLit "stg_SRT_5"
       6 -> String -> FastString
fsLit "stg_SRT_6"
       7 -> String -> FastString
fsLit "stg_SRT_7"
       8 -> String -> FastString
fsLit "stg_SRT_8"
       9 -> String -> FastString
fsLit "stg_SRT_9"
       10 -> String -> FastString
fsLit "stg_SRT_10"
       11 -> String -> FastString
fsLit "stg_SRT_11"
       12 -> String -> FastString
fsLit "stg_SRT_12"
       13 -> String -> FastString
fsLit "stg_SRT_13"
       14 -> String -> FastString
fsLit "stg_SRT_14"
       15 -> String -> FastString
fsLit "stg_SRT_15"
       16 -> String -> FastString
fsLit "stg_SRT_16"
       _ -> String -> FastString
forall a. String -> a
panic "mkSRTInfoLabel"

-----
mkCmmInfoLabel,   mkCmmEntryLabel, mkCmmRetInfoLabel, mkCmmRetLabel,
  mkCmmCodeLabel, mkCmmDataLabel,  mkCmmClosureLabel
        :: UnitId -> FastString -> CLabel

mkCmmInfoLabel :: UnitId -> FastString -> CLabel
mkCmmInfoLabel      pkg :: UnitId
pkg str :: FastString
str     = UnitId -> FastString -> CmmLabelInfo -> CLabel
CmmLabel UnitId
pkg FastString
str CmmLabelInfo
CmmInfo
mkCmmEntryLabel :: UnitId -> FastString -> CLabel
mkCmmEntryLabel     pkg :: UnitId
pkg str :: FastString
str     = UnitId -> FastString -> CmmLabelInfo -> CLabel
CmmLabel UnitId
pkg FastString
str CmmLabelInfo
CmmEntry
mkCmmRetInfoLabel :: UnitId -> FastString -> CLabel
mkCmmRetInfoLabel   pkg :: UnitId
pkg str :: FastString
str     = UnitId -> FastString -> CmmLabelInfo -> CLabel
CmmLabel UnitId
pkg FastString
str CmmLabelInfo
CmmRetInfo
mkCmmRetLabel :: UnitId -> FastString -> CLabel
mkCmmRetLabel       pkg :: UnitId
pkg str :: FastString
str     = UnitId -> FastString -> CmmLabelInfo -> CLabel
CmmLabel UnitId
pkg FastString
str CmmLabelInfo
CmmRet
mkCmmCodeLabel :: UnitId -> FastString -> CLabel
mkCmmCodeLabel      pkg :: UnitId
pkg str :: FastString
str     = UnitId -> FastString -> CmmLabelInfo -> CLabel
CmmLabel UnitId
pkg FastString
str CmmLabelInfo
CmmCode
mkCmmDataLabel :: UnitId -> FastString -> CLabel
mkCmmDataLabel      pkg :: UnitId
pkg str :: FastString
str     = UnitId -> FastString -> CmmLabelInfo -> CLabel
CmmLabel UnitId
pkg FastString
str CmmLabelInfo
CmmData
mkCmmClosureLabel :: UnitId -> FastString -> CLabel
mkCmmClosureLabel   pkg :: UnitId
pkg str :: FastString
str     = UnitId -> FastString -> CmmLabelInfo -> CLabel
CmmLabel UnitId
pkg FastString
str CmmLabelInfo
CmmClosure

mkLocalBlockLabel :: Unique -> CLabel
mkLocalBlockLabel :: Unique -> CLabel
mkLocalBlockLabel u :: Unique
u = Unique -> CLabel
LocalBlockLabel Unique
u

-- Constructing RtsLabels
mkRtsPrimOpLabel :: PrimOp -> CLabel
mkRtsPrimOpLabel :: PrimOp -> CLabel
mkRtsPrimOpLabel primop :: PrimOp
primop         = RtsLabelInfo -> CLabel
RtsLabel (PrimOp -> RtsLabelInfo
RtsPrimOp PrimOp
primop)

mkSelectorInfoLabel  :: Bool -> Int -> CLabel
mkSelectorEntryLabel :: Bool -> Int -> CLabel
mkSelectorInfoLabel :: Bool -> Int -> CLabel
mkSelectorInfoLabel  upd :: Bool
upd off :: Int
off    = RtsLabelInfo -> CLabel
RtsLabel (Bool -> Int -> RtsLabelInfo
RtsSelectorInfoTable Bool
upd Int
off)
mkSelectorEntryLabel :: Bool -> Int -> CLabel
mkSelectorEntryLabel upd :: Bool
upd off :: Int
off    = RtsLabelInfo -> CLabel
RtsLabel (Bool -> Int -> RtsLabelInfo
RtsSelectorEntry     Bool
upd Int
off)

mkApInfoTableLabel :: Bool -> Int -> CLabel
mkApEntryLabel     :: Bool -> Int -> CLabel
mkApInfoTableLabel :: Bool -> Int -> CLabel
mkApInfoTableLabel   upd :: Bool
upd off :: Int
off    = RtsLabelInfo -> CLabel
RtsLabel (Bool -> Int -> RtsLabelInfo
RtsApInfoTable       Bool
upd Int
off)
mkApEntryLabel :: Bool -> Int -> CLabel
mkApEntryLabel       upd :: Bool
upd off :: Int
off    = RtsLabelInfo -> CLabel
RtsLabel (Bool -> Int -> RtsLabelInfo
RtsApEntry           Bool
upd Int
off)


-- A call to some primitive hand written Cmm code
mkPrimCallLabel :: PrimCall -> CLabel
mkPrimCallLabel :: PrimCall -> CLabel
mkPrimCallLabel (PrimCall str :: FastString
str pkg :: UnitId
pkg)
        = UnitId -> FastString -> CmmLabelInfo -> CLabel
CmmLabel UnitId
pkg FastString
str CmmLabelInfo
CmmPrimCall


-- Constructing ForeignLabels

-- | Make a foreign label
mkForeignLabel
        :: FastString           -- name
        -> Maybe Int            -- size prefix
        -> ForeignLabelSource   -- what package it's in
        -> FunctionOrData
        -> CLabel

mkForeignLabel :: FastString
-> Maybe Int -> ForeignLabelSource -> FunctionOrData -> CLabel
mkForeignLabel str :: FastString
str mb_sz :: Maybe Int
mb_sz src :: ForeignLabelSource
src fod :: FunctionOrData
fod
    = FastString
-> Maybe Int -> ForeignLabelSource -> FunctionOrData -> CLabel
ForeignLabel FastString
str Maybe Int
mb_sz ForeignLabelSource
src  FunctionOrData
fod


-- | Update the label size field in a ForeignLabel
addLabelSize :: CLabel -> Int -> CLabel
addLabelSize :: CLabel -> Int -> CLabel
addLabelSize (ForeignLabel str :: FastString
str _ src :: ForeignLabelSource
src  fod :: FunctionOrData
fod) sz :: Int
sz
    = FastString
-> Maybe Int -> ForeignLabelSource -> FunctionOrData -> CLabel
ForeignLabel FastString
str (Int -> Maybe Int
forall a. a -> Maybe a
Just Int
sz) ForeignLabelSource
src FunctionOrData
fod
addLabelSize label :: CLabel
label _
    = CLabel
label

-- | Whether label is a top-level string literal
isBytesLabel :: CLabel -> Bool
isBytesLabel :: CLabel -> Bool
isBytesLabel (IdLabel _ _ Bytes) = Bool
True
isBytesLabel _lbl :: CLabel
_lbl = Bool
False

-- | Whether label is a non-haskell label (defined in C code)
isForeignLabel :: CLabel -> Bool
isForeignLabel :: CLabel -> Bool
isForeignLabel (ForeignLabel _ _ _ _) = Bool
True
isForeignLabel _lbl :: CLabel
_lbl = Bool
False

-- | Whether label is a static closure label (can come from haskell or cmm)
isStaticClosureLabel :: CLabel -> Bool
-- Closure defined in haskell (.hs)
isStaticClosureLabel :: CLabel -> Bool
isStaticClosureLabel (IdLabel _ _ Closure) = Bool
True
-- Closure defined in cmm
isStaticClosureLabel (CmmLabel _ _ CmmClosure) = Bool
True
isStaticClosureLabel _lbl :: CLabel
_lbl = Bool
False

-- | Whether label is a .rodata label
isSomeRODataLabel :: CLabel -> Bool
-- info table defined in haskell (.hs)
isSomeRODataLabel :: CLabel -> Bool
isSomeRODataLabel (IdLabel _ _ ClosureTable) = Bool
True
isSomeRODataLabel (IdLabel _ _ ConInfoTable) = Bool
True
isSomeRODataLabel (IdLabel _ _ InfoTable) = Bool
True
isSomeRODataLabel (IdLabel _ _ LocalInfoTable) = Bool
True
isSomeRODataLabel (IdLabel _ _ BlockInfoTable) = Bool
True
-- info table defined in cmm (.cmm)
isSomeRODataLabel (CmmLabel _ _ CmmInfo) = Bool
True
isSomeRODataLabel _lbl :: CLabel
_lbl = Bool
False

-- | Whether label is points to some kind of info table
isInfoTableLabel :: CLabel -> Bool
isInfoTableLabel :: CLabel -> Bool
isInfoTableLabel (IdLabel _ _ InfoTable)      = Bool
True
isInfoTableLabel (IdLabel _ _ LocalInfoTable) = Bool
True
isInfoTableLabel (IdLabel _ _ ConInfoTable)   = Bool
True
isInfoTableLabel (IdLabel _ _ BlockInfoTable) = Bool
True
isInfoTableLabel _                            = Bool
False

-- | Whether label is points to constructor info table
isConInfoTableLabel :: CLabel -> Bool
isConInfoTableLabel :: CLabel -> Bool
isConInfoTableLabel (IdLabel _ _ ConInfoTable)   = Bool
True
isConInfoTableLabel _                            = Bool
False

-- | Get the label size field from a ForeignLabel
foreignLabelStdcallInfo :: CLabel -> Maybe Int
foreignLabelStdcallInfo :: CLabel -> Maybe Int
foreignLabelStdcallInfo (ForeignLabel _ info :: Maybe Int
info _ _) = Maybe Int
info
foreignLabelStdcallInfo _lbl :: CLabel
_lbl = Maybe Int
forall a. Maybe a
Nothing


-- Constructing Large*Labels
mkBitmapLabel   :: Unique -> CLabel
mkBitmapLabel :: Unique -> CLabel
mkBitmapLabel   uniq :: Unique
uniq            = Unique -> CLabel
LargeBitmapLabel Unique
uniq

-- Constructing Cost Center Labels
mkCCLabel  :: CostCentre      -> CLabel
mkCCSLabel :: CostCentreStack -> CLabel
mkCCLabel :: CostCentre -> CLabel
mkCCLabel           cc :: CostCentre
cc          = CostCentre -> CLabel
CC_Label CostCentre
cc
mkCCSLabel :: CostCentreStack -> CLabel
mkCCSLabel          ccs :: CostCentreStack
ccs         = CostCentreStack -> CLabel
CCS_Label CostCentreStack
ccs

mkRtsApFastLabel :: FastString -> CLabel
mkRtsApFastLabel :: FastString -> CLabel
mkRtsApFastLabel str :: FastString
str = RtsLabelInfo -> CLabel
RtsLabel (FastString -> RtsLabelInfo
RtsApFast FastString
str)

mkRtsSlowFastTickyCtrLabel :: String -> CLabel
mkRtsSlowFastTickyCtrLabel :: String -> CLabel
mkRtsSlowFastTickyCtrLabel pat :: String
pat = RtsLabelInfo -> CLabel
RtsLabel (String -> RtsLabelInfo
RtsSlowFastTickyCtr String
pat)


-- Constructing Code Coverage Labels
mkHpcTicksLabel :: Module -> CLabel
mkHpcTicksLabel :: Module -> CLabel
mkHpcTicksLabel                = Module -> CLabel
HpcTicksLabel


-- Constructing labels used for dynamic linking
mkDynamicLinkerLabel :: DynamicLinkerLabelInfo -> CLabel -> CLabel
mkDynamicLinkerLabel :: DynamicLinkerLabelInfo -> CLabel -> CLabel
mkDynamicLinkerLabel            = DynamicLinkerLabelInfo -> CLabel -> CLabel
DynamicLinkerLabel

dynamicLinkerLabelInfo :: CLabel -> Maybe (DynamicLinkerLabelInfo, CLabel)
dynamicLinkerLabelInfo :: CLabel -> Maybe (DynamicLinkerLabelInfo, CLabel)
dynamicLinkerLabelInfo (DynamicLinkerLabel info :: DynamicLinkerLabelInfo
info lbl :: CLabel
lbl) = (DynamicLinkerLabelInfo, CLabel)
-> Maybe (DynamicLinkerLabelInfo, CLabel)
forall a. a -> Maybe a
Just (DynamicLinkerLabelInfo
info, CLabel
lbl)
dynamicLinkerLabelInfo _        = Maybe (DynamicLinkerLabelInfo, CLabel)
forall a. Maybe a
Nothing

mkPicBaseLabel :: CLabel
mkPicBaseLabel :: CLabel
mkPicBaseLabel                  = CLabel
PicBaseLabel


-- Constructing miscellaneous other labels
mkDeadStripPreventer :: CLabel -> CLabel
mkDeadStripPreventer :: CLabel -> CLabel
mkDeadStripPreventer lbl :: CLabel
lbl        = CLabel -> CLabel
DeadStripPreventer CLabel
lbl

mkStringLitLabel :: Unique -> CLabel
mkStringLitLabel :: Unique -> CLabel
mkStringLitLabel                = Unique -> CLabel
StringLitLabel

mkAsmTempLabel :: Uniquable a => a -> CLabel
mkAsmTempLabel :: a -> CLabel
mkAsmTempLabel a :: a
a                = Unique -> CLabel
AsmTempLabel (a -> Unique
forall a. Uniquable a => a -> Unique
getUnique a
a)

mkAsmTempDerivedLabel :: CLabel -> FastString -> CLabel
mkAsmTempDerivedLabel :: CLabel -> FastString -> CLabel
mkAsmTempDerivedLabel = CLabel -> FastString -> CLabel
AsmTempDerivedLabel

mkAsmTempEndLabel :: CLabel -> CLabel
mkAsmTempEndLabel :: CLabel -> CLabel
mkAsmTempEndLabel l :: CLabel
l = CLabel -> FastString -> CLabel
mkAsmTempDerivedLabel CLabel
l (String -> FastString
fsLit "_end")

-- | Construct a label for a DWARF Debug Information Entity (DIE)
-- describing another symbol.
mkAsmTempDieLabel :: CLabel -> CLabel
mkAsmTempDieLabel :: CLabel -> CLabel
mkAsmTempDieLabel l :: CLabel
l = CLabel -> FastString -> CLabel
mkAsmTempDerivedLabel CLabel
l (String -> FastString
fsLit "_die")

-- -----------------------------------------------------------------------------
-- Convert between different kinds of label

toClosureLbl :: CLabel -> CLabel
toClosureLbl :: CLabel -> CLabel
toClosureLbl (IdLabel n :: Name
n c :: CafInfo
c _) = Name -> CafInfo -> IdLabelInfo -> CLabel
IdLabel Name
n CafInfo
c IdLabelInfo
Closure
toClosureLbl (CmmLabel m :: UnitId
m str :: FastString
str _) = UnitId -> FastString -> CmmLabelInfo -> CLabel
CmmLabel UnitId
m FastString
str CmmLabelInfo
CmmClosure
toClosureLbl l :: CLabel
l = String -> SDoc -> CLabel
forall a. HasCallStack => String -> SDoc -> a
pprPanic "toClosureLbl" (CLabel -> SDoc
forall a. Outputable a => a -> SDoc
ppr CLabel
l)

toSlowEntryLbl :: CLabel -> CLabel
toSlowEntryLbl :: CLabel -> CLabel
toSlowEntryLbl (IdLabel n :: Name
n _ BlockInfoTable)
  = String -> SDoc -> CLabel
forall a. HasCallStack => String -> SDoc -> a
pprPanic "toSlowEntryLbl" (Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
n)
toSlowEntryLbl (IdLabel n :: Name
n c :: CafInfo
c _) = Name -> CafInfo -> IdLabelInfo -> CLabel
IdLabel Name
n CafInfo
c IdLabelInfo
Slow
toSlowEntryLbl l :: CLabel
l = String -> SDoc -> CLabel
forall a. HasCallStack => String -> SDoc -> a
pprPanic "toSlowEntryLbl" (CLabel -> SDoc
forall a. Outputable a => a -> SDoc
ppr CLabel
l)

toEntryLbl :: CLabel -> CLabel
toEntryLbl :: CLabel -> CLabel
toEntryLbl (IdLabel n :: Name
n c :: CafInfo
c LocalInfoTable)  = Name -> CafInfo -> IdLabelInfo -> CLabel
IdLabel Name
n CafInfo
c IdLabelInfo
LocalEntry
toEntryLbl (IdLabel n :: Name
n c :: CafInfo
c ConInfoTable)    = Name -> CafInfo -> IdLabelInfo -> CLabel
IdLabel Name
n CafInfo
c IdLabelInfo
ConEntry
toEntryLbl (IdLabel n :: Name
n _ BlockInfoTable)  = Unique -> CLabel
mkLocalBlockLabel (Name -> Unique
nameUnique Name
n)
                              -- See Note [Proc-point local block entry-point].
toEntryLbl (IdLabel n :: Name
n c :: CafInfo
c _)               = Name -> CafInfo -> IdLabelInfo -> CLabel
IdLabel Name
n CafInfo
c IdLabelInfo
Entry
toEntryLbl (CmmLabel m :: UnitId
m str :: FastString
str CmmInfo)      = UnitId -> FastString -> CmmLabelInfo -> CLabel
CmmLabel UnitId
m FastString
str CmmLabelInfo
CmmEntry
toEntryLbl (CmmLabel m :: UnitId
m str :: FastString
str CmmRetInfo)   = UnitId -> FastString -> CmmLabelInfo -> CLabel
CmmLabel UnitId
m FastString
str CmmLabelInfo
CmmRet
toEntryLbl l :: CLabel
l = String -> SDoc -> CLabel
forall a. HasCallStack => String -> SDoc -> a
pprPanic "toEntryLbl" (CLabel -> SDoc
forall a. Outputable a => a -> SDoc
ppr CLabel
l)

toInfoLbl :: CLabel -> CLabel
toInfoLbl :: CLabel -> CLabel
toInfoLbl (IdLabel n :: Name
n c :: CafInfo
c LocalEntry)     = Name -> CafInfo -> IdLabelInfo -> CLabel
IdLabel Name
n CafInfo
c IdLabelInfo
LocalInfoTable
toInfoLbl (IdLabel n :: Name
n c :: CafInfo
c ConEntry)       = Name -> CafInfo -> IdLabelInfo -> CLabel
IdLabel Name
n CafInfo
c IdLabelInfo
ConInfoTable
toInfoLbl (IdLabel n :: Name
n c :: CafInfo
c _)              = Name -> CafInfo -> IdLabelInfo -> CLabel
IdLabel Name
n CafInfo
c IdLabelInfo
InfoTable
toInfoLbl (CmmLabel m :: UnitId
m str :: FastString
str CmmEntry)    = UnitId -> FastString -> CmmLabelInfo -> CLabel
CmmLabel UnitId
m FastString
str CmmLabelInfo
CmmInfo
toInfoLbl (CmmLabel m :: UnitId
m str :: FastString
str CmmRet)      = UnitId -> FastString -> CmmLabelInfo -> CLabel
CmmLabel UnitId
m FastString
str CmmLabelInfo
CmmRetInfo
toInfoLbl l :: CLabel
l = String -> SDoc -> CLabel
forall a. HasCallStack => String -> SDoc -> a
pprPanic "CLabel.toInfoLbl" (CLabel -> SDoc
forall a. Outputable a => a -> SDoc
ppr CLabel
l)

hasHaskellName :: CLabel -> Maybe Name
hasHaskellName :: CLabel -> Maybe Name
hasHaskellName (IdLabel n :: Name
n _ _) = Name -> Maybe Name
forall a. a -> Maybe a
Just Name
n
hasHaskellName _               = Maybe Name
forall a. Maybe a
Nothing

-- -----------------------------------------------------------------------------
-- Does a CLabel's referent itself refer to a CAF?
hasCAF :: CLabel -> Bool
hasCAF :: CLabel -> Bool
hasCAF (IdLabel _ _ RednCounts) = Bool
False -- Note [ticky for LNE]
hasCAF (IdLabel _ MayHaveCafRefs _) = Bool
True
hasCAF _                            = Bool
False

-- Note [ticky for LNE]
-- ~~~~~~~~~~~~~~~~~~~~~

-- Until 14 Feb 2013, every ticky counter was associated with a
-- closure. Thus, ticky labels used IdLabel. It is odd that
-- CmmBuildInfoTables.cafTransfers would consider such a ticky label
-- reason to add the name to the CAFEnv (and thus eventually the SRT),
-- but it was harmless because the ticky was only used if the closure
-- was also.
--
-- Since we now have ticky counters for LNEs, it is no longer the case
-- that every ticky counter has an actual closure. So I changed the
-- generation of ticky counters' CLabels to not result in their
-- associated id ending up in the SRT.
--
-- NB IdLabel is still appropriate for ticky ids (as opposed to
-- CmmLabel) because the LNE's counter is still related to an .hs Id,
-- that Id just isn't for a proper closure.

-- -----------------------------------------------------------------------------
-- Does a CLabel need declaring before use or not?
--
-- See wiki:Commentary/Compiler/Backends/PprC#Prototypes

needsCDecl :: CLabel -> Bool
  -- False <=> it's pre-declared; don't bother
  -- don't bother declaring Bitmap labels, we always make sure
  -- they are defined before use.
needsCDecl :: CLabel -> Bool
needsCDecl (SRTLabel _)                 = Bool
True
needsCDecl (LargeBitmapLabel _)         = Bool
False
needsCDecl (IdLabel _ _ _)              = Bool
True
needsCDecl (LocalBlockLabel _)          = Bool
True

needsCDecl (StringLitLabel _)           = Bool
False
needsCDecl (AsmTempLabel _)             = Bool
False
needsCDecl (AsmTempDerivedLabel _ _)    = Bool
False
needsCDecl (RtsLabel _)                 = Bool
False

needsCDecl (CmmLabel pkgId :: UnitId
pkgId _ _)
        -- Prototypes for labels defined in the runtime system are imported
        --      into HC files via includes/Stg.h.
        | UnitId
pkgId UnitId -> UnitId -> Bool
forall a. Eq a => a -> a -> Bool
== UnitId
rtsUnitId         = Bool
False

        -- For other labels we inline one into the HC file directly.
        | Bool
otherwise                     = Bool
True

needsCDecl l :: CLabel
l@(ForeignLabel{})           = Bool -> Bool
not (CLabel -> Bool
isMathFun CLabel
l)
needsCDecl (CC_Label _)                 = Bool
True
needsCDecl (CCS_Label _)                = Bool
True
needsCDecl (HpcTicksLabel _)            = Bool
True
needsCDecl (DynamicLinkerLabel {})      = String -> Bool
forall a. String -> a
panic "needsCDecl DynamicLinkerLabel"
needsCDecl PicBaseLabel                 = String -> Bool
forall a. String -> a
panic "needsCDecl PicBaseLabel"
needsCDecl (DeadStripPreventer {})      = String -> Bool
forall a. String -> a
panic "needsCDecl DeadStripPreventer"

-- | If a label is a local block label then return just its 'BlockId', otherwise
-- 'Nothing'.
maybeLocalBlockLabel :: CLabel -> Maybe BlockId
maybeLocalBlockLabel :: CLabel -> Maybe BlockId
maybeLocalBlockLabel (LocalBlockLabel uq :: Unique
uq)  = BlockId -> Maybe BlockId
forall a. a -> Maybe a
Just (BlockId -> Maybe BlockId) -> BlockId -> Maybe BlockId
forall a b. (a -> b) -> a -> b
$ Unique -> BlockId
mkBlockId Unique
uq
maybeLocalBlockLabel _                     = Maybe BlockId
forall a. Maybe a
Nothing


-- | Check whether a label corresponds to a C function that has
--      a prototype in a system header somehere, or is built-in
--      to the C compiler. For these labels we avoid generating our
--      own C prototypes.
isMathFun :: CLabel -> Bool
isMathFun :: CLabel -> Bool
isMathFun (ForeignLabel fs :: FastString
fs _ _ _)       = FastString
fs FastString -> UniqSet FastString -> Bool
forall a. Uniquable a => a -> UniqSet a -> Bool
`elementOfUniqSet` UniqSet FastString
math_funs
isMathFun _ = Bool
False

math_funs :: UniqSet FastString
math_funs :: UniqSet FastString
math_funs = [FastString] -> UniqSet FastString
forall a. Uniquable a => [a] -> UniqSet a
mkUniqSet [
        -- _ISOC99_SOURCE
        (String -> FastString
fsLit "acos"),         (String -> FastString
fsLit "acosf"),        (String -> FastString
fsLit "acosh"),
        (String -> FastString
fsLit "acoshf"),       (String -> FastString
fsLit "acoshl"),       (String -> FastString
fsLit "acosl"),
        (String -> FastString
fsLit "asin"),         (String -> FastString
fsLit "asinf"),        (String -> FastString
fsLit "asinl"),
        (String -> FastString
fsLit "asinh"),        (String -> FastString
fsLit "asinhf"),       (String -> FastString
fsLit "asinhl"),
        (String -> FastString
fsLit "atan"),         (String -> FastString
fsLit "atanf"),        (String -> FastString
fsLit "atanl"),
        (String -> FastString
fsLit "atan2"),        (String -> FastString
fsLit "atan2f"),       (String -> FastString
fsLit "atan2l"),
        (String -> FastString
fsLit "atanh"),        (String -> FastString
fsLit "atanhf"),       (String -> FastString
fsLit "atanhl"),
        (String -> FastString
fsLit "cbrt"),         (String -> FastString
fsLit "cbrtf"),        (String -> FastString
fsLit "cbrtl"),
        (String -> FastString
fsLit "ceil"),         (String -> FastString
fsLit "ceilf"),        (String -> FastString
fsLit "ceill"),
        (String -> FastString
fsLit "copysign"),     (String -> FastString
fsLit "copysignf"),    (String -> FastString
fsLit "copysignl"),
        (String -> FastString
fsLit "cos"),          (String -> FastString
fsLit "cosf"),         (String -> FastString
fsLit "cosl"),
        (String -> FastString
fsLit "cosh"),         (String -> FastString
fsLit "coshf"),        (String -> FastString
fsLit "coshl"),
        (String -> FastString
fsLit "erf"),          (String -> FastString
fsLit "erff"),         (String -> FastString
fsLit "erfl"),
        (String -> FastString
fsLit "erfc"),         (String -> FastString
fsLit "erfcf"),        (String -> FastString
fsLit "erfcl"),
        (String -> FastString
fsLit "exp"),          (String -> FastString
fsLit "expf"),         (String -> FastString
fsLit "expl"),
        (String -> FastString
fsLit "exp2"),         (String -> FastString
fsLit "exp2f"),        (String -> FastString
fsLit "exp2l"),
        (String -> FastString
fsLit "expm1"),        (String -> FastString
fsLit "expm1f"),       (String -> FastString
fsLit "expm1l"),
        (String -> FastString
fsLit "fabs"),         (String -> FastString
fsLit "fabsf"),        (String -> FastString
fsLit "fabsl"),
        (String -> FastString
fsLit "fdim"),         (String -> FastString
fsLit "fdimf"),        (String -> FastString
fsLit "fdiml"),
        (String -> FastString
fsLit "floor"),        (String -> FastString
fsLit "floorf"),       (String -> FastString
fsLit "floorl"),
        (String -> FastString
fsLit "fma"),          (String -> FastString
fsLit "fmaf"),         (String -> FastString
fsLit "fmal"),
        (String -> FastString
fsLit "fmax"),         (String -> FastString
fsLit "fmaxf"),        (String -> FastString
fsLit "fmaxl"),
        (String -> FastString
fsLit "fmin"),         (String -> FastString
fsLit "fminf"),        (String -> FastString
fsLit "fminl"),
        (String -> FastString
fsLit "fmod"),         (String -> FastString
fsLit "fmodf"),        (String -> FastString
fsLit "fmodl"),
        (String -> FastString
fsLit "frexp"),        (String -> FastString
fsLit "frexpf"),       (String -> FastString
fsLit "frexpl"),
        (String -> FastString
fsLit "hypot"),        (String -> FastString
fsLit "hypotf"),       (String -> FastString
fsLit "hypotl"),
        (String -> FastString
fsLit "ilogb"),        (String -> FastString
fsLit "ilogbf"),       (String -> FastString
fsLit "ilogbl"),
        (String -> FastString
fsLit "ldexp"),        (String -> FastString
fsLit "ldexpf"),       (String -> FastString
fsLit "ldexpl"),
        (String -> FastString
fsLit "lgamma"),       (String -> FastString
fsLit "lgammaf"),      (String -> FastString
fsLit "lgammal"),
        (String -> FastString
fsLit "llrint"),       (String -> FastString
fsLit "llrintf"),      (String -> FastString
fsLit "llrintl"),
        (String -> FastString
fsLit "llround"),      (String -> FastString
fsLit "llroundf"),     (String -> FastString
fsLit "llroundl"),
        (String -> FastString
fsLit "log"),          (String -> FastString
fsLit "logf"),         (String -> FastString
fsLit "logl"),
        (String -> FastString
fsLit "log10l"),       (String -> FastString
fsLit "log10"),        (String -> FastString
fsLit "log10f"),
        (String -> FastString
fsLit "log1pl"),       (String -> FastString
fsLit "log1p"),        (String -> FastString
fsLit "log1pf"),
        (String -> FastString
fsLit "log2"),         (String -> FastString
fsLit "log2f"),        (String -> FastString
fsLit "log2l"),
        (String -> FastString
fsLit "logb"),         (String -> FastString
fsLit "logbf"),        (String -> FastString
fsLit "logbl"),
        (String -> FastString
fsLit "lrint"),        (String -> FastString
fsLit "lrintf"),       (String -> FastString
fsLit "lrintl"),
        (String -> FastString
fsLit "lround"),       (String -> FastString
fsLit "lroundf"),      (String -> FastString
fsLit "lroundl"),
        (String -> FastString
fsLit "modf"),         (String -> FastString
fsLit "modff"),        (String -> FastString
fsLit "modfl"),
        (String -> FastString
fsLit "nan"),          (String -> FastString
fsLit "nanf"),         (String -> FastString
fsLit "nanl"),
        (String -> FastString
fsLit "nearbyint"),    (String -> FastString
fsLit "nearbyintf"),   (String -> FastString
fsLit "nearbyintl"),
        (String -> FastString
fsLit "nextafter"),    (String -> FastString
fsLit "nextafterf"),   (String -> FastString
fsLit "nextafterl"),
        (String -> FastString
fsLit "nexttoward"),   (String -> FastString
fsLit "nexttowardf"),  (String -> FastString
fsLit "nexttowardl"),
        (String -> FastString
fsLit "pow"),          (String -> FastString
fsLit "powf"),         (String -> FastString
fsLit "powl"),
        (String -> FastString
fsLit "remainder"),    (String -> FastString
fsLit "remainderf"),   (String -> FastString
fsLit "remainderl"),
        (String -> FastString
fsLit "remquo"),       (String -> FastString
fsLit "remquof"),      (String -> FastString
fsLit "remquol"),
        (String -> FastString
fsLit "rint"),         (String -> FastString
fsLit "rintf"),        (String -> FastString
fsLit "rintl"),
        (String -> FastString
fsLit "round"),        (String -> FastString
fsLit "roundf"),       (String -> FastString
fsLit "roundl"),
        (String -> FastString
fsLit "scalbln"),      (String -> FastString
fsLit "scalblnf"),     (String -> FastString
fsLit "scalblnl"),
        (String -> FastString
fsLit "scalbn"),       (String -> FastString
fsLit "scalbnf"),      (String -> FastString
fsLit "scalbnl"),
        (String -> FastString
fsLit "sin"),          (String -> FastString
fsLit "sinf"),         (String -> FastString
fsLit "sinl"),
        (String -> FastString
fsLit "sinh"),         (String -> FastString
fsLit "sinhf"),        (String -> FastString
fsLit "sinhl"),
        (String -> FastString
fsLit "sqrt"),         (String -> FastString
fsLit "sqrtf"),        (String -> FastString
fsLit "sqrtl"),
        (String -> FastString
fsLit "tan"),          (String -> FastString
fsLit "tanf"),         (String -> FastString
fsLit "tanl"),
        (String -> FastString
fsLit "tanh"),         (String -> FastString
fsLit "tanhf"),        (String -> FastString
fsLit "tanhl"),
        (String -> FastString
fsLit "tgamma"),       (String -> FastString
fsLit "tgammaf"),      (String -> FastString
fsLit "tgammal"),
        (String -> FastString
fsLit "trunc"),        (String -> FastString
fsLit "truncf"),       (String -> FastString
fsLit "truncl"),
        -- ISO C 99 also defines these function-like macros in math.h:
        -- fpclassify, isfinite, isinf, isnormal, signbit, isgreater,
        -- isgreaterequal, isless, islessequal, islessgreater, isunordered

        -- additional symbols from _BSD_SOURCE
        (String -> FastString
fsLit "drem"),         (String -> FastString
fsLit "dremf"),        (String -> FastString
fsLit "dreml"),
        (String -> FastString
fsLit "finite"),       (String -> FastString
fsLit "finitef"),      (String -> FastString
fsLit "finitel"),
        (String -> FastString
fsLit "gamma"),        (String -> FastString
fsLit "gammaf"),       (String -> FastString
fsLit "gammal"),
        (String -> FastString
fsLit "isinf"),        (String -> FastString
fsLit "isinff"),       (String -> FastString
fsLit "isinfl"),
        (String -> FastString
fsLit "isnan"),        (String -> FastString
fsLit "isnanf"),       (String -> FastString
fsLit "isnanl"),
        (String -> FastString
fsLit "j0"),           (String -> FastString
fsLit "j0f"),          (String -> FastString
fsLit "j0l"),
        (String -> FastString
fsLit "j1"),           (String -> FastString
fsLit "j1f"),          (String -> FastString
fsLit "j1l"),
        (String -> FastString
fsLit "jn"),           (String -> FastString
fsLit "jnf"),          (String -> FastString
fsLit "jnl"),
        (String -> FastString
fsLit "lgamma_r"),     (String -> FastString
fsLit "lgammaf_r"),    (String -> FastString
fsLit "lgammal_r"),
        (String -> FastString
fsLit "scalb"),        (String -> FastString
fsLit "scalbf"),       (String -> FastString
fsLit "scalbl"),
        (String -> FastString
fsLit "significand"),  (String -> FastString
fsLit "significandf"), (String -> FastString
fsLit "significandl"),
        (String -> FastString
fsLit "y0"),           (String -> FastString
fsLit "y0f"),          (String -> FastString
fsLit "y0l"),
        (String -> FastString
fsLit "y1"),           (String -> FastString
fsLit "y1f"),          (String -> FastString
fsLit "y1l"),
        (String -> FastString
fsLit "yn"),           (String -> FastString
fsLit "ynf"),          (String -> FastString
fsLit "ynl"),

        -- These functions are described in IEEE Std 754-2008 -
        -- Standard for Floating-Point Arithmetic and ISO/IEC TS 18661
        (String -> FastString
fsLit "nextup"),       (String -> FastString
fsLit "nextupf"),      (String -> FastString
fsLit "nextupl"),
        (String -> FastString
fsLit "nextdown"),     (String -> FastString
fsLit "nextdownf"),    (String -> FastString
fsLit "nextdownl")
    ]

-- -----------------------------------------------------------------------------
-- | Is a CLabel visible outside this object file or not?
--      From the point of view of the code generator, a name is
--      externally visible if it has to be declared as exported
--      in the .o file's symbol table; that is, made non-static.
externallyVisibleCLabel :: CLabel -> Bool -- not C "static"
externallyVisibleCLabel :: CLabel -> Bool
externallyVisibleCLabel (StringLitLabel _)      = Bool
False
externallyVisibleCLabel (AsmTempLabel _)        = Bool
False
externallyVisibleCLabel (AsmTempDerivedLabel _ _)= Bool
False
externallyVisibleCLabel (RtsLabel _)            = Bool
True
externallyVisibleCLabel (LocalBlockLabel _)     = Bool
False
externallyVisibleCLabel (CmmLabel _ _ _)        = Bool
True
externallyVisibleCLabel (ForeignLabel{})        = Bool
True
externallyVisibleCLabel (IdLabel name :: Name
name _ info :: IdLabelInfo
info)   = Name -> Bool
isExternalName Name
name Bool -> Bool -> Bool
&& IdLabelInfo -> Bool
externallyVisibleIdLabel IdLabelInfo
info
externallyVisibleCLabel (CC_Label _)            = Bool
True
externallyVisibleCLabel (CCS_Label _)           = Bool
True
externallyVisibleCLabel (DynamicLinkerLabel _ _)  = Bool
False
externallyVisibleCLabel (HpcTicksLabel _)       = Bool
True
externallyVisibleCLabel (LargeBitmapLabel _)    = Bool
False
externallyVisibleCLabel (SRTLabel _)            = Bool
False
externallyVisibleCLabel (PicBaseLabel {}) = String -> Bool
forall a. String -> a
panic "externallyVisibleCLabel PicBaseLabel"
externallyVisibleCLabel (DeadStripPreventer {}) = String -> Bool
forall a. String -> a
panic "externallyVisibleCLabel DeadStripPreventer"

externallyVisibleIdLabel :: IdLabelInfo -> Bool
externallyVisibleIdLabel :: IdLabelInfo -> Bool
externallyVisibleIdLabel LocalInfoTable  = Bool
False
externallyVisibleIdLabel LocalEntry      = Bool
False
externallyVisibleIdLabel BlockInfoTable  = Bool
False
externallyVisibleIdLabel _               = Bool
True

-- -----------------------------------------------------------------------------
-- Finding the "type" of a CLabel

-- For generating correct types in label declarations:

data CLabelType
  = CodeLabel   -- Address of some executable instructions
  | DataLabel   -- Address of data, not a GC ptr
  | GcPtrLabel  -- Address of a (presumably static) GC object

isCFunctionLabel :: CLabel -> Bool
isCFunctionLabel :: CLabel -> Bool
isCFunctionLabel lbl :: CLabel
lbl = case CLabel -> CLabelType
labelType CLabel
lbl of
                        CodeLabel -> Bool
True
                        _other :: CLabelType
_other    -> Bool
False

isGcPtrLabel :: CLabel -> Bool
isGcPtrLabel :: CLabel -> Bool
isGcPtrLabel lbl :: CLabel
lbl = case CLabel -> CLabelType
labelType CLabel
lbl of
                        GcPtrLabel -> Bool
True
                        _other :: CLabelType
_other     -> Bool
False


-- | Work out the general type of data at the address of this label
--    whether it be code, data, or static GC object.
labelType :: CLabel -> CLabelType
labelType :: CLabel -> CLabelType
labelType (IdLabel _ _ info :: IdLabelInfo
info)                    = IdLabelInfo -> CLabelType
idInfoLabelType IdLabelInfo
info
labelType (CmmLabel _ _ CmmData)                = CLabelType
DataLabel
labelType (CmmLabel _ _ CmmClosure)             = CLabelType
GcPtrLabel
labelType (CmmLabel _ _ CmmCode)                = CLabelType
CodeLabel
labelType (CmmLabel _ _ CmmInfo)                = CLabelType
DataLabel
labelType (CmmLabel _ _ CmmEntry)               = CLabelType
CodeLabel
labelType (CmmLabel _ _ CmmPrimCall)            = CLabelType
CodeLabel
labelType (CmmLabel _ _ CmmRetInfo)             = CLabelType
DataLabel
labelType (CmmLabel _ _ CmmRet)                 = CLabelType
CodeLabel
labelType (RtsLabel (RtsSelectorInfoTable _ _)) = CLabelType
DataLabel
labelType (RtsLabel (RtsApInfoTable _ _))       = CLabelType
DataLabel
labelType (RtsLabel (RtsApFast _))              = CLabelType
CodeLabel
labelType (RtsLabel _)                          = CLabelType
DataLabel
labelType (LocalBlockLabel _)                   = CLabelType
CodeLabel
labelType (SRTLabel _)                          = CLabelType
DataLabel
labelType (ForeignLabel _ _ _ IsFunction)       = CLabelType
CodeLabel
labelType (ForeignLabel _ _ _ IsData)           = CLabelType
DataLabel
labelType (AsmTempLabel _)                      = String -> CLabelType
forall a. String -> a
panic "labelType(AsmTempLabel)"
labelType (AsmTempDerivedLabel _ _)             = String -> CLabelType
forall a. String -> a
panic "labelType(AsmTempDerivedLabel)"
labelType (StringLitLabel _)                    = CLabelType
DataLabel
labelType (CC_Label _)                          = CLabelType
DataLabel
labelType (CCS_Label _)                         = CLabelType
DataLabel
labelType (DynamicLinkerLabel _ _)              = CLabelType
DataLabel -- Is this right?
labelType PicBaseLabel                          = CLabelType
DataLabel
labelType (DeadStripPreventer _)                = CLabelType
DataLabel
labelType (HpcTicksLabel _)                     = CLabelType
DataLabel
labelType (LargeBitmapLabel _)                  = CLabelType
DataLabel

idInfoLabelType :: IdLabelInfo -> CLabelType
idInfoLabelType :: IdLabelInfo -> CLabelType
idInfoLabelType info :: IdLabelInfo
info =
  case IdLabelInfo
info of
    InfoTable     -> CLabelType
DataLabel
    LocalInfoTable -> CLabelType
DataLabel
    BlockInfoTable -> CLabelType
DataLabel
    Closure       -> CLabelType
GcPtrLabel
    ConInfoTable  -> CLabelType
DataLabel
    ClosureTable  -> CLabelType
DataLabel
    RednCounts    -> CLabelType
DataLabel
    Bytes         -> CLabelType
DataLabel
    _             -> CLabelType
CodeLabel


-- -----------------------------------------------------------------------------

-- | Is a 'CLabel' defined in the current module being compiled?
--
-- Sometimes we can optimise references within a compilation unit in ways that
-- we couldn't for inter-module references. This provides a conservative
-- estimate of whether a 'CLabel' lives in the current module.
isLocalCLabel :: Module -> CLabel -> Bool
isLocalCLabel :: Module -> CLabel -> Bool
isLocalCLabel this_mod :: Module
this_mod lbl :: CLabel
lbl =
  case CLabel
lbl of
    IdLabel name :: Name
name _ _
      | Name -> Bool
isInternalName Name
name -> Bool
True
      | Bool
otherwise           -> HasDebugCallStack => Name -> Module
Name -> Module
nameModule Name
name Module -> Module -> Bool
forall a. Eq a => a -> a -> Bool
== Module
this_mod
    LocalBlockLabel _       -> Bool
True
    _                       -> Bool
False

-- -----------------------------------------------------------------------------

-- | Does a 'CLabel' need dynamic linkage?
--
-- When referring to data in code, we need to know whether
-- that data resides in a DLL or not. [Win32 only.]
-- @labelDynamic@ returns @True@ if the label is located
-- in a DLL, be it a data reference or not.
labelDynamic :: DynFlags -> Module -> CLabel -> Bool
labelDynamic :: DynFlags -> Module -> CLabel -> Bool
labelDynamic dflags :: DynFlags
dflags this_mod :: Module
this_mod lbl :: CLabel
lbl =
  case CLabel
lbl of
   -- is the RTS in a DLL or not?
   RtsLabel _ ->
     Bool
externalDynamicRefs Bool -> Bool -> Bool
&& (UnitId
this_pkg UnitId -> UnitId -> Bool
forall a. Eq a => a -> a -> Bool
/= UnitId
rtsUnitId)

   IdLabel n :: Name
n _ _ ->
     DynFlags -> Module -> Name -> Bool
isDllName DynFlags
dflags Module
this_mod Name
n

   -- When compiling in the "dyn" way, each package is to be linked into
   -- its own shared library.
   CmmLabel pkg :: UnitId
pkg _ _
    | OS
os OS -> OS -> Bool
forall a. Eq a => a -> a -> Bool
== OS
OSMinGW32 ->
       Bool
externalDynamicRefs Bool -> Bool -> Bool
&& (UnitId
this_pkg UnitId -> UnitId -> Bool
forall a. Eq a => a -> a -> Bool
/= UnitId
pkg)
    | Bool
otherwise ->
       GeneralFlag -> DynFlags -> Bool
gopt GeneralFlag
Opt_ExternalDynamicRefs DynFlags
dflags

   LocalBlockLabel _    -> Bool
False

   ForeignLabel _ _ source :: ForeignLabelSource
source _  ->
       if OS
os OS -> OS -> Bool
forall a. Eq a => a -> a -> Bool
== OS
OSMinGW32
       then case ForeignLabelSource
source of
            -- Foreign label is in some un-named foreign package (or DLL).
            ForeignLabelInExternalPackage -> Bool
True

            -- Foreign label is linked into the same package as the
            -- source file currently being compiled.
            ForeignLabelInThisPackage -> Bool
False

            -- Foreign label is in some named package.
            -- When compiling in the "dyn" way, each package is to be
            -- linked into its own DLL.
            ForeignLabelInPackage pkgId :: UnitId
pkgId ->
                Bool
externalDynamicRefs Bool -> Bool -> Bool
&& (UnitId
this_pkg UnitId -> UnitId -> Bool
forall a. Eq a => a -> a -> Bool
/= UnitId
pkgId)

       else -- On Mac OS X and on ELF platforms, false positives are OK,
            -- so we claim that all foreign imports come from dynamic
            -- libraries
            Bool
True

   CC_Label cc :: CostCentre
cc ->
     Bool
externalDynamicRefs Bool -> Bool -> Bool
&& Bool -> Bool
not (CostCentre -> Module -> Bool
ccFromThisModule CostCentre
cc Module
this_mod)

   -- CCS_Label always contains a CostCentre defined in the current module
   CCS_Label _ -> Bool
False

   HpcTicksLabel m :: Module
m ->
     Bool
externalDynamicRefs Bool -> Bool -> Bool
&& Module
this_mod Module -> Module -> Bool
forall a. Eq a => a -> a -> Bool
/= Module
m

   -- Note that DynamicLinkerLabels do NOT require dynamic linking themselves.
   _                 -> Bool
False
  where
    externalDynamicRefs :: Bool
externalDynamicRefs = GeneralFlag -> DynFlags -> Bool
gopt GeneralFlag
Opt_ExternalDynamicRefs DynFlags
dflags
    os :: OS
os = Platform -> OS
platformOS (DynFlags -> Platform
targetPlatform DynFlags
dflags)
    this_pkg :: UnitId
this_pkg = Module -> UnitId
moduleUnitId Module
this_mod


-----------------------------------------------------------------------------
-- Printing out CLabels.

{-
Convention:

      <name>_<type>

where <name> is <Module>_<name> for external names and <unique> for
internal names. <type> is one of the following:

         info                   Info table
         srt                    Static reference table
         entry                  Entry code (function, closure)
         slow                   Slow entry code (if any)
         ret                    Direct return address
         vtbl                   Vector table
         <n>_alt                Case alternative (tag n)
         dflt                   Default case alternative
         btm                    Large bitmap vector
         closure                Static closure
         con_entry              Dynamic Constructor entry code
         con_info               Dynamic Constructor info table
         static_entry           Static Constructor entry code
         static_info            Static Constructor info table
         sel_info               Selector info table
         sel_entry              Selector entry code
         cc                     Cost centre
         ccs                    Cost centre stack

Many of these distinctions are only for documentation reasons.  For
example, _ret is only distinguished from _entry to make it easy to
tell whether a code fragment is a return point or a closure/function
entry.

Note [Closure and info labels]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
For a function 'foo, we have:
   foo_info    : Points to the info table describing foo's closure
                 (and entry code for foo with tables next to code)
   foo_closure : Static (no-free-var) closure only:
                 points to the statically-allocated closure

For a data constructor (such as Just or Nothing), we have:
    Just_con_info: Info table for the data constructor itself
                   the first word of a heap-allocated Just
    Just_info:     Info table for the *worker function*, an
                   ordinary Haskell function of arity 1 that
                   allocates a (Just x) box:
                      Just = \x -> Just x
    Just_closure:  The closure for this worker

    Nothing_closure: a statically allocated closure for Nothing
    Nothing_static_info: info table for Nothing_closure

All these must be exported symbol, EXCEPT Just_info.  We don't need to
export this because in other modules we either have
       * A reference to 'Just'; use Just_closure
       * A saturated call 'Just x'; allocate using Just_con_info
Not exporting these Just_info labels reduces the number of symbols
somewhat.

Note [Bytes label]
~~~~~~~~~~~~~~~~~~
For a top-level string literal 'foo', we have just one symbol 'foo_bytes', which
points to a static data block containing the content of the literal.

Note [Proc-point local block entry-points]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
A label for a proc-point local block entry-point has no "_entry" suffix. With
`infoTblLbl` we derive an info table label from a proc-point block ID. If
we convert such an info table label into an entry label we must produce
the label without an "_entry" suffix. So an info table label records
the fact that it was derived from a block ID in `IdLabelInfo` as
`BlockInfoTable`.

The info table label and the local block label are both local labels
and are not externally visible.
-}

instance Outputable CLabel where
  ppr :: CLabel -> SDoc
ppr c :: CLabel
c = (Platform -> SDoc) -> SDoc
sdocWithPlatform ((Platform -> SDoc) -> SDoc) -> (Platform -> SDoc) -> SDoc
forall a b. (a -> b) -> a -> b
$ \platform :: Platform
platform -> Platform -> CLabel -> SDoc
pprCLabel Platform
platform CLabel
c

pprCLabel :: Platform -> CLabel -> SDoc

pprCLabel :: Platform -> CLabel -> SDoc
pprCLabel _ (LocalBlockLabel u :: Unique
u)
  =  SDoc
tempLabelPrefixOrUnderscore SDoc -> SDoc -> SDoc
<> Unique -> SDoc
pprUniqueAlways Unique
u

pprCLabel platform :: Platform
platform (AsmTempLabel u :: Unique
u)
 | Bool -> Bool
not (Platform -> Bool
platformUnregisterised Platform
platform)
  =  SDoc
tempLabelPrefixOrUnderscore SDoc -> SDoc -> SDoc
<> Unique -> SDoc
pprUniqueAlways Unique
u

pprCLabel platform :: Platform
platform (AsmTempDerivedLabel l :: CLabel
l suf :: FastString
suf)
 | String
cGhcWithNativeCodeGen String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== "YES"
   = PtrString -> SDoc
ptext (Platform -> PtrString
asmTempLabelPrefix Platform
platform)
     SDoc -> SDoc -> SDoc
<> case CLabel
l of AsmTempLabel u :: Unique
u    -> Unique -> SDoc
pprUniqueAlways Unique
u
                  LocalBlockLabel u :: Unique
u -> Unique -> SDoc
pprUniqueAlways Unique
u
                  _other :: CLabel
_other            -> Platform -> CLabel -> SDoc
pprCLabel Platform
platform CLabel
l
     SDoc -> SDoc -> SDoc
<> FastString -> SDoc
ftext FastString
suf

pprCLabel platform :: Platform
platform (DynamicLinkerLabel info :: DynamicLinkerLabelInfo
info lbl :: CLabel
lbl)
 | String
cGhcWithNativeCodeGen String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== "YES"
   = Platform -> DynamicLinkerLabelInfo -> CLabel -> SDoc
pprDynamicLinkerAsmLabel Platform
platform DynamicLinkerLabelInfo
info CLabel
lbl

pprCLabel _ PicBaseLabel
 | String
cGhcWithNativeCodeGen String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== "YES"
   = String -> SDoc
text "1b"

pprCLabel platform :: Platform
platform (DeadStripPreventer lbl :: CLabel
lbl)
 | String
cGhcWithNativeCodeGen String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== "YES"
   =
   {-
      `lbl` can be temp one but we need to ensure that dsp label will stay
      in the final binary so we prepend non-temp prefix ("dsp_") and
      optional `_` (underscore) because this is how you mark non-temp symbols
      on some platforms (Darwin)
   -}
   SDoc -> SDoc
maybe_underscore (SDoc -> SDoc) -> SDoc -> SDoc
forall a b. (a -> b) -> a -> b
$ String -> SDoc
text "dsp_"
   SDoc -> SDoc -> SDoc
<> Platform -> CLabel -> SDoc
pprCLabel Platform
platform CLabel
lbl SDoc -> SDoc -> SDoc
<> String -> SDoc
text "_dsp"

pprCLabel _ (StringLitLabel u :: Unique
u)
 | String
cGhcWithNativeCodeGen String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== "YES"
  = Unique -> SDoc
pprUniqueAlways Unique
u SDoc -> SDoc -> SDoc
<> PtrString -> SDoc
ptext (String -> PtrString
sLit "_str")

pprCLabel platform :: Platform
platform lbl :: CLabel
lbl
   = (PprStyle -> SDoc) -> SDoc
getPprStyle ((PprStyle -> SDoc) -> SDoc) -> (PprStyle -> SDoc) -> SDoc
forall a b. (a -> b) -> a -> b
$ \ sty :: PprStyle
sty ->
     if String
cGhcWithNativeCodeGen String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== "YES" Bool -> Bool -> Bool
&& PprStyle -> Bool
asmStyle PprStyle
sty
     then SDoc -> SDoc
maybe_underscore (Platform -> CLabel -> SDoc
pprAsmCLbl Platform
platform CLabel
lbl)
     else CLabel -> SDoc
pprCLbl CLabel
lbl

maybe_underscore :: SDoc -> SDoc
maybe_underscore :: SDoc -> SDoc
maybe_underscore doc :: SDoc
doc
  | Bool
underscorePrefix = SDoc
pp_cSEP SDoc -> SDoc -> SDoc
<> SDoc
doc
  | Bool
otherwise        = SDoc
doc

pprAsmCLbl :: Platform -> CLabel -> SDoc
pprAsmCLbl :: Platform -> CLabel -> SDoc
pprAsmCLbl platform :: Platform
platform (ForeignLabel fs :: FastString
fs (Just sz :: Int
sz) _ _)
 | Platform -> OS
platformOS Platform
platform OS -> OS -> Bool
forall a. Eq a => a -> a -> Bool
== OS
OSMinGW32
    -- In asm mode, we need to put the suffix on a stdcall ForeignLabel.
    -- (The C compiler does this itself).
    = FastString -> SDoc
ftext FastString
fs SDoc -> SDoc -> SDoc
<> Char -> SDoc
char '@' SDoc -> SDoc -> SDoc
<> Int -> SDoc
int Int
sz
pprAsmCLbl _ lbl :: CLabel
lbl
   = CLabel -> SDoc
pprCLbl CLabel
lbl

pprCLbl :: CLabel -> SDoc
pprCLbl :: CLabel -> SDoc
pprCLbl (StringLitLabel u :: Unique
u)
  = Unique -> SDoc
pprUniqueAlways Unique
u SDoc -> SDoc -> SDoc
<> String -> SDoc
text "_str"

pprCLbl (SRTLabel u :: Unique
u)
  = SDoc
tempLabelPrefixOrUnderscore SDoc -> SDoc -> SDoc
<> Unique -> SDoc
pprUniqueAlways Unique
u SDoc -> SDoc -> SDoc
<> SDoc
pp_cSEP SDoc -> SDoc -> SDoc
<> String -> SDoc
text "srt"

pprCLbl (LargeBitmapLabel u :: Unique
u)  =
  SDoc
tempLabelPrefixOrUnderscore
  SDoc -> SDoc -> SDoc
<> Char -> SDoc
char 'b' SDoc -> SDoc -> SDoc
<> Unique -> SDoc
pprUniqueAlways Unique
u SDoc -> SDoc -> SDoc
<> SDoc
pp_cSEP SDoc -> SDoc -> SDoc
<> String -> SDoc
text "btm"
-- Some bitsmaps for tuple constructors have a numeric tag (e.g. '7')
-- until that gets resolved we'll just force them to start
-- with a letter so the label will be legal assembly code.


pprCLbl (CmmLabel _ str :: FastString
str CmmCode)        = FastString -> SDoc
ftext FastString
str
pprCLbl (CmmLabel _ str :: FastString
str CmmData)        = FastString -> SDoc
ftext FastString
str
pprCLbl (CmmLabel _ str :: FastString
str CmmPrimCall)    = FastString -> SDoc
ftext FastString
str

pprCLbl (LocalBlockLabel u :: Unique
u)             =
    SDoc
tempLabelPrefixOrUnderscore SDoc -> SDoc -> SDoc
<> String -> SDoc
text "blk_" SDoc -> SDoc -> SDoc
<> Unique -> SDoc
pprUniqueAlways Unique
u

pprCLbl (RtsLabel (RtsApFast str :: FastString
str))   = FastString -> SDoc
ftext FastString
str SDoc -> SDoc -> SDoc
<> String -> SDoc
text "_fast"

pprCLbl (RtsLabel (RtsSelectorInfoTable upd_reqd :: Bool
upd_reqd offset :: Int
offset))
  = (DynFlags -> SDoc) -> SDoc
sdocWithDynFlags ((DynFlags -> SDoc) -> SDoc) -> (DynFlags -> SDoc) -> SDoc
forall a b. (a -> b) -> a -> b
$ \dflags :: DynFlags
dflags ->
    ASSERT(offset >= 0 && offset <= mAX_SPEC_SELECTEE_SIZE dflags)
    [SDoc] -> SDoc
hcat [String -> SDoc
text "stg_sel_", String -> SDoc
text (Int -> String
forall a. Show a => a -> String
show Int
offset),
          PtrString -> SDoc
ptext (if Bool
upd_reqd
                 then (String -> PtrString
sLit "_upd_info")
                 else (String -> PtrString
sLit "_noupd_info"))
        ]

pprCLbl (RtsLabel (RtsSelectorEntry upd_reqd :: Bool
upd_reqd offset :: Int
offset))
  = (DynFlags -> SDoc) -> SDoc
sdocWithDynFlags ((DynFlags -> SDoc) -> SDoc) -> (DynFlags -> SDoc) -> SDoc
forall a b. (a -> b) -> a -> b
$ \dflags :: DynFlags
dflags ->
    ASSERT(offset >= 0 && offset <= mAX_SPEC_SELECTEE_SIZE dflags)
    [SDoc] -> SDoc
hcat [String -> SDoc
text "stg_sel_", String -> SDoc
text (Int -> String
forall a. Show a => a -> String
show Int
offset),
                PtrString -> SDoc
ptext (if Bool
upd_reqd
                        then (String -> PtrString
sLit "_upd_entry")
                        else (String -> PtrString
sLit "_noupd_entry"))
        ]

pprCLbl (RtsLabel (RtsApInfoTable upd_reqd :: Bool
upd_reqd arity :: Int
arity))
  = (DynFlags -> SDoc) -> SDoc
sdocWithDynFlags ((DynFlags -> SDoc) -> SDoc) -> (DynFlags -> SDoc) -> SDoc
forall a b. (a -> b) -> a -> b
$ \dflags :: DynFlags
dflags ->
    ASSERT(arity > 0 && arity <= mAX_SPEC_AP_SIZE dflags)
    [SDoc] -> SDoc
hcat [String -> SDoc
text "stg_ap_", String -> SDoc
text (Int -> String
forall a. Show a => a -> String
show Int
arity),
                PtrString -> SDoc
ptext (if Bool
upd_reqd
                        then (String -> PtrString
sLit "_upd_info")
                        else (String -> PtrString
sLit "_noupd_info"))
        ]

pprCLbl (RtsLabel (RtsApEntry upd_reqd :: Bool
upd_reqd arity :: Int
arity))
  = (DynFlags -> SDoc) -> SDoc
sdocWithDynFlags ((DynFlags -> SDoc) -> SDoc) -> (DynFlags -> SDoc) -> SDoc
forall a b. (a -> b) -> a -> b
$ \dflags :: DynFlags
dflags ->
    ASSERT(arity > 0 && arity <= mAX_SPEC_AP_SIZE dflags)
    [SDoc] -> SDoc
hcat [String -> SDoc
text "stg_ap_", String -> SDoc
text (Int -> String
forall a. Show a => a -> String
show Int
arity),
                PtrString -> SDoc
ptext (if Bool
upd_reqd
                        then (String -> PtrString
sLit "_upd_entry")
                        else (String -> PtrString
sLit "_noupd_entry"))
        ]

pprCLbl (CmmLabel _ fs :: FastString
fs CmmInfo)
  = FastString -> SDoc
ftext FastString
fs SDoc -> SDoc -> SDoc
<> String -> SDoc
text "_info"

pprCLbl (CmmLabel _ fs :: FastString
fs CmmEntry)
  = FastString -> SDoc
ftext FastString
fs SDoc -> SDoc -> SDoc
<> String -> SDoc
text "_entry"

pprCLbl (CmmLabel _ fs :: FastString
fs CmmRetInfo)
  = FastString -> SDoc
ftext FastString
fs SDoc -> SDoc -> SDoc
<> String -> SDoc
text "_info"

pprCLbl (CmmLabel _ fs :: FastString
fs CmmRet)
  = FastString -> SDoc
ftext FastString
fs SDoc -> SDoc -> SDoc
<> String -> SDoc
text "_ret"

pprCLbl (CmmLabel _ fs :: FastString
fs CmmClosure)
  = FastString -> SDoc
ftext FastString
fs SDoc -> SDoc -> SDoc
<> String -> SDoc
text "_closure"

pprCLbl (RtsLabel (RtsPrimOp primop :: PrimOp
primop))
  = String -> SDoc
text "stg_" SDoc -> SDoc -> SDoc
<> PrimOp -> SDoc
forall a. Outputable a => a -> SDoc
ppr PrimOp
primop

pprCLbl (RtsLabel (RtsSlowFastTickyCtr pat :: String
pat))
  = String -> SDoc
text "SLOW_CALL_fast_" SDoc -> SDoc -> SDoc
<> String -> SDoc
text String
pat SDoc -> SDoc -> SDoc
<> PtrString -> SDoc
ptext (String -> PtrString
sLit "_ctr")

pprCLbl (ForeignLabel str :: FastString
str _ _ _)
  = FastString -> SDoc
ftext FastString
str

pprCLbl (IdLabel name :: Name
name _cafs :: CafInfo
_cafs flavor :: IdLabelInfo
flavor) =
  Name -> SDoc
internalNamePrefix Name
name SDoc -> SDoc -> SDoc
<> Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
name SDoc -> SDoc -> SDoc
<> IdLabelInfo -> SDoc
ppIdFlavor IdLabelInfo
flavor

pprCLbl (CC_Label cc :: CostCentre
cc)           = CostCentre -> SDoc
forall a. Outputable a => a -> SDoc
ppr CostCentre
cc
pprCLbl (CCS_Label ccs :: CostCentreStack
ccs)         = CostCentreStack -> SDoc
forall a. Outputable a => a -> SDoc
ppr CostCentreStack
ccs

pprCLbl (HpcTicksLabel mod :: Module
mod)
  = String -> SDoc
text "_hpc_tickboxes_"  SDoc -> SDoc -> SDoc
<> Module -> SDoc
forall a. Outputable a => a -> SDoc
ppr Module
mod SDoc -> SDoc -> SDoc
<> PtrString -> SDoc
ptext (String -> PtrString
sLit "_hpc")

pprCLbl (AsmTempLabel {})       = String -> SDoc
forall a. String -> a
panic "pprCLbl AsmTempLabel"
pprCLbl (AsmTempDerivedLabel {})= String -> SDoc
forall a. String -> a
panic "pprCLbl AsmTempDerivedLabel"
pprCLbl (DynamicLinkerLabel {}) = String -> SDoc
forall a. String -> a
panic "pprCLbl DynamicLinkerLabel"
pprCLbl (PicBaseLabel {})       = String -> SDoc
forall a. String -> a
panic "pprCLbl PicBaseLabel"
pprCLbl (DeadStripPreventer {}) = String -> SDoc
forall a. String -> a
panic "pprCLbl DeadStripPreventer"

ppIdFlavor :: IdLabelInfo -> SDoc
ppIdFlavor :: IdLabelInfo -> SDoc
ppIdFlavor x :: IdLabelInfo
x = SDoc
pp_cSEP SDoc -> SDoc -> SDoc
<> String -> SDoc
text
               (case IdLabelInfo
x of
                       Closure          -> "closure"
                       InfoTable        -> "info"
                       LocalInfoTable   -> "info"
                       Entry            -> "entry"
                       LocalEntry       -> "entry"
                       Slow             -> "slow"
                       RednCounts       -> "ct"
                       ConEntry         -> "con_entry"
                       ConInfoTable     -> "con_info"
                       ClosureTable     -> "closure_tbl"
                       Bytes            -> "bytes"
                       BlockInfoTable   -> "info"
                      )


pp_cSEP :: SDoc
pp_cSEP :: SDoc
pp_cSEP = Char -> SDoc
char '_'


instance Outputable ForeignLabelSource where
 ppr :: ForeignLabelSource -> SDoc
ppr fs :: ForeignLabelSource
fs
  = case ForeignLabelSource
fs of
        ForeignLabelInPackage pkgId :: UnitId
pkgId     -> SDoc -> SDoc
parens (SDoc -> SDoc) -> SDoc -> SDoc
forall a b. (a -> b) -> a -> b
$ String -> SDoc
text "package: " SDoc -> SDoc -> SDoc
<> UnitId -> SDoc
forall a. Outputable a => a -> SDoc
ppr UnitId
pkgId
        ForeignLabelInThisPackage       -> SDoc -> SDoc
parens (SDoc -> SDoc) -> SDoc -> SDoc
forall a b. (a -> b) -> a -> b
$ String -> SDoc
text "this package"
        ForeignLabelInExternalPackage   -> SDoc -> SDoc
parens (SDoc -> SDoc) -> SDoc -> SDoc
forall a b. (a -> b) -> a -> b
$ String -> SDoc
text "external package"

internalNamePrefix :: Name -> SDoc
internalNamePrefix :: Name -> SDoc
internalNamePrefix name :: Name
name = (PprStyle -> SDoc) -> SDoc
getPprStyle ((PprStyle -> SDoc) -> SDoc) -> (PprStyle -> SDoc) -> SDoc
forall a b. (a -> b) -> a -> b
$ \ sty :: PprStyle
sty ->
  if PprStyle -> Bool
asmStyle PprStyle
sty Bool -> Bool -> Bool
&& Bool
isRandomGenerated then
    (Platform -> SDoc) -> SDoc
sdocWithPlatform ((Platform -> SDoc) -> SDoc) -> (Platform -> SDoc) -> SDoc
forall a b. (a -> b) -> a -> b
$ \platform :: Platform
platform ->
      PtrString -> SDoc
ptext (Platform -> PtrString
asmTempLabelPrefix Platform
platform)
  else
    SDoc
empty
  where
    isRandomGenerated :: Bool
isRandomGenerated = Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ Name -> Bool
isExternalName Name
name

tempLabelPrefixOrUnderscore :: SDoc
tempLabelPrefixOrUnderscore :: SDoc
tempLabelPrefixOrUnderscore = (Platform -> SDoc) -> SDoc
sdocWithPlatform ((Platform -> SDoc) -> SDoc) -> (Platform -> SDoc) -> SDoc
forall a b. (a -> b) -> a -> b
$ \platform :: Platform
platform ->
  (PprStyle -> SDoc) -> SDoc
getPprStyle ((PprStyle -> SDoc) -> SDoc) -> (PprStyle -> SDoc) -> SDoc
forall a b. (a -> b) -> a -> b
$ \ sty :: PprStyle
sty ->
   if PprStyle -> Bool
asmStyle PprStyle
sty then
      PtrString -> SDoc
ptext (Platform -> PtrString
asmTempLabelPrefix Platform
platform)
   else
      Char -> SDoc
char '_'

-- -----------------------------------------------------------------------------
-- Machine-dependent knowledge about labels.

underscorePrefix :: Bool   -- leading underscore on assembler labels?
underscorePrefix :: Bool
underscorePrefix = (String
cLeadingUnderscore String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== "YES")

asmTempLabelPrefix :: Platform -> PtrString  -- for formatting labels
asmTempLabelPrefix :: Platform -> PtrString
asmTempLabelPrefix platform :: Platform
platform = case Platform -> OS
platformOS Platform
platform of
    OSDarwin -> String -> PtrString
sLit "L"
    OSAIX    -> String -> PtrString
sLit "__L" -- follow IBM XL C's convention
    _        -> String -> PtrString
sLit ".L"

pprDynamicLinkerAsmLabel :: Platform -> DynamicLinkerLabelInfo -> CLabel -> SDoc
pprDynamicLinkerAsmLabel :: Platform -> DynamicLinkerLabelInfo -> CLabel -> SDoc
pprDynamicLinkerAsmLabel platform :: Platform
platform dllInfo :: DynamicLinkerLabelInfo
dllInfo lbl :: CLabel
lbl =
    case Platform -> OS
platformOS Platform
platform of
      OSDarwin
        | Platform -> Arch
platformArch Platform
platform Arch -> Arch -> Bool
forall a. Eq a => a -> a -> Bool
== Arch
ArchX86_64 ->
          case DynamicLinkerLabelInfo
dllInfo of
            CodeStub        -> Char -> SDoc
char 'L' SDoc -> SDoc -> SDoc
<> CLabel -> SDoc
forall a. Outputable a => a -> SDoc
ppr CLabel
lbl SDoc -> SDoc -> SDoc
<> String -> SDoc
text "$stub"
            SymbolPtr       -> Char -> SDoc
char 'L' SDoc -> SDoc -> SDoc
<> CLabel -> SDoc
forall a. Outputable a => a -> SDoc
ppr CLabel
lbl SDoc -> SDoc -> SDoc
<> String -> SDoc
text "$non_lazy_ptr"
            GotSymbolPtr    -> CLabel -> SDoc
forall a. Outputable a => a -> SDoc
ppr CLabel
lbl SDoc -> SDoc -> SDoc
<> String -> SDoc
text "@GOTPCREL"
            GotSymbolOffset -> CLabel -> SDoc
forall a. Outputable a => a -> SDoc
ppr CLabel
lbl
        | Bool
otherwise ->
          case DynamicLinkerLabelInfo
dllInfo of
            CodeStub  -> Char -> SDoc
char 'L' SDoc -> SDoc -> SDoc
<> CLabel -> SDoc
forall a. Outputable a => a -> SDoc
ppr CLabel
lbl SDoc -> SDoc -> SDoc
<> String -> SDoc
text "$stub"
            SymbolPtr -> Char -> SDoc
char 'L' SDoc -> SDoc -> SDoc
<> CLabel -> SDoc
forall a. Outputable a => a -> SDoc
ppr CLabel
lbl SDoc -> SDoc -> SDoc
<> String -> SDoc
text "$non_lazy_ptr"
            _         -> String -> SDoc
forall a. String -> a
panic "pprDynamicLinkerAsmLabel"

      OSAIX ->
          case DynamicLinkerLabelInfo
dllInfo of
            SymbolPtr -> String -> SDoc
text "LC.." SDoc -> SDoc -> SDoc
<> CLabel -> SDoc
forall a. Outputable a => a -> SDoc
ppr CLabel
lbl -- GCC's naming convention
            _         -> String -> SDoc
forall a. String -> a
panic "pprDynamicLinkerAsmLabel"

      _ | OS -> Bool
osElfTarget (Platform -> OS
platformOS Platform
platform) -> SDoc
elfLabel

      OSMinGW32 ->
          case DynamicLinkerLabelInfo
dllInfo of
            SymbolPtr -> String -> SDoc
text "__imp_" SDoc -> SDoc -> SDoc
<> CLabel -> SDoc
forall a. Outputable a => a -> SDoc
ppr CLabel
lbl
            _         -> String -> SDoc
forall a. String -> a
panic "pprDynamicLinkerAsmLabel"

      _ -> String -> SDoc
forall a. String -> a
panic "pprDynamicLinkerAsmLabel"
  where
    elfLabel :: SDoc
elfLabel
      | Platform -> Arch
platformArch Platform
platform Arch -> Arch -> Bool
forall a. Eq a => a -> a -> Bool
== Arch
ArchPPC
      = case DynamicLinkerLabelInfo
dllInfo of
          CodeStub  -> -- See Note [.LCTOC1 in PPC PIC code]
                       CLabel -> SDoc
forall a. Outputable a => a -> SDoc
ppr CLabel
lbl SDoc -> SDoc -> SDoc
<> String -> SDoc
text "+32768@plt"
          SymbolPtr -> String -> SDoc
text ".LC_" SDoc -> SDoc -> SDoc
<> CLabel -> SDoc
forall a. Outputable a => a -> SDoc
ppr CLabel
lbl
          _         -> String -> SDoc
forall a. String -> a
panic "pprDynamicLinkerAsmLabel"

      | Platform -> Arch
platformArch Platform
platform Arch -> Arch -> Bool
forall a. Eq a => a -> a -> Bool
== Arch
ArchX86_64
      = case DynamicLinkerLabelInfo
dllInfo of
          CodeStub        -> CLabel -> SDoc
forall a. Outputable a => a -> SDoc
ppr CLabel
lbl SDoc -> SDoc -> SDoc
<> String -> SDoc
text "@plt"
          GotSymbolPtr    -> CLabel -> SDoc
forall a. Outputable a => a -> SDoc
ppr CLabel
lbl SDoc -> SDoc -> SDoc
<> String -> SDoc
text "@gotpcrel"
          GotSymbolOffset -> CLabel -> SDoc
forall a. Outputable a => a -> SDoc
ppr CLabel
lbl
          SymbolPtr       -> String -> SDoc
text ".LC_" SDoc -> SDoc -> SDoc
<> CLabel -> SDoc
forall a. Outputable a => a -> SDoc
ppr CLabel
lbl

      | Platform -> Arch
platformArch Platform
platform Arch -> Arch -> Bool
forall a. Eq a => a -> a -> Bool
== PPC_64ABI -> Arch
ArchPPC_64 PPC_64ABI
ELF_V1
        Bool -> Bool -> Bool
|| Platform -> Arch
platformArch Platform
platform Arch -> Arch -> Bool
forall a. Eq a => a -> a -> Bool
== PPC_64ABI -> Arch
ArchPPC_64 PPC_64ABI
ELF_V2
      = case DynamicLinkerLabelInfo
dllInfo of
          GotSymbolPtr    -> String -> SDoc
text ".LC_"  SDoc -> SDoc -> SDoc
<> CLabel -> SDoc
forall a. Outputable a => a -> SDoc
ppr CLabel
lbl
                                  SDoc -> SDoc -> SDoc
<> String -> SDoc
text "@toc"
          GotSymbolOffset -> CLabel -> SDoc
forall a. Outputable a => a -> SDoc
ppr CLabel
lbl
          SymbolPtr       -> String -> SDoc
text ".LC_" SDoc -> SDoc -> SDoc
<> CLabel -> SDoc
forall a. Outputable a => a -> SDoc
ppr CLabel
lbl
          _               -> String -> SDoc
forall a. String -> a
panic "pprDynamicLinkerAsmLabel"

      | Bool
otherwise
      = case DynamicLinkerLabelInfo
dllInfo of
          CodeStub        -> CLabel -> SDoc
forall a. Outputable a => a -> SDoc
ppr CLabel
lbl SDoc -> SDoc -> SDoc
<> String -> SDoc
text "@plt"
          SymbolPtr       -> String -> SDoc
text ".LC_" SDoc -> SDoc -> SDoc
<> CLabel -> SDoc
forall a. Outputable a => a -> SDoc
ppr CLabel
lbl
          GotSymbolPtr    -> CLabel -> SDoc
forall a. Outputable a => a -> SDoc
ppr CLabel
lbl SDoc -> SDoc -> SDoc
<> String -> SDoc
text "@got"
          GotSymbolOffset -> CLabel -> SDoc
forall a. Outputable a => a -> SDoc
ppr CLabel
lbl SDoc -> SDoc -> SDoc
<> String -> SDoc
text "@gotoff"