    {-
    (c) The GRASP/AQUA Project, Glasgow University, 1992-1998

    \section[Foreign]{Foreign calls}
    -}

    {-# LANGUAGE DeriveDataTypeable #-}

    module GHC.Types.ForeignCall (
            ForeignCall(..), isSafeForeignCall,
            Safety(..), playSafe, playInterruptible,

            CExportSpec(..), CLabelString, isCLabelString, pprCLabelString,
            CCallSpec(..),
            CCallTarget(..), isDynamicTarget,
            CCallConv(..), defaultCCallConv, ccallConvToInt, ccallConvAttribute,

            Header(..), CType(..),
        ) where

    import GHC.Prelude

    import GHC.Data.FastString
    import GHC.Utils.Binary
    import GHC.Utils.Outputable
    import GHC.Utils.Panic
    import GHC.Unit.Module
    import GHC.Types.SourceText ( SourceText, pprWithSourceText )

    import Data.Char
    import Data.Data

    {-
    ************************************************************************
    *                                                                      *
    \subsubsection{Data types}
    *                                                                      *
    ************************************************************************
    -}

    newtype ForeignCall = CCall CCallSpec
      deriving ForeignCall -> ForeignCall -> Bool
    (ForeignCall -> ForeignCall -> Bool)
    -> (ForeignCall -> ForeignCall -> Bool) -> Eq ForeignCall
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: ForeignCall -> ForeignCall -> Bool
    == :: ForeignCall -> ForeignCall -> Bool
    $c/= :: ForeignCall -> ForeignCall -> Bool
    /= :: ForeignCall -> ForeignCall -> Bool
    Eq

    isSafeForeignCall :: ForeignCall -> Bool
    isSafeForeignCall :: ForeignCall -> Bool
    isSafeForeignCall (CCall (CCallSpec CCallTarget
    _ CCallConv
    _ Safety
    safe)) = Safety -> Bool
    playSafe Safety
    safe

    -- We may need more clues to distinguish foreign calls
    -- but this simple printer will do for now
    instance Outputable ForeignCall where
      ppr :: ForeignCall -> SDoc
    ppr (CCall CCallSpec
    cc)  = CCallSpec -> SDoc
    forall a. Outputable a => a -> SDoc
    ppr CCallSpec
    cc

    data Safety
      = PlaySafe          -- ^ Might invoke Haskell GC, or do a call back, or
                          --   switch threads, etc.  So make sure things are
                          --   tidy before the call. Additionally, in the threaded
                          --   RTS we arrange for the external call to be executed
                          --   by a separate OS thread, i.e., _concurrently_ to the
                          --   execution of other Haskell threads.

      | PlayInterruptible -- ^ Like PlaySafe, but additionally
                          --   the worker thread running this foreign call may
                          --   be unceremoniously killed, so it must be scheduled
                          --   on an unbound thread.

      | PlayRisky         -- ^ None of the above can happen; the call will return
                          --   without interacting with the runtime system at all.
                          --   Specifically:
                          --
                          --     * No GC
                          --     * No call backs
                          --     * No blocking
                          --     * No precise exceptions
                          --
      deriving ( Safety -> Safety -> Bool
    (Safety -> Safety -> Bool)
    -> (Safety -> Safety -> Bool) -> Eq Safety
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: Safety -> Safety -> Bool
    == :: Safety -> Safety -> Bool
    $c/= :: Safety -> Safety -> Bool
    /= :: Safety -> Safety -> Bool
    Eq, Int -> Safety -> ShowS
    [Safety] -> ShowS
    Safety -> String
    (Int -> Safety -> ShowS)
    -> (Safety -> String) -> ([Safety] -> ShowS) -> Show Safety
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> Safety -> ShowS
    showsPrec :: Int -> Safety -> ShowS
    $cshow :: Safety -> String
    show :: Safety -> String
    $cshowList :: [Safety] -> ShowS
    showList :: [Safety] -> ShowS
    Show, Typeable Safety
    Typeable Safety =>
    (forall (c :: * -> *).
     (forall d b. Data d => c (d -> b) -> d -> c b)
     -> (forall g. g -> c g) -> Safety -> c Safety)
    -> (forall (c :: * -> *).
        (forall b r. Data b => c (b -> r) -> c r)
        -> (forall r. r -> c r) -> Constr -> c Safety)
    -> (Safety -> Constr)
    -> (Safety -> DataType)
    -> (forall (t :: * -> *) (c :: * -> *).
        Typeable t =>
        (forall d. Data d => c (t d)) -> Maybe (c Safety))
    -> (forall (t :: * -> * -> *) (c :: * -> *).
        Typeable t =>
        (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Safety))
    -> ((forall b. Data b => b -> b) -> Safety -> Safety)
    -> (forall r r'.
        (r -> r' -> r)
        -> r -> (forall d. Data d => d -> r') -> Safety -> r)
    -> (forall r r'.
        (r' -> r -> r)
        -> r -> (forall d. Data d => d -> r') -> Safety -> r)
    -> (forall u. (forall d. Data d => d -> u) -> Safety -> [u])
    -> (forall u. Int -> (forall d. Data d => d -> u) -> Safety -> u)
    -> (forall (m :: * -> *).
        Monad m =>
        (forall d. Data d => d -> m d) -> Safety -> m Safety)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> Safety -> m Safety)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> Safety -> m Safety)
    -> Data Safety
    Safety -> Constr
    Safety -> DataType
    (forall b. Data b => b -> b) -> Safety -> Safety
    forall a.
    Typeable a =>
    (forall (c :: * -> *).
     (forall d b. Data d => c (d -> b) -> d -> c b)
     -> (forall g. g -> c g) -> a -> c a)
    -> (forall (c :: * -> *).
        (forall b r. Data b => c (b -> r) -> c r)
        -> (forall r. r -> c r) -> Constr -> c a)
    -> (a -> Constr)
    -> (a -> DataType)
    -> (forall (t :: * -> *) (c :: * -> *).
        Typeable t =>
        (forall d. Data d => c (t d)) -> Maybe (c a))
    -> (forall (t :: * -> * -> *) (c :: * -> *).
        Typeable t =>
        (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
    -> ((forall b. Data b => b -> b) -> a -> a)
    -> (forall r r'.
        (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
    -> (forall r r'.
        (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
    -> (forall u. (forall d. Data d => d -> u) -> a -> [u])
    -> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
    -> (forall (m :: * -> *).
        Monad m =>
        (forall d. Data d => d -> m d) -> a -> m a)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> a -> m a)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> a -> m a)
    -> Data a
    forall u. Int -> (forall d. Data d => d -> u) -> Safety -> u
    forall u. (forall d. Data d => d -> u) -> Safety -> [u]
    forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Safety -> r
    forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Safety -> r
    forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Safety -> m Safety
    forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Safety -> m Safety
    forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c Safety
    forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> Safety -> c Safety
    forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c Safety)
    forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Safety)
    $cgfoldl :: forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> Safety -> c Safety
    gfoldl :: forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> Safety -> c Safety
    $cgunfold :: forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c Safety
    gunfold :: forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c Safety
    $ctoConstr :: Safety -> Constr
    toConstr :: Safety -> Constr
    $cdataTypeOf :: Safety -> DataType
    dataTypeOf :: Safety -> DataType
    $cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c Safety)
    dataCast1 :: forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c Safety)
    $cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Safety)
    dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Safety)
    $cgmapT :: (forall b. Data b => b -> b) -> Safety -> Safety
    gmapT :: (forall b. Data b => b -> b) -> Safety -> Safety
    $cgmapQl :: forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Safety -> r
    gmapQl :: forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Safety -> r
    $cgmapQr :: forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Safety -> r
    gmapQr :: forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Safety -> r
    $cgmapQ :: forall u. (forall d. Data d => d -> u) -> Safety -> [u]
    gmapQ :: forall u. (forall d. Data d => d -> u) -> Safety -> [u]
    $cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Safety -> u
    gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Safety -> u
    $cgmapM :: forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Safety -> m Safety
    gmapM :: forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Safety -> m Safety
    $cgmapMp :: forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Safety -> m Safety
    gmapMp :: forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Safety -> m Safety
    $cgmapMo :: forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Safety -> m Safety
    gmapMo :: forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Safety -> m Safety
    Data, Int -> Safety
    Safety -> Int
    Safety -> [Safety]
    Safety -> Safety
    Safety -> Safety -> [Safety]
    Safety -> Safety -> Safety -> [Safety]
    (Safety -> Safety)
    -> (Safety -> Safety)
    -> (Int -> Safety)
    -> (Safety -> Int)
    -> (Safety -> [Safety])
    -> (Safety -> Safety -> [Safety])
    -> (Safety -> Safety -> [Safety])
    -> (Safety -> Safety -> Safety -> [Safety])
    -> Enum Safety
    forall a.
    (a -> a)
    -> (a -> a)
    -> (Int -> a)
    -> (a -> Int)
    -> (a -> [a])
    -> (a -> a -> [a])
    -> (a -> a -> [a])
    -> (a -> a -> a -> [a])
    -> Enum a
    $csucc :: Safety -> Safety
    succ :: Safety -> Safety
    $cpred :: Safety -> Safety
    pred :: Safety -> Safety
    $ctoEnum :: Int -> Safety
    toEnum :: Int -> Safety
    $cfromEnum :: Safety -> Int
    fromEnum :: Safety -> Int
    $cenumFrom :: Safety -> [Safety]
    enumFrom :: Safety -> [Safety]
    $cenumFromThen :: Safety -> Safety -> [Safety]
    enumFromThen :: Safety -> Safety -> [Safety]
    $cenumFromTo :: Safety -> Safety -> [Safety]
    enumFromTo :: Safety -> Safety -> [Safety]
    $cenumFromThenTo :: Safety -> Safety -> Safety -> [Safety]
    enumFromThenTo :: Safety -> Safety -> Safety -> [Safety]
    Enum )
            -- Show used just for Show Lex.Token, I think

    instance Outputable Safety where
      ppr :: Safety -> SDoc
    ppr Safety
    PlaySafe = String -> SDoc
    forall doc. IsLine doc => String -> doc
    text String
    "safe"
      ppr Safety
    PlayInterruptible = String -> SDoc
    forall doc. IsLine doc => String -> doc
    text String
    "interruptible"
      ppr Safety
    PlayRisky = String -> SDoc
    forall doc. IsLine doc => String -> doc
    text String
    "unsafe"

    playSafe :: Safety -> Bool
    playSafe :: Safety -> Bool
    playSafe Safety
    PlaySafe = Bool
    True
    playSafe Safety
    PlayInterruptible = Bool
    True
    playSafe Safety
    PlayRisky = Bool
    False

    playInterruptible :: Safety -> Bool
    playInterruptible :: Safety -> Bool
    playInterruptible Safety
    PlayInterruptible = Bool
    True
    playInterruptible Safety
    _ = Bool
    False

    {-
    ************************************************************************
    *                                                                      *
    \subsubsection{Calling C}
    *                                                                      *
    ************************************************************************
    -}

    data CExportSpec
      = CExportStatic               -- foreign export ccall foo :: ty
            SourceText              -- of the CLabelString.
                                    -- See Note [Pragma source text] in "GHC.Types.SourceText"
            CLabelString            -- C Name of exported function
            CCallConv
      deriving Typeable CExportSpec
    Typeable CExportSpec =>
    (forall (c :: * -> *).
     (forall d b. Data d => c (d -> b) -> d -> c b)
     -> (forall g. g -> c g) -> CExportSpec -> c CExportSpec)
    -> (forall (c :: * -> *).
        (forall b r. Data b => c (b -> r) -> c r)
        -> (forall r. r -> c r) -> Constr -> c CExportSpec)
    -> (CExportSpec -> Constr)
    -> (CExportSpec -> DataType)
    -> (forall (t :: * -> *) (c :: * -> *).
        Typeable t =>
        (forall d. Data d => c (t d)) -> Maybe (c CExportSpec))
    -> (forall (t :: * -> * -> *) (c :: * -> *).
        Typeable t =>
        (forall d e. (Data d, Data e) => c (t d e))
        -> Maybe (c CExportSpec))
    -> ((forall b. Data b => b -> b) -> CExportSpec -> CExportSpec)
    -> (forall r r'.
        (r -> r' -> r)
        -> r -> (forall d. Data d => d -> r') -> CExportSpec -> r)
    -> (forall r r'.
        (r' -> r -> r)
        -> r -> (forall d. Data d => d -> r') -> CExportSpec -> r)
    -> (forall u. (forall d. Data d => d -> u) -> CExportSpec -> [u])
    -> (forall u.
        Int -> (forall d. Data d => d -> u) -> CExportSpec -> u)
    -> (forall (m :: * -> *).
        Monad m =>
        (forall d. Data d => d -> m d) -> CExportSpec -> m CExportSpec)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> CExportSpec -> m CExportSpec)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> CExportSpec -> m CExportSpec)
    -> Data CExportSpec
    CExportSpec -> Constr
    CExportSpec -> DataType
    (forall b. Data b => b -> b) -> CExportSpec -> CExportSpec
    forall a.
    Typeable a =>
    (forall (c :: * -> *).
     (forall d b. Data d => c (d -> b) -> d -> c b)
     -> (forall g. g -> c g) -> a -> c a)
    -> (forall (c :: * -> *).
        (forall b r. Data b => c (b -> r) -> c r)
        -> (forall r. r -> c r) -> Constr -> c a)
    -> (a -> Constr)
    -> (a -> DataType)
    -> (forall (t :: * -> *) (c :: * -> *).
        Typeable t =>
        (forall d. Data d => c (t d)) -> Maybe (c a))
    -> (forall (t :: * -> * -> *) (c :: * -> *).
        Typeable t =>
        (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
    -> ((forall b. Data b => b -> b) -> a -> a)
    -> (forall r r'.
        (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
    -> (forall r r'.
        (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
    -> (forall u. (forall d. Data d => d -> u) -> a -> [u])
    -> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
    -> (forall (m :: * -> *).
        Monad m =>
        (forall d. Data d => d -> m d) -> a -> m a)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> a -> m a)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> a -> m a)
    -> Data a
    forall u. Int -> (forall d. Data d => d -> u) -> CExportSpec -> u
    forall u. (forall d. Data d => d -> u) -> CExportSpec -> [u]
    forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> CExportSpec -> r
    forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> CExportSpec -> r
    forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> CExportSpec -> m CExportSpec
    forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> CExportSpec -> m CExportSpec
    forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c CExportSpec
    forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> CExportSpec -> c CExportSpec
    forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c CExportSpec)
    forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c CExportSpec)
    $cgfoldl :: forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> CExportSpec -> c CExportSpec
    gfoldl :: forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> CExportSpec -> c CExportSpec
    $cgunfold :: forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c CExportSpec
    gunfold :: forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c CExportSpec
    $ctoConstr :: CExportSpec -> Constr
    toConstr :: CExportSpec -> Constr
    $cdataTypeOf :: CExportSpec -> DataType
    dataTypeOf :: CExportSpec -> DataType
    $cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c CExportSpec)
    dataCast1 :: forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c CExportSpec)
    $cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c CExportSpec)
    dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c CExportSpec)
    $cgmapT :: (forall b. Data b => b -> b) -> CExportSpec -> CExportSpec
    gmapT :: (forall b. Data b => b -> b) -> CExportSpec -> CExportSpec
    $cgmapQl :: forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> CExportSpec -> r
    gmapQl :: forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> CExportSpec -> r
    $cgmapQr :: forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> CExportSpec -> r
    gmapQr :: forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> CExportSpec -> r
    $cgmapQ :: forall u. (forall d. Data d => d -> u) -> CExportSpec -> [u]
    gmapQ :: forall u. (forall d. Data d => d -> u) -> CExportSpec -> [u]
    $cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> CExportSpec -> u
    gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> CExportSpec -> u
    $cgmapM :: forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> CExportSpec -> m CExportSpec
    gmapM :: forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> CExportSpec -> m CExportSpec
    $cgmapMp :: forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> CExportSpec -> m CExportSpec
    gmapMp :: forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> CExportSpec -> m CExportSpec
    $cgmapMo :: forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> CExportSpec -> m CExportSpec
    gmapMo :: forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> CExportSpec -> m CExportSpec
    Data

    data CCallSpec
      =  CCallSpec  CCallTarget     -- What to call
                    CCallConv       -- Calling convention to use.
                    Safety
      deriving( CCallSpec -> CCallSpec -> Bool
    (CCallSpec -> CCallSpec -> Bool)
    -> (CCallSpec -> CCallSpec -> Bool) -> Eq CCallSpec
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: CCallSpec -> CCallSpec -> Bool
    == :: CCallSpec -> CCallSpec -> Bool
    $c/= :: CCallSpec -> CCallSpec -> Bool
    /= :: CCallSpec -> CCallSpec -> Bool
    Eq )

    -- The call target:

    -- | How to call a particular function in C-land.
    data CCallTarget
      -- An "unboxed" ccall# to named function in a particular package.
      = StaticTarget
            SourceText                -- of the CLabelString.
                                      -- See Note [Pragma source text] in "GHC.Types.SourceText"
            CLabelString                    -- C-land name of label.

            (Maybe Unit)                    -- What package the function is in.
                                            -- If Nothing, then it's taken to be in the current package.
                                            -- Note: This information is only used for PrimCalls on Windows.
                                            --       See CLabel.labelDynamic and CoreToStg.coreToStgApp
                                            --       for the difference in representation between PrimCalls
                                            --       and ForeignCalls. If the CCallTarget is representing
                                            --       a regular ForeignCall then it's safe to set this to Nothing.

      -- The first argument of the import is the name of a function pointer (an Addr#).
      --    Used when importing a label as "foreign import ccall "dynamic" ..."
            Bool                            -- True => really a function
                                            -- False => a value; only
                                            -- allowed in CAPI imports
      | DynamicTarget

      deriving( CCallTarget -> CCallTarget -> Bool
    (CCallTarget -> CCallTarget -> Bool)
    -> (CCallTarget -> CCallTarget -> Bool) -> Eq CCallTarget
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: CCallTarget -> CCallTarget -> Bool
    == :: CCallTarget -> CCallTarget -> Bool
    $c/= :: CCallTarget -> CCallTarget -> Bool
    /= :: CCallTarget -> CCallTarget -> Bool
    Eq, Typeable CCallTarget
    Typeable CCallTarget =>
    (forall (c :: * -> *).
     (forall d b. Data d => c (d -> b) -> d -> c b)
     -> (forall g. g -> c g) -> CCallTarget -> c CCallTarget)
    -> (forall (c :: * -> *).
        (forall b r. Data b => c (b -> r) -> c r)
        -> (forall r. r -> c r) -> Constr -> c CCallTarget)
    -> (CCallTarget -> Constr)
    -> (CCallTarget -> DataType)
    -> (forall (t :: * -> *) (c :: * -> *).
        Typeable t =>
        (forall d. Data d => c (t d)) -> Maybe (c CCallTarget))
    -> (forall (t :: * -> * -> *) (c :: * -> *).
        Typeable t =>
        (forall d e. (Data d, Data e) => c (t d e))
        -> Maybe (c CCallTarget))
    -> ((forall b. Data b => b -> b) -> CCallTarget -> CCallTarget)
    -> (forall r r'.
        (r -> r' -> r)
        -> r -> (forall d. Data d => d -> r') -> CCallTarget -> r)
    -> (forall r r'.
        (r' -> r -> r)
        -> r -> (forall d. Data d => d -> r') -> CCallTarget -> r)
    -> (forall u. (forall d. Data d => d -> u) -> CCallTarget -> [u])
    -> (forall u.
        Int -> (forall d. Data d => d -> u) -> CCallTarget -> u)
    -> (forall (m :: * -> *).
        Monad m =>
        (forall d. Data d => d -> m d) -> CCallTarget -> m CCallTarget)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> CCallTarget -> m CCallTarget)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> CCallTarget -> m CCallTarget)
    -> Data CCallTarget
    CCallTarget -> Constr
    CCallTarget -> DataType
    (forall b. Data b => b -> b) -> CCallTarget -> CCallTarget
    forall a.
    Typeable a =>
    (forall (c :: * -> *).
     (forall d b. Data d => c (d -> b) -> d -> c b)
     -> (forall g. g -> c g) -> a -> c a)
    -> (forall (c :: * -> *).
        (forall b r. Data b => c (b -> r) -> c r)
        -> (forall r. r -> c r) -> Constr -> c a)
    -> (a -> Constr)
    -> (a -> DataType)
    -> (forall (t :: * -> *) (c :: * -> *).
        Typeable t =>
        (forall d. Data d => c (t d)) -> Maybe (c a))
    -> (forall (t :: * -> * -> *) (c :: * -> *).
        Typeable t =>
        (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
    -> ((forall b. Data b => b -> b) -> a -> a)
    -> (forall r r'.
        (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
    -> (forall r r'.
        (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
    -> (forall u. (forall d. Data d => d -> u) -> a -> [u])
    -> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
    -> (forall (m :: * -> *).
        Monad m =>
        (forall d. Data d => d -> m d) -> a -> m a)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> a -> m a)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> a -> m a)
    -> Data a
    forall u. Int -> (forall d. Data d => d -> u) -> CCallTarget -> u
    forall u. (forall d. Data d => d -> u) -> CCallTarget -> [u]
    forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> CCallTarget -> r
    forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> CCallTarget -> r
    forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> CCallTarget -> m CCallTarget
    forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> CCallTarget -> m CCallTarget
    forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c CCallTarget
    forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> CCallTarget -> c CCallTarget
    forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c CCallTarget)
    forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c CCallTarget)
    $cgfoldl :: forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> CCallTarget -> c CCallTarget
    gfoldl :: forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> CCallTarget -> c CCallTarget
    $cgunfold :: forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c CCallTarget
    gunfold :: forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c CCallTarget
    $ctoConstr :: CCallTarget -> Constr
    toConstr :: CCallTarget -> Constr
    $cdataTypeOf :: CCallTarget -> DataType
    dataTypeOf :: CCallTarget -> DataType
    $cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c CCallTarget)
    dataCast1 :: forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c CCallTarget)
    $cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c CCallTarget)
    dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c CCallTarget)
    $cgmapT :: (forall b. Data b => b -> b) -> CCallTarget -> CCallTarget
    gmapT :: (forall b. Data b => b -> b) -> CCallTarget -> CCallTarget
    $cgmapQl :: forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> CCallTarget -> r
    gmapQl :: forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> CCallTarget -> r
    $cgmapQr :: forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> CCallTarget -> r
    gmapQr :: forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> CCallTarget -> r
    $cgmapQ :: forall u. (forall d. Data d => d -> u) -> CCallTarget -> [u]
    gmapQ :: forall u. (forall d. Data d => d -> u) -> CCallTarget -> [u]
    $cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> CCallTarget -> u
    gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> CCallTarget -> u
    $cgmapM :: forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> CCallTarget -> m CCallTarget
    gmapM :: forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> CCallTarget -> m CCallTarget
    $cgmapMp :: forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> CCallTarget -> m CCallTarget
    gmapMp :: forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> CCallTarget -> m CCallTarget
    $cgmapMo :: forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> CCallTarget -> m CCallTarget
    gmapMo :: forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> CCallTarget -> m CCallTarget
    Data )

    isDynamicTarget :: CCallTarget -> Bool
    isDynamicTarget :: CCallTarget -> Bool
    isDynamicTarget CCallTarget
    DynamicTarget = Bool
    True
    isDynamicTarget CCallTarget
    _             = Bool
    False

    {-
    Stuff to do with calling convention:

    ccall:          Caller allocates parameters, *and* deallocates them.

    stdcall:        Caller allocates parameters, callee deallocates.
                    Function name has @N after it, where N is number of arg bytes
                    e.g.  _Foo@8. This convention is x86 (win32) specific.

    See: http://www.programmersheaven.com/2/Calling-conventions
    -}

    -- any changes here should be replicated in the Callconv type in template haskell
    data CCallConv
      = CCallConv
      | CApiConv
      | StdCallConv
      | PrimCallConv
      | JavaScriptCallConv
      deriving (CCallConv -> CCallConv -> Bool
    (CCallConv -> CCallConv -> Bool)
    -> (CCallConv -> CCallConv -> Bool) -> Eq CCallConv
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: CCallConv -> CCallConv -> Bool
    == :: CCallConv -> CCallConv -> Bool
    $c/= :: CCallConv -> CCallConv -> Bool
    /= :: CCallConv -> CCallConv -> Bool
    Eq, Typeable CCallConv
    Typeable CCallConv =>
    (forall (c :: * -> *).
     (forall d b. Data d => c (d -> b) -> d -> c b)
     -> (forall g. g -> c g) -> CCallConv -> c CCallConv)
    -> (forall (c :: * -> *).
        (forall b r. Data b => c (b -> r) -> c r)
        -> (forall r. r -> c r) -> Constr -> c CCallConv)
    -> (CCallConv -> Constr)
    -> (CCallConv -> DataType)
    -> (forall (t :: * -> *) (c :: * -> *).
        Typeable t =>
        (forall d. Data d => c (t d)) -> Maybe (c CCallConv))
    -> (forall (t :: * -> * -> *) (c :: * -> *).
        Typeable t =>
        (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c CCallConv))
    -> ((forall b. Data b => b -> b) -> CCallConv -> CCallConv)
    -> (forall r r'.
        (r -> r' -> r)
        -> r -> (forall d. Data d => d -> r') -> CCallConv -> r)
    -> (forall r r'.
        (r' -> r -> r)
        -> r -> (forall d. Data d => d -> r') -> CCallConv -> r)
    -> (forall u. (forall d. Data d => d -> u) -> CCallConv -> [u])
    -> (forall u.
        Int -> (forall d. Data d => d -> u) -> CCallConv -> u)
    -> (forall (m :: * -> *).
        Monad m =>
        (forall d. Data d => d -> m d) -> CCallConv -> m CCallConv)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> CCallConv -> m CCallConv)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> CCallConv -> m CCallConv)
    -> Data CCallConv
    CCallConv -> Constr
    CCallConv -> DataType
    (forall b. Data b => b -> b) -> CCallConv -> CCallConv
    forall a.
    Typeable a =>
    (forall (c :: * -> *).
     (forall d b. Data d => c (d -> b) -> d -> c b)
     -> (forall g. g -> c g) -> a -> c a)
    -> (forall (c :: * -> *).
        (forall b r. Data b => c (b -> r) -> c r)
        -> (forall r. r -> c r) -> Constr -> c a)
    -> (a -> Constr)
    -> (a -> DataType)
    -> (forall (t :: * -> *) (c :: * -> *).
        Typeable t =>
        (forall d. Data d => c (t d)) -> Maybe (c a))
    -> (forall (t :: * -> * -> *) (c :: * -> *).
        Typeable t =>
        (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
    -> ((forall b. Data b => b -> b) -> a -> a)
    -> (forall r r'.
        (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
    -> (forall r r'.
        (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
    -> (forall u. (forall d. Data d => d -> u) -> a -> [u])
    -> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
    -> (forall (m :: * -> *).
        Monad m =>
        (forall d. Data d => d -> m d) -> a -> m a)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> a -> m a)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> a -> m a)
    -> Data a
    forall u. Int -> (forall d. Data d => d -> u) -> CCallConv -> u
    forall u. (forall d. Data d => d -> u) -> CCallConv -> [u]
    forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> CCallConv -> r
    forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> CCallConv -> r
    forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> CCallConv -> m CCallConv
    forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> CCallConv -> m CCallConv
    forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c CCallConv
    forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> CCallConv -> c CCallConv
    forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c CCallConv)
    forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c CCallConv)
    $cgfoldl :: forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> CCallConv -> c CCallConv
    gfoldl :: forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> CCallConv -> c CCallConv
    $cgunfold :: forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c CCallConv
    gunfold :: forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c CCallConv
    $ctoConstr :: CCallConv -> Constr
    toConstr :: CCallConv -> Constr
    $cdataTypeOf :: CCallConv -> DataType
    dataTypeOf :: CCallConv -> DataType
    $cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c CCallConv)
    dataCast1 :: forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c CCallConv)
    $cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c CCallConv)
    dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c CCallConv)
    $cgmapT :: (forall b. Data b => b -> b) -> CCallConv -> CCallConv
    gmapT :: (forall b. Data b => b -> b) -> CCallConv -> CCallConv
    $cgmapQl :: forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> CCallConv -> r
    gmapQl :: forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> CCallConv -> r
    $cgmapQr :: forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> CCallConv -> r
    gmapQr :: forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> CCallConv -> r
    $cgmapQ :: forall u. (forall d. Data d => d -> u) -> CCallConv -> [u]
    gmapQ :: forall u. (forall d. Data d => d -> u) -> CCallConv -> [u]
    $cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> CCallConv -> u
    gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> CCallConv -> u
    $cgmapM :: forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> CCallConv -> m CCallConv
    gmapM :: forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> CCallConv -> m CCallConv
    $cgmapMp :: forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> CCallConv -> m CCallConv
    gmapMp :: forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> CCallConv -> m CCallConv
    $cgmapMo :: forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> CCallConv -> m CCallConv
    gmapMo :: forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> CCallConv -> m CCallConv
    Data, Int -> CCallConv
    CCallConv -> Int
    CCallConv -> [CCallConv]
    CCallConv -> CCallConv
    CCallConv -> CCallConv -> [CCallConv]
    CCallConv -> CCallConv -> CCallConv -> [CCallConv]
    (CCallConv -> CCallConv)
    -> (CCallConv -> CCallConv)
    -> (Int -> CCallConv)
    -> (CCallConv -> Int)
    -> (CCallConv -> [CCallConv])
    -> (CCallConv -> CCallConv -> [CCallConv])
    -> (CCallConv -> CCallConv -> [CCallConv])
    -> (CCallConv -> CCallConv -> CCallConv -> [CCallConv])
    -> Enum CCallConv
    forall a.
    (a -> a)
    -> (a -> a)
    -> (Int -> a)
    -> (a -> Int)
    -> (a -> [a])
    -> (a -> a -> [a])
    -> (a -> a -> [a])
    -> (a -> a -> a -> [a])
    -> Enum a
    $csucc :: CCallConv -> CCallConv
    succ :: CCallConv -> CCallConv
    $cpred :: CCallConv -> CCallConv
    pred :: CCallConv -> CCallConv
    $ctoEnum :: Int -> CCallConv
    toEnum :: Int -> CCallConv
    $cfromEnum :: CCallConv -> Int
    fromEnum :: CCallConv -> Int
    $cenumFrom :: CCallConv -> [CCallConv]
    enumFrom :: CCallConv -> [CCallConv]
    $cenumFromThen :: CCallConv -> CCallConv -> [CCallConv]
    enumFromThen :: CCallConv -> CCallConv -> [CCallConv]
    $cenumFromTo :: CCallConv -> CCallConv -> [CCallConv]
    enumFromTo :: CCallConv -> CCallConv -> [CCallConv]
    $cenumFromThenTo :: CCallConv -> CCallConv -> CCallConv -> [CCallConv]
    enumFromThenTo :: CCallConv -> CCallConv -> CCallConv -> [CCallConv]
    Enum)

    instance Outputable CCallConv where
      ppr :: CCallConv -> SDoc
    ppr CCallConv
    StdCallConv = String -> SDoc
    forall doc. IsLine doc => String -> doc
    text String
    "stdcall"
      ppr CCallConv
    CCallConv   = String -> SDoc
    forall doc. IsLine doc => String -> doc
    text String
    "ccall"
      ppr CCallConv
    CApiConv    = String -> SDoc
    forall doc. IsLine doc => String -> doc
    text String
    "capi"
      ppr CCallConv
    PrimCallConv = String -> SDoc
    forall doc. IsLine doc => String -> doc
    text String
    "prim"
      ppr CCallConv
    JavaScriptCallConv = String -> SDoc
    forall doc. IsLine doc => String -> doc
    text String
    "javascript"

    defaultCCallConv :: CCallConv
    defaultCCallConv :: CCallConv
    defaultCCallConv = CCallConv
    CCallConv

    ccallConvToInt :: CCallConv -> Int
    ccallConvToInt :: CCallConv -> Int
    ccallConvToInt CCallConv
    StdCallConv = Int
    0
    ccallConvToInt CCallConv
    CCallConv   = Int
    1
    ccallConvToInt CCallConv
    CApiConv    = String -> Int
    forall a. HasCallStack => String -> a
    panic String
    "ccallConvToInt CApiConv"
    ccallConvToInt (PrimCallConv {}) = String -> Int
    forall a. HasCallStack => String -> a
    panic String
    "ccallConvToInt PrimCallConv"
    ccallConvToInt CCallConv
    JavaScriptCallConv = String -> Int
    forall a. HasCallStack => String -> a
    panic String
    "ccallConvToInt JavaScriptCallConv"

    {-
    Generate the gcc attribute corresponding to the given
    calling convention (used by PprAbsC):
    -}

    ccallConvAttribute :: CCallConv -> SDoc
    ccallConvAttribute :: CCallConv -> SDoc
    ccallConvAttribute CCallConv
    StdCallConv       = String -> SDoc
    forall doc. IsLine doc => String -> doc
    text String
    "__attribute__((__stdcall__))"
    ccallConvAttribute CCallConv
    CCallConv         = SDoc
    forall doc. IsOutput doc => doc
    empty
    ccallConvAttribute CCallConv
    CApiConv          = SDoc
    forall doc. IsOutput doc => doc
    empty
    ccallConvAttribute (PrimCallConv {}) = String -> SDoc
    forall a. HasCallStack => String -> a
    panic String
    "ccallConvAttribute PrimCallConv"
    ccallConvAttribute CCallConv
    JavaScriptCallConv = SDoc
    forall doc. IsOutput doc => doc
    empty

    type CLabelString = FastString          -- A C label, completely unencoded

    pprCLabelString :: CLabelString -> SDoc
    pprCLabelString :: CLabelString -> SDoc
    pprCLabelString CLabelString
    lbl = CLabelString -> SDoc
    forall doc. IsLine doc => CLabelString -> doc
    ftext CLabelString
    lbl

    isCLabelString :: CLabelString -> Bool  -- Checks to see if this is a valid C label
    isCLabelString :: CLabelString -> Bool
    isCLabelString CLabelString
    lbl
      = (Char -> Bool) -> String -> Bool
    forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
    all Char -> Bool
    ok (CLabelString -> String
    unpackFS CLabelString
    lbl)
      where
        ok :: Char -> Bool
    ok Char
    c = Char -> Bool
    isAlphaNum Char
    c Bool -> Bool -> Bool
    || Char
    c Char -> Char -> Bool
    forall a. Eq a => a -> a -> Bool
    == Char
    '_' Bool -> Bool -> Bool
    || Char
    c Char -> Char -> Bool
    forall a. Eq a => a -> a -> Bool
    == Char
    '.'
            -- The '.' appears in e.g. "foo.so" in the
            -- module part of a ExtName.  Maybe it should be separate

    -- Printing into C files:

    instance Outputable CExportSpec where
      ppr :: CExportSpec -> SDoc
    ppr (CExportStatic SourceText
    _ CLabelString
    str CCallConv
    _) = CLabelString -> SDoc
    pprCLabelString CLabelString
    str

    instance Outputable CCallSpec where
      ppr :: CCallSpec -> SDoc
    ppr (CCallSpec CCallTarget
    fun CCallConv
    cconv Safety
    safety)
        = [SDoc] -> SDoc
    forall doc. IsLine doc => [doc] -> doc
    hcat [ SDoc -> SDoc
    forall doc. IsOutput doc => doc -> doc
    whenPprDebug SDoc
    callconv, CCallTarget -> SDoc
    ppr_fun CCallTarget
    fun, String -> SDoc
    forall doc. IsLine doc => String -> doc
    text String
    " ::" ]
        where
          callconv :: SDoc
    callconv = String -> SDoc
    forall doc. IsLine doc => String -> doc
    text String
    "{-" SDoc -> SDoc -> SDoc
    forall doc. IsLine doc => doc -> doc -> doc
    <> CCallConv -> SDoc
    forall a. Outputable a => a -> SDoc
    ppr CCallConv
    cconv SDoc -> SDoc -> SDoc
    forall doc. IsLine doc => doc -> doc -> doc
    <> String -> SDoc
    forall doc. IsLine doc => String -> doc
    text String
    "-}"

          gc_suf :: SDoc
    gc_suf | Safety -> Bool
    playSafe Safety
    safety = String -> SDoc
    forall doc. IsLine doc => String -> doc
    text String
    "_safe"
                 | Bool
    otherwise       = String -> SDoc
    forall doc. IsLine doc => String -> doc
    text String
    "_unsafe"

          ppr_fun :: CCallTarget -> SDoc
    ppr_fun (StaticTarget SourceText
    st CLabelString
    lbl Maybe Unit
    mPkgId Bool
    isFun)
            = (if Bool
    isFun then String -> SDoc
    forall doc. IsLine doc => String -> doc
    text String
    "__ffi_static_ccall"
                        else String -> SDoc
    forall doc. IsLine doc => String -> doc
    text String
    "__ffi_static_ccall_value")
           SDoc -> SDoc -> SDoc
    forall doc. IsLine doc => doc -> doc -> doc
    <> SDoc
    gc_suf
           SDoc -> SDoc -> SDoc
    forall doc. IsLine doc => doc -> doc -> doc
    <+> (case Maybe Unit
    mPkgId of
                Maybe Unit
    Nothing -> SDoc
    forall doc. IsOutput doc => doc
    empty
                Just Unit
    pkgId -> Unit -> SDoc
    forall a. Outputable a => a -> SDoc
    ppr Unit
    pkgId)
           SDoc -> SDoc -> SDoc
    forall doc. IsLine doc => doc -> doc -> doc
    <> String -> SDoc
    forall doc. IsLine doc => String -> doc
    text String
    ":"
           SDoc -> SDoc -> SDoc
    forall doc. IsLine doc => doc -> doc -> doc
    <> CLabelString -> SDoc
    forall a. Outputable a => a -> SDoc
    ppr CLabelString
    lbl
           SDoc -> SDoc -> SDoc
    forall doc. IsLine doc => doc -> doc -> doc
    <+> (SourceText -> SDoc -> SDoc
    pprWithSourceText SourceText
    st SDoc
    forall doc. IsOutput doc => doc
    empty)

          ppr_fun CCallTarget
    DynamicTarget
            = String -> SDoc
    forall doc. IsLine doc => String -> doc
    text String
    "__ffi_dyn_ccall" SDoc -> SDoc -> SDoc
    forall doc. IsLine doc => doc -> doc -> doc
    <> SDoc
    gc_suf SDoc -> SDoc -> SDoc
    forall doc. IsLine doc => doc -> doc -> doc
    <+> String -> SDoc
    forall doc. IsLine doc => String -> doc
    text String
    "\"\""

    -- The filename for a C header file
    -- Note [Pragma source text] in "GHC.Types.SourceText"
    data Header = Header SourceText FastString
        deriving (Header -> Header -> Bool
    (Header -> Header -> Bool)
    -> (Header -> Header -> Bool) -> Eq Header
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: Header -> Header -> Bool
    == :: Header -> Header -> Bool
    $c/= :: Header -> Header -> Bool
    /= :: Header -> Header -> Bool
    Eq, Typeable Header
    Typeable Header =>
    (forall (c :: * -> *).
     (forall d b. Data d => c (d -> b) -> d -> c b)
     -> (forall g. g -> c g) -> Header -> c Header)
    -> (forall (c :: * -> *).
        (forall b r. Data b => c (b -> r) -> c r)
        -> (forall r. r -> c r) -> Constr -> c Header)
    -> (Header -> Constr)
    -> (Header -> DataType)
    -> (forall (t :: * -> *) (c :: * -> *).
        Typeable t =>
        (forall d. Data d => c (t d)) -> Maybe (c Header))
    -> (forall (t :: * -> * -> *) (c :: * -> *).
        Typeable t =>
        (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Header))
    -> ((forall b. Data b => b -> b) -> Header -> Header)
    -> (forall r r'.
        (r -> r' -> r)
        -> r -> (forall d. Data d => d -> r') -> Header -> r)
    -> (forall r r'.
        (r' -> r -> r)
        -> r -> (forall d. Data d => d -> r') -> Header -> r)
    -> (forall u. (forall d. Data d => d -> u) -> Header -> [u])
    -> (forall u. Int -> (forall d. Data d => d -> u) -> Header -> u)
    -> (forall (m :: * -> *).
        Monad m =>
        (forall d. Data d => d -> m d) -> Header -> m Header)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> Header -> m Header)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> Header -> m Header)
    -> Data Header
    Header -> Constr
    Header -> DataType
    (forall b. Data b => b -> b) -> Header -> Header
    forall a.
    Typeable a =>
    (forall (c :: * -> *).
     (forall d b. Data d => c (d -> b) -> d -> c b)
     -> (forall g. g -> c g) -> a -> c a)
    -> (forall (c :: * -> *).
        (forall b r. Data b => c (b -> r) -> c r)
        -> (forall r. r -> c r) -> Constr -> c a)
    -> (a -> Constr)
    -> (a -> DataType)
    -> (forall (t :: * -> *) (c :: * -> *).
        Typeable t =>
        (forall d. Data d => c (t d)) -> Maybe (c a))
    -> (forall (t :: * -> * -> *) (c :: * -> *).
        Typeable t =>
        (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
    -> ((forall b. Data b => b -> b) -> a -> a)
    -> (forall r r'.
        (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
    -> (forall r r'.
        (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
    -> (forall u. (forall d. Data d => d -> u) -> a -> [u])
    -> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
    -> (forall (m :: * -> *).
        Monad m =>
        (forall d. Data d => d -> m d) -> a -> m a)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> a -> m a)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> a -> m a)
    -> Data a
    forall u. Int -> (forall d. Data d => d -> u) -> Header -> u
    forall u. (forall d. Data d => d -> u) -> Header -> [u]
    forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Header -> r
    forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Header -> r
    forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Header -> m Header
    forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Header -> m Header
    forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c Header
    forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> Header -> c Header
    forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c Header)
    forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Header)
    $cgfoldl :: forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> Header -> c Header
    gfoldl :: forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> Header -> c Header
    $cgunfold :: forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c Header
    gunfold :: forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c Header
    $ctoConstr :: Header -> Constr
    toConstr :: Header -> Constr
    $cdataTypeOf :: Header -> DataType
    dataTypeOf :: Header -> DataType
    $cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c Header)
    dataCast1 :: forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c Header)
    $cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Header)
    dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Header)
    $cgmapT :: (forall b. Data b => b -> b) -> Header -> Header
    gmapT :: (forall b. Data b => b -> b) -> Header -> Header
    $cgmapQl :: forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Header -> r
    gmapQl :: forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Header -> r
    $cgmapQr :: forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Header -> r
    gmapQr :: forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Header -> r
    $cgmapQ :: forall u. (forall d. Data d => d -> u) -> Header -> [u]
    gmapQ :: forall u. (forall d. Data d => d -> u) -> Header -> [u]
    $cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Header -> u
    gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Header -> u
    $cgmapM :: forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Header -> m Header
    gmapM :: forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Header -> m Header
    $cgmapMp :: forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Header -> m Header
    gmapMp :: forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Header -> m Header
    $cgmapMo :: forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Header -> m Header
    gmapMo :: forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Header -> m Header
    Data)

    instance Outputable Header where
        ppr :: Header -> SDoc
    ppr (Header SourceText
    st CLabelString
    h) = SourceText -> SDoc -> SDoc
    pprWithSourceText SourceText
    st (SDoc -> SDoc
    forall doc. IsLine doc => doc -> doc
    doubleQuotes (SDoc -> SDoc) -> SDoc -> SDoc
    forall a b. (a -> b) -> a -> b
    $ CLabelString -> SDoc
    forall a. Outputable a => a -> SDoc
    ppr CLabelString
    h)

    -- | A C type, used in CAPI FFI calls
    --
    --  - 'GHC.Parser.Annotation.AnnKeywordId' : 'GHC.Parser.Annotation.AnnOpen' @'{-\# CTYPE'@,
    --        'GHC.Parser.Annotation.AnnHeader','GHC.Parser.Annotation.AnnVal',
    --        'GHC.Parser.Annotation.AnnClose' @'\#-}'@,

    -- For details on above see Note [exact print annotations] in "GHC.Parser.Annotation"
    data CType = CType SourceText -- Note [Pragma source text] in "GHC.Types.SourceText"
                       (Maybe Header) -- header to include for this type
                       (SourceText,FastString) -- the type itself
        deriving (CType -> CType -> Bool
    (CType -> CType -> Bool) -> (CType -> CType -> Bool) -> Eq CType
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: CType -> CType -> Bool
    == :: CType -> CType -> Bool
    $c/= :: CType -> CType -> Bool
    /= :: CType -> CType -> Bool
    Eq, Typeable CType
    Typeable CType =>
    (forall (c :: * -> *).
     (forall d b. Data d => c (d -> b) -> d -> c b)
     -> (forall g. g -> c g) -> CType -> c CType)
    -> (forall (c :: * -> *).
        (forall b r. Data b => c (b -> r) -> c r)
        -> (forall r. r -> c r) -> Constr -> c CType)
    -> (CType -> Constr)
    -> (CType -> DataType)
    -> (forall (t :: * -> *) (c :: * -> *).
        Typeable t =>
        (forall d. Data d => c (t d)) -> Maybe (c CType))
    -> (forall (t :: * -> * -> *) (c :: * -> *).
        Typeable t =>
        (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c CType))
    -> ((forall b. Data b => b -> b) -> CType -> CType)
    -> (forall r r'.
        (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> CType -> r)
    -> (forall r r'.
        (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> CType -> r)
    -> (forall u. (forall d. Data d => d -> u) -> CType -> [u])
    -> (forall u. Int -> (forall d. Data d => d -> u) -> CType -> u)
    -> (forall (m :: * -> *).
        Monad m =>
        (forall d. Data d => d -> m d) -> CType -> m CType)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> CType -> m CType)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> CType -> m CType)
    -> Data CType
    CType -> Constr
    CType -> DataType
    (forall b. Data b => b -> b) -> CType -> CType
    forall a.
    Typeable a =>
    (forall (c :: * -> *).
     (forall d b. Data d => c (d -> b) -> d -> c b)
     -> (forall g. g -> c g) -> a -> c a)
    -> (forall (c :: * -> *).
        (forall b r. Data b => c (b -> r) -> c r)
        -> (forall r. r -> c r) -> Constr -> c a)
    -> (a -> Constr)
    -> (a -> DataType)
    -> (forall (t :: * -> *) (c :: * -> *).
        Typeable t =>
        (forall d. Data d => c (t d)) -> Maybe (c a))
    -> (forall (t :: * -> * -> *) (c :: * -> *).
        Typeable t =>
        (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
    -> ((forall b. Data b => b -> b) -> a -> a)
    -> (forall r r'.
        (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
    -> (forall r r'.
        (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
    -> (forall u. (forall d. Data d => d -> u) -> a -> [u])
    -> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
    -> (forall (m :: * -> *).
        Monad m =>
        (forall d. Data d => d -> m d) -> a -> m a)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> a -> m a)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> a -> m a)
    -> Data a
    forall u. Int -> (forall d. Data d => d -> u) -> CType -> u
    forall u. (forall d. Data d => d -> u) -> CType -> [u]
    forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> CType -> r
    forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> CType -> r
    forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> CType -> m CType
    forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> CType -> m CType
    forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c CType
    forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> CType -> c CType
    forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c CType)
    forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c CType)
    $cgfoldl :: forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> CType -> c CType
    gfoldl :: forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> CType -> c CType
    $cgunfold :: forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c CType
    gunfold :: forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c CType
    $ctoConstr :: CType -> Constr
    toConstr :: CType -> Constr
    $cdataTypeOf :: CType -> DataType
    dataTypeOf :: CType -> DataType
    $cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c CType)
    dataCast1 :: forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c CType)
    $cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c CType)
    dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c CType)
    $cgmapT :: (forall b. Data b => b -> b) -> CType -> CType
    gmapT :: (forall b. Data b => b -> b) -> CType -> CType
    $cgmapQl :: forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> CType -> r
    gmapQl :: forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> CType -> r
    $cgmapQr :: forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> CType -> r
    gmapQr :: forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> CType -> r
    $cgmapQ :: forall u. (forall d. Data d => d -> u) -> CType -> [u]
    gmapQ :: forall u. (forall d. Data d => d -> u) -> CType -> [u]
    $cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> CType -> u
    gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> CType -> u
    $cgmapM :: forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> CType -> m CType
    gmapM :: forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> CType -> m CType
    $cgmapMp :: forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> CType -> m CType
    gmapMp :: forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> CType -> m CType
    $cgmapMo :: forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> CType -> m CType
    gmapMo :: forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> CType -> m CType
    Data)

    instance Outputable CType where
        ppr :: CType -> SDoc
    ppr (CType SourceText
    stp Maybe Header
    mh (SourceText
    stct,CLabelString
    ct))
          = SourceText -> SDoc -> SDoc
    pprWithSourceText SourceText
    stp (String -> SDoc
    forall doc. IsLine doc => String -> doc
    text String
    "{-# CTYPE") SDoc -> SDoc -> SDoc
    forall doc. IsLine doc => doc -> doc -> doc
    <+> SDoc
    hDoc
            SDoc -> SDoc -> SDoc
    forall doc. IsLine doc => doc -> doc -> doc
    <+> SourceText -> SDoc -> SDoc
    pprWithSourceText SourceText
    stct (SDoc -> SDoc
    forall doc. IsLine doc => doc -> doc
    doubleQuotes (CLabelString -> SDoc
    forall doc. IsLine doc => CLabelString -> doc
    ftext CLabelString
    ct)) SDoc -> SDoc -> SDoc
    forall doc. IsLine doc => doc -> doc -> doc
    <+> String -> SDoc
    forall doc. IsLine doc => String -> doc
    text String
    "#-}"
            where hDoc :: SDoc
    hDoc = case Maybe Header
    mh of
                         Maybe Header
    Nothing -> SDoc
    forall doc. IsOutput doc => doc
    empty
                         Just Header
    h -> Header -> SDoc
    forall a. Outputable a => a -> SDoc
    ppr Header
    h

    {-
    ************************************************************************
    *                                                                      *
    \subsubsection{Misc}
    *                                                                      *
    ************************************************************************
    -}

    instance Binary ForeignCall where
        put_ :: BinHandle -> ForeignCall -> IO ()
    put_ BinHandle
    bh (CCall CCallSpec
    aa) = BinHandle -> CCallSpec -> IO ()
    forall a. Binary a => BinHandle -> a -> IO ()
    put_ BinHandle
    bh CCallSpec
    aa
        get :: BinHandle -> IO ForeignCall
    get BinHandle
    bh = do aa <- BinHandle -> IO CCallSpec
    forall a. Binary a => BinHandle -> IO a
    get BinHandle
    bh; return (CCall aa)

    instance Binary Safety where
        put_ :: BinHandle -> Safety -> IO ()
    put_ BinHandle
    bh Safety
    PlaySafe =
                BinHandle -> Word8 -> IO ()
    putByte BinHandle
    bh Word8
    0
        put_ BinHandle
    bh Safety
    PlayInterruptible =
                BinHandle -> Word8 -> IO ()
    putByte BinHandle
    bh Word8
    1
        put_ BinHandle
    bh Safety
    PlayRisky =
                BinHandle -> Word8 -> IO ()
    putByte BinHandle
    bh Word8
    2
        get :: BinHandle -> IO Safety
    get BinHandle
    bh = do
                h <- BinHandle -> IO Word8
    getByte BinHandle
    bh
                case h of
                  Word8
    0 -> Safety -> IO Safety
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return Safety
    PlaySafe
                  Word8
    1 -> Safety -> IO Safety
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return Safety
    PlayInterruptible
                  Word8
    _ -> Safety -> IO Safety
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return Safety
    PlayRisky

    instance Binary CExportSpec where
        put_ :: BinHandle -> CExportSpec -> IO ()
    put_ BinHandle
    bh (CExportStatic SourceText
    ss CLabelString
    aa CCallConv
    ab) = do
                BinHandle -> SourceText -> IO ()
    forall a. Binary a => BinHandle -> a -> IO ()
    put_ BinHandle
    bh SourceText
    ss
                BinHandle -> CLabelString -> IO ()
    forall a. Binary a => BinHandle -> a -> IO ()
    put_ BinHandle
    bh CLabelString
    aa
                BinHandle -> CCallConv -> IO ()
    forall a. Binary a => BinHandle -> a -> IO ()
    put_ BinHandle
    bh CCallConv
    ab
        get :: BinHandle -> IO CExportSpec
    get BinHandle
    bh = do
              ss <- BinHandle -> IO SourceText
    forall a. Binary a => BinHandle -> IO a
    get BinHandle
    bh
              aa <- get bh
              ab <- get bh
              return (CExportStatic ss aa ab)

    instance Binary CCallSpec where
        put_ :: BinHandle -> CCallSpec -> IO ()
    put_ BinHandle
    bh (CCallSpec CCallTarget
    aa CCallConv
    ab Safety
    ac) = do
                BinHandle -> CCallTarget -> IO ()
    forall a. Binary a => BinHandle -> a -> IO ()
    put_ BinHandle
    bh CCallTarget
    aa
                BinHandle -> CCallConv -> IO ()
    forall a. Binary a => BinHandle -> a -> IO ()
    put_ BinHandle
    bh CCallConv
    ab
                BinHandle -> Safety -> IO ()
    forall a. Binary a => BinHandle -> a -> IO ()
    put_ BinHandle
    bh Safety
    ac
        get :: BinHandle -> IO CCallSpec
    get BinHandle
    bh = do
              aa <- BinHandle -> IO CCallTarget
    forall a. Binary a => BinHandle -> IO a
    get BinHandle
    bh
              ab <- get bh
              ac <- get bh
              return (CCallSpec aa ab ac)

    instance Binary CCallTarget where
        put_ :: BinHandle -> CCallTarget -> IO ()
    put_ BinHandle
    bh (StaticTarget SourceText
    ss CLabelString
    aa Maybe Unit
    ab Bool
    ac) = do
                BinHandle -> Word8 -> IO ()
    putByte BinHandle
    bh Word8
    0
                BinHandle -> SourceText -> IO ()
    forall a. Binary a => BinHandle -> a -> IO ()
    put_ BinHandle
    bh SourceText
    ss
                BinHandle -> CLabelString -> IO ()
    forall a. Binary a => BinHandle -> a -> IO ()
    put_ BinHandle
    bh CLabelString
    aa
                BinHandle -> Maybe Unit -> IO ()
    forall a. Binary a => BinHandle -> a -> IO ()
    put_ BinHandle
    bh Maybe Unit
    ab
                BinHandle -> Bool -> IO ()
    forall a. Binary a => BinHandle -> a -> IO ()
    put_ BinHandle
    bh Bool
    ac
        put_ BinHandle
    bh CCallTarget
    DynamicTarget =
                BinHandle -> Word8 -> IO ()
    putByte BinHandle
    bh Word8
    1
        get :: BinHandle -> IO CCallTarget
    get BinHandle
    bh = do
                h <- BinHandle -> IO Word8
    getByte BinHandle
    bh
                case h of
                  Word8
    0 -> do ss <- BinHandle -> IO SourceText
    forall a. Binary a => BinHandle -> IO a
    get BinHandle
    bh
                          aa <- get bh
                          ab <- get bh
                          ac <- get bh
                          return (StaticTarget ss aa ab ac)
                  Word8
    _ -> CCallTarget -> IO CCallTarget
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return CCallTarget
    DynamicTarget

    instance Binary CCallConv where
        put_ :: BinHandle -> CCallConv -> IO ()
    put_ BinHandle
    bh CCallConv
    CCallConv =
                BinHandle -> Word8 -> IO ()
    putByte BinHandle
    bh Word8
    0
        put_ BinHandle
    bh CCallConv
    StdCallConv =
                BinHandle -> Word8 -> IO ()
    putByte BinHandle
    bh Word8
    1
        put_ BinHandle
    bh CCallConv
    PrimCallConv =
                BinHandle -> Word8 -> IO ()
    putByte BinHandle
    bh Word8
    2
        put_ BinHandle
    bh CCallConv
    CApiConv =
                BinHandle -> Word8 -> IO ()
    putByte BinHandle
    bh Word8
    3
        put_ BinHandle
    bh CCallConv
    JavaScriptCallConv =
                BinHandle -> Word8 -> IO ()
    putByte BinHandle
    bh Word8
    4
        get :: BinHandle -> IO CCallConv
    get BinHandle
    bh = do
                h <- BinHandle -> IO Word8
    getByte BinHandle
    bh
                case h of
                  Word8
    0 -> CCallConv -> IO CCallConv
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return CCallConv
    CCallConv
                  Word8
    1 -> CCallConv -> IO CCallConv
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return CCallConv
    StdCallConv
                  Word8
    2 -> CCallConv -> IO CCallConv
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return CCallConv
    PrimCallConv
                  Word8
    3 -> CCallConv -> IO CCallConv
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return CCallConv
    CApiConv
                  Word8
    _ -> CCallConv -> IO CCallConv
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return CCallConv
    JavaScriptCallConv

    instance Binary CType where
        put_ :: BinHandle -> CType -> IO ()
    put_ BinHandle
    bh (CType SourceText
    s Maybe Header
    mh (SourceText, CLabelString)
    fs) = do BinHandle -> SourceText -> IO ()
    forall a. Binary a => BinHandle -> a -> IO ()
    put_ BinHandle
    bh SourceText
    s
                                     BinHandle -> Maybe Header -> IO ()
    forall a. Binary a => BinHandle -> a -> IO ()
    put_ BinHandle
    bh Maybe Header
    mh
                                     BinHandle -> (SourceText, CLabelString) -> IO ()
    forall a. Binary a => BinHandle -> a -> IO ()
    put_ BinHandle
    bh (SourceText, CLabelString)
    fs
        get :: BinHandle -> IO CType
    get BinHandle
    bh = do s  <- BinHandle -> IO SourceText
    forall a. Binary a => BinHandle -> IO a
    get BinHandle
    bh
                    mh <- get bh
                    fs <- get bh
                    return (CType s mh fs)

    instance Binary Header where
        put_ :: BinHandle -> Header -> IO ()
    put_ BinHandle
    bh (Header SourceText
    s CLabelString
    h) = BinHandle -> SourceText -> IO ()
    forall a. Binary a => BinHandle -> a -> IO ()
    put_ BinHandle
    bh SourceText
    s IO () -> IO () -> IO ()
    forall a b. IO a -> IO b -> IO b
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> BinHandle -> CLabelString -> IO ()
    forall a. Binary a => BinHandle -> a -> IO ()
    put_ BinHandle
    bh CLabelString
    h
        get :: BinHandle -> IO Header
    get BinHandle
    bh = do s <- BinHandle -> IO SourceText
    forall a. Binary a => BinHandle -> IO a
    get BinHandle
    bh
                    h <- get bh
                    return (Header s h)