module LLVM.Core.Data (
IntN(..), WordN(..), FP128(..),
Array(..), Vector(..), Label, Struct(..), PackedStruct(..),
FixedList,
) where
import qualified LLVM.Core.UnaryVector as UnaryVector
import LLVM.Core.UnaryVector (FixedList)
import qualified Type.Data.Num.Decimal.Proof as DecProof
import qualified Type.Data.Num.Decimal.Number as Dec
import Type.Base.Proxy (Proxy(Proxy))
import qualified Data.Foldable as Fold
import qualified Data.Bits as Bits
import Data.Typeable (Typeable)
newtype IntN n = IntN Integer
deriving (Show, Eq, Ord, Typeable)
instance (Dec.Positive n) => Bounded (IntN n) where
minBound =
withBitSize $
IntN . negate . Bits.shiftL 1 . subtract 1 . Dec.integralFromProxy
maxBound =
withBitSize $
IntN . subtract 1 . Bits.shiftL 1 . subtract 1 . Dec.integralFromProxy
newtype WordN n = WordN Integer
deriving (Show, Eq, Ord, Typeable)
instance (Dec.Positive n) => Bounded (WordN n) where
minBound = WordN 0
maxBound =
withBitSize $ WordN . subtract 1 . Bits.shiftL 1 . Dec.integralFromProxy
withBitSize :: (Proxy n -> f n) -> f n
withBitSize f = f Proxy
newtype FP128 = FP128 Rational
deriving (Show, Typeable)
newtype Array n a = Array [a]
deriving (Show, Typeable)
newtype Vector n a = Vector (FixedList (Dec.ToUnary n) a)
instance (Dec.Natural n, Show a) => Show (Vector n a) where
showsPrec p (Vector xs) =
case DecProof.unaryNat :: DecProof.UnaryNat n of
DecProof.UnaryNat ->
showParen (p>10) $
showString "Vector " .
showList (Fold.toList
(UnaryVector.fromFixedList xs
:: UnaryVector.T (Dec.ToUnary n) a))
data Label
deriving (Typeable)
newtype Struct a = Struct a
deriving (Show, Typeable)
newtype PackedStruct a = PackedStruct a
deriving (Show, Typeable)