-- GENERATED by C->Haskell Compiler, version 0.16.5 Crystal Seed, 24 Jan 2009 (Haskell)
-- Edit the ORIGNAL .chs file instead!


{-# LINE 1 "src/LLVM/Internal/Interop.chs" #-}{-# LANGUAGE ForeignFunctionInterface, DeriveDataTypeable, RankNTypes, OverloadedStrings, CPP #-}
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)

{-# LINE 27 "src/LLVM/Internal/Interop.chs" #-}
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)

{-# LINE 28 "src/LLVM/Internal/Interop.chs" #-}
data MetaTag = MetaLocation
             | MetaDerivedtype
             | MetaCompositetype
             | MetaBasictype
             | MetaVariable
             | MetaSubprogram
             | MetaGlobalvariable
             | MetaFile
             | MetaCompileunit
             | MetaNamespace
             | MetaLexicalblock
             | MetaSubrange
             | MetaEnumerator
             | MetaArray
             | MetaTemplatetypeparameter
             | MetaTemplatevalueparameter
             | MetaUnknown
             deriving (Enum,Show,Eq)

{-# LINE 29 "src/LLVM/Internal/Interop.chs" #-}

data CModule
type ModulePtr = Ptr (CModule)
{-# LINE 32 "src/LLVM/Internal/Interop.chs" #-}

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})
{-# LINE 72 "src/LLVM/Internal/Interop.chs" #-}

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})
{-# LINE 84 "src/LLVM/Internal/Interop.chs" #-}

cModuleRetainedTypeMetadata :: ModulePtr -> IO [MetaPtr]
cModuleRetainedTypeMetadata m =
  peekArray m (\ptr -> do {peekByteOff ptr 120 ::IO (Ptr (Ptr ()))}) (\ptr -> do {peekByteOff ptr 128 ::IO CInt})
{-# LINE 88 "src/LLVM/Internal/Interop.chs" #-}

cModuleTypes :: ModulePtr -> IO [TypePtr]
cModuleTypes m =
  peekArray m (\ptr -> do {peekByteOff ptr 88 ::IO (Ptr (Ptr ()))}) (\ptr -> do {peekByteOff ptr 96 ::IO CInt})
{-# LINE 92 "src/LLVM/Internal/Interop.chs" #-}

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)
{-# LINE 109 "src/LLVM/Internal/Interop.chs" #-}
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})
{-# LINE 120 "src/LLVM/Internal/Interop.chs" #-}
cTypeInner :: TypePtr -> IO TypePtr
cTypeInner = (\ptr -> do {peekByteOff ptr 40 ::IO (TypePtr)})
{-# LINE 122 "src/LLVM/Internal/Interop.chs" #-}
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)
{-# LINE 138 "src/LLVM/Internal/Interop.chs" #-}
data CMeta
type MetaPtr = Ptr (CMeta)
{-# LINE 140 "src/LLVM/Internal/Interop.chs" #-}

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)})
{-# LINE 145 "src/LLVM/Internal/Interop.chs" #-}
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})
{-# LINE 163 "src/LLVM/Internal/Interop.chs" #-}
cValueSrcLoc :: ValuePtr -> IO MetaPtr
cValueSrcLoc = (\ptr -> do {peekByteOff ptr 32 ::IO (MetaPtr)})
{-# LINE 165 "src/LLVM/Internal/Interop.chs" #-}
cValueData :: ValuePtr -> IO (Ptr ())
cValueData = (\ptr -> do {peekByteOff ptr 48 ::IO (Ptr ())})
{-# LINE 167 "src/LLVM/Internal/Interop.chs" #-}


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})
{-# LINE 182 "src/LLVM/Internal/Interop.chs" #-}
  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)})
{-# LINE 190 "src/LLVM/Internal/Interop.chs" #-}
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)})
{-# LINE 194 "src/LLVM/Internal/Interop.chs" #-}
cMetaGlobalName :: InternString m => MetaPtr -> m Text
cMetaGlobalName = shareString (\ptr -> do {peekByteOff ptr 16 ::IO (Ptr CChar)})
{-# LINE 196 "src/LLVM/Internal/Interop.chs" #-}
cMetaGlobalDisplayName :: InternString m => MetaPtr -> m Text
cMetaGlobalDisplayName = shareString (\ptr -> do {peekByteOff ptr 24 ::IO (Ptr CChar)})
{-# LINE 198 "src/LLVM/Internal/Interop.chs" #-}
cMetaGlobalLinkageName :: InternString m => MetaPtr -> m Text
cMetaGlobalLinkageName = shareString (\ptr -> do {peekByteOff ptr 32 ::IO (Ptr CChar)})
{-# LINE 200 "src/LLVM/Internal/Interop.chs" #-}
-- cMetaGlobalCompileUnit :: MetaPtr -> IO MetaPtr
-- cMetaGlobalCompileUnit = {#get CMeta->u.metaGlobalInfo.compileUnit#}
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)})
{-# LINE 206 "src/LLVM/Internal/Interop.chs" #-}
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)})
{-# LINE 216 "src/LLVM/Internal/Interop.chs" #-}
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)})
{-# LINE 222 "src/LLVM/Internal/Interop.chs" #-}
cMetaTemplateTypeName :: InternString m => MetaPtr -> m Text
cMetaTemplateTypeName = shareString (\ptr -> do {peekByteOff ptr 16 ::IO (Ptr CChar)})
{-# LINE 224 "src/LLVM/Internal/Interop.chs" #-}
cMetaTemplateTypeType :: MetaPtr -> IO (Maybe MetaPtr)
cMetaTemplateTypeType = optionalField (\ptr -> do {peekByteOff ptr 24 ::IO (MetaPtr)})
{-# LINE 226 "src/LLVM/Internal/Interop.chs" #-}
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)})
{-# LINE 232 "src/LLVM/Internal/Interop.chs" #-}
cMetaTemplateValueName :: InternString m => MetaPtr -> m Text
cMetaTemplateValueName = shareString (\ptr -> do {peekByteOff ptr 16 ::IO (Ptr CChar)})
{-# LINE 234 "src/LLVM/Internal/Interop.chs" #-}
cMetaTemplateValueType :: MetaPtr -> IO (Maybe MetaPtr)
cMetaTemplateValueType = optionalField (\ptr -> do {peekByteOff ptr 24 ::IO (MetaPtr)})
{-# LINE 236 "src/LLVM/Internal/Interop.chs" #-}
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)})
{-# LINE 244 "src/LLVM/Internal/Interop.chs" #-}
cMetaVariableName :: InternString m => MetaPtr -> m Text
cMetaVariableName = shareString (\ptr -> do {peekByteOff ptr 16 ::IO (Ptr CChar)})
{-# LINE 246 "src/LLVM/Internal/Interop.chs" #-}
-- cMetaVariableCompileUnit :: MetaPtr -> IO MetaPtr
-- cMetaVariableCompileUnit = {#get CMeta->u.metaVariableInfo.compileUnit#}
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)})
{-# LINE 254 "src/LLVM/Internal/Interop.chs" #-}
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})
{-# LINE 263 "src/LLVM/Internal/Interop.chs" #-}
    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)})
{-# LINE 270 "src/LLVM/Internal/Interop.chs" #-}
cMetaCompileUnitDirectory :: InternString m => MetaPtr -> m Text
cMetaCompileUnitDirectory = shareString (\ptr -> do {peekByteOff ptr 24 ::IO (Ptr CChar)})
{-# LINE 272 "src/LLVM/Internal/Interop.chs" #-}
cMetaCompileUnitProducer :: InternString m => MetaPtr -> m Text
cMetaCompileUnitProducer = shareString (\ptr -> do {peekByteOff ptr 32 ::IO (Ptr CChar)})
{-# LINE 274 "src/LLVM/Internal/Interop.chs" #-}
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)})
{-# LINE 280 "src/LLVM/Internal/Interop.chs" #-}
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)})
{-# LINE 284 "src/LLVM/Internal/Interop.chs" #-}
cMetaCompileUnitRetainedTypes :: MetaPtr -> IO (Maybe MetaPtr)
cMetaCompileUnitRetainedTypes = optionalField (\ptr -> do {peekByteOff ptr 72 ::IO (MetaPtr)})
{-# LINE 286 "src/LLVM/Internal/Interop.chs" #-}
cMetaCompileUnitSubprograms :: MetaPtr -> IO (Maybe MetaPtr)
cMetaCompileUnitSubprograms = optionalField (\ptr -> do {peekByteOff ptr 80 ::IO (MetaPtr)})
{-# LINE 288 "src/LLVM/Internal/Interop.chs" #-}
cMetaCompileUnitGlobalVariables :: MetaPtr -> IO (Maybe MetaPtr)
cMetaCompileUnitGlobalVariables = optionalField (\ptr -> do {peekByteOff ptr 88 ::IO (MetaPtr)})
{-# LINE 290 "src/LLVM/Internal/Interop.chs" #-}
cMetaFileFilename :: InternString m => MetaPtr -> m Text
cMetaFileFilename = shareString (\ptr -> do {peekByteOff ptr 8 ::IO (Ptr CChar)})
{-# LINE 292 "src/LLVM/Internal/Interop.chs" #-}
cMetaFileDirectory :: InternString m => MetaPtr -> m Text
cMetaFileDirectory = shareString (\ptr -> do {peekByteOff ptr 16 ::IO (Ptr CChar)})
{-# LINE 294 "src/LLVM/Internal/Interop.chs" #-}
-- cMetaFileCompileUnit :: MetaPtr -> IO MetaPtr
-- cMetaFileCompileUnit = {#get CMeta->u.metaFileInfo.compileUnit#}
cMetaLexicalBlockContext :: MetaPtr -> IO (Maybe MetaPtr)
cMetaLexicalBlockContext = optionalField (\ptr -> do {peekByteOff ptr 8 ::IO (MetaPtr)})
{-# LINE 298 "src/LLVM/Internal/Interop.chs" #-}
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)})
{-# LINE 304 "src/LLVM/Internal/Interop.chs" #-}
cMetaNamespaceName :: InternString m => MetaPtr -> m Text
cMetaNamespaceName = shareString (\ptr -> do {peekByteOff ptr 16 ::IO (Ptr CChar)})
{-# LINE 306 "src/LLVM/Internal/Interop.chs" #-}
-- cMetaNamespaceCompileUnit :: MetaPtr -> IO MetaPtr
-- cMetaNamespaceCompileUnit = {#get CMeta->u.metaNamespaceInfo.compileUnit#}
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)})
{-# LINE 312 "src/LLVM/Internal/Interop.chs" #-}
cMetaSubprogramName :: InternString m => MetaPtr -> m Text
cMetaSubprogramName = shareString (\ptr -> do {peekByteOff ptr 16 ::IO (Ptr CChar)})
{-# LINE 314 "src/LLVM/Internal/Interop.chs" #-}
cMetaSubprogramDisplayName :: InternString m => MetaPtr -> m Text
cMetaSubprogramDisplayName = shareString (\ptr -> do {peekByteOff ptr 24 ::IO (Ptr CChar)})
{-# LINE 316 "src/LLVM/Internal/Interop.chs" #-}
cMetaSubprogramLinkageName :: InternString m => MetaPtr -> m Text
cMetaSubprogramLinkageName = shareString (\ptr -> do {peekByteOff ptr 32 ::IO (Ptr CChar)})
{-# LINE 318 "src/LLVM/Internal/Interop.chs" #-}
-- cMetaSubprogramCompileUnit :: MetaPtr -> IO MetaPtr
-- cMetaSubprogramCompileUnit = {#get CMeta->u.metaSubprogramInfo.compileUnit#}
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)})
{-# LINE 324 "src/LLVM/Internal/Interop.chs" #-}
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)})
{-# LINE 334 "src/LLVM/Internal/Interop.chs" #-}
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)})
{-# LINE 348 "src/LLVM/Internal/Interop.chs" #-}
cMetaTypeName :: InternString m => MetaPtr -> m Text
cMetaTypeName = shareString (\ptr -> do {peekByteOff ptr 16 ::IO (Ptr CChar)})
{-# LINE 350 "src/LLVM/Internal/Interop.chs" #-}
-- cMetaTypeCompileUnit :: MetaPtr -> IO (Maybe MetaPtr)
-- cMetaTypeCompileUnit = optionalField {#get CMeta->u.metaTypeInfo.compileUnit#}
-- cMetaTypeFile :: MetaPtr -> IO (Maybe MetaPtr)
-- cMetaTypeFile = optionalField {#get CMeta->u.metaTypeInfo.file#}
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)})
{-# LINE 378 "src/LLVM/Internal/Interop.chs" #-}
cMetaTypeFilename :: InternString m => MetaPtr -> m Text
cMetaTypeFilename = shareString (\ptr -> do {peekByteOff ptr 96 ::IO (Ptr CChar)})
{-# LINE 380 "src/LLVM/Internal/Interop.chs" #-}
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)})
{-# LINE 384 "src/LLVM/Internal/Interop.chs" #-}
cMetaTypeCompositeComponents :: MetaPtr -> IO (Maybe MetaPtr)
cMetaTypeCompositeComponents = optionalField (\ptr -> do {peekByteOff ptr 128 ::IO (MetaPtr)})
{-# LINE 386 "src/LLVM/Internal/Interop.chs" #-}
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)})
{-# LINE 390 "src/LLVM/Internal/Interop.chs" #-}
cMetaTypeTemplateParams :: MetaPtr -> IO (Maybe MetaPtr)
cMetaTypeTemplateParams = optionalField (\ptr -> do {peekByteOff ptr 152 ::IO (MetaPtr)})
{-# LINE 392 "src/LLVM/Internal/Interop.chs" #-}
cMetaUnknownRepr :: InternString m => MetaPtr -> m Text
cMetaUnknownRepr = shareString (\ptr -> do {peekByteOff ptr 8 ::IO (Ptr CChar)})
{-# LINE 394 "src/LLVM/Internal/Interop.chs" #-}

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

-- | This helper converts C char* strings into Texts, sharing
-- identical bytestrings on the Haskell side.  This is a simple
-- space-saving optimization (assuming the entire cache is garbage
-- collected)
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)
{-# LINE 420 "src/LLVM/Internal/Interop.chs" #-}
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)})
{-# LINE 438 "src/LLVM/Internal/Interop.chs" #-}
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)})
{-# LINE 442 "src/LLVM/Internal/Interop.chs" #-}
cGlobalIsConstant :: GlobalInfoPtr -> IO Bool
cGlobalIsConstant g = toBool <$> (\ptr -> do {peekByteOff ptr 36 ::IO CInt}) g

data CFunctionInfo
type FunctionInfoPtr = Ptr (CFunctionInfo)
{-# LINE 447 "src/LLVM/Internal/Interop.chs" #-}
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})
{-# LINE 478 "src/LLVM/Internal/Interop.chs" #-}
cFunctionBlocks :: FunctionInfoPtr -> IO [ValuePtr]
cFunctionBlocks f =
  peekArray f (\ptr -> do {peekByteOff ptr 56 ::IO (Ptr (ValuePtr))}) (\ptr -> do {peekByteOff ptr 64 ::IO CInt})
{-# LINE 481 "src/LLVM/Internal/Interop.chs" #-}

data CArgInfo
type ArgInfoPtr = Ptr (CArgInfo)
{-# LINE 484 "src/LLVM/Internal/Interop.chs" #-}
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)
{-# LINE 497 "src/LLVM/Internal/Interop.chs" #-}

cBasicBlockInstructions :: BasicBlockPtr -> IO [ValuePtr]
cBasicBlockInstructions b =
  peekArray b (\ptr -> do {peekByteOff ptr 0 ::IO (Ptr (ValuePtr))}) (\ptr -> do {peekByteOff ptr 8 ::IO CInt})
{-# LINE 501 "src/LLVM/Internal/Interop.chs" #-}

data CInlineAsmInfo
type InlineAsmInfoPtr = Ptr (CInlineAsmInfo)
{-# LINE 504 "src/LLVM/Internal/Interop.chs" #-}

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)
{-# LINE 514 "src/LLVM/Internal/Interop.chs" #-}

cBlockAddrFunc :: BlockAddrInfoPtr -> IO ValuePtr
cBlockAddrFunc = (\ptr -> do {peekByteOff ptr 0 ::IO (ValuePtr)})
{-# LINE 517 "src/LLVM/Internal/Interop.chs" #-}
cBlockAddrBlock :: BlockAddrInfoPtr -> IO ValuePtr
cBlockAddrBlock = (\ptr -> do {peekByteOff ptr 8 ::IO (ValuePtr)})
{-# LINE 519 "src/LLVM/Internal/Interop.chs" #-}

data CAggregateInfo
type AggregateInfoPtr = Ptr (CAggregateInfo)
{-# LINE 522 "src/LLVM/Internal/Interop.chs" #-}

cAggregateValues :: AggregateInfoPtr -> IO [ValuePtr]
cAggregateValues a =
  peekArray a (\ptr -> do {peekByteOff ptr 0 ::IO (Ptr (ValuePtr))}) (\ptr -> do {peekByteOff ptr 8 ::IO CInt})
{-# LINE 526 "src/LLVM/Internal/Interop.chs" #-}

data CConstFP
type FPInfoPtr = Ptr (CConstFP)
{-# LINE 529 "src/LLVM/Internal/Interop.chs" #-}
cFPVal :: FPInfoPtr -> IO Double
cFPVal f = realToFrac <$> ((\ptr -> do {peekByteOff ptr 0 ::IO CDouble}) f)

data CConstInt
type IntInfoPtr = Ptr (CConstInt)
{-# LINE 534 "src/LLVM/Internal/Interop.chs" #-}
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)
{-# LINE 545 "src/LLVM/Internal/Interop.chs" #-}
cInstructionOperands :: InstInfoPtr -> IO [ValuePtr]
cInstructionOperands i =
  peekArray i (\ptr -> do {peekByteOff ptr 0 ::IO (Ptr (ValuePtr))}) (\ptr -> do {peekByteOff ptr 8 ::IO CInt})
{-# LINE 548 "src/LLVM/Internal/Interop.chs" #-}
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})
{-# LINE 563 "src/LLVM/Internal/Interop.chs" #-}

data CConstExprInfo
type ConstExprPtr = Ptr (CConstExprInfo)
{-# LINE 566 "src/LLVM/Internal/Interop.chs" #-}
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)})
{-# LINE 570 "src/LLVM/Internal/Interop.chs" #-}

data CPHIInfo
type PHIInfoPtr = Ptr (CPHIInfo)
{-# LINE 573 "src/LLVM/Internal/Interop.chs" #-}
cPHIValues :: PHIInfoPtr -> IO [ValuePtr]
cPHIValues p =
  peekArray p (\ptr -> do {peekByteOff ptr 0 ::IO (Ptr (ValuePtr))}) (\ptr -> do {peekByteOff ptr 16 ::IO CInt})
{-# LINE 576 "src/LLVM/Internal/Interop.chs" #-}
cPHIBlocks :: PHIInfoPtr -> IO [ValuePtr]
cPHIBlocks p =
  peekArray p (\ptr -> do {peekByteOff ptr 8 ::IO (Ptr (ValuePtr))}) (\ptr -> do {peekByteOff ptr 16 ::IO CInt})
{-# LINE 579 "src/LLVM/Internal/Interop.chs" #-}

data CCallInfo
type CallInfoPtr = Ptr (CCallInfo)
{-# LINE 582 "src/LLVM/Internal/Interop.chs" #-}
cCallValue :: CallInfoPtr -> IO ValuePtr
cCallValue = (\ptr -> do {peekByteOff ptr 0 ::IO (ValuePtr)})
{-# LINE 584 "src/LLVM/Internal/Interop.chs" #-}
cCallArguments :: CallInfoPtr -> IO [ValuePtr]
cCallArguments c =
  peekArray c (\ptr -> do {peekByteOff ptr 8 ::IO (Ptr (ValuePtr))}) (\ptr -> do {peekByteOff ptr 16 ::IO CInt})
{-# LINE 587 "src/LLVM/Internal/Interop.chs" #-}
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)})
{-# LINE 595 "src/LLVM/Internal/Interop.chs" #-}
cCallNormalDest :: CallInfoPtr -> IO ValuePtr
cCallNormalDest = (\ptr -> do {peekByteOff ptr 32 ::IO (ValuePtr)})
{-# LINE 597 "src/LLVM/Internal/Interop.chs" #-}

data CAtomicInfo
type AtomicInfoPtr = Ptr (CAtomicInfo)
{-# LINE 600 "src/LLVM/Internal/Interop.chs" #-}
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)})
{-# LINE 612 "src/LLVM/Internal/Interop.chs" #-}
cAtomicValueOperand :: AtomicInfoPtr -> IO ValuePtr
cAtomicValueOperand = (\ptr -> do {peekByteOff ptr 32 ::IO (ValuePtr)})
{-# LINE 614 "src/LLVM/Internal/Interop.chs" #-}
cAtomicCompareOperand :: AtomicInfoPtr -> IO ValuePtr
cAtomicCompareOperand = (\ptr -> do {peekByteOff ptr 40 ::IO (ValuePtr)})
{-# LINE 616 "src/LLVM/Internal/Interop.chs" #-}

data CLandingPadInfo
type LandingPadInfoPtr = Ptr (CLandingPadInfo)
{-# LINE 619 "src/LLVM/Internal/Interop.chs" #-}
cLandingPadPersonality :: LandingPadInfoPtr -> IO ValuePtr
cLandingPadPersonality = (\ptr -> do {peekByteOff ptr 0 ::IO (ValuePtr)})
{-# LINE 621 "src/LLVM/Internal/Interop.chs" #-}
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})
{-# LINE 626 "src/LLVM/Internal/Interop.chs" #-}
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})
{-# LINE 629 "src/LLVM/Internal/Interop.chs" #-}
  return $ map toEnum arr

-- | Parse the named file into an FFI-friendly representation of an
-- LLVM module.
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')
{-# LINE 634 "src/LLVM/Internal/Interop.chs" #-}
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')
{-# LINE 635 "src/LLVM/Internal/Interop.chs" #-}

-- | Free all of the resources allocated by 'marshalLLVM'
disposeCModule :: (ModulePtr) -> IO ()
disposeCModule a1 =
  let {a1' = id a1} in 
  disposeCModule'_ a1' >>= \res ->
  return ()
{-# LINE 638 "src/LLVM/Internal/Interop.chs" #-}

-- Helpers

-- This only seems to be necessary on i386 for some reason.
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 ()))