llvm-general-pure-3.4.5.3: Pure Haskell LLVM functionality (no FFI).

Safe HaskellSafe-Inferred
LanguageHaskell98

LLVM.General.AST.Constant

Description

A representation of LLVM constants

Synopsis

Documentation

data Constant Source

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.

Constructors

Int 
Float 
Null 

Fields

constantType :: Type
 
Struct 
Array 
Vector 

Fields

memberValues :: [Constant]
 
Undef 

Fields

constantType :: Type
 
BlockAddress 
GlobalReference Type Name 
Add 
FAdd 
Sub 
FSub 
Mul 
FMul 
UDiv 
SDiv 
FDiv 
URem 
SRem 
FRem 
Shl 
LShr 
AShr 
And 
Or 
Xor 
GetElementPtr 
Trunc 

Fields

operand0 :: Constant
 
type' :: Type
 
ZExt 

Fields

operand0 :: Constant
 
type' :: Type
 
SExt 

Fields

operand0 :: Constant
 
type' :: Type
 
FPToUI 

Fields

operand0 :: Constant
 
type' :: Type
 
FPToSI 

Fields

operand0 :: Constant
 
type' :: Type
 
UIToFP 

Fields

operand0 :: Constant
 
type' :: Type
 
SIToFP 

Fields

operand0 :: Constant
 
type' :: Type
 
FPTrunc 

Fields

operand0 :: Constant
 
type' :: Type
 
FPExt 

Fields

operand0 :: Constant
 
type' :: Type
 
PtrToInt 

Fields

operand0 :: Constant
 
type' :: Type
 
IntToPtr 

Fields

operand0 :: Constant
 
type' :: Type
 
BitCast 

Fields

operand0 :: Constant
 
type' :: Type
 
ICmp 
FCmp 
Select 
ExtractElement 

Fields

vector :: Constant
 
index :: Constant
 
InsertElement 
ShuffleVector 
ExtractValue 
InsertValue 

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 Int 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 Int of unknown provenance as unsigned, then this function will serve.