llvm-ffi 9.1.0 → 9.1.0.1
raw patch · 6 files changed
+136/−76 lines, 6 filesdep ~basedep ~enumsetnew-component:exe:llvm-ffi-hostnew-component:exe:llvm-ffi-jitPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependency ranges changed: base, enumset
API changes (from Hackage documentation)
- LLVM.FFI.Core: cmpInstGetPredicate :: ValueRef -> IO CInt
- LLVM.FFI.Core: instance GHC.Classes.Eq LLVM.FFI.Core.CallingConvention
- LLVM.FFI.Core: instance GHC.Classes.Eq LLVM.FFI.Core.Linkage
- LLVM.FFI.Core: instance GHC.Classes.Eq LLVM.FFI.Core.TypeKind
- LLVM.FFI.Core: instance GHC.Classes.Eq LLVM.FFI.Core.Visibility
- LLVM.FFI.Core: instance GHC.Classes.Ord LLVM.FFI.Core.CallingConvention
- LLVM.FFI.Core: instance GHC.Classes.Ord LLVM.FFI.Core.Linkage
- LLVM.FFI.Core: instance GHC.Classes.Ord LLVM.FFI.Core.TypeKind
- LLVM.FFI.Core: instance GHC.Classes.Ord LLVM.FFI.Core.Visibility
- LLVM.FFI.Core: instance GHC.Enum.Bounded LLVM.FFI.Core.CallingConvention
- LLVM.FFI.Core: instance GHC.Enum.Bounded LLVM.FFI.Core.TypeKind
- LLVM.FFI.Core: instance GHC.Enum.Enum LLVM.FFI.Core.CallingConvention
- LLVM.FFI.Core: instance GHC.Enum.Enum LLVM.FFI.Core.Linkage
- LLVM.FFI.Core: instance GHC.Enum.Enum LLVM.FFI.Core.TypeKind
- LLVM.FFI.Core: instance GHC.Enum.Enum LLVM.FFI.Core.Visibility
- LLVM.FFI.Core: instance GHC.Read.Read LLVM.FFI.Core.TypeKind
- LLVM.FFI.Core: instance GHC.Show.Show LLVM.FFI.Core.CallingConvention
- LLVM.FFI.Core: instance GHC.Show.Show LLVM.FFI.Core.Linkage
- LLVM.FFI.Core: instance GHC.Show.Show LLVM.FFI.Core.TypeKind
- LLVM.FFI.Core: instance GHC.Show.Show LLVM.FFI.Core.Visibility
- LLVM.FFI.ExecutionEngine: instance GHC.Classes.Eq LLVM.FFI.ExecutionEngine.EngineKind
- LLVM.FFI.ExecutionEngine: instance GHC.Classes.Ord LLVM.FFI.ExecutionEngine.EngineKind
- LLVM.FFI.ExecutionEngine: instance GHC.Enum.Bounded LLVM.FFI.ExecutionEngine.EngineKind
- LLVM.FFI.ExecutionEngine: instance GHC.Enum.Enum LLVM.FFI.ExecutionEngine.EngineKind
- LLVM.FFI.ExecutionEngine: instance GHC.Read.Read LLVM.FFI.ExecutionEngine.EngineKind
- LLVM.FFI.ExecutionEngine: instance GHC.Show.Show LLVM.FFI.ExecutionEngine.EngineKind
- LLVM.FFI.Target: instance GHC.Classes.Eq LLVM.FFI.Target.ByteOrdering
+ LLVM.FFI.Core: FPFalse :: FPPredicate
+ LLVM.FFI.Core: FPOEQ :: FPPredicate
+ LLVM.FFI.Core: FPOGE :: FPPredicate
+ LLVM.FFI.Core: FPOGT :: FPPredicate
+ LLVM.FFI.Core: FPOLE :: FPPredicate
+ LLVM.FFI.Core: FPOLT :: FPPredicate
+ LLVM.FFI.Core: FPONE :: FPPredicate
+ LLVM.FFI.Core: FPORD :: FPPredicate
+ LLVM.FFI.Core: FPTrue :: FPPredicate
+ LLVM.FFI.Core: FPUEQ :: FPPredicate
+ LLVM.FFI.Core: FPUGE :: FPPredicate
+ LLVM.FFI.Core: FPUGT :: FPPredicate
+ LLVM.FFI.Core: FPULE :: FPPredicate
+ LLVM.FFI.Core: FPULT :: FPPredicate
+ LLVM.FFI.Core: FPUNE :: FPPredicate
+ LLVM.FFI.Core: FPUNO :: FPPredicate
+ LLVM.FFI.Core: IntEQ :: IntPredicate
+ LLVM.FFI.Core: IntNE :: IntPredicate
+ LLVM.FFI.Core: IntSGE :: IntPredicate
+ LLVM.FFI.Core: IntSGT :: IntPredicate
+ LLVM.FFI.Core: IntSLE :: IntPredicate
+ LLVM.FFI.Core: IntSLT :: IntPredicate
+ LLVM.FFI.Core: IntUGE :: IntPredicate
+ LLVM.FFI.Core: IntUGT :: IntPredicate
+ LLVM.FFI.Core: IntULE :: IntPredicate
+ LLVM.FFI.Core: IntULT :: IntPredicate
+ LLVM.FFI.Core: cmpInstGetIntPredicate :: ValueRef -> IO IntPredicate
+ LLVM.FFI.Core: cmpInstGetRealPredicate :: ValueRef -> IO RealPredicate
+ LLVM.FFI.Core: data FPPredicate
+ LLVM.FFI.Core: data IntPredicate
+ LLVM.FFI.Core: fromIntPredicate :: IntPredicate -> IntPredicate
+ LLVM.FFI.Core: fromRealPredicate :: FPPredicate -> RealPredicate
+ LLVM.FFI.Core: instance [safe] Bounded CallingConvention
+ LLVM.FFI.Core: instance [safe] Bounded TypeKind
+ LLVM.FFI.Core: instance [safe] Enum CallingConvention
+ LLVM.FFI.Core: instance [safe] Enum FPPredicate
+ LLVM.FFI.Core: instance [safe] Enum IntPredicate
+ LLVM.FFI.Core: instance [safe] Enum Linkage
+ LLVM.FFI.Core: instance [safe] Enum TypeKind
+ LLVM.FFI.Core: instance [safe] Enum Visibility
+ LLVM.FFI.Core: instance [safe] Eq CallingConvention
+ LLVM.FFI.Core: instance [safe] Eq FPPredicate
+ LLVM.FFI.Core: instance [safe] Eq IntPredicate
+ LLVM.FFI.Core: instance [safe] Eq Linkage
+ LLVM.FFI.Core: instance [safe] Eq TypeKind
+ LLVM.FFI.Core: instance [safe] Eq Visibility
+ LLVM.FFI.Core: instance [safe] Ord CallingConvention
+ LLVM.FFI.Core: instance [safe] Ord FPPredicate
+ LLVM.FFI.Core: instance [safe] Ord IntPredicate
+ LLVM.FFI.Core: instance [safe] Ord Linkage
+ LLVM.FFI.Core: instance [safe] Ord TypeKind
+ LLVM.FFI.Core: instance [safe] Ord Visibility
+ LLVM.FFI.Core: instance [safe] Read TypeKind
+ LLVM.FFI.Core: instance [safe] Show CallingConvention
+ LLVM.FFI.Core: instance [safe] Show FPPredicate
+ LLVM.FFI.Core: instance [safe] Show IntPredicate
+ LLVM.FFI.Core: instance [safe] Show Linkage
+ LLVM.FFI.Core: instance [safe] Show TypeKind
+ LLVM.FFI.Core: instance [safe] Show Visibility
+ LLVM.FFI.Core: instance [safe] Typeable CallingConvention
+ LLVM.FFI.Core: instance [safe] Typeable FPPredicate
+ LLVM.FFI.Core: instance [safe] Typeable IntPredicate
+ LLVM.FFI.Core: instance [safe] Typeable Linkage
+ LLVM.FFI.Core: instance [safe] Typeable TypeKind
+ LLVM.FFI.Core: toIntPredicate :: IntPredicate -> IntPredicate
+ LLVM.FFI.Core: toRealPredicate :: RealPredicate -> FPPredicate
+ LLVM.FFI.Core: type AttributeRef = Ptr Attribute
+ LLVM.FFI.ExecutionEngine: instance [safe] Bounded EngineKind
+ LLVM.FFI.ExecutionEngine: instance [safe] Enum EngineKind
+ LLVM.FFI.ExecutionEngine: instance [safe] Eq EngineKind
+ LLVM.FFI.ExecutionEngine: instance [safe] Ord EngineKind
+ LLVM.FFI.ExecutionEngine: instance [safe] Read EngineKind
+ LLVM.FFI.ExecutionEngine: instance [safe] Show EngineKind
+ LLVM.FFI.ExecutionEngine: instance [safe] Typeable EngineKind
+ LLVM.FFI.ExecutionEngine: instance [safe] Typeable ExecutionEngine
+ LLVM.FFI.ExecutionEngine: instance [safe] Typeable GenericValue
+ LLVM.FFI.ExecutionEngine: instance [safe] Typeable MCJITCompilerOptions
+ LLVM.FFI.Support.Host: instance [safe] Typeable FeatureIterator
+ LLVM.FFI.Support.Host: instance [safe] Typeable FeatureMap
+ LLVM.FFI.Target: instance [safe] Eq ByteOrdering
+ LLVM.FFI.Target: instance [safe] Typeable TargetData
+ LLVM.FFI.Target: instance [safe] Typeable TargetLibraryInfo
+ LLVM.FFI.Transforms.PassManagerBuilder: instance [safe] Typeable PassManagerBuilder
- LLVM.FFI.Analysis: verifyModule :: ModuleRef -> VerifierFailureAction -> Ptr CString -> IO Bool
+ LLVM.FFI.Analysis: verifyModule :: ModuleRef -> VerifierFailureAction -> (Ptr CString) -> IO Bool
- LLVM.FFI.BitReader: getBitcodeModule :: MemoryBufferRef -> Ptr ModuleRef -> Ptr CString -> IO Bool
+ LLVM.FFI.BitReader: getBitcodeModule :: MemoryBufferRef -> (Ptr ModuleRef) -> (Ptr CString) -> IO Bool
- LLVM.FFI.BitReader: getBitcodeModuleInContext :: ContextRef -> MemoryBufferRef -> Ptr ModuleRef -> Ptr CString -> IO Bool
+ LLVM.FFI.BitReader: getBitcodeModuleInContext :: ContextRef -> MemoryBufferRef -> (Ptr ModuleRef) -> (Ptr CString) -> IO Bool
- LLVM.FFI.BitReader: parseBitcode :: MemoryBufferRef -> Ptr ModuleRef -> Ptr CString -> IO Bool
+ LLVM.FFI.BitReader: parseBitcode :: MemoryBufferRef -> (Ptr ModuleRef) -> (Ptr CString) -> IO Bool
- LLVM.FFI.BitReader: parseBitcodeInContext :: ContextRef -> MemoryBufferRef -> Ptr ModuleRef -> Ptr CString -> IO Bool
+ LLVM.FFI.BitReader: parseBitcodeInContext :: ContextRef -> MemoryBufferRef -> (Ptr ModuleRef) -> (Ptr CString) -> IO Bool
- LLVM.FFI.Core: Bool :: Int32 -> Bool
+ LLVM.FFI.Core: Bool :: (Int32) -> Bool
- LLVM.FFI.Core: addFunction :: ModuleRef -> CString -> TypeRef -> IO ValueRef
+ LLVM.FFI.Core: addFunction :: ModuleRef -> CString -> TypeRef -> IO FunctionRef
- LLVM.FFI.Core: buildAggregateRet :: BuilderRef -> Ptr ValueRef -> CUInt -> IO ValueRef
+ LLVM.FFI.Core: buildAggregateRet :: BuilderRef -> (Ptr ValueRef) -> CUInt -> IO ValueRef
- LLVM.FFI.Core: buildBinOp :: BuilderRef -> CUInt -> ValueRef -> ValueRef -> CString -> IO ValueRef
+ LLVM.FFI.Core: buildBinOp :: BuilderRef -> Opcode -> ValueRef -> ValueRef -> CString -> IO ValueRef
- LLVM.FFI.Core: buildCast :: BuilderRef -> CUInt -> ValueRef -> TypeRef -> CString -> IO ValueRef
+ LLVM.FFI.Core: buildCast :: BuilderRef -> Opcode -> ValueRef -> TypeRef -> CString -> IO ValueRef
- LLVM.FFI.Core: buildFCmp :: BuilderRef -> CInt -> ValueRef -> ValueRef -> CString -> IO ValueRef
+ LLVM.FFI.Core: buildFCmp :: BuilderRef -> RealPredicate -> ValueRef -> ValueRef -> CString -> IO ValueRef
- LLVM.FFI.Core: buildICmp :: BuilderRef -> CInt -> ValueRef -> ValueRef -> CString -> IO ValueRef
+ LLVM.FFI.Core: buildICmp :: BuilderRef -> IntPredicate -> ValueRef -> ValueRef -> CString -> IO ValueRef
- LLVM.FFI.Core: constFCmp :: CInt -> ValueRef -> ValueRef -> IO ValueRef
+ LLVM.FFI.Core: constFCmp :: RealPredicate -> ValueRef -> ValueRef -> IO ValueRef
- LLVM.FFI.Core: constICmp :: CInt -> ValueRef -> ValueRef -> IO ValueRef
+ LLVM.FFI.Core: constICmp :: IntPredicate -> ValueRef -> ValueRef -> IO ValueRef
- LLVM.FFI.Core: constIntCast :: ValueRef -> TypeRef -> CUInt -> IO ValueRef
+ LLVM.FFI.Core: constIntCast :: ValueRef -> TypeRef -> Bool -> IO ValueRef
- LLVM.FFI.Core: constIntOfArbitraryPrecision :: TypeRef -> CUInt -> Ptr CULLong -> IO ValueRef
+ LLVM.FFI.Core: constIntOfArbitraryPrecision :: TypeRef -> CUInt -> Ptr Word64 -> IO ValueRef
- LLVM.FFI.Core: constIntOfString :: TypeRef -> CString -> CUInt -> IO ValueRef
+ LLVM.FFI.Core: constIntOfString :: TypeRef -> CString -> Word8 -> IO ValueRef
- LLVM.FFI.Core: constIntOfStringAndSize :: TypeRef -> CString -> CUInt -> CUInt -> IO ValueRef
+ LLVM.FFI.Core: constIntOfStringAndSize :: TypeRef -> CString -> CUInt -> Word8 -> IO ValueRef
- LLVM.FFI.Core: countParams :: ValueRef -> IO CUInt
+ LLVM.FFI.Core: countParams :: FunctionRef -> IO CUInt
- LLVM.FFI.Core: deleteFunction :: ValueRef -> IO ()
+ LLVM.FFI.Core: deleteFunction :: FunctionRef -> IO ()
- LLVM.FFI.Core: fromCallingConvention :: CallingConvention -> CUInt
+ LLVM.FFI.Core: fromCallingConvention :: CallingConvention -> CallingConvention
- LLVM.FFI.Core: fromLinkage :: Linkage -> CUInt
+ LLVM.FFI.Core: fromLinkage :: Linkage -> Linkage
- LLVM.FFI.Core: fromVisibility :: Visibility -> CUInt
+ LLVM.FFI.Core: fromVisibility :: Visibility -> Visibility
- LLVM.FFI.Core: getConstOpcode :: ValueRef -> IO CUInt
+ LLVM.FFI.Core: getConstOpcode :: ValueRef -> IO Opcode
- LLVM.FFI.Core: getFunctionCallConv :: ValueRef -> IO CUInt
+ LLVM.FFI.Core: getFunctionCallConv :: FunctionRef -> IO CallingConvention
- LLVM.FFI.Core: getICmpPredicate :: ValueRef -> IO Int
+ LLVM.FFI.Core: getICmpPredicate :: ValueRef -> IO IntPredicate
- LLVM.FFI.Core: getInstructionCallConv :: ValueRef -> IO CUInt
+ LLVM.FFI.Core: getInstructionCallConv :: ValueRef -> IO CallingConvention
- LLVM.FFI.Core: getInstructionOpcode :: ValueRef -> IO Int
+ LLVM.FFI.Core: getInstructionOpcode :: ValueRef -> IO Opcode
- LLVM.FFI.Core: getIntrinsicID :: ValueRef -> IO CUInt
+ LLVM.FFI.Core: getIntrinsicID :: FunctionRef -> IO CUInt
- LLVM.FFI.Core: getLinkage :: ValueRef -> IO CUInt
+ LLVM.FFI.Core: getLinkage :: ValueRef -> IO Linkage
- LLVM.FFI.Core: getNamedFunction :: ModuleRef -> CString -> IO ValueRef
+ LLVM.FFI.Core: getNamedFunction :: ModuleRef -> CString -> IO FunctionRef
- LLVM.FFI.Core: getParam :: ValueRef -> CUInt -> IO ValueRef
+ LLVM.FFI.Core: getParam :: FunctionRef -> CUInt -> IO ValueRef
- LLVM.FFI.Core: getParams :: ValueRef -> Ptr ValueRef -> IO ()
+ LLVM.FFI.Core: getParams :: FunctionRef -> Ptr ValueRef -> IO ()
- LLVM.FFI.Core: getVisibility :: ValueRef -> IO CUInt
+ LLVM.FFI.Core: getVisibility :: ValueRef -> IO Visibility
- LLVM.FFI.Core: setFunctionCallConv :: ValueRef -> CUInt -> IO ()
+ LLVM.FFI.Core: setFunctionCallConv :: FunctionRef -> CallingConvention -> IO ()
- LLVM.FFI.Core: setInstructionCallConv :: ValueRef -> CUInt -> IO ()
+ LLVM.FFI.Core: setInstructionCallConv :: ValueRef -> CallingConvention -> IO ()
- LLVM.FFI.Core: setLinkage :: ValueRef -> CUInt -> IO ()
+ LLVM.FFI.Core: setLinkage :: ValueRef -> Linkage -> IO ()
- LLVM.FFI.Core: setVisibility :: ValueRef -> CUInt -> IO ()
+ LLVM.FFI.Core: setVisibility :: ValueRef -> Visibility -> IO ()
- LLVM.FFI.Core: toCallingConvention :: CUInt -> CallingConvention
+ LLVM.FFI.Core: toCallingConvention :: CallingConvention -> CallingConvention
- LLVM.FFI.Core: toLinkage :: CUInt -> Linkage
+ LLVM.FFI.Core: toLinkage :: Linkage -> Linkage
- LLVM.FFI.Core: toVisibility :: CUInt -> Visibility
+ LLVM.FFI.Core: toVisibility :: Visibility -> Visibility
- LLVM.FFI.ExecutionEngine: createExecutionEngineForModule :: Ptr ExecutionEngineRef -> ModuleRef -> Ptr CString -> IO Bool
+ LLVM.FFI.ExecutionEngine: createExecutionEngineForModule :: (Ptr ExecutionEngineRef) -> ModuleRef -> (Ptr CString) -> IO Bool
- LLVM.FFI.ExecutionEngine: createExecutionEngineForModuleCPU :: Ptr ExecutionEngineRef -> ModuleRef -> Ptr CString -> IO Bool
+ LLVM.FFI.ExecutionEngine: createExecutionEngineForModuleCPU :: (Ptr ExecutionEngineRef) -> ModuleRef -> (Ptr CString) -> IO Bool
- LLVM.FFI.ExecutionEngine: createExecutionEngineKindForModuleCPU :: Ptr ExecutionEngineRef -> EngineKindSet -> ModuleRef -> Ptr CString -> IO Bool
+ LLVM.FFI.ExecutionEngine: createExecutionEngineKindForModuleCPU :: (Ptr ExecutionEngineRef) -> EngineKindSet -> ModuleRef -> (Ptr CString) -> IO Bool
- LLVM.FFI.ExecutionEngine: createInterpreterForModule :: Ptr ExecutionEngineRef -> ModuleRef -> Ptr CString -> IO Bool
+ LLVM.FFI.ExecutionEngine: createInterpreterForModule :: (Ptr ExecutionEngineRef) -> ModuleRef -> (Ptr CString) -> IO Bool
- LLVM.FFI.ExecutionEngine: createInterpreterForModuleCPU :: Ptr ExecutionEngineRef -> ModuleRef -> Ptr CString -> IO Bool
+ LLVM.FFI.ExecutionEngine: createInterpreterForModuleCPU :: (Ptr ExecutionEngineRef) -> ModuleRef -> (Ptr CString) -> IO Bool
- LLVM.FFI.ExecutionEngine: createJITCompilerForModule :: Ptr ExecutionEngineRef -> ModuleRef -> CUInt -> Ptr CString -> IO Bool
+ LLVM.FFI.ExecutionEngine: createJITCompilerForModule :: (Ptr ExecutionEngineRef) -> ModuleRef -> CUInt -> (Ptr CString) -> IO Bool
- LLVM.FFI.ExecutionEngine: removeModule :: ExecutionEngineRef -> ModuleRef -> Ptr ModuleRef -> Ptr CString -> IO Bool
+ LLVM.FFI.ExecutionEngine: removeModule :: ExecutionEngineRef -> ModuleRef -> (Ptr ModuleRef) -> (Ptr CString) -> IO Bool
- LLVM.FFI.Target: ByteOrdering :: Word32 -> ByteOrdering
+ LLVM.FFI.Target: ByteOrdering :: (Word32) -> ByteOrdering
Files
- example/Common.hs +44/−0
- example/Host.hs +31/−0
- example/JIT.hs +14/−36
- example/Offset.hs +9/−33
- llvm-ffi.cabal +34/−3
- src/LLVM/FFI/Target.hsc +4/−4
+ example/Common.hs view
@@ -0,0 +1,44 @@+module Common where++import qualified LLVM.FFI.ExecutionEngine as EE+import qualified LLVM.FFI.Core as LLVM++import qualified Foreign.C.String as CStr+import qualified Foreign.Marshal.Array as Array+import qualified Foreign.Marshal.Alloc as Alloc+import Foreign.C.Types (CUInt)+import Foreign.Storable (Storable, peek)+import Foreign.Ptr (Ptr)++import Control.Exception (bracket)+import Control.Monad (when)++import qualified System.Exit as Exit+import Text.Printf (printf)+++withArrayLen :: (Storable a) => [a] -> (CUInt -> Ptr a -> IO b) -> IO b+withArrayLen xs act =+ Array.withArrayLen xs $ \len ptr -> act (fromIntegral len) ptr++noResult :: IO () -> IO ()+noResult = id+++getString :: IO CStr.CString -> IO String+getString get = bracket get LLVM.disposeMessage CStr.peekCString++createExecutionEngine :: LLVM.ModuleRef -> IO EE.ExecutionEngineRef+createExecutionEngine modul =+ Alloc.alloca $ \execEngineRef ->+ Alloc.alloca $ \errorMsgRef -> do+ err <-+ EE.createExecutionEngineForModuleCPU+ execEngineRef modul errorMsgRef+ when (err/=LLVM.false) $ do+ bracket (peek errorMsgRef) Alloc.free $ \errorMsg -> do+ noResult $+ printf "createExecutionEngine: %s\n"+ =<< CStr.peekCString errorMsg+ Exit.exitFailure+ peek execEngineRef
+ example/Host.hs view
@@ -0,0 +1,31 @@+{- |+This program shows some interesting facts about the host machine.+-}+module Main where++import Common (getString, createExecutionEngine)++import qualified LLVM.FFI.ExecutionEngine as EE+import qualified LLVM.FFI.Target as Target+import qualified LLVM.FFI.Support.Host as Host+import qualified LLVM.FFI.Core as LLVM+import qualified LLVM.Target.Native as Native++import Foreign.C.String (withCString)++import Control.Exception (bracket)+++main :: IO ()+main = do+ Native.initializeNativeTarget++ putStrLn =<< getString Host.getHostCPUName+ putStrLn LLVM.hostTriple++ modul <- withCString "host" LLVM.moduleCreateWithName+ withCString LLVM.hostTriple $ LLVM.setTarget modul+ bracket (createExecutionEngine modul) EE.disposeExecutionEngine $+ \execEngine -> do+ td <- EE.getExecutionEngineTargetData execEngine+ putStrLn =<< getString (Target.copyStringRepOfTargetData td)
example/JIT.hs view
@@ -7,10 +7,11 @@ -} module Main where +import Common (withArrayLen, createExecutionEngine)+ import qualified LLVM.FFI.Transforms.PassManagerBuilder as PMB import qualified LLVM.FFI.Transforms.Scalar as Transform import qualified LLVM.FFI.ExecutionEngine as EE-import qualified LLVM.FFI.Support.Host as Host import qualified LLVM.FFI.BitWriter as BW import qualified LLVM.FFI.Core as Core import qualified LLVM.Target.Native as Native@@ -19,19 +20,16 @@ import qualified Foreign.Marshal.Array as Array import qualified Foreign.Marshal.Alloc as Alloc import Foreign.C.String (withCString)-import Foreign.C.Types (CUInt, CFloat)-import Foreign.Storable (Storable, peek, sizeOf)+import Foreign.C.Types (CFloat)+import Foreign.Storable (sizeOf) import Foreign.Ptr (Ptr, FunPtr) -import Control.Exception (bracket, bracket_, finally)+import Control.Exception (bracket, bracket_) import Control.Monad (when, void) import Data.Tuple.HT (mapSnd) -import qualified System.Exit as Exit-import Text.Printf (printf) - vectorSize :: Int roundName :: String @@ -40,13 +38,6 @@ then (4, "llvm.x86.sse41.round.ps") else (8, "llvm.x86.avx.round.ps.256") -withArrayLen :: (Storable a) => [a] -> (CUInt -> Ptr a -> IO b) -> IO b-withArrayLen xs act =- Array.withArrayLen xs $ \len ptr -> act (fromIntegral len) ptr--noResult :: IO () -> IO ()-noResult = id- type Importer f = FunPtr f -> f foreign import ccall safe "dynamic" derefFuncPtr :: Importer (Ptr a -> IO ())@@ -57,9 +48,6 @@ main = do Native.initializeNativeTarget - bracket Host.getHostCPUName Core.disposeMessage $ \strPtr ->- putStrLn =<< CStr.peekCString strPtr- modul <- withCString "_module" Core.moduleCreateWithName withCString Core.hostTriple $ Core.setTarget modul vectorType <-@@ -136,22 +124,12 @@ void $ withCString "round-avx-opt.bc" $ BW.writeBitcodeToFile modul - Alloc.alloca $ \execEngineRef -> do- Alloc.alloca $ \errorMsgRef -> do- err <-- EE.createExecutionEngineForModuleCPU execEngineRef modul errorMsgRef- when (err/=Core.false) $ do- noResult $- printf "createExecutionEngine: %s\n"- =<< CStr.peekCString =<< peek errorMsgRef- Exit.exitFailure-- execEngine <- peek execEngineRef- flip finally (EE.disposeExecutionEngine execEngine) $ do- let vector = take vectorSize $ iterate (1+) (-1.3 :: CFloat)- funcPtr <- EE.getPointerToFunction execEngine func- let size = sum $ map sizeOf vector- Alloc.allocaBytesAligned size size $ \ptr -> do- Array.pokeArray ptr vector- derefFuncPtr funcPtr ptr- print =<< Array.peekArray vectorSize ptr+ bracket (createExecutionEngine modul) EE.disposeExecutionEngine $+ \execEngine -> do+ let vector = take vectorSize $ iterate (1+) (-1.3 :: CFloat)+ funcPtr <- EE.getPointerToFunction execEngine func+ let size = sum $ map sizeOf vector+ Alloc.allocaBytesAligned size size $ \ptr -> do+ Array.pokeArray ptr vector+ derefFuncPtr funcPtr ptr+ print =<< Array.peekArray vectorSize ptr
example/Offset.hs view
@@ -1,28 +1,18 @@ module Main where +import Common (withArrayLen, createExecutionEngine)+ import qualified LLVM.FFI.ExecutionEngine as EE import qualified LLVM.FFI.Target as Target import qualified LLVM.FFI.Core as LLVM import qualified LLVM.Target.Native as Native -import qualified Foreign.Marshal.Array as Array-import qualified Foreign.Marshal.Alloc as Alloc-import Foreign.C.String (withCString, peekCString)-import Foreign.C.Types (CUInt, CULLong)-import Foreign.Storable (Storable, peek)-import Foreign.Ptr (Ptr)--import qualified System.Exit as Exit-import Control.Exception (finally)-import Control.Monad (when)+import Foreign.C.String (withCString)+import Foreign.C.Types (CULLong) -import Text.Printf (printf)+import Control.Exception (bracket) -withArrayLen :: (Storable a) => [a] -> (CUInt -> Ptr a -> IO b) -> IO b-withArrayLen xs act =- Array.withArrayLen xs $ \len ptr -> act (fromIntegral len) ptr- offset :: IO CULLong offset = do Native.initializeNativeTarget@@ -45,9 +35,6 @@ elementOffset <- LLVM.constPtrToInt elementPtr int64Type LLVM.constIntGetZExtValue elementOffset -noResult :: IO () -> IO ()-noResult = id- offsetTarget :: IO [CULLong] offsetTarget = do Native.initializeNativeTarget@@ -61,21 +48,10 @@ modul <- withCString "_module" LLVM.moduleCreateWithName withCString LLVM.hostTriple $ LLVM.setTarget modul - Alloc.alloca $ \execEngineRef -> do- Alloc.alloca $ \errorMsgRef -> do- err <-- EE.createExecutionEngineForModuleCPU- execEngineRef modul errorMsgRef- when (err/=LLVM.false) $ do- noResult $- printf "createExecutionEngine: %s\n"- =<< peekCString =<< peek errorMsgRef- Exit.exitFailure-- execEngine <- peek execEngineRef- flip finally (EE.disposeExecutionEngine execEngine) $ do- td <- EE.getExecutionEngineTargetData execEngine- mapM (Target.offsetOfElement td structType) [0..2]+ bracket (createExecutionEngine modul) EE.disposeExecutionEngine $+ \execEngine -> do+ td <- EE.getExecutionEngineTargetData execEngine+ mapM (Target.offsetOfElement td structType) [0..2] main :: IO () main = print =<< offsetTarget
llvm-ffi.cabal view
@@ -1,6 +1,6 @@ Cabal-Version: 2.2 Name: llvm-ffi-Version: 9.1.0+Version: 9.1.0.1 License: BSD-3-Clause License-File: LICENSE Synopsis: FFI bindings to the LLVM compiler toolkit.@@ -19,6 +19,17 @@ . > cabal install --extra-include-dirs=/usr/lib/llvm-9/include --extra-lib-dirs=/usr/lib/llvm-9/lib llvm-ffi .+ For @cabal new-build@ this does not work,+ because every package build is bound to all influencing flags.+ That is, if you build, say @llvm-tf@,+ it depends on @llvm-ffi@ without the extra-lib-dirs flag.+ In order to solve this problem,+ you may specify the extra directories in the global Cabal configuration.+ I.e. you may add the following lines to @.cabal/config@:+ .+ > extra-include-dirs: /usr/lib/llvm-9/include+ > extra-lib-dirs: /usr/lib/llvm-9/lib+ . You can store such paths permanently in a @pkg-config@ file like @llvm.pc@. The optimal way would be if LLVM installations or GNU/Linux distributions would contain such a file, but they don't.@@ -102,7 +113,7 @@ Location: http://hub.darcs.net/thielema/llvm-ffi/ Source-Repository this- Tag: 9.1.0+ Tag: 9.1.0.1 Type: darcs Location: http://hub.darcs.net/thielema/llvm-ffi/ @@ -246,7 +257,7 @@ Cxx-Sources: cbits/support.cpp -Executable llvm-ffi-example+Executable llvm-ffi-host If flag(buildExamples) Build-Depends: llvm-ffi,@@ -261,7 +272,26 @@ Hs-Source-Dirs: example GHC-Options: -Wall Default-Language: Haskell2010+ Main-Is: Host.hs+ Other-Modules: Common++Executable llvm-ffi-jit+ If flag(buildExamples)+ Build-Depends:+ llvm-ffi,+ utility-ht >=0.0.9 && <0.1,+ base+ Else+ Buildable: False++ If flag(developer)+ GHC-Options: -Werror++ Hs-Source-Dirs: example+ GHC-Options: -Wall+ Default-Language: Haskell2010 Main-Is: JIT.hs+ Other-Modules: Common Executable llvm-ffi-offset If flag(buildExamples)@@ -279,3 +309,4 @@ GHC-Options: -Wall Default-Language: Haskell2010 Main-Is: Offset.hs+ Other-Modules: Common
src/LLVM/FFI/Target.hsc view
@@ -39,6 +39,10 @@ foreign import ccall unsafe "LLVMCreateTargetData" createTargetData :: CString -> IO TargetDataRef+foreign import ccall unsafe "LLVMDisposeTargetData" disposeTargetData+ :: TargetDataRef -> IO ()+foreign import ccall unsafe "&LLVMDisposeTargetData" ptrDisposeTargetData+ :: FunPtr (TargetDataRef -> IO ()) foreign import ccall unsafe "LLVMAddTargetLibraryInfo" addTargetLibraryInfo :: TargetLibraryInfoRef -> PassManagerRef -> IO () foreign import ccall unsafe "LLVMCopyStringRepOfTargetData" copyStringRepOfTargetData@@ -67,7 +71,3 @@ :: TargetDataRef -> TypeRef -> CULLong -> IO CUInt foreign import ccall unsafe "LLVMOffsetOfElement" offsetOfElement :: TargetDataRef -> TypeRef -> CUInt -> IO CULLong-foreign import ccall unsafe "LLVMDisposeTargetData" disposeTargetData- :: TargetDataRef -> IO ()-foreign import ccall unsafe "&LLVMDisposeTargetData" ptrDisposeTargetData- :: FunPtr (TargetDataRef -> IO ())