-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Bindings to the LLVM compiler toolkit using type families. -- -- High-level bindings to the LLVM compiler toolkit using type families -- instead of functional dependencies. -- -- We use the same module names as the llvm package, which makes -- it harder to work with both packages from GHCi. You may use the -- -hide-package option. We may change the module names later. -- -- A note on versioning: The versions of this package are loosely based -- on the LLVM version. However, we depend on a relatively stable part of -- LLVM and provide a relatively stable API for it. We conform to the -- Package Versioning Policy PVP, i.e. we increase the version of this -- package when its API changes, but not necessarily when we add support -- for a new LLVM version. We support all those LLVM versions that are -- supported by our llvm-ffi dependency. @package llvm-tf @version 9.0 module LLVM.Util.Proxy data Proxy a Proxy :: Proxy a fromValue :: a -> Proxy a element :: Proxy (f a) -> Proxy a instance Applicative Proxy instance Functor Proxy module LLVM.Util.Foreign with :: Storable a => a -> (Ptr a -> IO b) -> IO b alloca :: Storable a => (Ptr a -> IO b) -> IO b withArrayLen :: Storable a => [a] -> (Int -> Ptr a -> IO b) -> IO b module LLVM.Util.Optimize -- | Result tells whether the module was modified by any of the passes. optimizeModule :: Int -> Module -> IO Bool module LLVM.Core.Attribute zeroext :: Attribute signext :: Attribute inreg :: Attribute byval :: Attribute sret :: Attribute align :: Word64 -> Attribute noalias :: Attribute nocapture :: Attribute nest :: Attribute returned :: Attribute nonnull :: Attribute dereferenceable :: Word64 -> Attribute dereferenceableOrNull :: Word64 -> Attribute swiftself :: Attribute swifterror :: Attribute immarg :: Attribute alignstack :: Word64 -> Attribute allocsize :: Attribute alwaysinline :: Attribute builtin :: Attribute cold :: Attribute convergent :: Attribute inaccessiblememonly :: Attribute inaccessiblememOrArgmemonly :: Attribute inlinehint :: Attribute jumptable :: Attribute minsize :: Attribute naked :: Attribute noJumpTables :: Attribute nobuiltin :: Attribute noduplicate :: Attribute nofree :: Attribute noimplicitfloat :: Attribute noinline :: Attribute nonlazybind :: Attribute noredzone :: Attribute indirectTlsSegRefs :: Attribute noreturn :: Attribute norecurse :: Attribute willreturn :: Attribute nosync :: Attribute nounwind :: Attribute nullPointerIsValid :: Attribute optforfuzzing :: Attribute optnone :: Attribute optsize :: Attribute patchableFunction :: Attribute probeStack :: Attribute readnone :: Attribute readonly :: Attribute stackProbeSize :: Attribute noStackArgProbe :: Attribute writeonly :: Attribute argmemonly :: Attribute returnsTwice :: Attribute safestack :: Attribute sanitizeAddress :: Attribute sanitizeMemory :: Attribute sanitizeThread :: Attribute sanitizeHwaddress :: Attribute sanitizeMemtag :: Attribute speculativeLoadHardening :: Attribute speculatable :: Attribute ssp :: Attribute sspreq :: Attribute sspstrong :: Attribute strictfp :: Attribute uwtable :: Attribute nocfCheck :: Attribute shadowcallstack :: Attribute module LLVM.Core.Guided data Guide shape elem scalar :: Guide ScalarShape a vector :: Positive n => Guide (VectorShape n) a getElementPtr :: (ValueCons value, GetElementPtr o i, IsIndexType i0) => Guide shape (Ptr o, i0) -> VT value shape (Ptr o) -> (VT value shape i0, i) -> CodeGenFunction r (VT value shape (Ptr (ElementPtrType o i))) getElementPtr0 :: (ValueCons value, GetElementPtr o i) => Guide shape (Ptr o) -> VT value shape (Ptr o) -> i -> CodeGenFunction r (VT value shape (Ptr (ElementPtrType o i))) -- | Truncate a value to a shorter bit width. trunc :: (ValueCons value, IsInteger av, IsInteger bv, IsPrimitive a, IsPrimitive b, Type shape a ~ av, Type shape b ~ bv, IsSized a, IsSized b, SizeOf a :>: SizeOf b) => Guide shape (a, b) -> value av -> CodeGenFunction r (value bv) -- | Extend a value to wider width. If the target type is signed, then -- preserve the sign, If the target type is unsigned, then extended by -- zeros. ext :: (ValueCons value, IsInteger a, IsInteger b, IsType bv, Signed a ~ Signed b, IsPrimitive a, IsPrimitive b, Type shape a ~ av, Type shape b ~ bv, IsSized a, IsSized b, SizeOf a :<: SizeOf b) => Guide shape (a, b) -> value av -> CodeGenFunction r (value bv) extBool :: (ValueCons value, IsInteger b, IsType bv, IsPrimitive b, Type shape Bool ~ av, Type shape b ~ bv) => Guide shape (Bool, b) -> value av -> CodeGenFunction r (value bv) -- | It is zext, trunc or nop depending on the relation of -- the sizes. zadapt :: (ValueCons value, IsInteger a, IsInteger b, IsType bv, IsPrimitive a, IsPrimitive b, Type shape a ~ av, Type shape b ~ bv) => Guide shape (a, b) -> value av -> CodeGenFunction r (value bv) -- | It is sext, trunc or nop depending on the relation of -- the sizes. sadapt :: (ValueCons value, IsInteger a, IsInteger b, IsType bv, IsPrimitive a, IsPrimitive b, Type shape a ~ av, Type shape b ~ bv) => Guide shape (a, b) -> value av -> CodeGenFunction r (value bv) -- | It is sadapt or zadapt depending on the sign mode. adapt :: (ValueCons value, IsInteger a, IsInteger b, IsType bv, IsPrimitive a, IsPrimitive b, Type shape a ~ av, Type shape b ~ bv, Signed a ~ Signed b) => Guide shape (a, b) -> value av -> CodeGenFunction r (value bv) -- | Truncate a floating point value. fptrunc :: (ValueCons value, IsFloating av, IsFloating bv, IsPrimitive a, IsPrimitive b, Type shape a ~ av, Type shape b ~ bv, IsSized a, IsSized b, SizeOf a :>: SizeOf b) => Guide shape (a, b) -> value av -> CodeGenFunction r (value bv) -- | Extend a floating point value. fpext :: (ValueCons value, IsFloating av, IsFloating bv, IsPrimitive a, IsPrimitive b, Type shape a ~ av, Type shape b ~ bv, IsSized a, IsSized b, SizeOf a :<: SizeOf b) => Guide shape (a, b) -> value av -> CodeGenFunction r (value bv) -- | Convert a floating point value to an integer. It is mapped to -- fptosi or fptoui depending on the type a. fptoint :: (ValueCons value, IsFloating a, IsInteger b, IsType bv, IsPrimitive a, IsPrimitive b, Type shape a ~ av, Type shape b ~ bv) => Guide shape (a, b) -> value av -> CodeGenFunction r (value bv) -- | Convert an integer to a floating point value. It is mapped to -- sitofp or uitofp depending on the type a. inttofp :: (ValueCons value, IsInteger a, IsFloating b, IsType bv, IsPrimitive a, IsPrimitive b, Type shape a ~ av, Type shape b ~ bv) => Guide shape (a, b) -> value av -> CodeGenFunction r (value bv) -- | Convert a pointer to an integer. ptrtoint :: (ValueCons value, IsType a, IsInteger b, IsType bv, IsPrimitive b, Type shape (Ptr a) ~ av, Type shape b ~ bv) => Guide shape (Ptr a, b) -> value av -> CodeGenFunction r (value bv) -- | Convert an integer to a pointer. inttoptr :: (ValueCons value, IsInteger a, IsType b, IsType bv, IsPrimitive a, Type shape a ~ av, Type shape (Ptr b) ~ bv) => Guide shape (a, Ptr b) -> value av -> CodeGenFunction r (value bv) -- | Convert between to values of the same size by just copying the bit -- pattern. bitcast :: (ValueCons value, IsFirstClass a, IsFirstClass bv, IsPrimitive a, IsPrimitive b, Type shape a ~ av, Type shape b ~ bv, IsSized a, IsSized b, SizeOf a ~ SizeOf b) => Guide shape (a, b) -> value av -> CodeGenFunction r (value bv) select :: (ValueCons value, IsPrimitive a, Type shape a ~ av, Type shape Bool ~ bv) => Guide shape a -> value bv -> value av -> value av -> CodeGenFunction r (value av) cmp :: (ValueCons value, IsArithmetic a, IsPrimitive a, Type shape a ~ av, Type shape Bool ~ bv) => Guide shape a -> CmpPredicate -> value av -> value av -> CodeGenFunction r (value bv) -- | Compare integers. -- | Deprecated: use cmp or pcmp instead icmp :: (ValueCons value, IsIntegerOrPointer a, IsPrimitive a, Type shape a ~ av, Type shape Bool ~ bv) => Guide shape a -> IntPredicate -> value av -> value av -> CodeGenFunction r (value bv) -- | Compare pointers. pcmp :: (ValueCons value, Type shape (Ptr a) ~ av, Type shape Bool ~ bv) => Guide shape (Ptr a) -> IntPredicate -> value av -> value av -> CodeGenFunction r (value bv) -- | Compare floating point values. fcmp :: (ValueCons value, IsFloating a, IsPrimitive a, Type shape a ~ av, Type shape Bool ~ bv) => Guide shape a -> FPPredicate -> value av -> value av -> CodeGenFunction r (value bv) -- | The LLVM (Low Level Virtual Machine) is virtual machine at a machine -- code level. It supports both stand alone code generation and JITing. -- The Haskell llvm package is a (relatively) high level interface to the -- LLVM. The high level interface makes it easy to construct LLVM code. -- There is also an interface to the raw low level LLVM API as exposed by -- the LLVM C interface. -- -- LLVM code is organized into modules (type Module). Each module -- contains a number of global variables and functions (type -- Function). Each functions has a number of basic blocks (type -- BasicBlock). Each basic block has a number instructions, where -- each instruction produces a value (type Value). -- -- Unlike assembly code for a real processor the assembly code for LLVM -- is in SSA (Static Single Assignment) form. This means that each -- instruction generates a new bound variable which may not be assigned -- again. A consequence of this is that where control flow joins from -- several execution paths there has to be a phi pseudo instruction if -- you want different variables to be joined into one. -- -- The definition of several of the LLVM entities (Module, -- Function, and BasicBlock) follow the same pattern. First -- the entity has to be created using newX (where X is -- one of Module, Function, or BasicBlock), -- then at some later point it has to given its definition using -- defineX. The reason for splitting the creation and definition -- is that you often need to be able to refer to an entity before giving -- it's body, e.g., in two mutually recursive functions. The the -- newX and defineX function can also be done at the -- same time by using createX. Furthermore, an explicit name can -- be given to an entity by the newNamedX function; the -- newX function just generates a fresh name. module LLVM.Core -- | Initialize jitter to the native target. The operation is idempotent. initializeNativeTarget :: IO () -- | Type of top level modules. data Module -- | Create a new module. newModule :: IO Module -- | Create a new explicitely named module. newNamedModule :: String -> IO Module -- | Give the body for a module. defineModule :: Module -> CodeGenModule a -> IO a -- | Free all storage related to a module. *Note*, this is a dangerous -- call, since referring to the module after this call is an error. The -- reason for the explicit call to free the module instead of an -- automatic lifetime management is that modules have a somewhat -- complicated ownership. Handing a module to a module provider changes -- the ownership of the module, and the module provider will free the -- module when necessary. destroyModule :: Module -> IO () -- | Create a new module with the given body. createModule :: CodeGenModule a -> IO a setTarget :: String -> CodeGenModule () hostTriple :: String -- | Manage compile passes. data PassManager -- | Create a pass manager. createPassManager :: IO PassManager -- | Create a pass manager for a module. createFunctionPassManager :: Module -> IO PassManager -- | Write a module to a file. writeBitcodeToFile :: String -> Module -> IO () -- | Read a module from a file. readBitcodeFromFile :: String -> IO Module getModuleValues :: Module -> IO [(String, ModuleValue)] getFunctions :: Module -> IO [(String, Value)] getGlobalVariables :: Module -> IO [(String, Value)] data ModuleValue castModuleValue :: IsType a => ModuleValue -> Maybe (Value a) data BinOpDesc BOAdd :: BinOpDesc BOAddNuw :: BinOpDesc BOAddNsw :: BinOpDesc BOAddNuwNsw :: BinOpDesc BOFAdd :: BinOpDesc BOSub :: BinOpDesc BOSubNuw :: BinOpDesc BOSubNsw :: BinOpDesc BOSubNuwNsw :: BinOpDesc BOFSub :: BinOpDesc BOMul :: BinOpDesc BOMulNuw :: BinOpDesc BOMulNsw :: BinOpDesc BOMulNuwNsw :: BinOpDesc BOFMul :: BinOpDesc BOUDiv :: BinOpDesc BOSDiv :: BinOpDesc BOSDivExact :: BinOpDesc BOFDiv :: BinOpDesc BOURem :: BinOpDesc BOSRem :: BinOpDesc BOFRem :: BinOpDesc BOShL :: BinOpDesc BOLShR :: BinOpDesc BOAShR :: BinOpDesc BOAnd :: BinOpDesc BOOr :: BinOpDesc BOXor :: BinOpDesc data InstrDesc IDRet :: TypeDesc -> ArgDesc -> InstrDesc IDRetVoid :: InstrDesc IDBrCond :: ArgDesc -> ArgDesc -> ArgDesc -> InstrDesc IDBrUncond :: ArgDesc -> InstrDesc IDSwitch :: [(ArgDesc, ArgDesc)] -> InstrDesc IDIndirectBr :: InstrDesc IDInvoke :: InstrDesc IDUnwind :: InstrDesc IDUnreachable :: InstrDesc IDBinOp :: BinOpDesc -> TypeDesc -> ArgDesc -> ArgDesc -> InstrDesc IDAlloca :: TypeDesc -> Int -> Int -> InstrDesc IDLoad :: TypeDesc -> ArgDesc -> InstrDesc IDStore :: TypeDesc -> ArgDesc -> ArgDesc -> InstrDesc IDGetElementPtr :: TypeDesc -> [ArgDesc] -> InstrDesc IDTrunc :: TypeDesc -> TypeDesc -> ArgDesc -> InstrDesc IDZExt :: TypeDesc -> TypeDesc -> ArgDesc -> InstrDesc IDSExt :: TypeDesc -> TypeDesc -> ArgDesc -> InstrDesc IDFPtoUI :: TypeDesc -> TypeDesc -> ArgDesc -> InstrDesc IDFPtoSI :: TypeDesc -> TypeDesc -> ArgDesc -> InstrDesc IDUItoFP :: TypeDesc -> TypeDesc -> ArgDesc -> InstrDesc IDSItoFP :: TypeDesc -> TypeDesc -> ArgDesc -> InstrDesc IDFPTrunc :: TypeDesc -> TypeDesc -> ArgDesc -> InstrDesc IDFPExt :: TypeDesc -> TypeDesc -> ArgDesc -> InstrDesc IDPtrToInt :: TypeDesc -> TypeDesc -> ArgDesc -> InstrDesc IDIntToPtr :: TypeDesc -> TypeDesc -> ArgDesc -> InstrDesc IDBitcast :: TypeDesc -> TypeDesc -> ArgDesc -> InstrDesc IDICmp :: IntPredicate -> ArgDesc -> ArgDesc -> InstrDesc IDFCmp :: FPPredicate -> ArgDesc -> ArgDesc -> InstrDesc IDPhi :: TypeDesc -> [(ArgDesc, ArgDesc)] -> InstrDesc IDCall :: TypeDesc -> ArgDesc -> [ArgDesc] -> InstrDesc IDSelect :: TypeDesc -> ArgDesc -> ArgDesc -> InstrDesc IDUserOp1 :: InstrDesc IDUserOp2 :: InstrDesc IDVAArg :: InstrDesc IDExtractElement :: InstrDesc IDInsertElement :: InstrDesc IDShuffleVector :: InstrDesc IDExtractValue :: InstrDesc IDInsertValue :: InstrDesc IDInvalidOp :: InstrDesc data ArgDesc AV :: String -> ArgDesc AI :: Int -> ArgDesc AL :: String -> ArgDesc AE :: ArgDesc getInstrDesc :: ValueRef -> IO (String, InstrDesc) -- | Return from the current function with the given value. Use () as the -- return value for what would be a void function in C. ret :: Ret a r => a -> CodeGenFunction r Terminate -- | Branch to the first basic block if the boolean is true, otherwise to -- the second basic block. condBr :: Value Bool -> BasicBlock -> BasicBlock -> CodeGenFunction r Terminate -- | Unconditionally branch to the given basic block. br :: BasicBlock -> CodeGenFunction r Terminate -- | Branch table instruction. switch :: IsInteger a => Value a -> BasicBlock -> [(ConstValue a, BasicBlock)] -> CodeGenFunction r Terminate -- | Call a function with exception handling. invoke :: CallArgs f g r => BasicBlock -> BasicBlock -> Function f -> g -- | Call a function with exception handling. This also sets the calling -- convention of the call to the function. As LLVM itself defines, if the -- calling conventions of the calling instruction and the function -- being called are different, undefined behavior results. invokeWithConv :: CallArgs f g r => CallingConvention -> BasicBlock -> BasicBlock -> Function f -> g invokeFromFunction :: BasicBlock -> BasicBlock -> Function f -> Call f invokeWithConvFromFunction :: CallingConvention -> BasicBlock -> BasicBlock -> Function f -> Call f -- | Inform the code generator that this code can never be reached. unreachable :: CodeGenFunction r Terminate add :: (ValueCons2 value0 value1, IsArithmetic a) => value0 a -> value1 a -> CodeGenFunction r (BinOpValue value0 value1 a) sub :: (ValueCons2 value0 value1, IsArithmetic a) => value0 a -> value1 a -> CodeGenFunction r (BinOpValue value0 value1 a) mul :: (ValueCons2 value0 value1, IsArithmetic a) => value0 a -> value1 a -> CodeGenFunction r (BinOpValue value0 value1 a) neg :: (ValueCons value, IsArithmetic a) => value a -> CodeGenFunction r (value a) iadd :: (ValueCons2 value0 value1, IsInteger a) => value0 a -> value1 a -> CodeGenFunction r (BinOpValue value0 value1 a) isub :: (ValueCons2 value0 value1, IsInteger a) => value0 a -> value1 a -> CodeGenFunction r (BinOpValue value0 value1 a) imul :: (ValueCons2 value0 value1, IsInteger a) => value0 a -> value1 a -> CodeGenFunction r (BinOpValue value0 value1 a) ineg :: (ValueCons value, IsInteger a) => value a -> CodeGenFunction r (value a) iaddNoWrap :: (ValueCons2 value0 value1, IsInteger a) => value0 a -> value1 a -> CodeGenFunction r (BinOpValue value0 value1 a) isubNoWrap :: (ValueCons2 value0 value1, IsInteger a) => value0 a -> value1 a -> CodeGenFunction r (BinOpValue value0 value1 a) imulNoWrap :: (ValueCons2 value0 value1, IsInteger a) => value0 a -> value1 a -> CodeGenFunction r (BinOpValue value0 value1 a) inegNoWrap :: (ValueCons value, IsInteger a) => value a -> CodeGenFunction r (value a) fadd :: (ValueCons2 value0 value1, IsFloating a) => value0 a -> value1 a -> CodeGenFunction r (BinOpValue value0 value1 a) fsub :: (ValueCons2 value0 value1, IsFloating a) => value0 a -> value1 a -> CodeGenFunction r (BinOpValue value0 value1 a) fmul :: (ValueCons2 value0 value1, IsFloating a) => value0 a -> value1 a -> CodeGenFunction r (BinOpValue value0 value1 a) fneg :: (ValueCons value, IsFloating a) => value a -> CodeGenFunction r (value a) -- | signed or unsigned integer division depending on the type idiv :: (ValueCons2 value0 value1, IsInteger a) => value0 a -> value1 a -> CodeGenFunction r (BinOpValue value0 value1 a) -- | signed or unsigned remainder depending on the type irem :: (ValueCons2 value0 value1, IsInteger a) => value0 a -> value1 a -> CodeGenFunction r (BinOpValue value0 value1 a) -- | Deprecated: use idiv instead udiv :: (ValueCons2 value0 value1, IsInteger a) => value0 a -> value1 a -> CodeGenFunction r (BinOpValue value0 value1 a) -- | Deprecated: use idiv instead sdiv :: (ValueCons2 value0 value1, IsInteger a) => value0 a -> value1 a -> CodeGenFunction r (BinOpValue value0 value1 a) -- | Floating point division. fdiv :: (ValueCons2 value0 value1, IsFloating a) => value0 a -> value1 a -> CodeGenFunction r (BinOpValue value0 value1 a) -- | Deprecated: use irem instead urem :: (ValueCons2 value0 value1, IsInteger a) => value0 a -> value1 a -> CodeGenFunction r (BinOpValue value0 value1 a) -- | Deprecated: use irem instead srem :: (ValueCons2 value0 value1, IsInteger a) => value0 a -> value1 a -> CodeGenFunction r (BinOpValue value0 value1 a) -- | Floating point remainder. frem :: (ValueCons2 value0 value1, IsFloating a) => value0 a -> value1 a -> CodeGenFunction r (BinOpValue value0 value1 a) shl :: (ValueCons2 value0 value1, IsInteger a) => value0 a -> value1 a -> CodeGenFunction r (BinOpValue value0 value1 a) shr :: (ValueCons2 value0 value1, IsInteger a) => value0 a -> value1 a -> CodeGenFunction r (BinOpValue value0 value1 a) lshr :: (ValueCons2 value0 value1, IsInteger a) => value0 a -> value1 a -> CodeGenFunction r (BinOpValue value0 value1 a) ashr :: (ValueCons2 value0 value1, IsInteger a) => value0 a -> value1 a -> CodeGenFunction r (BinOpValue value0 value1 a) and :: (ValueCons2 value0 value1, IsInteger a) => value0 a -> value1 a -> CodeGenFunction r (BinOpValue value0 value1 a) or :: (ValueCons2 value0 value1, IsInteger a) => value0 a -> value1 a -> CodeGenFunction r (BinOpValue value0 value1 a) xor :: (ValueCons2 value0 value1, IsInteger a) => value0 a -> value1 a -> CodeGenFunction r (BinOpValue value0 value1 a) inv :: (ValueCons value, IsInteger a) => value a -> CodeGenFunction r (value a) -- | Get a value from a vector. extractelement :: (Positive n, IsPrimitive a) => Value (Vector n a) -> Value Word32 -> CodeGenFunction r (Value a) -- | Insert a value into a vector, nondestructive. insertelement :: (Positive n, IsPrimitive a) => Value (Vector n a) -> Value a -> Value Word32 -> CodeGenFunction r (Value (Vector n a)) -- | Permute vector. shufflevector :: (Positive n, Positive m, IsPrimitive a) => Value (Vector n a) -> Value (Vector n a) -> ConstValue (Vector m Word32) -> CodeGenFunction r (Value (Vector m a)) -- | Get a value from an aggregate. extractvalue :: GetValue agg i => Value agg -> i -> CodeGenFunction r (Value (ValueType agg i)) -- | Insert a value into an aggregate, nondestructive. insertvalue :: GetValue agg i => Value agg -> Value (ValueType agg i) -> i -> CodeGenFunction r (Value agg) -- | Allocate heap memory. malloc :: IsSized a => CodeGenFunction r (Value (Ptr a)) -- | Allocate heap (array) memory. arrayMalloc :: (IsSized a, AllocArg s) => s -> CodeGenFunction r (Value (Ptr a)) -- | Allocate stack memory. alloca :: IsSized a => CodeGenFunction r (Value (Ptr a)) -- | Allocate stack (array) memory. arrayAlloca :: (IsSized a, AllocArg s) => s -> CodeGenFunction r (Value (Ptr a)) -- | Free heap memory. free :: IsType a => Value (Ptr a) -> CodeGenFunction r () -- | Load a value from memory. load :: Value (Ptr a) -> CodeGenFunction r (Value a) -- | Store a value in memory store :: Value a -> Value (Ptr a) -> CodeGenFunction r () -- | Address arithmetic. See LLVM description. The index is a nested tuple -- of the form (i1,(i2,( ... ()))). (This is without a doubt the -- most confusing LLVM instruction, but the types help.) getElementPtr :: (GetElementPtr o i, IsIndexArg a) => Value (Ptr o) -> (a, i) -> CodeGenFunction r (Value (Ptr (ElementPtrType o i))) -- | Like getElementPtr, but with an initial index that is 0. This is -- useful since any pointer first need to be indexed off the pointer, and -- then into its actual value. This first indexing is often with 0. getElementPtr0 :: GetElementPtr o i => Value (Ptr o) -> i -> CodeGenFunction r (Value (Ptr (ElementPtrType o i))) class ValueCons value -- | Truncate a value to a shorter bit width. trunc :: (ValueCons value, IsInteger a, IsInteger b, ShapeOf a ~ ShapeOf b, IsSized a, IsSized b, SizeOf a :>: SizeOf b) => value a -> CodeGenFunction r (value b) -- | Zero extend a value to a wider width. If possible, use ext that -- chooses the right padding according to the types zext :: (ValueCons value, IsInteger a, IsInteger b, ShapeOf a ~ ShapeOf b, IsSized a, IsSized b, SizeOf a :<: SizeOf b) => value a -> CodeGenFunction r (value b) -- | Sign extend a value to wider width. If possible, use ext that -- chooses the right padding according to the types sext :: (ValueCons value, IsInteger a, IsInteger b, ShapeOf a ~ ShapeOf b, IsSized a, IsSized b, SizeOf a :<: SizeOf b) => value a -> CodeGenFunction r (value b) -- | Extend a value to wider width. If the target type is signed, then -- preserve the sign, If the target type is unsigned, then extended by -- zeros. ext :: (ValueCons value, IsInteger a, IsInteger b, ShapeOf a ~ ShapeOf b, Signed a ~ Signed b, IsSized a, IsSized b, SizeOf a :<: SizeOf b) => value a -> CodeGenFunction r (value b) -- | It is zext, trunc or nop depending on the relation of -- the sizes. zadapt :: (ValueCons value, IsInteger a, IsInteger b, ShapeOf a ~ ShapeOf b) => value a -> CodeGenFunction r (value b) -- | It is sext, trunc or nop depending on the relation of -- the sizes. sadapt :: (ValueCons value, IsInteger a, IsInteger b, ShapeOf a ~ ShapeOf b) => value a -> CodeGenFunction r (value b) -- | It is sadapt or zadapt depending on the sign mode. adapt :: (ValueCons value, IsInteger a, IsInteger b, ShapeOf a ~ ShapeOf b, Signed a ~ Signed b) => value a -> CodeGenFunction r (value b) -- | Truncate a floating point value. fptrunc :: (ValueCons value, IsFloating a, IsFloating b, ShapeOf a ~ ShapeOf b, IsSized a, IsSized b, SizeOf a :>: SizeOf b) => value a -> CodeGenFunction r (value b) -- | Extend a floating point value. fpext :: (ValueCons value, IsFloating a, IsFloating b, ShapeOf a ~ ShapeOf b, IsSized a, IsSized b, SizeOf a :<: SizeOf b) => value a -> CodeGenFunction r (value b) -- | Convert a floating point value to an unsigned integer. -- | Deprecated: use fptoint since it is type-safe with respect to -- signs fptoui :: (ValueCons value, IsFloating a, IsInteger b, ShapeOf a ~ ShapeOf b) => value a -> CodeGenFunction r (value b) -- | Convert a floating point value to a signed integer. -- | Deprecated: use fptoint since it is type-safe with respect to -- signs fptosi :: (ValueCons value, IsFloating a, IsInteger b, ShapeOf a ~ ShapeOf b) => value a -> CodeGenFunction r (value b) -- | Convert a floating point value to an integer. It is mapped to -- fptosi or fptoui depending on the type a. fptoint :: (ValueCons value, IsFloating a, IsInteger b, ShapeOf a ~ ShapeOf b) => value a -> CodeGenFunction r (value b) -- | Convert an unsigned integer to a floating point value. Although -- inttofp should be prefered, this function may be useful for -- conversion from Bool. uitofp :: (ValueCons value, IsInteger a, IsFloating b, ShapeOf a ~ ShapeOf b) => value a -> CodeGenFunction r (value b) -- | Convert a signed integer to a floating point value. Although -- inttofp should be prefered, this function may be useful for -- conversion from Bool. sitofp :: (ValueCons value, IsInteger a, IsFloating b, ShapeOf a ~ ShapeOf b) => value a -> CodeGenFunction r (value b) -- | Convert an integer to a floating point value. It is mapped to -- sitofp or uitofp depending on the type a. inttofp :: (ValueCons value, IsInteger a, IsFloating b, ShapeOf a ~ ShapeOf b) => value a -> CodeGenFunction r (value b) -- | Convert a pointer to an integer. ptrtoint :: (ValueCons value, IsInteger b, IsPrimitive b) => value (Ptr a) -> CodeGenFunction r (value b) -- | Convert an integer to a pointer. inttoptr :: (ValueCons value, IsInteger a, IsType b) => value a -> CodeGenFunction r (value (Ptr b)) -- | Convert between to values of the same size by just copying the bit -- pattern. bitcast :: (ValueCons value, IsFirstClass a, IsFirstClass b, IsSized a, IsSized b, SizeOf a ~ SizeOf b) => value a -> CodeGenFunction r (value b) data CmpPredicate -- | equal CmpEQ :: CmpPredicate -- | not equal CmpNE :: CmpPredicate -- | greater than CmpGT :: CmpPredicate -- | greater or equal CmpGE :: CmpPredicate -- | less than CmpLT :: CmpPredicate -- | less or equal CmpLE :: CmpPredicate data IntPredicate -- | equal IntEQ :: IntPredicate -- | not equal IntNE :: IntPredicate -- | unsigned greater than IntUGT :: IntPredicate -- | unsigned greater or equal IntUGE :: IntPredicate -- | unsigned less than IntULT :: IntPredicate -- | unsigned less or equal IntULE :: IntPredicate -- | signed greater than IntSGT :: IntPredicate -- | signed greater or equal IntSGE :: IntPredicate -- | signed less than IntSLT :: IntPredicate -- | signed less or equal IntSLE :: IntPredicate data FPPredicate -- | Always false (always folded) FPFalse :: FPPredicate -- | True if ordered and equal FPOEQ :: FPPredicate -- | True if ordered and greater than FPOGT :: FPPredicate -- | True if ordered and greater than or equal FPOGE :: FPPredicate -- | True if ordered and less than FPOLT :: FPPredicate -- | True if ordered and less than or equal FPOLE :: FPPredicate -- | True if ordered and operands are unequal FPONE :: FPPredicate -- | True if ordered (no nans) FPORD :: FPPredicate -- | True if unordered: isnan(X) | isnan(Y) FPUNO :: FPPredicate -- | True if unordered or equal FPUEQ :: FPPredicate -- | True if unordered or greater than FPUGT :: FPPredicate -- | True if unordered, greater than, or equal FPUGE :: FPPredicate -- | True if unordered or less than FPULT :: FPPredicate -- | True if unordered, less than, or equal FPULE :: FPPredicate -- | True if unordered or not equal FPUNE :: FPPredicate -- | Always true (always folded) FPTrue :: FPPredicate class IsFirstClass c => CmpRet c type CmpResult c = ShapedType (ShapeOf c) Bool type CmpValueResult value0 value1 a = BinOpValue value0 value1 (CmpResult a) -- | Compare values of ordered types and choose predicates according to the -- compared types. Floating point numbers are compared in "ordered" mode, -- that is NaN operands yields False as result. Pointers -- are compared unsigned. These choices are consistent with comparison in -- plain Haskell. cmp :: (ValueCons2 value0 value1, CmpRet a) => CmpPredicate -> value0 a -> value1 a -> CodeGenFunction r (CmpValueResult value0 value1 a) pcmp :: (ValueCons2 value0 value1, IsType a) => IntPredicate -> value0 (Ptr a) -> value1 (Ptr a) -> CodeGenFunction r (BinOpValue value0 value1 (Ptr a)) -- | Compare integers. -- | Deprecated: use cmp or pcmp instead icmp :: (ValueCons2 value0 value1, CmpRet a, IsIntegerOrPointer a) => IntPredicate -> value0 a -> value1 a -> CodeGenFunction r (CmpValueResult value0 value1 a) -- | Compare floating point values. fcmp :: (ValueCons2 value0 value1, CmpRet a, IsFloating a) => FPPredicate -> value0 a -> value1 a -> CodeGenFunction r (CmpValueResult value0 value1 a) -- | Select between two values depending on a boolean. select :: CmpRet a => Value (CmpResult a) -> Value a -> Value a -> CodeGenFunction r (Value a) setHasNoNaNs :: IsFloating a => Bool -> Value a -> CodeGenFunction r () setHasNoInfs :: IsFloating a => Bool -> Value a -> CodeGenFunction r () setHasNoSignedZeros :: IsFloating a => Bool -> Value a -> CodeGenFunction r () setHasAllowReciprocal :: IsFloating a => Bool -> Value a -> CodeGenFunction r () setFastMath :: IsFloating a => Bool -> Value a -> CodeGenFunction r () -- | Join several variables (virtual registers) from different basic blocks -- into one. All of the variables in the list are joined. See also -- addPhiInputs. phi :: IsFirstClass a => [(Value a, BasicBlock)] -> CodeGenFunction r (Value a) -- | Add additional inputs to an existing phi node. The reason for this -- instruction is that sometimes the structure of the code makes it -- impossible to have all variables in scope at the point where you need -- the phi node. addPhiInputs :: IsFirstClass a => Value a -> [(Value a, BasicBlock)] -> CodeGenFunction r () -- | Call a function with the given arguments. The call instruction -- is variadic, i.e., the number of arguments it takes depends on the -- type of f. call :: CallArgs f g r => Function f -> g -- | Call a function with the given arguments. The call instruction -- is variadic, i.e., the number of arguments it takes depends on the -- type of f. This also sets the calling convention of the call to -- the function. As LLVM itself defines, if the calling conventions of -- the calling instruction and the function being called -- are different, undefined behavior results. callWithConv :: CallArgs f g r => CallingConvention -> Function f -> g callFromFunction :: Function a -> Call a callWithConvFromFunction :: CallingConvention -> Function f -> Call f data Call a applyCall :: Call (a -> b) -> Value a -> Call b runCall :: Call (IO a) -> CodeGenFunction r (Value a) class (ValueCons value0, ValueCons value1) => ValueCons2 value0 value1 where type family BinOpValue (value0 :: * -> *) (value1 :: * -> *) :: * -> * type Terminate = () -- | Acceptable arguments to the ret instruction. class Ret a r -- | Acceptable arguments to call. class (f ~ CalledFunction g, r ~ CallerResult g, g ~ CallerFunction f r) => CallArgs f g r class IsConst a class IsFunction f => FunctionArgs f where type family FunctionCodeGen f :: * type family FunctionResult f :: * -- | Acceptable argument to array memory allocation. class AllocArg a -- | Acceptable arguments to getElementPointer. class GetElementPtr optr ixs where type family ElementPtrType optr ixs :: * -- | Acceptable single index to getElementPointer. class IsIndexArg a -- | In principle we do not need the getValueArg method, because we could -- just use unValue. However, we want to prevent users from -- defining their own (disfunctional) IsIndexType instances. class IsPrimitive i => IsIndexType i -- | Acceptable arguments to extractvalue and insertvalue. class GetValue agg ix where type family ValueType agg ix :: * class GetField as i where type family FieldType as i :: * -- | The IsType class classifies all types that have an LLVM -- representation. class IsType a typeDesc :: IsType a => Proxy a -> TypeDesc class Integer n => Natural n class Natural n => Positive n -- | Arithmetic types, i.e., integral and floating types. class IsFirstClass a => IsArithmetic a arithmeticType :: IsArithmetic a => ArithmeticType a data ArithmeticType a IntegerType :: ArithmeticType a FloatingType :: ArithmeticType a -- | Integral types. class (IsArithmetic a, IsIntegerOrPointer a) => IsInteger a where type family Signed a :: * -- | Integral or pointer type. class IsIntegerOrPointer a -- | Floating types. class IsArithmetic a => IsFloating a -- | Primitive types. class (IsType a) => IsPrimitive a class (IsScalarOrVector a, ShapeOf a ~ ScalarShape) => IsPrimitive a -- | First class types, i.e., the types that can be passed as arguments, -- etc. class IsType a => IsFirstClass a -- | Types with a fixed size. class (IsType a, Natural (SizeOf a)) => IsSized a where type family SizeOf a :: * sizeOf :: TypeDesc -> Integer -- | Function type. class IsType a => IsFunction a -- | Number of elements for instructions that handle both primitive and -- vector types class IsFirstClass a => IsScalarOrVector a where type family ShapeOf a :: * data ScalarShape data VectorShape n class Shape shape where type family ShapedType shape a :: * class StructFields as type UnknownSize = D99 type :& a as = (a, as) (&) :: a -> as -> a :& as -- | Type descriptor, used to convey type information through the LLVM API. data TypeDesc TDFloat :: TypeDesc TDDouble :: TypeDesc TDFP128 :: TypeDesc TDVoid :: TypeDesc TDInt :: Bool -> Integer -> TypeDesc TDArray :: Integer -> TypeDesc -> TypeDesc TDVector :: Integer -> TypeDesc -> TypeDesc TDPtr :: TypeDesc -> TypeDesc TDFunction :: Bool -> [TypeDesc] -> TypeDesc -> TypeDesc TDLabel :: TypeDesc TDStruct :: [TypeDesc] -> Bool -> TypeDesc TDInvalidType :: TypeDesc isFloating :: IsArithmetic a => Proxy a -> Bool isSigned :: IsArithmetic a => Proxy a -> Bool typeRef :: IsType a => Proxy a -> IO TypeRef unsafeTypeRef :: IsType a => Proxy a -> TypeRef typeName :: IsType a => Proxy a -> String intrinsicTypeName :: IsType a => Proxy a -> String typeDesc2 :: TypeRef -> IO TypeDesc -- | The VarArgs type is a placeholder for the real IO type -- that can be obtained with castVarArgs. data VarArgs a -- | Define what vararg types are permissible. class CastVarArgs a b -- | Variable sized signed integer. The n parameter should belong to -- PosI. newtype IntN n IntN :: Integer -> IntN n -- | Variable sized unsigned integer. The n parameter should belong -- to PosI. newtype WordN n WordN :: Integer -> WordN n -- | 128 bit floating point. newtype FP128 FP128 :: Rational -> FP128 -- | Fixed sized arrays, the array size is encoded in the n -- parameter. newtype Array n a Array :: [a] -> Array n a -- | Fixed sized vector, the array size is encoded in the n -- parameter. newtype Vector n a Vector :: (FixedList (ToUnary n) a) -> Vector n a -- | Label type, produced by a basic block. data Label -- | Struct types; a list (nested tuple) of component types. newtype Struct a Struct :: a -> Struct a newtype PackedStruct a PackedStruct :: a -> PackedStruct a type FixedList n = List n data Value a data ConstValue a valueOf :: IsConst a => a -> Value a value :: ConstValue a -> Value a zero :: IsType a => ConstValue a allOnes :: IsInteger a => ConstValue a undef :: IsType a => ConstValue a createString :: String -> TGlobal (Array n Word8) createStringNul :: String -> TGlobal (Array n Word8) withString :: String -> (forall n. Natural n => Global (Array n Word8) -> CodeGenModule a) -> CodeGenModule a withStringNul :: String -> (forall n. Natural n => Global (Array n Word8) -> CodeGenModule a) -> CodeGenModule a -- | Make a constant vector. constVector :: (Positive n, ToUnary n ~ u, Length (FixedList u) ~ u) => FixedList u (ConstValue a) -> ConstValue (Vector n a) constArray :: (IsSized a, Natural n) => [ConstValue a] -> ConstValue (Array n a) -- | Make a constant vector. Replicates or truncates the list to get length -- n. constCyclicVector :: Positive n => T [] (ConstValue a) -> ConstValue (Vector n a) -- | Make a constant array. Replicates or truncates the list to get length -- n. constCyclicArray :: (IsSized a, Natural n) => T [] (ConstValue a) -> ConstValue (Vector n a) -- | Make a constant struct. constStruct :: IsConstStruct c => c -> ConstValue (Struct (ConstStructOf c)) -- | Make a constant packed struct. constPackedStruct :: IsConstStruct c => c -> ConstValue (PackedStruct (ConstStructOf c)) toVector :: MkVector n a => Tuple n a -> Vector n a fromVector :: MkVector n a => Vector n a -> Tuple n a vector :: Positive n => FixedList (ToUnary n) a -> Vector n a -- | Make a constant vector. Replicates or truncates the list to get length -- n. This behaviour is consistent uncurry that of -- constCyclicVector. May be abused for constructing vectors from -- lists uncurry statically unknown size. cyclicVector :: Positive n => T [] a -> Vector n a data CodeGenFunction r a data CodeGenModule a -- | A function is simply a pointer to the function. type Function a = Value (FunPtr a) -- | Create a new function. Use newNamedFunction to create a -- function with external linkage, since it needs a known name. newFunction :: IsFunction a => Linkage -> CodeGenModule (Function a) -- | Create a new named function. newNamedFunction :: IsFunction a => Linkage -> String -> CodeGenModule (Function a) -- | Define a function body. The basic block returned by the function is -- the function entry point. defineFunction :: FunctionArgs f => Function f -> FunctionCodeGen f -> CodeGenModule () -- | Create a new function with the given body. createFunction :: FunctionArgs f => Linkage -> FunctionCodeGen f -> CodeGenModule (Function f) -- | Create a new function with the given body. createNamedFunction :: FunctionArgs f => Linkage -> String -> FunctionCodeGen f -> CodeGenModule (Function f) -- | Set the calling convention of a function. By default it is the C -- calling convention. setFuncCallConv :: Function a -> CallingConvention -> CodeGenModule () type TFunction a = CodeGenModule (Function a) -- | Allows you to define part of a module while in the middle of defining -- a function. liftCodeGenModule :: CodeGenModule a -> CodeGenFunction r a getParams :: Value -> IO [(String, Value)] type Global a = Value (Ptr a) -- | Create a new global variable. newGlobal :: IsType a => Bool -> Linkage -> TGlobal a -- | Create a new named global variable. newNamedGlobal :: IsType a => Bool -> Linkage -> String -> TGlobal a -- | Give a global variable a (constant) value. defineGlobal :: Global a -> ConstValue a -> CodeGenModule () -- | Create and define a global variable. createGlobal :: IsType a => Bool -> Linkage -> ConstValue a -> TGlobal a -- | Create and define a named global variable. createNamedGlobal :: IsType a => Bool -> Linkage -> String -> ConstValue a -> TGlobal a -- | Create a reference to an external function while code generating for a -- function. If LLVM cannot resolve its name, then you may try -- staticFunction. externFunction :: IsFunction a => String -> CodeGenFunction r (Function a) -- | Make an external C function with a fixed address callable from LLVM -- code. This callback function can also be a Haskell function, that was -- imported like -- --
-- foreign import ccall "&nextElement" -- nextElementFunPtr :: FunPtr (StablePtr (IORef [Word32]) -> IO Word32) ---- -- See examples/List.hs. -- -- When you only use externFunction, then LLVM cannot resolve the -- name. (However, I do not know why.) Thus staticFunction manages -- a list of static functions. This list is automatically installed by -- simpleFunction and can be manually obtained by -- getGlobalMappings and installed by addGlobalMappings. -- "Installing" means calling LLVM's addGlobalMapping according -- to -- http://old.nabble.com/jit-with-external-functions-td7769793.html. staticFunction :: IsFunction f => FunPtr f -> CodeGenFunction r (Function f) -- | Due to https://llvm.org/bugs/show_bug.cgi?id=20656 this will -- fail with MCJIT of LLVM-3.6. staticNamedFunction :: IsFunction f => String -> FunPtr f -> CodeGenFunction r (Function f) -- | As externFunction, but for Globals rather than -- Functions externGlobal :: IsType a => Bool -> String -> CodeGenFunction r (Global a) -- | As staticFunction, but for Globals rather than -- Functions staticGlobal :: IsType a => Bool -> Ptr a -> CodeGenFunction r (Global a) data GlobalMappings -- | Get a list created by calls to staticFunction that must be -- passed to the execution engine via addGlobalMappings. getGlobalMappings :: CodeGenModule GlobalMappings type TGlobal a = CodeGenModule (Global a) -- | An enumeration for the kinds of linkage for global values. data Linkage :: * -- | Externally visible function ExternalLinkage :: Linkage AvailableExternallyLinkage :: Linkage -- | Keep one copy of function when linking (inline) LinkOnceAnyLinkage :: Linkage -- | Same, but only replaced by something equivalent. LinkOnceODRLinkage :: Linkage -- | Like LinkOnceODR, but possibly hidden. LinkOnceODRAutoHideLinkage :: Linkage -- | Keep one copy of named function when linking (weak) WeakAnyLinkage :: Linkage -- | Same, but only replaced by something equivalent. WeakODRLinkage :: Linkage -- | Special purpose, only applies to global arrays AppendingLinkage :: Linkage -- | Rename collisions when linking (static functions) InternalLinkage :: Linkage -- | Like Internal, but omit from symbol table PrivateLinkage :: Linkage -- | Function to be imported from DLL DLLImportLinkage :: Linkage -- | Function to be accessible from DLL DLLExportLinkage :: Linkage -- | ExternalWeak linkage description ExternalWeakLinkage :: Linkage -- | Stand-in functions for streaming fns from BC files GhostLinkage :: Linkage -- | Tentative definitions CommonLinkage :: Linkage -- | Like Private, but linker removes. LinkerPrivateLinkage :: Linkage -- | Like LinkerPrivate, but is weak. LinkerPrivateWeakLinkage :: Linkage -- | A basic block is a sequence of non-branching instructions, terminated -- by a control flow instruction. data BasicBlock newBasicBlock :: CodeGenFunction r BasicBlock newNamedBasicBlock :: String -> CodeGenFunction r BasicBlock defineBasicBlock :: BasicBlock -> CodeGenFunction r () createBasicBlock :: CodeGenFunction r BasicBlock getCurrentBasicBlock :: CodeGenFunction r BasicBlock getBasicBlocks :: Value -> IO [(String, BasicBlock)] fromLabel :: Value Label -> BasicBlock toLabel :: BasicBlock -> Value Label getInstructions :: BasicBlock -> IO [(String, Value)] getOperands :: Value -> IO [(String, Value)] hasUsers :: Value -> IO Bool getUsers :: [Use] -> IO [(String, Value)] getUses :: Value -> IO [Use] getUser :: Use -> IO Value isChildOf :: BasicBlock -> Value -> IO Bool getDep :: Use -> IO (String, String) -- | Add attributes to a value. Beware, what attributes are allowed depends -- on what kind of value it is. addAttributes :: Value a -> AttributeIndex -> [Attribute] -> CodeGenFunction r () data Attribute newtype AttributeIndex :: * AttributeIndex :: Word32 -> AttributeIndex attributeReturnIndex :: AttributeIndex attributeFunctionIndex :: AttributeIndex -- | Convert a varargs function to a regular function. castVarArgs :: CastVarArgs a b => Function a -> Function b -- | Print a value. dumpValue :: Value a -> IO () -- | Print a type. dumpType :: Value a -> IO () -- | Get the name of a Value. getValueName :: Value a -> IO String annotateValueList :: [Value] -> IO [(String, Value)] -- | An ExecutionEngine is JIT compiler that is used to generate -- code for an LLVM module. module LLVM.ExecutionEngine data EngineAccess a data ExecutionEngine getEngine :: EngineAccess ExecutionEngine -- | The LLVM execution engine is encapsulated so it cannot be accessed -- directly. The reason is that (currently) there must only ever be one -- engine, so access to it is wrapped in a monad. runEngineAccess :: EngineAccess a -> IO a runEngineAccessWithModule :: Module -> EngineAccess a -> IO a addModule :: Module -> EngineAccess () class ExecutionFunction f getExecutionFunction :: ExecutionFunction f => (FunPtr f -> f) -> Function f -> EngineAccess f -- | In contrast to generateFunction this compiles a function -- once. Thus it is faster for many calls to the same function. See -- examples/Vector.hs. -- -- If the function calls back into Haskell code, you also have to set the -- function addresses using addFunctionValue or -- addGlobalMappings. -- -- You must keep the execution engine alive as long as you want to call -- the function. Better use getExecutionFunction which handles -- this for you. getPointerToFunction :: Function f -> EngineAccess (FunPtr f) -- | Tell LLVM the address of an external function if it cannot resolve a -- name automatically. Alternatively you may declare the function with -- staticFunction instead of externFunction. addFunctionValue :: Function f -> FunPtr f -> EngineAccess () -- | Pass a list of global mappings to LLVM that can be obtained from -- getGlobalMappings. addGlobalMappings :: GlobalMappings -> EngineAccess () -- | Class of LLVM function types that can be translated to the -- corresponding Haskell type. class Translatable f class Generic a -- | Generate a Haskell function from an LLVM function. -- -- Note that the function is compiled for every call (Just-In-Time -- compilation). If you want to compile the function once and call it a -- lot of times then you should better use getPointerToFunction. generateFunction :: Translatable f => Function f -> EngineAccess f class Unsafe a unsafeRemoveIO :: Unsafe a => a -> RemoveIO a -- | Translate a function to Haskell code. This is a simplified interface -- to the execution engine and module mechanism. It is based on -- generateFunction, so see there for limitations. simpleFunction :: Translatable f => CodeGenModule (Function f) -> IO f -- | Combine simpleFunction and unsafeRemoveIO. unsafeGenerateFunction :: (Unsafe t, Translatable t) => CodeGenModule (Function t) -> RemoveIO t data TargetData TargetData :: (Type -> Int) -> (Type -> Int) -> Bool -> (Type -> Int) -> Type -> Int -> (Type -> Int) -> (Type -> Int) -> (Type -> Int) -> TargetData abiAlignmentOfType :: TargetData -> Type -> Int abiSizeOfType :: TargetData -> Type -> Int littleEndian :: TargetData -> Bool callFrameAlignmentOfType :: TargetData -> Type -> Int intPtrType :: TargetData -> Type pointerSize :: TargetData -> Int preferredAlignmentOfType :: TargetData -> Type -> Int sizeOfTypeInBits :: TargetData -> Type -> Int storeSizeOfType :: TargetData -> Type -> Int getTargetData :: IO TargetData targetDataFromString :: String -> TargetData withIntPtrType :: (forall n. Positive n => WordN n -> a) -> a instance Unsafe (IO a) instance Unsafe b => Unsafe (a -> b) instance Generic a => Translatable (IO a) instance (Generic a, Translatable b) => Translatable (a -> b) module LLVM.Util.Intrinsic min :: IsArithmetic a => Value a -> Value a -> CodeGenFunction r (Value a) max :: IsArithmetic a => Value a -> Value a -> CodeGenFunction r (Value a) abs :: IsArithmetic a => Value a -> CodeGenFunction r (Value a) truncate :: IsFloating a => Value a -> CodeGenFunction r (Value a) floor :: IsFloating a => Value a -> CodeGenFunction r (Value a) -- | Available since LLVM-8. maybeUAddSat :: IsInteger a => Maybe (Value a -> Value a -> CodeGenFunction r (Value a)) -- | Available since LLVM-8. maybeSAddSat :: IsInteger a => Maybe (Value a -> Value a -> CodeGenFunction r (Value a)) -- | Available since LLVM-8. maybeUSubSat :: IsInteger a => Maybe (Value a -> Value a -> CodeGenFunction r (Value a)) -- | Available since LLVM-8. maybeSSubSat :: IsInteger a => Maybe (Value a -> Value a -> CodeGenFunction r (Value a)) call1 :: IsFirstClass a => String -> Value a -> CodeGenFunction r (Value a) call2 :: IsFirstClass a => String -> Value a -> Value a -> CodeGenFunction r (Value a) module LLVM.Util.Loop class Phi a phis :: Phi a => BasicBlock -> a -> CodeGenFunction r a addPhis :: Phi a => BasicBlock -> a -> a -> CodeGenFunction r () forLoop :: (Phi a, Num i, IsConst i, IsInteger i, IsFirstClass i, CmpRet i, CmpResult i ~ Bool) => Value i -> Value i -> a -> (Value i -> a -> CodeGenFunction r a) -> CodeGenFunction r a mapVector :: (Positive n, IsPrimitive a, IsPrimitive b) => (Value a -> CodeGenFunction r (Value b)) -> Value (Vector n a) -> CodeGenFunction r (Value (Vector n b)) mapVector2 :: (Positive n, IsPrimitive a, IsPrimitive b, IsPrimitive c) => (Value a -> Value b -> CodeGenFunction r (Value c)) -> Value (Vector n a) -> Value (Vector n b) -> CodeGenFunction r (Value (Vector n c)) instance (Phi a, Phi b, Phi c) => Phi (a, b, c) instance (Phi a, Phi b) => Phi (a, b) instance IsFirstClass a => Phi (Value a) instance Phi () module LLVM.Util.Arithmetic -- | Synonym for CodeGenFunction r (Value a). type TValue r a = CodeGenFunction r (Value a) -- | Comparison functions. (%==) :: CmpRet a => TValue r a -> TValue r a -> TValue r (CmpResult a) -- | Comparison functions. (%/=) :: CmpRet a => TValue r a -> TValue r a -> TValue r (CmpResult a) -- | Comparison functions. (%<) :: CmpRet a => TValue r a -> TValue r a -> TValue r (CmpResult a) -- | Comparison functions. (%<=) :: CmpRet a => TValue r a -> TValue r a -> TValue r (CmpResult a) -- | Comparison functions. (%>) :: CmpRet a => TValue r a -> TValue r a -> TValue r (CmpResult a) -- | Comparison functions. (%>=) :: CmpRet a => TValue r a -> TValue r a -> TValue r (CmpResult a) -- | Lazy and. (%&&) :: TValue r Bool -> TValue r Bool -> TValue r Bool -- | Lazy or. (%||) :: TValue r Bool -> TValue r Bool -> TValue r Bool -- | Conditional, returns first element of the pair when condition is true, -- otherwise second. (?) :: IsFirstClass a => TValue r Bool -> (TValue r a, TValue r a) -> TValue r a (??) :: (IsFirstClass a, CmpRet a) => TValue r (CmpResult a) -> (TValue r a, TValue r a) -> TValue r a -- | Return a value from an arithFunction. retrn :: Ret (Value a) r => TValue r a -> CodeGenFunction r () -- | Use x <- set $ ... to make a binding. set :: TValue r a -> CodeGenFunction r (TValue r a) class ArithFunction r z a b | a -> b r z, b r z -> a -- | Unlift a function with TValue to have Value -- arguments. arithFunction :: ArithFunction r z a b => a -> b class ToArithFunction r a b | a r -> b, b -> a r -- | Lift a function from having Value arguments to having -- TValue arguments. toArithFunction :: ToArithFunction r f g => Function f -> g -- | Define a recursive arithFunction, gets passed itself as the -- first argument. recursiveFunction :: (IsFunction f, FunctionArgs f, code ~ FunctionCodeGen f, ArithFunction r1 z arith code, ToArithFunction r0 f g) => (g -> arith) -> CodeGenModule (Function f) class CallIntrinsic a instance (Positive n, IsPrimitive a, CallIntrinsic a) => CallIntrinsic (Vector n a) instance CallIntrinsic Double instance CallIntrinsic Float instance ToArithFunction r b0 b1 => ToArithFunction r (a -> b0) (CodeGenFunction r (Value a) -> b1) instance ToArithFunction r (IO b) (CodeGenFunction r (Value b)) instance ArithFunction r z b0 b1 => ArithFunction r z (CodeGenFunction r a -> b0) (a -> b1) instance Ret a r => ArithFunction r a (CodeGenFunction r a) (CodeGenFunction r ()) instance (CmpRet a, CallIntrinsic a, RealFloat a, IsConst a, IsFloating a) => RealFloat (TValue r a) instance (CmpRet a, CallIntrinsic a, Floating a, IsConst a, IsFloating a) => Floating (TValue r a) instance (CmpRet a, Fractional a, IsConst a, IsFloating a) => RealFrac (TValue r a) instance (CmpRet a, Fractional a, IsConst a, IsFloating a) => Fractional (TValue r a) instance (CmpRet a, Num a, IsConst a, IsInteger a) => Integral (TValue r a) instance (IsArithmetic a, CmpRet a, Num a, IsConst a) => Real (TValue r a) instance (IsArithmetic a, CmpRet a, Num a, IsConst a) => Enum (TValue r a) instance (IsArithmetic a, CmpRet a, Num a, IsConst a) => Num (TValue r a) instance Ord (TValue r a) instance Eq (TValue r a) module LLVM.Util.File writeCodeGenModule :: FilePath -> CodeGenModule a -> IO () module LLVM.Util.Memory memcpy :: IsLengthType len => CodeGenModule (Value (Ptr Word8) -> Value (Ptr Word8) -> Value len -> Value Word32 -> Value Bool -> CodeGenFunction r ()) memmove :: IsLengthType len => CodeGenModule (Value (Ptr Word8) -> Value (Ptr Word8) -> Value len -> Value Word32 -> Value Bool -> CodeGenFunction r ()) memset :: IsLengthType len => CodeGenModule (Value (Ptr Word8) -> Value Word8 -> Value len -> Value Word32 -> Value Bool -> CodeGenFunction r ()) class IsFirstClass len => IsLengthType len instance IsLengthType Word64 instance IsLengthType Word32