module LLVM.AST.Constant where
import LLVM.Prelude
import Data.Bits ((.|.), (.&.), complement, testBit, shiftL)
import LLVM.AST.Type
import LLVM.AST.Name
import LLVM.AST.FloatingPointPredicate (FloatingPointPredicate)
import LLVM.AST.IntegerPredicate (IntegerPredicate)
import LLVM.AST.AddrSpace ( AddrSpace(..) )
import qualified LLVM.AST.Float as F
data Constant
= Int { Constant -> Word32
integerBits :: Word32, Constant -> Integer
integerValue :: Integer }
| Float { Constant -> SomeFloat
floatValue :: F.SomeFloat }
| Null { Constant -> Type
constantType :: Type }
| AggregateZero { constantType :: Type }
| Struct { Constant -> Maybe Name
structName :: Maybe Name, Constant -> Bool
isPacked :: Bool, Constant -> [Constant]
memberValues :: [ Constant ] }
| Array { Constant -> Type
memberType :: Type, memberValues :: [ Constant ] }
| Vector { memberValues :: [ Constant ] }
| Undef { constantType :: Type }
| BlockAddress { Constant -> Name
blockAddressFunction :: Name, Constant -> Name
blockAddressBlock :: Name }
| GlobalReference Type Name
| TokenNone
| Add {
Constant -> Bool
nsw :: Bool,
Constant -> Bool
nuw :: Bool,
Constant -> Constant
operand0 :: Constant,
Constant -> Constant
operand1 :: Constant
}
| FAdd {
operand0 :: Constant,
operand1 :: Constant
}
| Sub {
nsw :: Bool,
nuw :: Bool,
operand0 :: Constant,
operand1 :: Constant
}
| FSub {
operand0 :: Constant,
operand1 :: Constant
}
| Mul {
nsw :: Bool,
nuw :: Bool,
operand0 :: Constant,
operand1 :: Constant
}
| FMul {
operand0 :: Constant,
operand1 :: Constant
}
| UDiv {
Constant -> Bool
exact :: Bool,
operand0 :: Constant,
operand1 :: Constant
}
| SDiv {
exact :: Bool,
operand0 :: Constant,
operand1 :: Constant
}
| FDiv {
operand0 :: Constant,
operand1 :: Constant
}
| URem {
operand0 :: Constant,
operand1 :: Constant
}
| SRem {
operand0 :: Constant,
operand1 :: Constant
}
| FRem {
operand0 :: Constant,
operand1 :: Constant
}
| Shl {
nsw :: Bool,
nuw :: Bool,
operand0 :: Constant,
operand1 :: Constant
}
| LShr {
exact :: Bool,
operand0 :: Constant,
operand1 :: Constant
}
| AShr {
exact :: Bool,
operand0 :: Constant,
operand1 :: Constant
}
| And {
operand0 :: Constant,
operand1 :: Constant
}
| Or {
operand0 :: Constant,
operand1 :: Constant
}
| Xor {
operand0 :: Constant,
operand1 :: Constant
}
| GetElementPtr {
Constant -> Bool
inBounds :: Bool,
Constant -> Constant
address :: Constant,
Constant -> [Constant]
indices :: [Constant]
}
| Trunc {
operand0 :: Constant,
Constant -> Type
type' :: Type
}
| ZExt {
operand0 :: Constant,
type' :: Type
}
| SExt {
operand0 :: Constant,
type' :: Type
}
| FPToUI {
operand0 :: Constant,
type' :: Type
}
| FPToSI {
operand0 :: Constant,
type' :: Type
}
| UIToFP {
operand0 :: Constant,
type' :: Type
}
| SIToFP {
operand0 :: Constant,
type' :: Type
}
| FPTrunc {
operand0 :: Constant,
type' :: Type
}
| FPExt {
operand0 :: Constant,
type' :: Type
}
| PtrToInt {
operand0 :: Constant,
type' :: Type
}
| IntToPtr {
operand0 :: Constant,
type' :: Type
}
| BitCast {
operand0 :: Constant,
type' :: Type
}
| AddrSpaceCast {
operand0 :: Constant,
type' :: Type
}
| ICmp {
Constant -> IntegerPredicate
iPredicate :: IntegerPredicate,
operand0 :: Constant,
operand1 :: Constant
}
| FCmp {
Constant -> FloatingPointPredicate
fpPredicate :: FloatingPointPredicate,
operand0 :: Constant,
operand1 :: Constant
}
| Select {
Constant -> Constant
condition' :: Constant,
Constant -> Constant
trueValue :: Constant,
Constant -> Constant
falseValue :: Constant
}
| {
Constant -> Constant
vector :: Constant,
Constant -> Constant
index :: Constant
}
| InsertElement {
vector :: Constant,
Constant -> Constant
element :: Constant,
index :: Constant
}
| ShuffleVector {
operand0 :: Constant,
operand1 :: Constant,
Constant -> Constant
mask :: Constant
}
| {
Constant -> Constant
aggregate :: Constant,
Constant -> [Word32]
indices' :: [Word32]
}
| InsertValue {
aggregate :: Constant,
element :: Constant,
indices' :: [Word32]
}
deriving (Constant -> Constant -> Bool
(Constant -> Constant -> Bool)
-> (Constant -> Constant -> Bool) -> Eq Constant
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Constant -> Constant -> Bool
$c/= :: Constant -> Constant -> Bool
== :: Constant -> Constant -> Bool
$c== :: Constant -> Constant -> Bool
Eq, Eq Constant
Eq Constant =>
(Constant -> Constant -> Ordering)
-> (Constant -> Constant -> Bool)
-> (Constant -> Constant -> Bool)
-> (Constant -> Constant -> Bool)
-> (Constant -> Constant -> Bool)
-> (Constant -> Constant -> Constant)
-> (Constant -> Constant -> Constant)
-> Ord Constant
Constant -> Constant -> Bool
Constant -> Constant -> Ordering
Constant -> Constant -> Constant
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Constant -> Constant -> Constant
$cmin :: Constant -> Constant -> Constant
max :: Constant -> Constant -> Constant
$cmax :: Constant -> Constant -> Constant
>= :: Constant -> Constant -> Bool
$c>= :: Constant -> Constant -> Bool
> :: Constant -> Constant -> Bool
$c> :: Constant -> Constant -> Bool
<= :: Constant -> Constant -> Bool
$c<= :: Constant -> Constant -> Bool
< :: Constant -> Constant -> Bool
$c< :: Constant -> Constant -> Bool
compare :: Constant -> Constant -> Ordering
$ccompare :: Constant -> Constant -> Ordering
$cp1Ord :: Eq Constant
Ord, ReadPrec [Constant]
ReadPrec Constant
Int -> ReadS Constant
ReadS [Constant]
(Int -> ReadS Constant)
-> ReadS [Constant]
-> ReadPrec Constant
-> ReadPrec [Constant]
-> Read Constant
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Constant]
$creadListPrec :: ReadPrec [Constant]
readPrec :: ReadPrec Constant
$creadPrec :: ReadPrec Constant
readList :: ReadS [Constant]
$creadList :: ReadS [Constant]
readsPrec :: Int -> ReadS Constant
$creadsPrec :: Int -> ReadS Constant
Read, Int -> Constant -> ShowS
[Constant] -> ShowS
Constant -> String
(Int -> Constant -> ShowS)
-> (Constant -> String) -> ([Constant] -> ShowS) -> Show Constant
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Constant] -> ShowS
$cshowList :: [Constant] -> ShowS
show :: Constant -> String
$cshow :: Constant -> String
showsPrec :: Int -> Constant -> ShowS
$cshowsPrec :: Int -> Constant -> ShowS
Show, Typeable, , (forall x. Constant -> Rep Constant x)
-> (forall x. Rep Constant x -> Constant) -> Generic Constant
forall x. Rep Constant x -> Constant
forall x. Constant -> Rep Constant x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Constant x -> Constant
$cfrom :: forall x. Constant -> Rep Constant x
Generic)
signedIntegerValue :: Constant -> Integer
signedIntegerValue :: Constant -> Integer
signedIntegerValue (Int nBits' :: Word32
nBits' bits :: Integer
bits) =
let nBits :: Int
nBits = Word32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
nBits'
in
if Integer
bits Integer -> Int -> Bool
forall a. Bits a => a -> Int -> Bool
`testBit` (Int
nBits Int -> Int -> Int
forall a. Num a => a -> a -> a
- 1) then Integer
bits Integer -> Integer -> Integer
forall a. Bits a => a -> a -> a
.|. (-1 Integer -> Int -> Integer
forall a. Bits a => a -> Int -> a
`shiftL` Int
nBits) else Integer
bits
signedIntegerValue _ = String -> Integer
forall a. HasCallStack => String -> a
error "signedIntegerValue is only defined for Int"
unsignedIntegerValue :: Constant -> Integer
unsignedIntegerValue :: Constant -> Integer
unsignedIntegerValue (Int nBits :: Word32
nBits bits :: Integer
bits) =
Integer
bits Integer -> Integer -> Integer
forall a. Bits a => a -> a -> a
.&. (Integer -> Integer
forall a. Bits a => a -> a
complement (-1 Integer -> Int -> Integer
forall a. Bits a => a -> Int -> a
`shiftL` (Word32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
nBits)))
unsignedIntegerValue _ = String -> Integer
forall a. HasCallStack => String -> a
error "unsignedIntegerValue is only defined for Int"
sizeof :: Type -> Constant
sizeof :: Type -> Constant
sizeof t :: Type
t = Constant -> Type -> Constant
PtrToInt Constant
szPtr (Word32 -> Type
IntegerType 32)
where
ptrType :: Type
ptrType = Type -> AddrSpace -> Type
PointerType Type
t (Word32 -> AddrSpace
AddrSpace 0)
nullPtr :: Constant
nullPtr = Constant -> Type -> Constant
IntToPtr (Word32 -> Integer -> Constant
Int 32 0) Type
ptrType
szPtr :: Constant
szPtr = Bool -> Constant -> [Constant] -> Constant
GetElementPtr Bool
True Constant
nullPtr [Word32 -> Integer -> Constant
Int 32 1]