llvm-general 3.2.2.0 → 3.2.3.0
raw patch · 68 files changed
+185/−197 lines, 68 files
Files
- llvm-general.cabal +13/−3
- src/Control/Monad/AnyCont.hs +0/−1
- src/Control/Monad/AnyCont/Class.hs +0/−1
- src/LLVM/General/AST/CallingConvention.hs +0/−3
- src/LLVM/General/AST/FloatingPointPredicate.hs +0/−3
- src/LLVM/General/AST/InlineAssembly.hs +0/−3
- src/LLVM/General/AST/Instruction.hs +0/−3
- src/LLVM/General/AST/IntegerPredicate.hs +0/−3
- src/LLVM/General/AST/Linkage.hs +0/−4
- src/LLVM/General/AST/RMWOperation.hs +0/−3
- src/LLVM/General/AST/Visibility.hs +0/−3
- src/LLVM/General/CodeGenOpt.hs +0/−3
- src/LLVM/General/CodeModel.hs +0/−3
- src/LLVM/General/Diagnostic.hs +0/−3
- src/LLVM/General/Internal/Atomicity.hs +1/−3
- src/LLVM/General/Internal/Attribute.hs +1/−3
- src/LLVM/General/Internal/CallingConvention.hs +1/−2
- src/LLVM/General/Internal/Coding.hs +0/−2
- src/LLVM/General/Internal/Constant.hs +0/−3
- src/LLVM/General/Internal/DecodeAST.hs +0/−3
- src/LLVM/General/Internal/Diagnostic.hs +1/−3
- src/LLVM/General/Internal/EncodeAST.hs +0/−3
- src/LLVM/General/Internal/ExecutionEngine.hs +3/−7
- src/LLVM/General/Internal/FFI/Assembly.hs +2/−1
- src/LLVM/General/Internal/FFI/BasicBlock.hs +0/−1
- src/LLVM/General/Internal/FFI/BinaryOperator.hs +0/−3
- src/LLVM/General/Internal/FFI/Builder.hs +0/−2
- src/LLVM/General/Internal/FFI/Constant.hs +0/−3
- src/LLVM/General/Internal/FFI/Context.hs +1/−2
- src/LLVM/General/Internal/FFI/ExecutionEngine.hs +5/−5
- src/LLVM/General/Internal/FFI/Function.hs +0/−1
- src/LLVM/General/Internal/FFI/GlobalAlias.hs +0/−3
- src/LLVM/General/Internal/FFI/GlobalValue.hs +0/−3
- src/LLVM/General/Internal/FFI/GlobalVariable.hs +0/−3
- src/LLVM/General/Internal/FFI/Instruction.hs +0/−3
- src/LLVM/General/Internal/FFI/InstructionDefs.hsc +0/−1
- src/LLVM/General/Internal/FFI/LLVMCTypes.hsc +3/−2
- src/LLVM/General/Internal/FFI/Module.hs +3/−4
- src/LLVM/General/Internal/FFI/PassManager.hs +1/−2
- src/LLVM/General/Internal/FFI/PtrHierarchy.hs +0/−3
- src/LLVM/General/Internal/FFI/SMDiagnostic.hs +1/−3
- src/LLVM/General/Internal/FFI/Target.hs +16/−4
- src/LLVM/General/Internal/FFI/TargetC.cpp +35/−0
- src/LLVM/General/Internal/FFI/Type.hs +1/−3
- src/LLVM/General/Internal/FFI/User.hs +0/−3
- src/LLVM/General/Internal/FFI/Value.hs +0/−4
- src/LLVM/General/Internal/FloatingPointPredicate.hs +1/−3
- src/LLVM/General/Internal/Global.hs +1/−3
- src/LLVM/General/Internal/InlineAssembly.hs +1/−2
- src/LLVM/General/Internal/Instruction.hs +0/−3
- src/LLVM/General/Internal/IntegerPredicate.hs +1/−3
- src/LLVM/General/Internal/Metadata.hs +1/−2
- src/LLVM/General/Internal/Module.hs +5/−8
- src/LLVM/General/Internal/Operand.hs +1/−2
- src/LLVM/General/Internal/PassManager.hs +1/−3
- src/LLVM/General/Internal/RMWOperation.hs +1/−3
- src/LLVM/General/Internal/String.hs +12/−4
- src/LLVM/General/Internal/Target.hs +61/−13
- src/LLVM/General/Internal/Type.hs +0/−1
- src/LLVM/General/Internal/Value.hs +0/−2
- src/LLVM/General/Relocation.hs +0/−3
- src/LLVM/General/Target.hs +6/−2
- src/LLVM/General/Target/Options.hs +0/−3
- src/LLVM/General/Transforms.hs +0/−3
- test/LLVM/General/Test/ExecutionEngine.hs +1/−2
- test/LLVM/General/Test/Module.hs +2/−0
- test/LLVM/General/Test/Optimization.hs +2/−1
- test/LLVM/General/Test/Support.hs +0/−4
llvm-general.cabal view
@@ -1,5 +1,5 @@ name: llvm-general-version: 3.2.2.0+version: 3.2.3.0 license: BSD3 license-file: LICENSE author: Benjamin S.Scarlet <fgthb0@greynode.net>@@ -33,7 +33,7 @@ type: git location: git://github.com/bscarlet/llvm-general.git branch: llvm-3.2- tag: v3.2.2.0+ tag: v3.2.3.0 flag shared-llvm description: link against llvm shared rather than static library@@ -59,6 +59,13 @@ setenv >= 0.1.0 extra-libraries: stdc++ hs-source-dirs: src+ extensions:+ TupleSections+ DeriveDataTypeable+ EmptyDataDecls+ FlexibleContexts+ FlexibleInstances+ StandaloneDeriving exposed-modules: LLVM.General LLVM.General.AST@@ -189,6 +196,10 @@ containers >= 0.4.2.1, mtl >= 2.0.1.0 hs-source-dirs: test+ extensions:+ TupleSections+ FlexibleInstances+ FlexibleContexts main-is: Test.hs other-modules: LLVM.General.Test.Constants@@ -203,4 +214,3 @@ LLVM.General.Test.Support LLVM.General.Test.Target LLVM.General.Test.Tests-
src/Control/Monad/AnyCont.hs view
@@ -1,5 +1,4 @@ {-# LANGUAGE- FlexibleInstances, MultiParamTypeClasses, UndecidableInstances #-}
src/Control/Monad/AnyCont/Class.hs view
@@ -1,7 +1,6 @@ {-# LANGUAGE RankNTypes, MultiParamTypeClasses,- FlexibleInstances, UndecidableInstances #-} module Control.Monad.AnyCont.Class where
src/LLVM/General/AST/CallingConvention.hs view
@@ -1,6 +1,3 @@-{-# LANGUAGE- DeriveDataTypeable- #-} -- | Module to allow importing 'CallingConvention' distinctly qualified. module LLVM.General.AST.CallingConvention where
src/LLVM/General/AST/FloatingPointPredicate.hs view
@@ -1,6 +1,3 @@-{-# LANGUAGE- DeriveDataTypeable - #-} -- | Predicates for the 'LLVM.General.AST.Instruction.FCmp' instruction module LLVM.General.AST.FloatingPointPredicate where
src/LLVM/General/AST/InlineAssembly.hs view
@@ -1,6 +1,3 @@-{-# LANGUAGE- DeriveDataTypeable- #-} -- | A representation of an LLVM inline assembly module LLVM.General.AST.InlineAssembly where
src/LLVM/General/AST/Instruction.hs view
@@ -1,6 +1,3 @@-{-# LANGUAGE- DeriveDataTypeable- #-} -- | LLVM instructions -- <http://llvm.org/docs/LangRef.html#instruction-reference> module LLVM.General.AST.Instruction where
src/LLVM/General/AST/IntegerPredicate.hs view
@@ -1,6 +1,3 @@-{-# LANGUAGE- DeriveDataTypeable - #-} -- | Predicates for the 'LLVM.General.AST.Instruction.ICmp' instruction module LLVM.General.AST.IntegerPredicate where
src/LLVM/General/AST/Linkage.hs view
@@ -1,7 +1,3 @@-{-# LANGUAGE- DeriveDataTypeable- #-}- -- | Module to allow importing 'Linkage' distinctly qualified. module LLVM.General.AST.Linkage where
src/LLVM/General/AST/RMWOperation.hs view
@@ -1,6 +1,3 @@-{-# LANGUAGE- DeriveDataTypeable - #-} -- | Operations for the 'LLVM.General.AST.Instruction.AtomicRMW' instruction module LLVM.General.AST.RMWOperation where
src/LLVM/General/AST/Visibility.hs view
@@ -1,6 +1,3 @@-{-# LANGUAGE- DeriveDataTypeable- #-} -- | Module to allow importing 'Visibility' distinctly qualified. module LLVM.General.AST.Visibility where
src/LLVM/General/CodeGenOpt.hs view
@@ -1,6 +1,3 @@-{-# LANGUAGE- DeriveDataTypeable- #-} -- | Code generation options, used in specifying TargetMachine module LLVM.General.CodeGenOpt where
src/LLVM/General/CodeModel.hs view
@@ -1,6 +1,3 @@-{-# LANGUAGE- DeriveDataTypeable- #-} -- | Relocations, used in specifying TargetMachine module LLVM.General.CodeModel where
src/LLVM/General/Diagnostic.hs view
@@ -1,6 +1,3 @@-{-# LANGUAGE- DeriveDataTypeable- #-} -- | Diagnostics describe parse errors module LLVM.General.Diagnostic ( DiagnosticKind(..),
src/LLVM/General/Internal/Atomicity.hs view
@@ -1,9 +1,7 @@ {-# LANGUAGE TemplateHaskell,- MultiParamTypeClasses,- FlexibleInstances+ MultiParamTypeClasses #-}- module LLVM.General.Internal.Atomicity where import Control.Monad
src/LLVM/General/Internal/Attribute.hs view
@@ -1,10 +1,8 @@ {-# LANGUAGE TemplateHaskell, MultiParamTypeClasses,- ConstraintKinds,- FlexibleInstances+ ConstraintKinds #-}- module LLVM.General.Internal.Attribute where import Language.Haskell.TH
src/LLVM/General/Internal/CallingConvention.hs view
@@ -1,8 +1,7 @@ {-# LANGUAGE MultiParamTypeClasses, TemplateHaskell,- QuasiQuotes,- FlexibleInstances+ QuasiQuotes #-} module LLVM.General.Internal.CallingConvention where
src/LLVM/General/Internal/Coding.hs view
@@ -1,7 +1,5 @@ {-# LANGUAGE TemplateHaskell,- FlexibleInstances,- FlexibleContexts, MultiParamTypeClasses, FunctionalDependencies, UndecidableInstances
src/LLVM/General/Internal/Constant.hs view
@@ -1,10 +1,7 @@ {-# LANGUAGE TemplateHaskell, QuasiQuotes,- TupleSections, MultiParamTypeClasses,- FlexibleInstances,- FlexibleContexts, ScopedTypeVariables #-} module LLVM.General.Internal.Constant where
src/LLVM/General/Internal/DecodeAST.hs view
@@ -1,8 +1,5 @@ {-# LANGUAGE GeneralizedNewtypeDeriving,- FlexibleContexts,- FlexibleInstances,- TypeFamilies, MultiParamTypeClasses, UndecidableInstances #-}
src/LLVM/General/Internal/Diagnostic.hs view
@@ -1,8 +1,6 @@ {-# LANGUAGE TemplateHaskell,- DeriveDataTypeable,- MultiParamTypeClasses,- FlexibleInstances+ MultiParamTypeClasses #-} module LLVM.General.Internal.Diagnostic where
src/LLVM/General/Internal/EncodeAST.hs view
@@ -1,11 +1,8 @@ {-# LANGUAGE GeneralizedNewtypeDeriving,- FlexibleContexts,- FlexibleInstances, MultiParamTypeClasses, UndecidableInstances #-}- module LLVM.General.Internal.EncodeAST where import Control.Exception
src/LLVM/General/Internal/ExecutionEngine.hs view
@@ -1,7 +1,6 @@ {-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies,- FlexibleInstances, RankNTypes #-} module LLVM.General.Internal.ExecutionEngine where@@ -14,13 +13,12 @@ import Data.Word import Foreign.Ptr-import Foreign.C.String (CString) import Foreign.C.Types (CUInt)-import Foreign.Marshal.Alloc (free) import qualified LLVM.General.Internal.FFI.PtrHierarchy as FFI import qualified LLVM.General.Internal.FFI.ExecutionEngine as FFI import qualified LLVM.General.Internal.FFI.Module as FFI+import qualified LLVM.General.Internal.FFI.LLVMCTypes as FFI import LLVM.General.Internal.Module import LLVM.General.Internal.Context@@ -60,7 +58,7 @@ withExecutionEngine :: Context -> Maybe (Ptr FFI.Module) -> - (Ptr (Ptr FFI.ExecutionEngine) -> Ptr FFI.Module -> Ptr CString -> IO CUInt) ->+ (Ptr (Ptr FFI.ExecutionEngine) -> Ptr FFI.Module -> Ptr FFI.MallocedCString -> IO CUInt) -> (Ptr FFI.ExecutionEngine -> IO a) -> IO a withExecutionEngine c m createEngine f = flip runAnyContT return $ do@@ -71,9 +69,7 @@ . withModuleFromAST c (A.Module "" Nothing Nothing [])) (return . Module) m r <- liftIO $ createEngine outExecutionEngine dummyModule outErrorCStringPtr- when (r /= 0) $ do- s <- anyContToM $ bracket (peek outErrorCStringPtr) free- fail =<< decodeM s+ when (r /= 0) $ fail =<< decodeM outErrorCStringPtr executionEngine <- anyContToM $ bracket (peek outExecutionEngine) FFI.disposeExecutionEngine liftIO $ removeModule executionEngine dummyModule liftIO $ f executionEngine
src/LLVM/General/Internal/FFI/Assembly.hs view
@@ -8,6 +8,7 @@ import LLVM.General.Internal.FFI.Context import LLVM.General.Internal.FFI.Module import LLVM.General.Internal.FFI.SMDiagnostic+import LLVM.General.Internal.FFI.LLVMCTypes import Foreign.C import Foreign.Ptr@@ -18,7 +19,7 @@ -- | LLVM's serializer to generate a string of llvm assembly from a module foreign import ccall unsafe "LLVM_General_GetModuleAssembly" getModuleAssembly ::- Ptr Module -> IO CString+ Ptr Module -> IO MallocedCString
src/LLVM/General/Internal/FFI/BasicBlock.hs view
@@ -1,6 +1,5 @@ {-# LANGUAGE ForeignFunctionInterface,- EmptyDataDecls, MultiParamTypeClasses #-}
src/LLVM/General/Internal/FFI/BinaryOperator.hs view
@@ -1,12 +1,9 @@ {-# LANGUAGE ForeignFunctionInterface,- EmptyDataDecls, MultiParamTypeClasses,- FlexibleInstances, UndecidableInstances, OverlappingInstances #-}- -- | FFI functions for handling the LLVM BinaryOperator class module LLVM.General.Internal.FFI.BinaryOperator where
src/LLVM/General/Internal/FFI/Builder.hs view
@@ -1,10 +1,8 @@ {-# LANGUAGE ForeignFunctionInterface,- EmptyDataDecls, TemplateHaskell #-}- -- | FFI glue for llvm::IRBuilder - llvm's IR construction state object module LLVM.General.Internal.FFI.Builder where
src/LLVM/General/Internal/FFI/Constant.hs view
@@ -1,13 +1,10 @@ {-# LANGUAGE TemplateHaskell, ForeignFunctionInterface,- EmptyDataDecls, MultiParamTypeClasses,- FlexibleInstances, UndecidableInstances, OverlappingInstances #-}- -- | FFI functions for handling the LLVM Constant class module LLVM.General.Internal.FFI.Constant where
src/LLVM/General/Internal/FFI/Context.hs view
@@ -1,6 +1,5 @@ {-# LANGUAGE- ForeignFunctionInterface,- EmptyDataDecls+ ForeignFunctionInterface #-} -- | Functions for handling the LLVMContext class. In all other LLVM interfaces,
src/LLVM/General/Internal/FFI/ExecutionEngine.hs view
@@ -1,6 +1,5 @@ {-# LANGUAGE- ForeignFunctionInterface,- EmptyDataDecls+ ForeignFunctionInterface #-} module LLVM.General.Internal.FFI.ExecutionEngine where@@ -9,18 +8,19 @@ import Foreign.C import LLVM.General.Internal.FFI.PtrHierarchy+import LLVM.General.Internal.FFI.LLVMCTypes import LLVM.General.Internal.FFI.Module data ExecutionEngine foreign import ccall unsafe "LLVMCreateExecutionEngineForModule" createExecutionEngineForModule ::- Ptr (Ptr ExecutionEngine) -> Ptr Module -> Ptr CString -> IO CUInt+ Ptr (Ptr ExecutionEngine) -> Ptr Module -> Ptr MallocedCString -> IO CUInt foreign import ccall unsafe "LLVMCreateInterpreterForModule" createInterpreterForModule ::- Ptr (Ptr ExecutionEngine) -> Ptr Module -> Ptr CString -> IO CUInt+ Ptr (Ptr ExecutionEngine) -> Ptr Module -> Ptr MallocedCString -> IO CUInt foreign import ccall unsafe "LLVMCreateJITCompilerForModule" createJITCompilerForModule ::- Ptr (Ptr ExecutionEngine) -> Ptr Module -> CUInt -> Ptr CString -> IO CUInt+ Ptr (Ptr ExecutionEngine) -> Ptr Module -> CUInt -> Ptr MallocedCString -> IO CUInt foreign import ccall unsafe "LLVMDisposeExecutionEngine" disposeExecutionEngine :: Ptr ExecutionEngine -> IO ()
src/LLVM/General/Internal/FFI/Function.hs view
@@ -1,6 +1,5 @@ {-# LANGUAGE ForeignFunctionInterface,- EmptyDataDecls, MultiParamTypeClasses #-}
src/LLVM/General/Internal/FFI/GlobalAlias.hs view
@@ -1,12 +1,9 @@ {-# LANGUAGE ForeignFunctionInterface,- EmptyDataDecls, MultiParamTypeClasses,- FlexibleInstances, UndecidableInstances, OverlappingInstances #-}- -- | FFI functions for handling the LLVM GlobalAlias class module LLVM.General.Internal.FFI.GlobalAlias where
src/LLVM/General/Internal/FFI/GlobalValue.hs view
@@ -1,12 +1,9 @@ {-# LANGUAGE ForeignFunctionInterface,- EmptyDataDecls, MultiParamTypeClasses,- FlexibleInstances, UndecidableInstances, OverlappingInstances #-}- -- | FFI functions for handling the LLVM GlobalValue class module LLVM.General.Internal.FFI.GlobalValue where
src/LLVM/General/Internal/FFI/GlobalVariable.hs view
@@ -1,12 +1,9 @@ {-# LANGUAGE ForeignFunctionInterface,- EmptyDataDecls, MultiParamTypeClasses,- FlexibleInstances, UndecidableInstances, OverlappingInstances #-}- -- | FFI functions for handling the LLVM GlobalVariable class module LLVM.General.Internal.FFI.GlobalVariable where
src/LLVM/General/Internal/FFI/Instruction.hs view
@@ -1,13 +1,10 @@ {-# LANGUAGE ForeignFunctionInterface,- EmptyDataDecls, MultiParamTypeClasses,- FlexibleInstances, UndecidableInstances, OverlappingInstances, TemplateHaskell #-}- module LLVM.General.Internal.FFI.Instruction where import Control.Monad
src/LLVM/General/Internal/FFI/InstructionDefs.hsc view
@@ -1,4 +1,3 @@-{-# LANGUAGE DeriveDataTypeable #-} -- This module translates the instruction data in "llvm/Instruction.def" into a Haskell data structure, -- so it may be accessed conveniently with Template Haskell code module LLVM.General.Internal.FFI.InstructionDefs where
src/LLVM/General/Internal/FFI/LLVMCTypes.hsc view
@@ -1,6 +1,4 @@ {-# LANGUAGE- DeriveDataTypeable,- StandaloneDeriving, GeneralizedNewtypeDeriving #-} -- | Define types which correspond cleanly with some simple types on the C/C++ side.@@ -51,6 +49,9 @@ deriving instance Data CUInt newtype LLVMBool = LLVMBool CUInt++newtype MallocedCString = MallocedCString CString+ deriving (Storable) newtype CPPOpcode = CPPOpcode CUInt deriving (Eq, Ord, Show, Typeable, Data)
src/LLVM/General/Internal/FFI/Module.hs view
@@ -1,6 +1,5 @@ {-# LANGUAGE- ForeignFunctionInterface,- EmptyDataDecls+ ForeignFunctionInterface #-} module LLVM.General.Internal.FFI.Module where @@ -36,7 +35,7 @@ Ptr Module -> CString -> IO () foreign import ccall unsafe "LLVM_General_GetModuleIdentifier" getModuleIdentifier ::- Ptr Module -> IO CString+ Ptr Module -> IO MallocedCString foreign import ccall unsafe "LLVMGetFirstGlobal" getFirstGlobal :: Ptr Module -> IO (Ptr GlobalVariable)@@ -89,4 +88,4 @@ Ptr Module -> IO (ModuleAsm CString) foreign import ccall unsafe "LLVM_General_WriteBitcodeToFile" writeBitcodeToFile ::- Ptr Module -> CString -> Ptr CString -> IO LLVMBool+ Ptr Module -> CString -> Ptr MallocedCString -> IO LLVMBool
src/LLVM/General/Internal/FFI/PassManager.hs view
@@ -1,7 +1,6 @@ {-# LANGUAGE TemplateHaskell,- ForeignFunctionInterface,- EmptyDataDecls+ ForeignFunctionInterface #-} module LLVM.General.Internal.FFI.PassManager where
src/LLVM/General/Internal/FFI/PtrHierarchy.hs view
@@ -1,13 +1,10 @@ {-# LANGUAGE ForeignFunctionInterface, MultiParamTypeClasses,- EmptyDataDecls, FunctionalDependencies,- FlexibleInstances, UndecidableInstances, OverlappingInstances #-}- -- | This module defines typeclasses to represent the relationships of an object-oriented inheritance hierarchy module LLVM.General.Internal.FFI.PtrHierarchy where
src/LLVM/General/Internal/FFI/SMDiagnostic.hs view
@@ -1,8 +1,6 @@ {-# LANGUAGE- ForeignFunctionInterface,- EmptyDataDecls+ ForeignFunctionInterface #-}- -- | FFI functions for handling the LLVM SMDiagnostic class module LLVM.General.Internal.FFI.SMDiagnostic where
src/LLVM/General/Internal/FFI/Target.hs view
@@ -1,7 +1,6 @@ {-# LANGUAGE ForeignFunctionInterface,- GeneralizedNewtypeDeriving,- EmptyDataDecls+ GeneralizedNewtypeDeriving #-} module LLVM.General.Internal.FFI.Target where @@ -17,7 +16,7 @@ IO LLVMBool foreign import ccall unsafe "LLVM_General_LookupTarget" lookupTarget ::- CString -> CString -> Ptr CString -> Ptr CString -> IO (Ptr Target)+ CString -> CString -> Ptr MallocedCString -> Ptr MallocedCString -> IO (Ptr Target) data TargetOptions @@ -80,10 +79,23 @@ Ptr TargetMachine -> IO () foreign import ccall unsafe "LLVMTargetMachineEmitToFile" targetMachineEmitToFile ::- Ptr TargetMachine -> Ptr Module -> CString -> CodeGenFileType -> Ptr CString -> IO LLVMBool+ Ptr TargetMachine -> Ptr Module -> CString -> CodeGenFileType -> Ptr MallocedCString -> IO LLVMBool data TargetLowering foreign import ccall unsafe "LLVM_General_GetTargetLowering" getTargetLowering :: Ptr TargetMachine -> IO (Ptr TargetLowering) +foreign import ccall unsafe "LLVM_General_GetDefaultTargetTriple" getDefaultTargetTriple :: + IO MallocedCString++foreign import ccall unsafe "LLVM_General_GetHostCPUName" getHostCPUName :: + IO MallocedCString++foreign import ccall unsafe "LLVM_General_GetHostCPUFeatures" getHostCPUFeatures :: + IO MallocedCString++foreign import ccall unsafe "LLVM_General_GetTargetMachineDataLayout" getTargetMachineDataLayout ::+ Ptr TargetMachine -> IO MallocedCString++foreign import ccall unsafe "LLVM_General_InitializeAllTargets" initializeAllTargets :: IO ()
src/LLVM/General/Internal/FFI/TargetC.cpp view
@@ -1,8 +1,11 @@ #define __STDC_LIMIT_MACROS #include "llvm/Support/TargetRegistry.h"+#include "llvm/Support/TargetSelect.h"+#include "llvm/Support/Host.h" #include "llvm/Target/TargetMachine.h" #include "llvm/ADT/Triple.h" #include "llvm/ExecutionEngine/Interpreter.h"+#include "llvm/DataLayout.h" #include "llvm-c/Target.h" #include "llvm-c/TargetMachine.h" #include "llvm-c/Core.h"@@ -198,5 +201,37 @@ return unwrap(t)->getTargetLowering(); } +char *LLVM_General_GetDefaultTargetTriple() {+ return strdup(sys::getDefaultTargetTriple().c_str()); } +char *LLVM_General_GetHostCPUName() {+ return strdup(sys::getHostCPUName().c_str());+}++char *LLVM_General_GetHostCPUFeatures() {+ StringMap<bool> featureMap;+ std::string features;+ if (sys::getHostCPUFeatures(featureMap)) {+ for(llvm::StringMap<bool>::const_iterator it = featureMap.begin(); it != featureMap.end(); ++it) {+ if (it->second) {+ features += it->first().str() + " ";+ }+ }+ }+ return strdup(features.c_str());+}++char *LLVM_General_GetTargetMachineDataLayout(LLVMTargetMachineRef t) {+ return strdup(unwrap(t)->getDataLayout()->getStringRepresentation().c_str());+}++void LLVM_General_InitializeAllTargets() {+ InitializeAllTargetInfos();+ InitializeAllTargets();+ InitializeAllTargetMCs();+ InitializeAllAsmPrinters();+ // None of the other components are bound yet+}++}
src/LLVM/General/Internal/FFI/Type.hs view
@@ -1,8 +1,6 @@ {-# LANGUAGE- ForeignFunctionInterface,- EmptyDataDecls+ ForeignFunctionInterface #-}- -- | Functions for handling the LLVM types module LLVM.General.Internal.FFI.Type where
src/LLVM/General/Internal/FFI/User.hs view
@@ -1,12 +1,9 @@ {-# LANGUAGE ForeignFunctionInterface,- EmptyDataDecls, MultiParamTypeClasses,- FlexibleInstances, UndecidableInstances, OverlappingInstances #-}- -- | FFI functions for handling the LLVM User class module LLVM.General.Internal.FFI.User where
src/LLVM/General/Internal/FFI/Value.hs view
@@ -1,13 +1,9 @@ {-# LANGUAGE ForeignFunctionInterface,- EmptyDataDecls, MultiParamTypeClasses,- FlexibleContexts,- FlexibleInstances, UndecidableInstances, OverlappingInstances #-}- -- | FFI functions for handling the LLVM Value class module LLVM.General.Internal.FFI.Value where
src/LLVM/General/Internal/FloatingPointPredicate.hs view
@@ -1,9 +1,7 @@ {-# LANGUAGE MultiParamTypeClasses,- TemplateHaskell,- FlexibleInstances+ TemplateHaskell #-}- module LLVM.General.Internal.FloatingPointPredicate where import LLVM.General.Internal.Coding
src/LLVM/General/Internal/Global.hs view
@@ -1,8 +1,6 @@ {-# LANGUAGE TemplateHaskell,- FlexibleInstances,- MultiParamTypeClasses,- FlexibleContexts+ MultiParamTypeClasses #-} module LLVM.General.Internal.Global where
src/LLVM/General/Internal/InlineAssembly.hs view
@@ -1,7 +1,6 @@ {-# LANGUAGE TemplateHaskell,- MultiParamTypeClasses,- FlexibleInstances+ MultiParamTypeClasses #-} module LLVM.General.Internal.InlineAssembly where
src/LLVM/General/Internal/Instruction.hs view
@@ -1,10 +1,7 @@ {-# LANGUAGE TemplateHaskell, QuasiQuotes,- TupleSections, MultiParamTypeClasses,- FlexibleContexts,- FlexibleInstances, UndecidableInstances #-} module LLVM.General.Internal.Instruction where
src/LLVM/General/Internal/IntegerPredicate.hs view
@@ -1,9 +1,7 @@ {-# LANGUAGE TemplateHaskell,- MultiParamTypeClasses,- FlexibleInstances+ MultiParamTypeClasses #-}- module LLVM.General.Internal.IntegerPredicate where import LLVM.General.Internal.Coding
src/LLVM/General/Internal/Metadata.hs view
@@ -1,6 +1,5 @@ {-# LANGUAGE- MultiParamTypeClasses,- FlexibleInstances+ MultiParamTypeClasses #-} module LLVM.General.Internal.Metadata where
src/LLVM/General/Internal/Module.hs view
@@ -1,8 +1,6 @@ {-# LANGUAGE- TupleSections,- ScopedTypeVariables,- FlexibleInstances+ ScopedTypeVariables #-} -- | This Haskell module is for/of functions for handling LLVM modules. module LLVM.General.Internal.Module where@@ -15,7 +13,6 @@ import Control.Exception import Foreign.Ptr-import Foreign.Marshal.Alloc (free) import qualified LLVM.General.Internal.FFI.Assembly as FFI import qualified LLVM.General.Internal.FFI.Builder as FFI@@ -71,7 +68,7 @@ -- | generate LLVM assembly from a 'Module' moduleString :: Module -> IO String-moduleString (Module m) = bracket (FFI.getModuleAssembly m) free $ decodeM+moduleString (Module m) = decodeM =<< FFI.getModuleAssembly m -- | generate LLVM bitcode from a 'Module' writeBitcodeToFile :: FilePath -> Module -> ErrorT String IO ()@@ -79,14 +76,14 @@ msgPtr <- alloca path <- encodeM path result <- decodeM =<< (liftIO $ FFI.writeBitcodeToFile m path msgPtr)- when result $ fail =<< (decodeM =<< (anyContToM $ bracket (peek msgPtr) free))+ when result $ fail =<< decodeM msgPtr emitToFile :: FFI.CodeGenFileType -> TargetMachine -> FilePath -> Module -> ErrorT String IO () emitToFile fileType (TargetMachine tm) path (Module m) = flip runAnyContT return $ do msgPtr <- alloca path <- encodeM path result <- decodeM =<< (liftIO $ FFI.targetMachineEmitToFile tm m path fileType msgPtr)- when result $ fail =<< decodeM =<< anyContToM (bracket (peek msgPtr) free)+ when result $ fail =<< decodeM msgPtr -- | write target-specific assembly directly into a file writeAssemblyToFile :: TargetMachine -> FilePath -> Module -> ErrorT String IO ()@@ -237,7 +234,7 @@ c <- return Context `ap` liftIO (FFI.getModuleContext mod) getMetadataKindNames c return A.Module - `ap` (liftIO $ bracket (FFI.getModuleIdentifier mod) free decodeM)+ `ap` (liftIO $ decodeM =<< FFI.getModuleIdentifier mod) `ap` (liftIO $ getDataLayout mod) `ap` (liftIO $ do s <- decodeM <=< FFI.getTargetTriple $ mod
src/LLVM/General/Internal/Operand.hs view
@@ -1,6 +1,5 @@ {-# LANGUAGE- MultiParamTypeClasses,- FlexibleInstances+ MultiParamTypeClasses #-} module LLVM.General.Internal.Operand where
src/LLVM/General/Internal/PassManager.hs view
@@ -1,8 +1,6 @@ {-# LANGUAGE- TemplateHaskell,- FlexibleInstances+ TemplateHaskell #-}- module LLVM.General.Internal.PassManager where import qualified Language.Haskell.TH as TH
src/LLVM/General/Internal/RMWOperation.hs view
@@ -1,9 +1,7 @@ {-# LANGUAGE TemplateHaskell,- MultiParamTypeClasses,- FlexibleInstances+ MultiParamTypeClasses #-}- module LLVM.General.Internal.RMWOperation where import LLVM.General.AST.RMWOperation
src/LLVM/General/Internal/String.hs view
@@ -1,19 +1,21 @@ {-# LANGUAGE MultiParamTypeClasses,- FlexibleInstances, UndecidableInstances #-} module LLVM.General.Internal.String where import Control.Arrow import Control.Monad-import Foreign.C (CString, CChar)-import Foreign.Ptr import Control.Monad.AnyCont import Control.Monad.IO.Class+import Control.Exception (finally)+import Foreign.C (CString, CChar)+import Foreign.Ptr import Foreign.Storable (Storable)-import Foreign.Marshal.Alloc as F.M (alloca)+import Foreign.Marshal.Alloc as F.M (alloca, free) +import LLVM.General.Internal.FFI.LLVMCTypes+ import LLVM.General.Internal.Coding import qualified Data.ByteString as BS@@ -37,6 +39,12 @@ instance (MonadIO d) => DecodeM d String CString where decodeM = decodeM . UTF8ByteString <=< liftIO . BS.packCString++instance (MonadIO d) => DecodeM d String MallocedCString where+ decodeM (MallocedCString s) = liftIO $ finally (decodeM s) (free s)++instance (MonadIO d) => DecodeM d String (Ptr MallocedCString) where+ decodeM = liftIO . decodeM <=< peek instance (Integral i, MonadIO d) => DecodeM d String (Ptr CChar, i) where decodeM = decodeM . UTF8ByteString <=< liftIO . BS.packCStringLen . second fromIntegral
src/LLVM/General/Internal/Target.hs view
@@ -1,9 +1,8 @@ {-# LANGUAGE TemplateHaskell,- FlexibleInstances, MultiParamTypeClasses,- TupleSections,- RecordWildCards+ RecordWildCards,+ UndecidableInstances #-} module LLVM.General.Internal.Target where @@ -12,13 +11,19 @@ import Control.Exception import Data.Functor import Control.Monad.AnyCont+import Data.Maybe import Foreign.Ptr-import Foreign.Marshal.Alloc (free)+import Data.List (intercalate)+import Data.Set (Set)+import qualified Data.Set as Set import LLVM.General.Internal.Coding import LLVM.General.Internal.String ()+import LLVM.General.Internal.DataLayout +import LLVM.General.AST.DataLayout+ import qualified LLVM.General.Internal.FFI.LLVMCTypes as FFI import qualified LLVM.General.Internal.FFI.Target as FFI @@ -62,10 +67,22 @@ (FFI.fpOpFusionModeStrict, TO.FloatingPointOperationFusionStrict) ] +-- | <http://llvm.org/doxygen/classllvm_1_1Target.html> newtype Target = Target (Ptr FFI.Target) --- | Find a Target given an architecture and/or a \"triple\".+-- | e.g. an instruction set extension+newtype CPUFeature = CPUFeature String+ deriving (Eq, Ord, Read, Show)++instance EncodeM e String es => EncodeM e (Set CPUFeature) es where+ encodeM = encodeM . intercalate " " . map (\(CPUFeature f) -> f) . Set.toList++instance (Monad d, DecodeM d String es) => DecodeM d (Set CPUFeature) es where+ decodeM = liftM (Set.fromList . map CPUFeature . words) . decodeM++-- | Find a 'Target' given an architecture and/or a \"triple\". -- | <http://llvm.org/doxygen/structllvm_1_1TargetRegistry.html#a3105b45e546c9cc3cf78d0f2ec18ad89>+-- | Be sure to run either 'initializeAllTargets' or 'initializeNativeTarget' before expecting this to succeed, depending on what target(s) you want to use. lookupTarget :: Maybe String -- ^ arch -> String -- ^ \"triple\" - e.g. x86_64-unknown-linux-gnu@@ -76,13 +93,8 @@ arch <- encodeM (maybe "" id arch) triple <- encodeM triple target <- liftIO $ FFI.lookupTarget arch triple cNewTripleP cErrorP- let readString p = do- s <- peek p- r <- decodeM s- liftIO $ free s- return r- when (target == nullPtr) $ fail =<< readString cErrorP- liftM (Target target, ) $ readString cNewTripleP+ when (target == nullPtr) $ fail =<< decodeM cErrorP+ liftM (Target target, ) $ decodeM cNewTripleP -- | <http://llvm.org/doxygen/classllvm_1_1TargetOptions.html> newtype TargetOptions = TargetOptions (Ptr FFI.TargetOptions)@@ -183,7 +195,7 @@ Target -> String -- ^ triple -> String -- ^ cpu- -> String -- ^ features+ -> Set CPUFeature -- ^ features -> TargetOptions -> Reloc.Model -> CodeModel.Model@@ -226,7 +238,43 @@ getTargetLowering :: TargetMachine -> IO TargetLowering getTargetLowering (TargetMachine tm) = TargetLowering <$> FFI.getTargetLowering tm +-- | Initialize the native target. This function is called automatically in these Haskell bindings+-- when creating an 'LLVM.General.ExecutionEngine.ExecutionEngine' which will require it, and so it should+-- not be necessary to call it separately. initializeNativeTarget :: IO () initializeNativeTarget = do failure <- decodeM =<< liftIO FFI.initializeNativeTarget when failure $ fail "native target initialization failed"++-- | the default target triple that LLVM has been configured to produce code for+getDefaultTargetTriple :: IO String+getDefaultTargetTriple = decodeM =<< FFI.getDefaultTargetTriple++-- | the LLVM name for the host CPU+getHostCPUName :: IO String+getHostCPUName = decodeM =<< FFI.getHostCPUName++-- | a space-separated list of LLVM feature names supported by the host CPU+getHostCPUFeatures :: IO (Set CPUFeature)+getHostCPUFeatures = decodeM =<< FFI.getHostCPUFeatures+ +-- | 'DataLayout' to use for the given 'TargetMachine'+getTargetMachineDataLayout :: TargetMachine -> IO DataLayout+getTargetMachineDataLayout (TargetMachine m) =+ fromMaybe (error "parseDataLayout failed") . parseDataLayout <$> (decodeM =<< (FFI.getTargetMachineDataLayout m))+++-- | Initialize all targets so they can be found by 'lookupTarget'+initializeAllTargets :: IO ()+initializeAllTargets = FFI.initializeAllTargets++-- | Bracket creation and destruction of a TargetMachine configured for the host+withDefaultTargetMachine :: (TargetMachine -> IO a) -> ErrorT String IO a+withDefaultTargetMachine f = do+ liftIO $ initializeAllTargets+ triple <- liftIO $ getDefaultTargetTriple+ cpu <- liftIO $ getHostCPUName+ features <- liftIO $ getHostCPUFeatures+ (target, _) <- lookupTarget Nothing triple+ liftIO $ withTargetOptions $ \options ->+ withTargetMachine target triple cpu features options Reloc.Default CodeModel.Default CodeGenOpt.Default f
src/LLVM/General/Internal/Type.hs view
@@ -1,6 +1,5 @@ {-# LANGUAGE QuasiQuotes,- FlexibleInstances, MultiParamTypeClasses #-} module LLVM.General.Internal.Type where
src/LLVM/General/Internal/Value.hs view
@@ -1,6 +1,4 @@ {-# LANGUAGE- FlexibleContexts,- FlexibleInstances, MultiParamTypeClasses #-} module LLVM.General.Internal.Value where
src/LLVM/General/Relocation.hs view
@@ -1,6 +1,3 @@-{-# LANGUAGE- DeriveDataTypeable- #-} -- | Relocations, used in specifying TargetMachine module LLVM.General.Relocation where
src/LLVM/General/Target.hs view
@@ -4,9 +4,13 @@ module LLVM.General.Target ( lookupTarget, TargetOptions,+ TargetMachine,+ CPUFeature(..), withTargetOptions, peekTargetOptions, pokeTargetOptions,- withTargetMachine,- getTargetLowering+ withTargetMachine, withDefaultTargetMachine,+ getTargetLowering,+ getDefaultTargetTriple, getHostCPUName, getHostCPUFeatures,+ getTargetMachineDataLayout, initializeNativeTarget, initializeAllTargets ) where import LLVM.General.Internal.Target
src/LLVM/General/Target/Options.hs view
@@ -1,6 +1,3 @@-{-# LANGUAGE- DeriveDataTypeable - #-} -- | <http://llvm.org/doxygen/classllvm_1_1TargetOptions.html> module LLVM.General.Target.Options where
src/LLVM/General/Transforms.hs view
@@ -1,6 +1,3 @@-{-# LANGUAGE- DeriveDataTypeable- #-} -- | This module provides an enumeration of the various transformation (e.g. optimization) passes -- provided by LLVM. They can be used to create a 'LLVM.General.PassManager.PassManager' to, in turn, -- run the passes on 'LLVM.General.Module.Module's. If you don't know what passes you want, consider
test/LLVM/General/Test/ExecutionEngine.hs view
@@ -1,6 +1,5 @@ {-# LANGUAGE- ForeignFunctionInterface,- FlexibleContexts+ ForeignFunctionInterface #-} module LLVM.General.Test.ExecutionEngine where
test/LLVM/General/Test/Module.hs view
@@ -11,6 +11,8 @@ import Data.Word import Data.Functor +import qualified Data.Set as Set+ import LLVM.General.Context import LLVM.General.Module import LLVM.General.Diagnostic
test/LLVM/General/Test/Optimization.hs view
@@ -7,6 +7,7 @@ import LLVM.General.Test.Support import Data.Functor+import qualified Data.Set as Set import qualified Data.Map as Map import LLVM.General.Module@@ -293,7 +294,7 @@ let triple = "x86_64-apple-darwin" (target, _) <- failInIO $ lookupTarget Nothing triple withTargetOptions $ \targetOptions -> do- withTargetMachine target triple "" "" targetOptions+ withTargetMachine target triple "" Set.empty targetOptions R.Default CM.Default CGO.Default $ \targetMachine -> do targetLowering <- getTargetLowering targetMachine withPassManager ([LowerInvoke False], targetLowering) $ \passManager -> do
test/LLVM/General/Test/Support.hs view
@@ -1,7 +1,3 @@-{-# LANGUAGE- TypeSynonymInstances,- FlexibleInstances- #-} module LLVM.General.Test.Support where import Test.Framework