module LLVM.Core.Type(
IsType(..),
IsArithmetic(..),
IsInteger(..),
IsFloating,
IsPrimitive,
IsFirstClass,
IsSized,
IsFunction,
IsSequence,
IsPowerOf2
) where
import Data.Int
import Data.Word
import Data.TypeNumbers
import LLVM.Core.Util(functionType)
import LLVM.Core.Data
import qualified LLVM.FFI.Core as FFI
class (IsTypeNumber n) => IsPowerOf2 n
instance IsPowerOf2 (D1 End)
instance IsPowerOf2 (D2 End)
instance IsPowerOf2 (D4 End)
instance IsPowerOf2 (D8 End)
instance IsPowerOf2 (D1 (D6 End))
instance IsPowerOf2 (D3 (D2 End))
instance IsPowerOf2 (D6 (D4 End))
instance IsPowerOf2 (D1 (D2 (D8 End)))
instance IsPowerOf2 (D2 (D5 (D6 End)))
instance IsPowerOf2 (D5 (D1 (D2 End)))
class IsType a where
typeRef :: a -> FFI.TypeRef
class IsType a => IsArithmetic a where
isFloating :: a -> Bool
isFloating _ = False
class IsArithmetic a => IsInteger a where
isSigned :: a -> Bool
class IsArithmetic a => IsFloating a
class IsType a => IsPrimitive a
class IsType a => IsFirstClass a
class IsSequence c where dummy__ :: c a -> a; dummy__ = undefined
class (IsType a) => IsSized a
class (IsType a) => IsFunction a where
funcType :: [FFI.TypeRef] -> a -> FFI.TypeRef
instance IsType Float where typeRef _ = FFI.floatType
instance IsType Double where typeRef _ = FFI.doubleType
instance IsType FP128 where typeRef _ = FFI.fp128Type
instance IsType () where typeRef _ = FFI.voidType
instance (IsTypeNumber n) => IsType (IntN n)
where typeRef _ = FFI.integerType (typeNumber (undefined :: n))
instance (IsTypeNumber n) => IsType (WordN n)
where typeRef _ = FFI.integerType (typeNumber (undefined :: n))
instance IsType Bool where typeRef _ = FFI.int1Type
instance IsType Word8 where typeRef _ = FFI.int8Type
instance IsType Word16 where typeRef _ = FFI.int16Type
instance IsType Word32 where typeRef _ = FFI.int32Type
instance IsType Word64 where typeRef _ = FFI.int64Type
instance IsType Int8 where typeRef _ = FFI.int8Type
instance IsType Int16 where typeRef _ = FFI.int16Type
instance IsType Int32 where typeRef _ = FFI.int32Type
instance IsType Int64 where typeRef _ = FFI.int64Type
instance (IsTypeNumber n, IsSized a) => IsType (Array n a)
where typeRef _ = FFI.arrayType (typeRef (undefined :: a))
(typeNumber (undefined :: n))
instance (IsPowerOf2 n, IsPrimitive a) => IsType (Vector n a)
where typeRef _ = FFI.vectorType (typeRef (undefined :: a))
(typeNumber (undefined :: n))
instance (IsType a) => IsType (Ptr a) where
typeRef _ = FFI.pointerType (typeRef (undefined :: a)) 0
instance (IsFirstClass a, IsFunction b) => IsType (a->b) where
typeRef = funcType []
instance (IsFirstClass a) => IsType (IO a) where
typeRef = funcType []
instance IsArithmetic Float where isFloating _ = True
instance IsArithmetic Double where isFloating _ = True
instance IsArithmetic FP128 where isFloating _ = True
instance (IsTypeNumber n) => IsArithmetic (IntN n)
instance (IsTypeNumber n) => IsArithmetic (WordN n)
instance IsArithmetic Bool
instance IsArithmetic Int8
instance IsArithmetic Int16
instance IsArithmetic Int32
instance IsArithmetic Int64
instance IsArithmetic Word8
instance IsArithmetic Word16
instance IsArithmetic Word32
instance IsArithmetic Word64
instance (IsPowerOf2 n, IsPrimitive a, IsArithmetic a) => IsArithmetic (Vector n a)
instance IsFloating Float
instance IsFloating Double
instance IsFloating FP128
instance (IsTypeNumber n) => IsInteger (IntN n) where isSigned _ = True
instance (IsTypeNumber n) => IsInteger (WordN n) where isSigned _ = False
instance IsInteger Bool where isSigned _ = False
instance IsInteger Int8 where isSigned _ = True
instance IsInteger Int16 where isSigned _ = True
instance IsInteger Int32 where isSigned _ = True
instance IsInteger Int64 where isSigned _ = True
instance IsInteger Word8 where isSigned _ = False
instance IsInteger Word16 where isSigned _ = False
instance IsInteger Word32 where isSigned _ = False
instance IsInteger Word64 where isSigned _ = False
instance IsFirstClass Float
instance IsFirstClass Double
instance IsFirstClass FP128
instance (IsTypeNumber n) => IsFirstClass (IntN n)
instance (IsTypeNumber n) => IsFirstClass (WordN n)
instance IsFirstClass Bool
instance IsFirstClass Int8
instance IsFirstClass Int16
instance IsFirstClass Int32
instance IsFirstClass Int64
instance IsFirstClass Word8
instance IsFirstClass Word16
instance IsFirstClass Word32
instance IsFirstClass Word64
instance (IsPowerOf2 n, IsPrimitive a) => IsFirstClass (Vector n a)
instance (IsType a) => IsFirstClass (Ptr a)
instance IsFirstClass ()
instance (IsTypeNumber n) => IsSequence (Array n)
instance IsSized Float
instance IsSized Double
instance IsSized FP128
instance (IsTypeNumber n) => IsSized (IntN n)
instance (IsTypeNumber n) => IsSized (WordN n)
instance IsSized Bool
instance IsSized Int8
instance IsSized Int16
instance IsSized Int32
instance IsSized Int64
instance IsSized Word8
instance IsSized Word16
instance IsSized Word32
instance IsSized Word64
instance (IsTypeNumber n, IsSized a) => IsSized (Array n a)
instance (IsPowerOf2 n, IsPrimitive a) => IsSized (Vector n a)
instance (IsType a) => IsSized (Ptr a)
instance IsPrimitive Float
instance IsPrimitive Double
instance IsPrimitive FP128
instance (IsTypeNumber n) => IsPrimitive (IntN n)
instance (IsTypeNumber n) => IsPrimitive (WordN n)
instance IsPrimitive Bool
instance IsPrimitive Int8
instance IsPrimitive Int16
instance IsPrimitive Int32
instance IsPrimitive Int64
instance IsPrimitive Word8
instance IsPrimitive Word16
instance IsPrimitive Word32
instance IsPrimitive Word64
instance IsPrimitive ()
instance (IsFirstClass a, IsFunction b) => IsFunction (a->b) where
funcType ts _ = funcType (typeRef (undefined :: a) : ts) (undefined :: b)
instance (IsFirstClass a) => IsFunction (IO a) where
funcType ts _ = functionType False (typeRef (undefined :: a)) (reverse ts)