{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# OPTIONS_HADDOCK hide #-}
module LLVM.AST.Type.Representation (
module LLVM.AST.Type.Representation,
module Data.Array.Accelerate.Type,
Ptr,
AddrSpace(..),
) where
import Data.Array.Accelerate.Type
import Data.Array.Accelerate.Product
import LLVM.AST.Type.AddrSpace
import Foreign.Ptr
import Text.Printf
data Type a where
VoidType :: Type ()
PrimType :: PrimType a -> Type a
data PrimType a where
ScalarPrimType :: ScalarType a -> PrimType a
PtrPrimType :: PrimType a -> AddrSpace -> PrimType (Ptr a)
StructPrimType :: TupleType (ProdRepr a) -> PrimType a
ArrayPrimType :: Word64 -> ScalarType a -> PrimType a
class IsType a where
type' :: Type a
instance IsType () where
type' = VoidType
instance IsType Int where
type' = PrimType primType
instance IsType Int8 where
type' = PrimType primType
instance IsType Int16 where
type' = PrimType primType
instance IsType Int32 where
type' = PrimType primType
instance IsType Int64 where
type' = PrimType primType
instance IsType Word where
type' = PrimType primType
instance IsType Word8 where
type' = PrimType primType
instance IsType Word16 where
type' = PrimType primType
instance IsType Word32 where
type' = PrimType primType
instance IsType Word64 where
type' = PrimType primType
instance IsType CShort where
type' = PrimType primType
instance IsType CUShort where
type' = PrimType primType
instance IsType CInt where
type' = PrimType primType
instance IsType CUInt where
type' = PrimType primType
instance IsType CLong where
type' = PrimType primType
instance IsType CULong where
type' = PrimType primType
instance IsType CLLong where
type' = PrimType primType
instance IsType CULLong where
type' = PrimType primType
instance IsType Float where
type' = PrimType primType
instance IsType Double where
type' = PrimType primType
instance IsType CFloat where
type' = PrimType primType
instance IsType CDouble where
type' = PrimType primType
instance IsType Bool where
type' = PrimType primType
instance IsType Char where
type' = PrimType primType
instance IsType CChar where
type' = PrimType primType
instance IsType CSChar where
type' = PrimType primType
instance IsType CUChar where
type' = PrimType primType
instance IsType (Ptr Int) where
type' = PrimType primType
instance IsType (Ptr Int8) where
type' = PrimType primType
instance IsType (Ptr Int16) where
type' = PrimType primType
instance IsType (Ptr Int32) where
type' = PrimType primType
instance IsType (Ptr Int64) where
type' = PrimType primType
instance IsType (Ptr Word) where
type' = PrimType primType
instance IsType (Ptr Word8) where
type' = PrimType primType
instance IsType (Ptr Word16) where
type' = PrimType primType
instance IsType (Ptr Word32) where
type' = PrimType primType
instance IsType (Ptr Word64) where
type' = PrimType primType
instance IsType (Ptr CShort) where
type' = PrimType primType
instance IsType (Ptr CUShort) where
type' = PrimType primType
instance IsType (Ptr CInt) where
type' = PrimType primType
instance IsType (Ptr CUInt) where
type' = PrimType primType
instance IsType (Ptr CLong) where
type' = PrimType primType
instance IsType (Ptr CULong) where
type' = PrimType primType
instance IsType (Ptr CLLong) where
type' = PrimType primType
instance IsType (Ptr CULLong) where
type' = PrimType primType
instance IsType (Ptr Float) where
type' = PrimType primType
instance IsType (Ptr Double) where
type' = PrimType primType
instance IsType (Ptr CFloat) where
type' = PrimType primType
instance IsType (Ptr CDouble) where
type' = PrimType primType
instance IsType (Ptr Bool) where
type' = PrimType primType
instance IsType (Ptr Char) where
type' = PrimType primType
instance IsType (Ptr CChar) where
type' = PrimType primType
instance IsType (Ptr CSChar) where
type' = PrimType primType
instance IsType (Ptr CUChar) where
type' = PrimType primType
class IsPrim a where
primType :: PrimType a
instance IsPrim Int where
primType = ScalarPrimType scalarType
instance IsPrim Int8 where
primType = ScalarPrimType scalarType
instance IsPrim Int16 where
primType = ScalarPrimType scalarType
instance IsPrim Int32 where
primType = ScalarPrimType scalarType
instance IsPrim Int64 where
primType = ScalarPrimType scalarType
instance IsPrim Word where
primType = ScalarPrimType scalarType
instance IsPrim Word8 where
primType = ScalarPrimType scalarType
instance IsPrim Word16 where
primType = ScalarPrimType scalarType
instance IsPrim Word32 where
primType = ScalarPrimType scalarType
instance IsPrim Word64 where
primType = ScalarPrimType scalarType
instance IsPrim CShort where
primType = ScalarPrimType scalarType
instance IsPrim CUShort where
primType = ScalarPrimType scalarType
instance IsPrim CInt where
primType = ScalarPrimType scalarType
instance IsPrim CUInt where
primType = ScalarPrimType scalarType
instance IsPrim CLong where
primType = ScalarPrimType scalarType
instance IsPrim CULong where
primType = ScalarPrimType scalarType
instance IsPrim CLLong where
primType = ScalarPrimType scalarType
instance IsPrim CULLong where
primType = ScalarPrimType scalarType
instance IsPrim Float where
primType = ScalarPrimType scalarType
instance IsPrim Double where
primType = ScalarPrimType scalarType
instance IsPrim CFloat where
primType = ScalarPrimType scalarType
instance IsPrim CDouble where
primType = ScalarPrimType scalarType
instance IsPrim Bool where
primType = ScalarPrimType scalarType
instance IsPrim Char where
primType = ScalarPrimType scalarType
instance IsPrim CChar where
primType = ScalarPrimType scalarType
instance IsPrim CSChar where
primType = ScalarPrimType scalarType
instance IsPrim CUChar where
primType = ScalarPrimType scalarType
instance IsPrim (Ptr Int) where
primType = PtrPrimType primType defaultAddrSpace
instance IsPrim (Ptr Int8) where
primType = PtrPrimType primType defaultAddrSpace
instance IsPrim (Ptr Int16) where
primType = PtrPrimType primType defaultAddrSpace
instance IsPrim (Ptr Int32) where
primType = PtrPrimType primType defaultAddrSpace
instance IsPrim (Ptr Int64) where
primType = PtrPrimType primType defaultAddrSpace
instance IsPrim (Ptr Word) where
primType = PtrPrimType primType defaultAddrSpace
instance IsPrim (Ptr Word8) where
primType = PtrPrimType primType defaultAddrSpace
instance IsPrim (Ptr Word16) where
primType = PtrPrimType primType defaultAddrSpace
instance IsPrim (Ptr Word32) where
primType = PtrPrimType primType defaultAddrSpace
instance IsPrim (Ptr Word64) where
primType = PtrPrimType primType defaultAddrSpace
instance IsPrim (Ptr CShort) where
primType = PtrPrimType primType defaultAddrSpace
instance IsPrim (Ptr CUShort) where
primType = PtrPrimType primType defaultAddrSpace
instance IsPrim (Ptr CInt) where
primType = PtrPrimType primType defaultAddrSpace
instance IsPrim (Ptr CUInt) where
primType = PtrPrimType primType defaultAddrSpace
instance IsPrim (Ptr CLong) where
primType = PtrPrimType primType defaultAddrSpace
instance IsPrim (Ptr CULong) where
primType = PtrPrimType primType defaultAddrSpace
instance IsPrim (Ptr CLLong) where
primType = PtrPrimType primType defaultAddrSpace
instance IsPrim (Ptr CULLong) where
primType = PtrPrimType primType defaultAddrSpace
instance IsPrim (Ptr Float) where
primType = PtrPrimType primType defaultAddrSpace
instance IsPrim (Ptr Double) where
primType = PtrPrimType primType defaultAddrSpace
instance IsPrim (Ptr CFloat) where
primType = PtrPrimType primType defaultAddrSpace
instance IsPrim (Ptr CDouble) where
primType = PtrPrimType primType defaultAddrSpace
instance IsPrim (Ptr Bool) where
primType = PtrPrimType primType defaultAddrSpace
instance IsPrim (Ptr Char) where
primType = PtrPrimType primType defaultAddrSpace
instance IsPrim (Ptr CChar) where
primType = PtrPrimType primType defaultAddrSpace
instance IsPrim (Ptr CSChar) where
primType = PtrPrimType primType defaultAddrSpace
instance IsPrim (Ptr CUChar) where
primType = PtrPrimType primType defaultAddrSpace
instance Show (Type a) where
show VoidType = "()"
show (PrimType t) = show t
instance Show (PrimType a) where
show (ScalarPrimType t) = show t
show (StructPrimType t) = show t
show (ArrayPrimType n t) = printf "[%d x %s]" n (show t)
show (PtrPrimType t (AddrSpace n)) = printf "Ptr%s %s" a p
where
p = show t
a | n == 0 = ""
| otherwise = printf "[addrspace %d]" n