module LLVM.Internal.ObjectFile where
import Control.Monad.IO.Class
import Control.Monad.AnyCont
import Foreign.Ptr
import LLVM.Prelude
import LLVM.Internal.Coding
import LLVM.Internal.MemoryBuffer
import qualified LLVM.Internal.FFI.ObjectFile as FFI
newtype ObjectFile = ObjectFile (Ptr FFI.ObjectFile)
disposeObjectFile :: ObjectFile -> IO ()
disposeObjectFile (ObjectFile obj) = FFI.disposeObjectFile obj
createObjectFile :: FilePath -> IO ObjectFile
createObjectFile path = flip runAnyContT return $ do
buf <- encodeM (File path)
obj <- liftIO $ FFI.createObjectFile buf
when (obj == nullPtr) $ error "LLVMCreateObjectFile returned a null pointer."
return (ObjectFile obj)