{-# 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
newtype ForeignCall = CCall CCallSpec
deriving ForeignCall -> ForeignCall -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ForeignCall -> ForeignCall -> Bool
$c/= :: ForeignCall -> ForeignCall -> Bool
== :: ForeignCall -> ForeignCall -> Bool
$c== :: ForeignCall -> ForeignCall -> Bool
Eq
isSafeForeignCall :: ForeignCall -> Bool
isSafeForeignCall :: ForeignCall -> Bool
isSafeForeignCall (CCall (CCallSpec CCallTarget
_ CCallConv
_ Safety
safe)) = Safety -> Bool
playSafe Safety
safe
instance Outputable ForeignCall where
ppr :: ForeignCall -> SDoc
ppr (CCall CCallSpec
cc) = forall a. Outputable a => a -> SDoc
ppr CCallSpec
cc
data Safety
= PlaySafe
| PlayInterruptible
| PlayRisky
deriving ( Safety -> Safety -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Safety -> Safety -> Bool
$c/= :: Safety -> Safety -> Bool
== :: Safety -> Safety -> Bool
$c== :: Safety -> Safety -> Bool
Eq, Int -> Safety -> ShowS
[Safety] -> ShowS
Safety -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Safety] -> ShowS
$cshowList :: [Safety] -> ShowS
show :: Safety -> String
$cshow :: Safety -> String
showsPrec :: Int -> Safety -> ShowS
$cshowsPrec :: Int -> Safety -> ShowS
Show, Typeable Safety
Safety -> DataType
Safety -> Constr
(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)
gmapMo :: 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
gmapMp :: forall (m :: * -> *).
MonadPlus 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
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Safety -> m Safety
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Safety -> m Safety
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Safety -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Safety -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> Safety -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Safety -> [u]
gmapQr :: 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
gmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Safety -> r
$cgmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Safety -> r
gmapT :: (forall b. Data b => b -> b) -> Safety -> Safety
$cgmapT :: (forall b. Data b => b -> b) -> Safety -> Safety
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Safety)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Safety)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Safety)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Safety)
dataTypeOf :: Safety -> DataType
$cdataTypeOf :: Safety -> DataType
toConstr :: Safety -> Constr
$ctoConstr :: Safety -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Safety
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Safety
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Safety -> c Safety
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Safety -> c Safety
Data )
instance Outputable Safety where
ppr :: Safety -> SDoc
ppr Safety
PlaySafe = String -> SDoc
text String
"safe"
ppr Safety
PlayInterruptible = String -> SDoc
text String
"interruptible"
ppr Safety
PlayRisky = String -> SDoc
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
data CExportSpec
= CExportStatic
SourceText
CLabelString
CCallConv
deriving Typeable CExportSpec
CExportSpec -> DataType
CExportSpec -> Constr
(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)
gmapMo :: 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
gmapMp :: forall (m :: * -> *).
MonadPlus 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
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> CExportSpec -> m CExportSpec
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> CExportSpec -> m CExportSpec
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> CExportSpec -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> CExportSpec -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> CExportSpec -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> CExportSpec -> [u]
gmapQr :: 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
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> CExportSpec -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> CExportSpec -> r
gmapT :: (forall b. Data b => b -> b) -> CExportSpec -> CExportSpec
$cgmapT :: (forall b. Data b => b -> b) -> CExportSpec -> CExportSpec
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c CExportSpec)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c CExportSpec)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c CExportSpec)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c CExportSpec)
dataTypeOf :: CExportSpec -> DataType
$cdataTypeOf :: CExportSpec -> DataType
toConstr :: CExportSpec -> Constr
$ctoConstr :: CExportSpec -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c CExportSpec
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c CExportSpec
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> CExportSpec -> c CExportSpec
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> CExportSpec -> c CExportSpec
Data
data CCallSpec
= CCallSpec CCallTarget
CCallConv
Safety
deriving( CCallSpec -> CCallSpec -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CCallSpec -> CCallSpec -> Bool
$c/= :: CCallSpec -> CCallSpec -> Bool
== :: CCallSpec -> CCallSpec -> Bool
$c== :: CCallSpec -> CCallSpec -> Bool
Eq )
data CCallTarget
= StaticTarget
SourceText
CLabelString
(Maybe Unit)
Bool
| DynamicTarget
deriving( CCallTarget -> CCallTarget -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CCallTarget -> CCallTarget -> Bool
$c/= :: CCallTarget -> CCallTarget -> Bool
== :: CCallTarget -> CCallTarget -> Bool
$c== :: CCallTarget -> CCallTarget -> Bool
Eq, Typeable CCallTarget
CCallTarget -> DataType
CCallTarget -> Constr
(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)
gmapMo :: 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
gmapMp :: forall (m :: * -> *).
MonadPlus 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
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> CCallTarget -> m CCallTarget
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> CCallTarget -> m CCallTarget
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> CCallTarget -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> CCallTarget -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> CCallTarget -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> CCallTarget -> [u]
gmapQr :: 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
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> CCallTarget -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> CCallTarget -> r
gmapT :: (forall b. Data b => b -> b) -> CCallTarget -> CCallTarget
$cgmapT :: (forall b. Data b => b -> b) -> CCallTarget -> CCallTarget
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c CCallTarget)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c CCallTarget)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c CCallTarget)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c CCallTarget)
dataTypeOf :: CCallTarget -> DataType
$cdataTypeOf :: CCallTarget -> DataType
toConstr :: CCallTarget -> Constr
$ctoConstr :: CCallTarget -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c CCallTarget
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c CCallTarget
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> CCallTarget -> c CCallTarget
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> CCallTarget -> c CCallTarget
Data )
isDynamicTarget :: CCallTarget -> Bool
isDynamicTarget :: CCallTarget -> Bool
isDynamicTarget CCallTarget
DynamicTarget = Bool
True
isDynamicTarget CCallTarget
_ = Bool
False
data CCallConv = CCallConv | CApiConv | StdCallConv | PrimCallConv | JavaScriptCallConv
deriving (CCallConv -> CCallConv -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CCallConv -> CCallConv -> Bool
$c/= :: CCallConv -> CCallConv -> Bool
== :: CCallConv -> CCallConv -> Bool
$c== :: CCallConv -> CCallConv -> Bool
Eq, Typeable CCallConv
CCallConv -> DataType
CCallConv -> Constr
(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)
gmapMo :: 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
gmapMp :: forall (m :: * -> *).
MonadPlus 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
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> CCallConv -> m CCallConv
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> CCallConv -> m CCallConv
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> CCallConv -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> CCallConv -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> CCallConv -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> CCallConv -> [u]
gmapQr :: 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
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> CCallConv -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> CCallConv -> r
gmapT :: (forall b. Data b => b -> b) -> CCallConv -> CCallConv
$cgmapT :: (forall b. Data b => b -> b) -> CCallConv -> CCallConv
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c CCallConv)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c CCallConv)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c CCallConv)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c CCallConv)
dataTypeOf :: CCallConv -> DataType
$cdataTypeOf :: CCallConv -> DataType
toConstr :: CCallConv -> Constr
$ctoConstr :: CCallConv -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c CCallConv
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c CCallConv
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> CCallConv -> c CCallConv
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> CCallConv -> c CCallConv
Data)
instance Outputable CCallConv where
ppr :: CCallConv -> SDoc
ppr CCallConv
StdCallConv = String -> SDoc
text String
"stdcall"
ppr CCallConv
CCallConv = String -> SDoc
text String
"ccall"
ppr CCallConv
CApiConv = String -> SDoc
text String
"capi"
ppr CCallConv
PrimCallConv = String -> SDoc
text String
"prim"
ppr CCallConv
JavaScriptCallConv = String -> SDoc
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 = forall a. String -> a
panic String
"ccallConvToInt CApiConv"
ccallConvToInt (PrimCallConv {}) = forall a. String -> a
panic String
"ccallConvToInt PrimCallConv"
ccallConvToInt CCallConv
JavaScriptCallConv = forall a. String -> a
panic String
"ccallConvToInt JavaScriptCallConv"
ccallConvAttribute :: CCallConv -> SDoc
ccallConvAttribute :: CCallConv -> SDoc
ccallConvAttribute CCallConv
StdCallConv = String -> SDoc
text String
"__attribute__((__stdcall__))"
ccallConvAttribute CCallConv
CCallConv = SDoc
empty
ccallConvAttribute CCallConv
CApiConv = SDoc
empty
ccallConvAttribute (PrimCallConv {}) = forall a. String -> a
panic String
"ccallConvAttribute PrimCallConv"
ccallConvAttribute CCallConv
JavaScriptCallConv = forall a. String -> a
panic String
"ccallConvAttribute JavaScriptCallConv"
type CLabelString = FastString
pprCLabelString :: CLabelString -> SDoc
pprCLabelString :: CLabelString -> SDoc
pprCLabelString CLabelString
lbl = CLabelString -> SDoc
ftext CLabelString
lbl
isCLabelString :: CLabelString -> Bool
isCLabelString :: CLabelString -> Bool
isCLabelString CLabelString
lbl
= 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 forall a. Eq a => a -> a -> Bool
== Char
'_' Bool -> Bool -> Bool
|| Char
c forall a. Eq a => a -> a -> Bool
== Char
'.'
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
hcat [ SDoc -> SDoc
whenPprDebug SDoc
callconv, CCallTarget -> SDoc
ppr_fun CCallTarget
fun, String -> SDoc
text String
" ::" ]
where
callconv :: SDoc
callconv = String -> SDoc
text String
"{-" SDoc -> SDoc -> SDoc
<> forall a. Outputable a => a -> SDoc
ppr CCallConv
cconv SDoc -> SDoc -> SDoc
<> String -> SDoc
text String
"-}"
gc_suf :: SDoc
gc_suf | Safety -> Bool
playSafe Safety
safety = String -> SDoc
text String
"_safe"
| Bool
otherwise = String -> SDoc
text String
"_unsafe"
ppr_fun :: CCallTarget -> SDoc
ppr_fun (StaticTarget SourceText
st CLabelString
lbl Maybe Unit
mPkgId Bool
isFun)
= String -> SDoc
text (if Bool
isFun then String
"__ffi_static_ccall"
else String
"__ffi_static_ccall_value")
SDoc -> SDoc -> SDoc
<> SDoc
gc_suf
SDoc -> SDoc -> SDoc
<+> (case Maybe Unit
mPkgId of
Maybe Unit
Nothing -> SDoc
empty
Just Unit
pkgId -> forall a. Outputable a => a -> SDoc
ppr Unit
pkgId)
SDoc -> SDoc -> SDoc
<> String -> SDoc
text String
":"
SDoc -> SDoc -> SDoc
<> forall a. Outputable a => a -> SDoc
ppr CLabelString
lbl
SDoc -> SDoc -> SDoc
<+> (SourceText -> SDoc -> SDoc
pprWithSourceText SourceText
st SDoc
empty)
ppr_fun CCallTarget
DynamicTarget
= String -> SDoc
text String
"__ffi_dyn_ccall" SDoc -> SDoc -> SDoc
<> SDoc
gc_suf SDoc -> SDoc -> SDoc
<+> String -> SDoc
text String
"\"\""
data = SourceText FastString
deriving (Header -> Header -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Header -> Header -> Bool
$c/= :: Header -> Header -> Bool
== :: Header -> Header -> Bool
$c== :: Header -> Header -> Bool
Eq, Typeable Header
Header -> DataType
Header -> Constr
(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)
gmapMo :: 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
gmapMp :: forall (m :: * -> *).
MonadPlus 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
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Header -> m Header
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Header -> m Header
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Header -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Header -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> Header -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Header -> [u]
gmapQr :: 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
gmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Header -> r
$cgmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Header -> r
gmapT :: (forall b. Data b => b -> b) -> Header -> Header
$cgmapT :: (forall b. Data b => b -> b) -> Header -> Header
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Header)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Header)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Header)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Header)
dataTypeOf :: Header -> DataType
$cdataTypeOf :: Header -> DataType
toConstr :: Header -> Constr
$ctoConstr :: Header -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Header
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Header
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Header -> c Header
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Header -> c Header
Data)
instance Outputable Header where
ppr :: Header -> SDoc
ppr (Header SourceText
st CLabelString
h) = SourceText -> SDoc -> SDoc
pprWithSourceText SourceText
st (SDoc -> SDoc
doubleQuotes forall a b. (a -> b) -> a -> b
$ forall a. Outputable a => a -> SDoc
ppr CLabelString
h)
data CType = CType SourceText
(Maybe Header)
(SourceText,FastString)
deriving (CType -> CType -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CType -> CType -> Bool
$c/= :: CType -> CType -> Bool
== :: CType -> CType -> Bool
$c== :: CType -> CType -> Bool
Eq, Typeable CType
CType -> DataType
CType -> Constr
(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)
gmapMo :: 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
gmapMp :: forall (m :: * -> *).
MonadPlus 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
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> CType -> m CType
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> CType -> m CType
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> CType -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> CType -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> CType -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> CType -> [u]
gmapQr :: 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
gmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> CType -> r
$cgmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> CType -> r
gmapT :: (forall b. Data b => b -> b) -> CType -> CType
$cgmapT :: (forall b. Data b => b -> b) -> CType -> CType
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c CType)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c CType)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c CType)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c CType)
dataTypeOf :: CType -> DataType
$cdataTypeOf :: CType -> DataType
toConstr :: CType -> Constr
$ctoConstr :: CType -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c CType
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c CType
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> CType -> c CType
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> CType -> c 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
text String
"{-# CTYPE") SDoc -> SDoc -> SDoc
<+> SDoc
hDoc
SDoc -> SDoc -> SDoc
<+> SourceText -> SDoc -> SDoc
pprWithSourceText SourceText
stct (SDoc -> SDoc
doubleQuotes (CLabelString -> SDoc
ftext CLabelString
ct)) SDoc -> SDoc -> SDoc
<+> String -> SDoc
text String
"#-}"
where hDoc :: SDoc
hDoc = case Maybe Header
mh of
Maybe Header
Nothing -> SDoc
empty
Just Header
h -> forall a. Outputable a => a -> SDoc
ppr Header
h
instance Binary ForeignCall where
put_ :: BinHandle -> ForeignCall -> IO ()
put_ BinHandle
bh (CCall CCallSpec
aa) = forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh CCallSpec
aa
get :: BinHandle -> IO ForeignCall
get BinHandle
bh = do CCallSpec
aa <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh; forall (m :: * -> *) a. Monad m => a -> m a
return (CCallSpec -> ForeignCall
CCall CCallSpec
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
Word8
h <- BinHandle -> IO Word8
getByte BinHandle
bh
case Word8
h of
Word8
0 -> forall (m :: * -> *) a. Monad m => a -> m a
return Safety
PlaySafe
Word8
1 -> forall (m :: * -> *) a. Monad m => a -> m a
return Safety
PlayInterruptible
Word8
_ -> 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
forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh SourceText
ss
forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh CLabelString
aa
forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh CCallConv
ab
get :: BinHandle -> IO CExportSpec
get BinHandle
bh = do
SourceText
ss <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
CLabelString
aa <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
CCallConv
ab <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
forall (m :: * -> *) a. Monad m => a -> m a
return (SourceText -> CLabelString -> CCallConv -> CExportSpec
CExportStatic SourceText
ss CLabelString
aa CCallConv
ab)
instance Binary CCallSpec where
put_ :: BinHandle -> CCallSpec -> IO ()
put_ BinHandle
bh (CCallSpec CCallTarget
aa CCallConv
ab Safety
ac) = do
forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh CCallTarget
aa
forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh CCallConv
ab
forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh Safety
ac
get :: BinHandle -> IO CCallSpec
get BinHandle
bh = do
CCallTarget
aa <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
CCallConv
ab <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
Safety
ac <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
forall (m :: * -> *) a. Monad m => a -> m a
return (CCallTarget -> CCallConv -> Safety -> CCallSpec
CCallSpec CCallTarget
aa CCallConv
ab Safety
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
forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh SourceText
ss
forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh CLabelString
aa
forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh Maybe Unit
ab
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
Word8
h <- BinHandle -> IO Word8
getByte BinHandle
bh
case Word8
h of
Word8
0 -> do SourceText
ss <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
CLabelString
aa <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
Maybe Unit
ab <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
Bool
ac <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
forall (m :: * -> *) a. Monad m => a -> m a
return (SourceText -> CLabelString -> Maybe Unit -> Bool -> CCallTarget
StaticTarget SourceText
ss CLabelString
aa Maybe Unit
ab Bool
ac)
Word8
_ -> 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
Word8
h <- BinHandle -> IO Word8
getByte BinHandle
bh
case Word8
h of
Word8
0 -> forall (m :: * -> *) a. Monad m => a -> m a
return CCallConv
CCallConv
Word8
1 -> forall (m :: * -> *) a. Monad m => a -> m a
return CCallConv
StdCallConv
Word8
2 -> forall (m :: * -> *) a. Monad m => a -> m a
return CCallConv
PrimCallConv
Word8
3 -> forall (m :: * -> *) a. Monad m => a -> m a
return CCallConv
CApiConv
Word8
_ -> 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 forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh SourceText
s
forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh Maybe Header
mh
forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh (SourceText, CLabelString)
fs
get :: BinHandle -> IO CType
get BinHandle
bh = do SourceText
s <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
Maybe Header
mh <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
(SourceText, CLabelString)
fs <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
forall (m :: * -> *) a. Monad m => a -> m a
return (SourceText -> Maybe Header -> (SourceText, CLabelString) -> CType
CType SourceText
s Maybe Header
mh (SourceText, CLabelString)
fs)
instance Binary Header where
put_ :: BinHandle -> Header -> IO ()
put_ BinHandle
bh (Header SourceText
s CLabelString
h) = forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh SourceText
s forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh CLabelString
h
get :: BinHandle -> IO Header
get BinHandle
bh = do SourceText
s <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
CLabelString
h <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
forall (m :: * -> *) a. Monad m => a -> m a
return (SourceText -> CLabelString -> Header
Header SourceText
s CLabelString
h)