module LLVM.AST.DataLayout where
import LLVM.Prelude
import Data.Map (Map)
import qualified Data.Map as Map
import Data.Set (Set)
import LLVM.AST.AddrSpace
data Endianness = LittleEndian | BigEndian
deriving (Eq, Ord, Read, Show, Typeable, Data)
data AlignmentInfo = AlignmentInfo {
abiAlignment :: Word32,
preferredAlignment :: Maybe Word32
}
deriving (Eq, Ord, Read, Show, Typeable, Data)
data AlignType
= IntegerAlign
| VectorAlign
| FloatAlign
deriving (Eq, Ord, Read, Show, Typeable, Data)
data Mangling
= ELFMangling
| MIPSMangling
| MachOMangling
| WindowsCOFFMangling
deriving (Eq, Ord, Read, Show, Typeable, Data)
data DataLayout = DataLayout {
endianness :: Endianness,
mangling :: Maybe Mangling,
stackAlignment :: Maybe Word32,
pointerLayouts :: Map AddrSpace (Word32, AlignmentInfo),
typeLayouts :: Map (AlignType, Word32) AlignmentInfo,
aggregateLayout :: AlignmentInfo,
nativeSizes :: Maybe (Set Word32)
}
deriving (Eq, Ord, Read, Show, Typeable, Data)
defaultDataLayout :: Endianness -> DataLayout
defaultDataLayout endianness = DataLayout {
endianness = endianness,
mangling = Nothing,
stackAlignment = Nothing,
pointerLayouts = Map.fromList [
(AddrSpace 0, (64, AlignmentInfo 64 (Just 64)))
],
typeLayouts = Map.fromList [
((IntegerAlign, 1), AlignmentInfo 8 (Just 8)),
((IntegerAlign, 8), AlignmentInfo 8 (Just 8)),
((IntegerAlign, 16), AlignmentInfo 16 (Just 16)),
((IntegerAlign, 32), AlignmentInfo 32 (Just 32)),
((IntegerAlign, 64), AlignmentInfo 32 (Just 64)),
((FloatAlign, 16), AlignmentInfo 16 (Just 16)),
((FloatAlign, 32), AlignmentInfo 32 (Just 32)),
((FloatAlign, 64), AlignmentInfo 64 (Just 64)),
((FloatAlign, 128), AlignmentInfo 128 (Just 128)),
((VectorAlign, 64), AlignmentInfo 64 (Just 64)),
((VectorAlign, 128), AlignmentInfo 128 (Just 128))
],
aggregateLayout = AlignmentInfo 0 (Just 64),
nativeSizes = Nothing
}