Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
A representation of LLVM constants
Synopsis
- data Constant
- = Int { }
- | Float { }
- | Null {
- constantType :: Type
- | AggregateZero {
- constantType :: Type
- | Struct {
- structName :: Maybe Name
- isPacked :: Bool
- memberValues :: [Constant]
- | Array {
- memberType :: Type
- memberValues :: [Constant]
- | Vector {
- memberValues :: [Constant]
- | Undef {
- constantType :: Type
- | BlockAddress { }
- | GlobalReference Type Name
- | TokenNone
- | Add { }
- | FAdd { }
- | Sub { }
- | FSub { }
- | Mul { }
- | FMul { }
- | UDiv { }
- | SDiv { }
- | FDiv { }
- | URem { }
- | SRem { }
- | FRem { }
- | Shl { }
- | LShr { }
- | AShr { }
- | And { }
- | Or { }
- | Xor { }
- | GetElementPtr { }
- | Trunc { }
- | ZExt { }
- | SExt { }
- | FPToUI { }
- | FPToSI { }
- | UIToFP { }
- | SIToFP { }
- | FPTrunc { }
- | FPExt { }
- | PtrToInt { }
- | IntToPtr { }
- | BitCast { }
- | AddrSpaceCast { }
- | ICmp { }
- | FCmp { }
- | Select { }
- | ExtractElement { }
- | InsertElement { }
- | ShuffleVector { }
- | ExtractValue { }
- | InsertValue { }
- signedIntegerValue :: Constant -> Integer
- unsignedIntegerValue :: Constant -> Integer
- sizeof :: Word32 -> Type -> Constant
Documentation
http://llvm.org/docs/LangRef.html#constants
N.B. - http://llvm.org/docs/LangRef.html#constant-expressions
Although constant expressions and instructions have many similarites, there are important differences - so they're represented using different types in this AST. At the cost of making it harder to move an code back and forth between being constant and not, this approach embeds more of the rules of what IR is legal into the Haskell types.
Instances
signedIntegerValue :: Constant -> Integer Source #
Since LLVM types don't include signedness, there's ambiguity in interpreting
an constant as an Integer. The LLVM assembly printer prints integers as signed, but
cheats for 1-bit integers and prints them as true
or false
. That way it circuments the
otherwise awkward fact that a twos complement 1-bit number only has the values -1 and 0.
unsignedIntegerValue :: Constant -> Integer Source #
This library's conversion from LLVM C++ objects will always produce integer constants
as unsigned, so this function in many cases is not necessary. However, nothing's to keep
stop direct construction of an Constant
with a negative integerValue
. There's nothing in principle
wrong with such a value - it has perfectly good low order bits like any integer, and will be used
as such, likely producing the intended result if lowered to C++. If, however one wishes to interpret
an Constant
of unknown provenance as unsigned, then this function will serve.