module LLVM.Internal.Interop where
import Control.Applicative
import Control.Monad ( when )
import Control.Monad.Trans ( MonadIO, liftIO )
import Data.Array.Storable ( getElems )
import Data.Array.Unsafe ( unsafeForeignPtrToStorableArray )
import qualified Data.ByteString.Char8 as BS
import Data.Int
import Data.Text ( Text )
import Data.Text.Encoding ( decodeUtf8 )
import Foreign.C
import Foreign.ForeignPtr
import Foreign.Marshal.Utils
import Foreign.Ptr
import Foreign.Storable
import Data.LLVM.Types
data TypeTag = TYPE_VOID
| TYPE_FLOAT
| TYPE_DOUBLE
| TYPE_X86_FP80
| TYPE_FP128
| TYPE_PPC_FP128
| TYPE_LABEL
| TYPE_METADATA
| TYPE_X86_MMX
| TYPE_INTEGER
| TYPE_FUNCTION
| TYPE_STRUCT
| TYPE_ARRAY
| TYPE_POINTER
| TYPE_VECTOR
deriving (Enum,Show,Eq)
data ValueTag = ValArgument
| ValBasicblock
| ValInlineasm
| ValBlockaddress
| ValConstantaggregatezero
| ValConstantarray
| ValConstantfp
| ValConstantint
| ValConstantpointernull
| ValConstantstruct
| ValConstantvector
| ValUndefvalue
| ValConstantexpr
| ValRetinst
| ValBranchinst
| ValSwitchinst
| ValIndirectbrinst
| ValInvokeinst
| ValResumeinst
| ValUnreachableinst
| ValAddinst
| ValFaddinst
| ValSubinst
| ValFsubinst
| ValMulinst
| ValFmulinst
| ValUdivinst
| ValSdivinst
| ValFdivinst
| ValUreminst
| ValSreminst
| ValFreminst
| ValShlinst
| ValLshrinst
| ValAshrinst
| ValAndinst
| ValOrinst
| ValXorinst
| ValAllocainst
| ValLoadinst
| ValStoreinst
| ValGetelementptrinst
| ValFenceinst
| ValAtomiccmpxchginst
| ValAtomicrmwinst
| ValTruncinst
| ValZextinst
| ValSextinst
| ValFptouiinst
| ValFptosiinst
| ValUitofpinst
| ValSitofpinst
| ValFptruncinst
| ValFpextinst
| ValPtrtointinst
| ValInttoptrinst
| ValBitcastinst
| ValIcmpinst
| ValFcmpinst
| ValPhinode
| ValCallinst
| ValSelectinst
| ValVaarginst
| ValExtractelementinst
| ValInsertelementinst
| ValShufflevectorinst
| ValExtractvalueinst
| ValInsertvalueinst
| ValLandingpadinst
| ValFunction
| ValGlobalvariable
| ValAlias
deriving (Enum,Show,Eq)
data MetaTag = MetaLocation
| MetaDerivedtype
| MetaCompositetype
| MetaBasictype
| MetaVariable
| MetaSubprogram
| MetaGlobalvariable
| MetaFile
| MetaCompileunit
| MetaNamespace
| MetaLexicalblock
| MetaSubrange
| MetaEnumerator
| MetaArray
| MetaTemplatetypeparameter
| MetaTemplatevalueparameter
| MetaUnknown
deriving (Enum,Show,Eq)
data CModule
type ModulePtr = Ptr (CModule)
makeText :: CString -> IO Text
makeText p = do
s <- BS.packCString p
return (decodeUtf8 s)
cModuleIdentifier :: ModulePtr -> IO Text
cModuleIdentifier m = ((\ptr -> do {peekByteOff ptr 0 ::IO (Ptr CChar)}) m) >>= makeText
cModuleDataLayout :: ModulePtr -> IO Text
cModuleDataLayout m = ((\ptr -> do {peekByteOff ptr 8 ::IO (Ptr CChar)}) m) >>= makeText
cModuleTargetTriple :: ModulePtr -> IO Text
cModuleTargetTriple m = ((\ptr -> do {peekByteOff ptr 16 ::IO (Ptr CChar)}) m) >>= makeText
cModuleInlineAsm :: ModulePtr -> IO Text
cModuleInlineAsm m = ((\ptr -> do {peekByteOff ptr 32 ::IO (Ptr CChar)}) m) >>= makeText
cModuleHasError :: ModulePtr -> IO Bool
cModuleHasError m = toBool <$> ((\ptr -> do {peekByteOff ptr 132 ::IO CInt}) m)
cModuleErrorMessage :: ModulePtr -> IO (Maybe String)
cModuleErrorMessage m = do
hasError <- cModuleHasError m
case hasError of
True -> do
msgPtr <- ((\ptr -> do {peekByteOff ptr 136 ::IO (Ptr CChar)}) m)
s <- peekCString msgPtr
return (Just s)
False -> return Nothing
cModuleLittleEndian :: ModulePtr -> IO Bool
cModuleLittleEndian m = toBool <$> ((\ptr -> do {peekByteOff ptr 24 ::IO CInt}) m)
cModulePointerSize :: ModulePtr -> IO Int
cModulePointerSize m = fromIntegral <$> ((\ptr -> do {peekByteOff ptr 28 ::IO CInt}) m)
cModuleGlobalVariables :: ModulePtr -> IO [ValuePtr]
cModuleGlobalVariables m =
peekArray m (\ptr -> do {peekByteOff ptr 40 ::IO (Ptr (Ptr ()))}) (\ptr -> do {peekByteOff ptr 48 ::IO CInt})
cModuleGlobalAliases :: ModulePtr -> IO [ValuePtr]
cModuleGlobalAliases m =
peekArray m ((\ptr -> do {peekByteOff ptr 56 ::IO (Ptr (Ptr ()))})) ((\ptr -> do {peekByteOff ptr 64 ::IO CInt}))
cModuleFunctions :: ModulePtr -> IO [ValuePtr]
cModuleFunctions m =
peekArray m ((\ptr -> do {peekByteOff ptr 72 ::IO (Ptr (Ptr ()))})) ((\ptr -> do {peekByteOff ptr 80 ::IO CInt}))
cModuleEnumMetadata :: ModulePtr -> IO [MetaPtr]
cModuleEnumMetadata m =
peekArray m (\ptr -> do {peekByteOff ptr 104 ::IO (Ptr (Ptr ()))}) (\ptr -> do {peekByteOff ptr 112 ::IO CInt})
cModuleRetainedTypeMetadata :: ModulePtr -> IO [MetaPtr]
cModuleRetainedTypeMetadata m =
peekArray m (\ptr -> do {peekByteOff ptr 120 ::IO (Ptr (Ptr ()))}) (\ptr -> do {peekByteOff ptr 128 ::IO CInt})
cModuleTypes :: ModulePtr -> IO [TypePtr]
cModuleTypes m =
peekArray m (\ptr -> do {peekByteOff ptr 88 ::IO (Ptr (Ptr ()))}) (\ptr -> do {peekByteOff ptr 96 ::IO CInt})
peekArray :: forall a b c e . (Integral c, Storable e) =>
a -> (a -> IO (Ptr b)) -> (a -> IO c) -> IO [e]
peekArray obj arrAccessor sizeAccessor = do
nElts <- sizeAccessor obj
arrPtr <- arrAccessor obj
case nElts == 0 || arrPtr == nullPtr of
True -> return []
False -> do
fArrPtr <- newForeignPtr_ (castPtr arrPtr)
let elementCount :: Int
elementCount = fromIntegral nElts
arr <- unsafeForeignPtrToStorableArray fArrPtr (1, elementCount)
getElems arr
data CType
type TypePtr = Ptr (CType)
cTypeTag :: TypePtr -> IO TypeTag
cTypeTag t = toEnum . fromIntegral <$> (\ptr -> do {peekByteOff ptr 0 ::IO CInt}) t
cTypeSize :: TypePtr -> IO Int
cTypeSize t = fromIntegral <$> (\ptr -> do {peekByteOff ptr 8 ::IO CULLong}) t
cTypeIsVarArg :: TypePtr -> IO Bool
cTypeIsVarArg t = toBool <$> (\ptr -> do {peekByteOff ptr 16 ::IO CInt}) t
cTypeIsPacked :: TypePtr -> IO Bool
cTypeIsPacked t = toBool <$> (\ptr -> do {peekByteOff ptr 20 ::IO CInt}) t
cTypeList :: TypePtr -> IO [TypePtr]
cTypeList t =
peekArray t (\ptr -> do {peekByteOff ptr 24 ::IO (Ptr (TypePtr))}) (\ptr -> do {peekByteOff ptr 32 ::IO CInt})
cTypeInner :: TypePtr -> IO TypePtr
cTypeInner = (\ptr -> do {peekByteOff ptr 40 ::IO (TypePtr)})
cTypeName :: TypePtr -> IO (Maybe String)
cTypeName t = do
n <- optionalField (\ptr -> do {peekByteOff ptr 48 ::IO (Ptr CChar)}) t
case n of
Nothing -> return Nothing
Just n' -> do
s <- peekCString n'
return (Just s)
cTypeAddrSpace :: TypePtr -> IO Int
cTypeAddrSpace t = fromIntegral <$> (\ptr -> do {peekByteOff ptr 56 ::IO CInt}) t
cTypeSizeInBytes :: TypePtr -> IO Int
cTypeSizeInBytes t = fromIntegral <$> (\ptr -> do {peekByteOff ptr 60 ::IO CInt}) t
data CValue
type ValuePtr = Ptr (CValue)
data CMeta
type MetaPtr = Ptr (CMeta)
cValueTag :: ValuePtr -> IO ValueTag
cValueTag v = toEnum . fromIntegral <$> ((\ptr -> do {peekByteOff ptr 0 ::IO CInt}) v)
cValueType :: ValuePtr -> IO TypePtr
cValueType = (\ptr -> do {peekByteOff ptr 8 ::IO (TypePtr)})
cValueName :: (InternString m) => ValuePtr -> m (Maybe Identifier)
cValueName v = do
tag <- liftIO $ cValueTag v
namePtr <- liftIO $ ((\ptr -> do {peekByteOff ptr 16 ::IO (Ptr CChar)})) v
case namePtr == nullPtr of
True -> return Nothing
False -> do
rawName <- liftIO $ makeText namePtr
name <- internString rawName
rawIdent <- case tag of
ValFunction -> return $! makeGlobalIdentifier name
ValGlobalvariable -> return $! makeGlobalIdentifier name
ValAlias -> return $! makeGlobalIdentifier name
_ -> return $! makeLocalIdentifier name
ident <- internIdentifier rawIdent
return $! (Just ident)
cValueMetadata :: ValuePtr -> IO [MetaPtr]
cValueMetadata v = peekArray v (\ptr -> do {peekByteOff ptr 24 ::IO (Ptr (MetaPtr))}) (\ptr -> do {peekByteOff ptr 40 ::IO CInt})
cValueSrcLoc :: ValuePtr -> IO MetaPtr
cValueSrcLoc = (\ptr -> do {peekByteOff ptr 32 ::IO (MetaPtr)})
cValueData :: ValuePtr -> IO (Ptr ())
cValueData = (\ptr -> do {peekByteOff ptr 48 ::IO (Ptr ())})
cMetaTypeTag :: MetaPtr -> IO MetaTag
cMetaTypeTag v = toEnum . fromIntegral <$> (\ptr -> do {peekByteOff ptr 0 ::IO CInt}) v
cMetaTag :: MetaPtr -> IO DW_TAG
cMetaTag p = do
t <- (\ptr -> do {peekByteOff ptr 4 ::IO CUInt}) p
case dw_tag t of
Nothing -> return DW_TAG_unspecified_type
Just t' -> return t'
cMetaArrayElts :: MetaPtr -> IO [Maybe MetaPtr]
cMetaArrayElts p = map convertNull <$>
peekArray p (\ptr -> do {peekByteOff ptr 16 ::IO (Ptr (MetaPtr))}) (\ptr -> do {peekByteOff ptr 8 ::IO CInt})
where
convertNull ptr =
case ptr == nullPtr of
True -> Nothing
False -> Just ptr
cMetaEnumeratorName :: InternString m => MetaPtr -> m Text
cMetaEnumeratorName = shareString (\ptr -> do {peekByteOff ptr 8 ::IO (Ptr CChar)})
cMetaEnumeratorValue :: MetaPtr -> IO Int64
cMetaEnumeratorValue p = fromIntegral <$> (\ptr -> do {peekByteOff ptr 16 ::IO CULong}) p
cMetaGlobalContext :: MetaPtr -> IO (Maybe MetaPtr)
cMetaGlobalContext = optionalField (\ptr -> do {peekByteOff ptr 8 ::IO (MetaPtr)})
cMetaGlobalName :: InternString m => MetaPtr -> m Text
cMetaGlobalName = shareString (\ptr -> do {peekByteOff ptr 16 ::IO (Ptr CChar)})
cMetaGlobalDisplayName :: InternString m => MetaPtr -> m Text
cMetaGlobalDisplayName = shareString (\ptr -> do {peekByteOff ptr 24 ::IO (Ptr CChar)})
cMetaGlobalLinkageName :: InternString m => MetaPtr -> m Text
cMetaGlobalLinkageName = shareString (\ptr -> do {peekByteOff ptr 32 ::IO (Ptr CChar)})
cMetaGlobalLine :: MetaPtr -> IO Int32
cMetaGlobalLine p = fromIntegral <$> (\ptr -> do {peekByteOff ptr 40 ::IO CUInt}) p
cMetaGlobalType :: MetaPtr -> IO (Maybe MetaPtr)
cMetaGlobalType = optionalField (\ptr -> do {peekByteOff ptr 48 ::IO (MetaPtr)})
cMetaGlobalIsLocal :: MetaPtr -> IO Bool
cMetaGlobalIsLocal p = toBool <$> (\ptr -> do {peekByteOff ptr 56 ::IO CInt}) p
cMetaGlobalIsDefinition :: MetaPtr -> IO Bool
cMetaGlobalIsDefinition p = toBool <$> (\ptr -> do {peekByteOff ptr 60 ::IO CInt}) p
cMetaLocationLine :: MetaPtr -> IO Int32
cMetaLocationLine p = fromIntegral <$> (\ptr -> do {peekByteOff ptr 8 ::IO CUInt}) p
cMetaLocationColumn :: MetaPtr -> IO Int32
cMetaLocationColumn p = fromIntegral <$> (\ptr -> do {peekByteOff ptr 12 ::IO CUInt}) p
cMetaLocationScope :: MetaPtr -> IO (Maybe MetaPtr)
cMetaLocationScope = optionalField (\ptr -> do {peekByteOff ptr 16 ::IO (MetaPtr)})
cMetaSubrangeLo :: MetaPtr -> IO Int64
cMetaSubrangeLo p = fromIntegral <$> (\ptr -> do {peekByteOff ptr 8 ::IO CLong}) p
cMetaSubrangeHi :: MetaPtr -> IO Int64
cMetaSubrangeHi p = fromIntegral <$> (\ptr -> do {peekByteOff ptr 16 ::IO CLong}) p
cMetaTemplateTypeContext :: MetaPtr -> IO (Maybe MetaPtr)
cMetaTemplateTypeContext = optionalField (\ptr -> do {peekByteOff ptr 8 ::IO (MetaPtr)})
cMetaTemplateTypeName :: InternString m => MetaPtr -> m Text
cMetaTemplateTypeName = shareString (\ptr -> do {peekByteOff ptr 16 ::IO (Ptr CChar)})
cMetaTemplateTypeType :: MetaPtr -> IO (Maybe MetaPtr)
cMetaTemplateTypeType = optionalField (\ptr -> do {peekByteOff ptr 24 ::IO (MetaPtr)})
cMetaTemplateTypeLine :: MetaPtr -> IO Int32
cMetaTemplateTypeLine p = fromIntegral <$> (\ptr -> do {peekByteOff ptr 48 ::IO CUInt}) p
cMetaTemplateTypeColumn :: MetaPtr -> IO Int32
cMetaTemplateTypeColumn p = fromIntegral <$> (\ptr -> do {peekByteOff ptr 52 ::IO CUInt}) p
cMetaTemplateValueContext :: MetaPtr -> IO (Maybe MetaPtr)
cMetaTemplateValueContext = optionalField (\ptr -> do {peekByteOff ptr 8 ::IO (MetaPtr)})
cMetaTemplateValueName :: InternString m => MetaPtr -> m Text
cMetaTemplateValueName = shareString (\ptr -> do {peekByteOff ptr 16 ::IO (Ptr CChar)})
cMetaTemplateValueType :: MetaPtr -> IO (Maybe MetaPtr)
cMetaTemplateValueType = optionalField (\ptr -> do {peekByteOff ptr 24 ::IO (MetaPtr)})
cMetaTemplateValueValue :: MetaPtr -> IO Int64
cMetaTemplateValueValue p = fromIntegral <$> (\ptr -> do {peekByteOff ptr 32 ::IO CULong}) p
cMetaTemplateValueLine :: MetaPtr -> IO Int32
cMetaTemplateValueLine p = fromIntegral <$> (\ptr -> do {peekByteOff ptr 56 ::IO CUInt}) p
cMetaTemplateValueColumn :: MetaPtr -> IO Int32
cMetaTemplateValueColumn p = fromIntegral <$> (\ptr -> do {peekByteOff ptr 60 ::IO CUInt}) p
cMetaVariableContext :: MetaPtr -> IO (Maybe MetaPtr)
cMetaVariableContext = optionalField (\ptr -> do {peekByteOff ptr 8 ::IO (MetaPtr)})
cMetaVariableName :: InternString m => MetaPtr -> m Text
cMetaVariableName = shareString (\ptr -> do {peekByteOff ptr 16 ::IO (Ptr CChar)})
cMetaVariableLine :: MetaPtr -> IO Int32
cMetaVariableLine p = fromIntegral <$> (\ptr -> do {peekByteOff ptr 24 ::IO CUInt}) p
cMetaVariableArgNumber :: MetaPtr -> IO Int32
cMetaVariableArgNumber p = fromIntegral <$> (\ptr -> do {peekByteOff ptr 28 ::IO CUInt}) p
cMetaVariableType :: MetaPtr -> IO (Maybe MetaPtr)
cMetaVariableType = optionalField (\ptr -> do {peekByteOff ptr 32 ::IO (MetaPtr)})
cMetaVariableIsArtificial :: MetaPtr -> IO Bool
cMetaVariableIsArtificial p = toBool <$> (\ptr -> do {peekByteOff ptr 40 ::IO CInt}) p
cMetaVariableHasComplexAddress :: MetaPtr -> IO Bool
cMetaVariableHasComplexAddress p = toBool <$> (\ptr -> do {peekByteOff ptr 44 ::IO CInt}) p
cMetaVariableAddrElements :: MetaPtr -> IO [Int64]
cMetaVariableAddrElements p = do
ca <- cMetaVariableHasComplexAddress p
case ca of
True -> peekArray p (\ptr -> do {peekByteOff ptr 56 ::IO (Ptr CULong)}) (\ptr -> do {peekByteOff ptr 48 ::IO CUInt})
False -> return []
cMetaVariableIsBlockByRefVar :: MetaPtr -> IO Bool
cMetaVariableIsBlockByRefVar p = toBool <$> (\ptr -> do {peekByteOff ptr 64 ::IO CInt}) p
cMetaCompileUnitLanguage :: MetaPtr -> IO DW_LANG
cMetaCompileUnitLanguage p = dw_lang <$> (\ptr -> do {peekByteOff ptr 8 ::IO CUInt}) p
cMetaCompileUnitFilename :: InternString m => MetaPtr -> m Text
cMetaCompileUnitFilename = shareString (\ptr -> do {peekByteOff ptr 16 ::IO (Ptr CChar)})
cMetaCompileUnitDirectory :: InternString m => MetaPtr -> m Text
cMetaCompileUnitDirectory = shareString (\ptr -> do {peekByteOff ptr 24 ::IO (Ptr CChar)})
cMetaCompileUnitProducer :: InternString m => MetaPtr -> m Text
cMetaCompileUnitProducer = shareString (\ptr -> do {peekByteOff ptr 32 ::IO (Ptr CChar)})
cMetaCompileUnitIsMain :: MetaPtr -> IO Bool
cMetaCompileUnitIsMain p = toBool <$> (\ptr -> do {peekByteOff ptr 40 ::IO CInt}) p
cMetaCompileUnitIsOptimized :: MetaPtr -> IO Bool
cMetaCompileUnitIsOptimized p = toBool <$> (\ptr -> do {peekByteOff ptr 44 ::IO CInt}) p
cMetaCompileUnitFlags :: InternString m => MetaPtr -> m Text
cMetaCompileUnitFlags = shareString (\ptr -> do {peekByteOff ptr 48 ::IO (Ptr CChar)})
cMetaCompileUnitRuntimeVersion :: MetaPtr -> IO Int32
cMetaCompileUnitRuntimeVersion p = fromIntegral <$> (\ptr -> do {peekByteOff ptr 56 ::IO CUInt}) p
cMetaCompileUnitEnumTypes :: MetaPtr -> IO (Maybe MetaPtr)
cMetaCompileUnitEnumTypes = optionalField (\ptr -> do {peekByteOff ptr 64 ::IO (MetaPtr)})
cMetaCompileUnitRetainedTypes :: MetaPtr -> IO (Maybe MetaPtr)
cMetaCompileUnitRetainedTypes = optionalField (\ptr -> do {peekByteOff ptr 72 ::IO (MetaPtr)})
cMetaCompileUnitSubprograms :: MetaPtr -> IO (Maybe MetaPtr)
cMetaCompileUnitSubprograms = optionalField (\ptr -> do {peekByteOff ptr 80 ::IO (MetaPtr)})
cMetaCompileUnitGlobalVariables :: MetaPtr -> IO (Maybe MetaPtr)
cMetaCompileUnitGlobalVariables = optionalField (\ptr -> do {peekByteOff ptr 88 ::IO (MetaPtr)})
cMetaFileFilename :: InternString m => MetaPtr -> m Text
cMetaFileFilename = shareString (\ptr -> do {peekByteOff ptr 8 ::IO (Ptr CChar)})
cMetaFileDirectory :: InternString m => MetaPtr -> m Text
cMetaFileDirectory = shareString (\ptr -> do {peekByteOff ptr 16 ::IO (Ptr CChar)})
cMetaLexicalBlockContext :: MetaPtr -> IO (Maybe MetaPtr)
cMetaLexicalBlockContext = optionalField (\ptr -> do {peekByteOff ptr 8 ::IO (MetaPtr)})
cMetaLexicalBlockLine :: MetaPtr -> IO Int32
cMetaLexicalBlockLine p = fromIntegral <$> (\ptr -> do {peekByteOff ptr 16 ::IO CUInt}) p
cMetaLexicalBlockColumn :: MetaPtr -> IO Int32
cMetaLexicalBlockColumn p = fromIntegral <$> (\ptr -> do {peekByteOff ptr 20 ::IO CUInt}) p
cMetaNamespaceContext :: MetaPtr -> IO (Maybe MetaPtr)
cMetaNamespaceContext = optionalField (\ptr -> do {peekByteOff ptr 8 ::IO (MetaPtr)})
cMetaNamespaceName :: InternString m => MetaPtr -> m Text
cMetaNamespaceName = shareString (\ptr -> do {peekByteOff ptr 16 ::IO (Ptr CChar)})
cMetaNamespaceLine :: MetaPtr -> IO Int32
cMetaNamespaceLine p = fromIntegral <$> (\ptr -> do {peekByteOff ptr 40 ::IO CUInt}) p
cMetaSubprogramContext :: MetaPtr -> IO (Maybe MetaPtr)
cMetaSubprogramContext = optionalField (\ptr -> do {peekByteOff ptr 8 ::IO (MetaPtr)})
cMetaSubprogramName :: InternString m => MetaPtr -> m Text
cMetaSubprogramName = shareString (\ptr -> do {peekByteOff ptr 16 ::IO (Ptr CChar)})
cMetaSubprogramDisplayName :: InternString m => MetaPtr -> m Text
cMetaSubprogramDisplayName = shareString (\ptr -> do {peekByteOff ptr 24 ::IO (Ptr CChar)})
cMetaSubprogramLinkageName :: InternString m => MetaPtr -> m Text
cMetaSubprogramLinkageName = shareString (\ptr -> do {peekByteOff ptr 32 ::IO (Ptr CChar)})
cMetaSubprogramLine :: MetaPtr -> IO Int32
cMetaSubprogramLine p = fromIntegral <$> (\ptr -> do {peekByteOff ptr 40 ::IO CUInt}) p
cMetaSubprogramType :: MetaPtr -> IO (Maybe MetaPtr)
cMetaSubprogramType = optionalField (\ptr -> do {peekByteOff ptr 48 ::IO (MetaPtr)})
cMetaSubprogramIsLocal :: MetaPtr -> IO Bool
cMetaSubprogramIsLocal p = toBool <$> (\ptr -> do {peekByteOff ptr 64 ::IO CInt}) p
cMetaSubprogramIsDefinition :: MetaPtr -> IO Bool
cMetaSubprogramIsDefinition p = toBool <$> (\ptr -> do {peekByteOff ptr 68 ::IO CInt}) p
cMetaSubprogramVirtuality :: MetaPtr -> IO DW_VIRTUALITY
cMetaSubprogramVirtuality p = dw_virtuality <$> (\ptr -> do {peekByteOff ptr 72 ::IO CUInt}) p
cMetaSubprogramVirtualIndex :: MetaPtr -> IO Int32
cMetaSubprogramVirtualIndex p = fromIntegral <$> (\ptr -> do {peekByteOff ptr 76 ::IO CUInt}) p
cMetaSubprogramContainingType :: MetaPtr -> IO (Maybe MetaPtr)
cMetaSubprogramContainingType = optionalField (\ptr -> do {peekByteOff ptr 80 ::IO (MetaPtr)})
cMetaSubprogramIsArtificial :: MetaPtr -> IO Bool
cMetaSubprogramIsArtificial p = toBool <$> (\ptr -> do {peekByteOff ptr 88 ::IO CInt}) p
cMetaSubprogramIsPrivate :: MetaPtr -> IO Bool
cMetaSubprogramIsPrivate p = toBool <$> (\ptr -> do {peekByteOff ptr 92 ::IO CInt}) p
cMetaSubprogramIsProtected :: MetaPtr -> IO Bool
cMetaSubprogramIsProtected p = toBool <$> (\ptr -> do {peekByteOff ptr 96 ::IO CInt}) p
cMetaSubprogramIsExplicit :: MetaPtr -> IO Bool
cMetaSubprogramIsExplicit p = toBool <$> (\ptr -> do {peekByteOff ptr 100 ::IO CInt}) p
cMetaSubprogramIsPrototyped :: MetaPtr -> IO Bool
cMetaSubprogramIsPrototyped p = toBool <$> (\ptr -> do {peekByteOff ptr 104 ::IO CInt}) p
cMetaSubprogramIsOptimized :: MetaPtr -> IO Bool
cMetaSubprogramIsOptimized p = toBool <$> (\ptr -> do {peekByteOff ptr 108 ::IO CInt}) p
cMetaTypeContext :: MetaPtr -> IO (Maybe MetaPtr)
cMetaTypeContext = optionalField (\ptr -> do {peekByteOff ptr 8 ::IO (MetaPtr)})
cMetaTypeName :: InternString m => MetaPtr -> m Text
cMetaTypeName = shareString (\ptr -> do {peekByteOff ptr 16 ::IO (Ptr CChar)})
cMetaTypeLine :: MetaPtr -> IO Int32
cMetaTypeLine p = fromIntegral <$> (\ptr -> do {peekByteOff ptr 24 ::IO CUInt}) p
cMetaTypeSize :: MetaPtr -> IO Int64
cMetaTypeSize p = fromIntegral <$> (\ptr -> do {peekByteOff ptr 32 ::IO CULong}) p
cMetaTypeAlign :: MetaPtr -> IO Int64
cMetaTypeAlign p = fromIntegral <$> (\ptr -> do {peekByteOff ptr 40 ::IO CULong}) p
cMetaTypeOffset :: MetaPtr -> IO Int64
cMetaTypeOffset p = fromIntegral <$> (\ptr -> do {peekByteOff ptr 48 ::IO CULong}) p
cMetaTypeFlags :: MetaPtr -> IO Int32
cMetaTypeFlags p = fromIntegral <$> (\ptr -> do {peekByteOff ptr 56 ::IO CUInt}) p
cMetaTypeIsPrivate :: MetaPtr -> IO Bool
cMetaTypeIsPrivate p = toBool <$> (\ptr -> do {peekByteOff ptr 60 ::IO CInt}) p
cMetaTypeIsProtected :: MetaPtr -> IO Bool
cMetaTypeIsProtected p = toBool <$> (\ptr -> do {peekByteOff ptr 64 ::IO CInt}) p
cMetaTypeIsForward :: MetaPtr -> IO Bool
cMetaTypeIsForward p = toBool <$> (\ptr -> do {peekByteOff ptr 68 ::IO CInt}) p
cMetaTypeIsByRefStruct :: MetaPtr -> IO Bool
cMetaTypeIsByRefStruct p = toBool <$> (\ptr -> do {peekByteOff ptr 72 ::IO CInt}) p
cMetaTypeIsVirtual :: MetaPtr -> IO Bool
cMetaTypeIsVirtual p = toBool <$> (\ptr -> do {peekByteOff ptr 76 ::IO CInt}) p
cMetaTypeIsArtificial :: MetaPtr -> IO Bool
cMetaTypeIsArtificial p = toBool <$> (\ptr -> do {peekByteOff ptr 80 ::IO CInt}) p
cMetaTypeDirectory :: InternString m => MetaPtr -> m Text
cMetaTypeDirectory = shareString (\ptr -> do {peekByteOff ptr 88 ::IO (Ptr CChar)})
cMetaTypeFilename :: InternString m => MetaPtr -> m Text
cMetaTypeFilename = shareString (\ptr -> do {peekByteOff ptr 96 ::IO (Ptr CChar)})
cMetaTypeEncoding :: MetaPtr -> IO DW_ATE
cMetaTypeEncoding p = dw_ate <$> (\ptr -> do {peekByteOff ptr 104 ::IO CUInt}) p
cMetaTypeDerivedFrom :: MetaPtr -> IO (Maybe MetaPtr)
cMetaTypeDerivedFrom = optionalField (\ptr -> do {peekByteOff ptr 112 ::IO (MetaPtr)})
cMetaTypeCompositeComponents :: MetaPtr -> IO (Maybe MetaPtr)
cMetaTypeCompositeComponents = optionalField (\ptr -> do {peekByteOff ptr 128 ::IO (MetaPtr)})
cMetaTypeRuntimeLanguage :: MetaPtr -> IO Int32
cMetaTypeRuntimeLanguage p = fromIntegral <$> (\ptr -> do {peekByteOff ptr 136 ::IO CUInt}) p
cMetaTypeContainingType :: MetaPtr -> IO (Maybe MetaPtr)
cMetaTypeContainingType = optionalField (\ptr -> do {peekByteOff ptr 144 ::IO (MetaPtr)})
cMetaTypeTemplateParams :: MetaPtr -> IO (Maybe MetaPtr)
cMetaTypeTemplateParams = optionalField (\ptr -> do {peekByteOff ptr 152 ::IO (MetaPtr)})
cMetaUnknownRepr :: InternString m => MetaPtr -> m Text
cMetaUnknownRepr = shareString (\ptr -> do {peekByteOff ptr 8 ::IO (Ptr CChar)})
optionalField :: (a -> IO (Ptr b)) -> a -> IO (Maybe (Ptr b))
optionalField accessor p = do
v <- accessor p
case v == nullPtr of
True -> return Nothing
False -> return (Just v)
class MonadIO m => InternString m where
internString :: Text -> m Text
internIdentifier :: Identifier -> m Identifier
shareString :: InternString m => (a -> IO CString) -> a -> m Text
shareString accessor ptr = do
sp <- liftIO $ accessor ptr
str <- case sp == nullPtr of
False -> liftIO $ BS.packCString sp
True -> return $ BS.pack ""
internString (decodeUtf8 str)
data CGlobalInfo
type GlobalInfoPtr = Ptr (CGlobalInfo)
cGlobalIsExternal :: GlobalInfoPtr -> IO Bool
cGlobalIsExternal g = toBool <$> ((\ptr -> do {peekByteOff ptr 0 ::IO CInt}) g)
cGlobalAlignment :: GlobalInfoPtr -> IO Int64
cGlobalAlignment g = fromIntegral <$> ((\ptr -> do {peekByteOff ptr 4 ::IO CInt}) g)
cGlobalVisibility :: GlobalInfoPtr -> IO VisibilityStyle
cGlobalVisibility g = toEnum . fromIntegral <$> ((\ptr -> do {peekByteOff ptr 8 ::IO CInt}) g)
cGlobalLinkage :: GlobalInfoPtr -> IO LinkageType
cGlobalLinkage g = toEnum . fromIntegral <$> ((\ptr -> do {peekByteOff ptr 12 ::IO CInt}) g)
cGlobalSection :: GlobalInfoPtr -> IO (Maybe Text)
cGlobalSection g = do
s <- (\ptr -> do {peekByteOff ptr 16 ::IO (Ptr CChar)}) g
case s == nullPtr of
True -> return Nothing
False -> do
bs <- BS.packCString s
return $! Just (decodeUtf8 bs)
cGlobalInitializer :: GlobalInfoPtr -> IO ValuePtr
cGlobalInitializer = (\ptr -> do {peekByteOff ptr 24 ::IO (ValuePtr)})
cGlobalIsThreadLocal :: GlobalInfoPtr -> IO Bool
cGlobalIsThreadLocal g = toBool <$> ((\ptr -> do {peekByteOff ptr 32 ::IO CInt}) g)
cGlobalAliasee :: GlobalInfoPtr -> IO ValuePtr
cGlobalAliasee = (\ptr -> do {peekByteOff ptr 40 ::IO (ValuePtr)})
cGlobalIsConstant :: GlobalInfoPtr -> IO Bool
cGlobalIsConstant g = toBool <$> (\ptr -> do {peekByteOff ptr 36 ::IO CInt}) g
data CFunctionInfo
type FunctionInfoPtr = Ptr (CFunctionInfo)
cFunctionIsExternal :: FunctionInfoPtr -> IO Bool
cFunctionIsExternal f = toBool <$> (\ptr -> do {peekByteOff ptr 0 ::IO CInt}) f
cFunctionAlignment :: FunctionInfoPtr -> IO Int64
cFunctionAlignment f = fromIntegral <$> (\ptr -> do {peekByteOff ptr 4 ::IO CInt}) f
cFunctionVisibility :: FunctionInfoPtr -> IO VisibilityStyle
cFunctionVisibility f = toEnum . fromIntegral <$> (\ptr -> do {peekByteOff ptr 8 ::IO CInt}) f
cFunctionLinkage :: FunctionInfoPtr -> IO LinkageType
cFunctionLinkage f = toEnum . fromIntegral <$> (\ptr -> do {peekByteOff ptr 12 ::IO CInt}) f
cFunctionSection :: FunctionInfoPtr -> IO (Maybe Text)
cFunctionSection f = do
s <- (\ptr -> do {peekByteOff ptr 16 ::IO (Ptr CChar)}) f
case s == nullPtr of
True -> return Nothing
False -> do
bs <- BS.packCString s
return $! Just (decodeUtf8 bs)
cFunctionIsVarArg :: FunctionInfoPtr -> IO Bool
cFunctionIsVarArg f = toBool <$> (\ptr -> do {peekByteOff ptr 28 ::IO CInt}) f
cFunctionCallingConvention :: FunctionInfoPtr -> IO CallingConvention
cFunctionCallingConvention f = toEnum . fromIntegral <$> (\ptr -> do {peekByteOff ptr 24 ::IO CInt}) f
cFunctionGCName :: FunctionInfoPtr -> IO (Maybe Text)
cFunctionGCName f = do
s <- (\ptr -> do {peekByteOff ptr 32 ::IO (Ptr CChar)}) f
case s == nullPtr of
True -> return Nothing
False -> do
bs <- BS.packCString s
return $! Just (decodeUtf8 bs)
cFunctionArguments :: FunctionInfoPtr -> IO [ValuePtr]
cFunctionArguments f =
peekArray f (\ptr -> do {peekByteOff ptr 40 ::IO (Ptr (ValuePtr))}) (\ptr -> do {peekByteOff ptr 48 ::IO CInt})
cFunctionBlocks :: FunctionInfoPtr -> IO [ValuePtr]
cFunctionBlocks f =
peekArray f (\ptr -> do {peekByteOff ptr 56 ::IO (Ptr (ValuePtr))}) (\ptr -> do {peekByteOff ptr 64 ::IO CInt})
data CArgInfo
type ArgInfoPtr = Ptr (CArgInfo)
cArgInfoHasSRet :: ArgInfoPtr -> IO Bool
cArgInfoHasSRet a = toBool <$> ((\ptr -> do {peekByteOff ptr 0 ::IO CInt}) a)
cArgInfoHasByVal :: ArgInfoPtr -> IO Bool
cArgInfoHasByVal a = toBool <$> ((\ptr -> do {peekByteOff ptr 4 ::IO CInt}) a)
cArgInfoHasNest :: ArgInfoPtr -> IO Bool
cArgInfoHasNest a = toBool <$> ((\ptr -> do {peekByteOff ptr 8 ::IO CInt}) a)
cArgInfoHasNoAlias :: ArgInfoPtr -> IO Bool
cArgInfoHasNoAlias a = toBool <$> ((\ptr -> do {peekByteOff ptr 12 ::IO CInt}) a)
cArgInfoHasNoCapture :: ArgInfoPtr -> IO Bool
cArgInfoHasNoCapture a = toBool <$> ((\ptr -> do {peekByteOff ptr 16 ::IO CInt}) a)
data CBasicBlockInfo
type BasicBlockPtr = Ptr (CBasicBlockInfo)
cBasicBlockInstructions :: BasicBlockPtr -> IO [ValuePtr]
cBasicBlockInstructions b =
peekArray b (\ptr -> do {peekByteOff ptr 0 ::IO (Ptr (ValuePtr))}) (\ptr -> do {peekByteOff ptr 8 ::IO CInt})
data CInlineAsmInfo
type InlineAsmInfoPtr = Ptr (CInlineAsmInfo)
cInlineAsmString :: InlineAsmInfoPtr -> IO Text
cInlineAsmString a =
((\ptr -> do {peekByteOff ptr 0 ::IO (Ptr CChar)}) a) >>= makeText
cInlineAsmConstraints :: InlineAsmInfoPtr -> IO Text
cInlineAsmConstraints a =
((\ptr -> do {peekByteOff ptr 8 ::IO (Ptr CChar)}) a) >>= makeText
data CBlockAddrInfo
type BlockAddrInfoPtr = Ptr (CBlockAddrInfo)
cBlockAddrFunc :: BlockAddrInfoPtr -> IO ValuePtr
cBlockAddrFunc = (\ptr -> do {peekByteOff ptr 0 ::IO (ValuePtr)})
cBlockAddrBlock :: BlockAddrInfoPtr -> IO ValuePtr
cBlockAddrBlock = (\ptr -> do {peekByteOff ptr 8 ::IO (ValuePtr)})
data CAggregateInfo
type AggregateInfoPtr = Ptr (CAggregateInfo)
cAggregateValues :: AggregateInfoPtr -> IO [ValuePtr]
cAggregateValues a =
peekArray a (\ptr -> do {peekByteOff ptr 0 ::IO (Ptr (ValuePtr))}) (\ptr -> do {peekByteOff ptr 8 ::IO CInt})
data CConstFP
type FPInfoPtr = Ptr (CConstFP)
cFPVal :: FPInfoPtr -> IO Double
cFPVal f = realToFrac <$> ((\ptr -> do {peekByteOff ptr 0 ::IO CDouble}) f)
data CConstInt
type IntInfoPtr = Ptr (CConstInt)
cIntVal :: IntInfoPtr -> IO Integer
cIntVal i = fromIntegral <$> ((\ptr -> do {peekByteOff ptr 0 ::IO CLLong}) i)
cIntHugeVal :: IntInfoPtr -> IO (Maybe Integer)
cIntHugeVal i = do
s <- (\ptr -> do {peekByteOff ptr 8 ::IO (Ptr CChar)}) i
case s == nullPtr of
True -> return Nothing
False -> (Just . read) <$> peekCString s
data CInstructionInfo
type InstInfoPtr = Ptr (CInstructionInfo)
cInstructionOperands :: InstInfoPtr -> IO [ValuePtr]
cInstructionOperands i =
peekArray i (\ptr -> do {peekByteOff ptr 0 ::IO (Ptr (ValuePtr))}) (\ptr -> do {peekByteOff ptr 8 ::IO CInt})
cInstructionArithFlags :: InstInfoPtr -> IO ArithFlags
cInstructionArithFlags o = toEnum . fromIntegral <$> (\ptr -> do {peekByteOff ptr 32 ::IO CInt}) o
cInstructionAlign :: InstInfoPtr -> IO Int64
cInstructionAlign u = fromIntegral <$> (\ptr -> do {peekByteOff ptr 36 ::IO CInt}) u
cInstructionIsVolatile :: InstInfoPtr -> IO Bool
cInstructionIsVolatile u = toBool <$> (\ptr -> do {peekByteOff ptr 44 ::IO CInt}) u
cInstructionAddrSpace :: InstInfoPtr -> IO Int
cInstructionAddrSpace u = fromIntegral <$> (\ptr -> do {peekByteOff ptr 40 ::IO CInt}) u
cInstructionCmpPred :: InstInfoPtr -> IO CmpPredicate
cInstructionCmpPred c = toEnum . fromIntegral <$> (\ptr -> do {peekByteOff ptr 28 ::IO CInt}) c
cInstructionInBounds :: InstInfoPtr -> IO Bool
cInstructionInBounds g = toBool <$> (\ptr -> do {peekByteOff ptr 48 ::IO CInt}) g
cInstructionIndices :: InstInfoPtr -> IO [Int]
cInstructionIndices i =
peekArray i (\ptr -> do {peekByteOff ptr 16 ::IO (Ptr CInt)}) (\ptr -> do {peekByteOff ptr 24 ::IO CInt})
data CConstExprInfo
type ConstExprPtr = Ptr (CConstExprInfo)
cConstExprTag :: ConstExprPtr -> IO ValueTag
cConstExprTag e = toEnum . fromIntegral <$> (\ptr -> do {peekByteOff ptr 8 ::IO CInt}) e
cConstExprInstInfo :: ConstExprPtr -> IO InstInfoPtr
cConstExprInstInfo = (\ptr -> do {peekByteOff ptr 0 ::IO (InstInfoPtr)})
data CPHIInfo
type PHIInfoPtr = Ptr (CPHIInfo)
cPHIValues :: PHIInfoPtr -> IO [ValuePtr]
cPHIValues p =
peekArray p (\ptr -> do {peekByteOff ptr 0 ::IO (Ptr (ValuePtr))}) (\ptr -> do {peekByteOff ptr 16 ::IO CInt})
cPHIBlocks :: PHIInfoPtr -> IO [ValuePtr]
cPHIBlocks p =
peekArray p (\ptr -> do {peekByteOff ptr 8 ::IO (Ptr (ValuePtr))}) (\ptr -> do {peekByteOff ptr 16 ::IO CInt})
data CCallInfo
type CallInfoPtr = Ptr (CCallInfo)
cCallValue :: CallInfoPtr -> IO ValuePtr
cCallValue = (\ptr -> do {peekByteOff ptr 0 ::IO (ValuePtr)})
cCallArguments :: CallInfoPtr -> IO [ValuePtr]
cCallArguments c =
peekArray c (\ptr -> do {peekByteOff ptr 8 ::IO (Ptr (ValuePtr))}) (\ptr -> do {peekByteOff ptr 16 ::IO CInt})
cCallConvention :: CallInfoPtr -> IO CallingConvention
cCallConvention c = toEnum . fromIntegral <$> (\ptr -> do {peekByteOff ptr 20 ::IO CInt}) c
cCallHasSRet :: CallInfoPtr -> IO Bool
cCallHasSRet c = toBool <$> (\ptr -> do {peekByteOff ptr 24 ::IO CInt}) c
cCallIsTail :: CallInfoPtr -> IO Bool
cCallIsTail c = toBool <$> (\ptr -> do {peekByteOff ptr 28 ::IO CInt}) c
cCallUnwindDest :: CallInfoPtr -> IO ValuePtr
cCallUnwindDest = (\ptr -> do {peekByteOff ptr 40 ::IO (ValuePtr)})
cCallNormalDest :: CallInfoPtr -> IO ValuePtr
cCallNormalDest = (\ptr -> do {peekByteOff ptr 32 ::IO (ValuePtr)})
data CAtomicInfo
type AtomicInfoPtr = Ptr (CAtomicInfo)
cAtomicOrdering :: AtomicInfoPtr -> IO AtomicOrdering
cAtomicOrdering ai = toEnum . fromIntegral <$> (\ptr -> do {peekByteOff ptr 0 ::IO CInt}) ai
cAtomicScope :: AtomicInfoPtr -> IO SynchronizationScope
cAtomicScope ai = toEnum . fromIntegral <$> (\ptr -> do {peekByteOff ptr 4 ::IO CInt}) ai
cAtomicOperation :: AtomicInfoPtr -> IO AtomicOperation
cAtomicOperation ai = toEnum . fromIntegral <$> (\ptr -> do {peekByteOff ptr 8 ::IO CInt}) ai
cAtomicIsVolatile :: AtomicInfoPtr -> IO Bool
cAtomicIsVolatile ai = toBool <$> (\ptr -> do {peekByteOff ptr 12 ::IO CInt}) ai
cAtomicAddressSpace :: AtomicInfoPtr -> IO Int
cAtomicAddressSpace ai = fromIntegral <$> (\ptr -> do {peekByteOff ptr 16 ::IO CInt}) ai
cAtomicPointerOperand :: AtomicInfoPtr -> IO ValuePtr
cAtomicPointerOperand = (\ptr -> do {peekByteOff ptr 24 ::IO (ValuePtr)})
cAtomicValueOperand :: AtomicInfoPtr -> IO ValuePtr
cAtomicValueOperand = (\ptr -> do {peekByteOff ptr 32 ::IO (ValuePtr)})
cAtomicCompareOperand :: AtomicInfoPtr -> IO ValuePtr
cAtomicCompareOperand = (\ptr -> do {peekByteOff ptr 40 ::IO (ValuePtr)})
data CLandingPadInfo
type LandingPadInfoPtr = Ptr (CLandingPadInfo)
cLandingPadPersonality :: LandingPadInfoPtr -> IO ValuePtr
cLandingPadPersonality = (\ptr -> do {peekByteOff ptr 0 ::IO (ValuePtr)})
cLandingPadIsCleanup :: LandingPadInfoPtr -> IO Bool
cLandingPadIsCleanup li = toBool <$> (\ptr -> do {peekByteOff ptr 8 ::IO CInt}) li
cLandingPadClauses :: LandingPadInfoPtr -> IO [ValuePtr]
cLandingPadClauses li =
peekArray li (\ptr -> do {peekByteOff ptr 16 ::IO (Ptr (ValuePtr))}) (\ptr -> do {peekByteOff ptr 12 ::IO CInt})
cLandingPadClauseTypes :: LandingPadInfoPtr -> IO [LandingPadClause]
cLandingPadClauseTypes li = do
arr <- peekArray li (\ptr -> do {peekByteOff ptr 24 ::IO (Ptr CInt)}) (\ptr -> do {peekByteOff ptr 12 ::IO CInt})
return $ map toEnum arr
marshalLLVM :: (Ptr CChar) -> (Int) -> (Bool) -> IO ((ModulePtr))
marshalLLVM a1 a2 a3 =
let {a1' = id a1} in
let {a2' = fromIntegral a2} in
let {a3' = fromBool a3} in
marshalLLVM'_ a1' a2' a3' >>= \res ->
let {res' = id res} in
return (res')
marshalLLVMFile :: (String) -> (Bool) -> IO ((ModulePtr))
marshalLLVMFile a1 a2 =
withCString a1 $ \a1' ->
let {a2' = fromBool a2} in
marshalLLVMFile'_ a1' a2' >>= \res ->
let {res' = id res} in
return (res')
disposeCModule :: (ModulePtr) -> IO ()
disposeCModule a1 =
let {a1' = id a1} in
disposeCModule'_ a1' >>= \res ->
return ()
cIntConv :: (Integral a, Num b) => a -> b
cIntConv = fromIntegral
foreign import ccall safe "LLVM/Internal/Interop.chs.h marshalLLVM"
marshalLLVM'_ :: ((Ptr CChar) -> (CInt -> (CInt -> (IO (ModulePtr)))))
foreign import ccall safe "LLVM/Internal/Interop.chs.h marshalLLVMFile"
marshalLLVMFile'_ :: ((Ptr CChar) -> (CInt -> (IO (ModulePtr))))
foreign import ccall safe "LLVM/Internal/Interop.chs.h disposeCModule"
disposeCModule'_ :: ((ModulePtr) -> (IO ()))