module DDC.Llvm.Syntax.Type
(
FunctionDecl (..)
, ParamListType (..)
, Param (..)
, Align (..)
, Type (..)
, TypeAlias (..)
, isInt
, isFloat
, isPointer
, takeBytesOfType)
where
import DDC.Llvm.Syntax.Attr
import Control.Monad
data FunctionDecl
= FunctionDecl
{
declName :: String
, declLinkage :: Linkage
, declCallConv :: CallConv
, declReturnType :: Type
, declParamListType :: ParamListType
, declParams :: [Param]
, declAlign :: Align }
deriving (Eq, Show)
data ParamListType
= FixedArgs
| VarArgs
deriving (Eq,Show)
data Param
= Param
{ paramType :: Type
, paramAttrs :: [ParamAttr] }
deriving (Show, Eq)
data Align
= AlignNone
| AlignBytes Integer
deriving (Show, Eq)
data TypeAlias
= TypeAlias String Type
deriving (Eq, Show)
data Type
= TVoid
| TInt Integer
| TFloat
| TDouble
| TFloat80
| TFloat128
| TLabel
| TPointer Type
| TArray Integer Type
| TStruct [Type]
| TAlias TypeAlias
| TFunction FunctionDecl
deriving (Eq, Show)
isInt :: Type -> Bool
isInt tt
= case tt of
TInt _ -> True
_ -> False
isFloat :: Type -> Bool
isFloat tt
= case tt of
TFloat -> True
TDouble -> True
TFloat80 -> True
TFloat128 -> True
_ -> False
isPointer :: Type -> Bool
isPointer tt
= case tt of
TPointer _ -> True
_ -> False
takeBytesOfType :: Integer -> Type -> Maybe Integer
takeBytesOfType bytesPtr tt
= case tt of
TInt bits -> Just $ fromIntegral $ div bits 8
TFloat -> Just 4
TDouble -> Just 8
TFloat80 -> Just 10
TFloat128 -> Just 16
TPointer{} -> Just bytesPtr
TArray n t
| Just s <- takeBytesOfType bytesPtr t
-> Just (n * s)
TLabel{} -> Nothing
TVoid{} -> Nothing
TStruct tys
-> liftM sum $ sequence $ map (takeBytesOfType bytesPtr) tys
TAlias (TypeAlias _ t)
-> takeBytesOfType bytesPtr t
_ -> Nothing