llvm-pretty-0.5: A pretty printing library inspired by the llvm binding.

Safe HaskellSafe
LanguageHaskell2010

Text.LLVM.AST

Synopsis

Documentation

data NamedMd Source #

Constructors

NamedMd 

Fields

Instances

parseDataLayout :: MonadPlus m => String -> m DataLayout Source #

Parse the data layout string.

parseLayoutSpec :: MonadPlus m => String -> m LayoutSpec Source #

Parse a single layout specification from a string.

newtype Ident Source #

Constructors

Ident String 

Instances

data Type' ident Source #

Constructors

PrimType PrimType 
Alias ident 
Array Int32 (Type' ident) 
FunTy (Type' ident) [Type' ident] Bool 
PtrTo (Type' ident) 
Struct [Type' ident] 
PackedStruct [Type' ident] 
Vector Int32 (Type' ident) 
Opaque 

Instances

Functor Type' Source # 

Methods

fmap :: (a -> b) -> Type' a -> Type' b #

(<$) :: a -> Type' b -> Type' a #

DefineArgs Type (Typed Value -> BB ()) Source # 

Methods

defineBody :: [Typed Ident] -> Type -> (Typed Value -> BB ()) -> LLVM ([Typed Ident], [BasicBlock])

Eq ident => Eq (Type' ident) Source # 

Methods

(==) :: Type' ident -> Type' ident -> Bool #

(/=) :: Type' ident -> Type' ident -> Bool #

Ord ident => Ord (Type' ident) Source # 

Methods

compare :: Type' ident -> Type' ident -> Ordering #

(<) :: Type' ident -> Type' ident -> Bool #

(<=) :: Type' ident -> Type' ident -> Bool #

(>) :: Type' ident -> Type' ident -> Bool #

(>=) :: Type' ident -> Type' ident -> Bool #

max :: Type' ident -> Type' ident -> Type' ident #

min :: Type' ident -> Type' ident -> Type' ident #

Show ident => Show (Type' ident) Source # 

Methods

showsPrec :: Int -> Type' ident -> ShowS #

show :: Type' ident -> String #

showList :: [Type' ident] -> ShowS #

DefineArgs (Type, Type) (Typed Value -> Typed Value -> BB ()) Source # 

Methods

defineBody :: [Typed Ident] -> (Type, Type) -> (Typed Value -> Typed Value -> BB ()) -> LLVM ([Typed Ident], [BasicBlock])

DefineArgs as k => DefineArgs ((:>) Type as) (Typed Value -> k) Source # 

Methods

defineBody :: [Typed Ident] -> (Type :> as) -> (Typed Value -> k) -> LLVM ([Typed Ident], [BasicBlock])

DefineArgs (Type, Type, Type) (Typed Value -> Typed Value -> Typed Value -> BB ()) Source # 

Methods

defineBody :: [Typed Ident] -> (Type, Type, Type) -> (Typed Value -> Typed Value -> Typed Value -> BB ()) -> LLVM ([Typed Ident], [BasicBlock])

updateAliases :: (a -> Type' b) -> Type' a -> Type' b Source #

Traverse a type, updating or removing aliases.

data NullResult lab Source #

Constructors

HasNull (Value' lab) 
ResolveNull Ident 

elimSequentialType :: MonadPlus m => Type -> m Type Source #

Eliminator for array, pointer and vector types.

data TypeDecl Source #

Constructors

TypeDecl 

Fields

data Declare Source #

Constructors

Declare 

Instances

decFunType :: Declare -> Type Source #

The function type of this declaration

data FunAttrs Source #

Constructors

FunAttrs 

data BlockLabel Source #

Constructors

Named Ident 
Anon Int 

Instances

Eq BlockLabel Source # 
Ord BlockLabel Source # 
Show BlockLabel Source # 
IsString BlockLabel Source # 
IsValue Value Source # 

Methods

toValue :: Value -> Value Source #

DefineArgs Type (Typed Value -> BB ()) Source # 

Methods

defineBody :: [Typed Ident] -> Type -> (Typed Value -> BB ()) -> LLVM ([Typed Ident], [BasicBlock])

DefineArgs (Type, Type) (Typed Value -> Typed Value -> BB ()) Source # 

Methods

defineBody :: [Typed Ident] -> (Type, Type) -> (Typed Value -> Typed Value -> BB ()) -> LLVM ([Typed Ident], [BasicBlock])

DefineArgs as k => DefineArgs ((:>) Type as) (Typed Value -> k) Source # 

Methods

defineBody :: [Typed Ident] -> (Type :> as) -> (Typed Value -> k) -> LLVM ([Typed Ident], [BasicBlock])

DefineArgs (Type, Type, Type) (Typed Value -> Typed Value -> Typed Value -> BB ()) Source # 

Methods

defineBody :: [Typed Ident] -> (Type, Type, Type) -> (Typed Value -> Typed Value -> Typed Value -> BB ()) -> LLVM ([Typed Ident], [BasicBlock])

data BasicBlock' lab Source #

Constructors

BasicBlock 

Fields

Instances

Show lab => Show (BasicBlock' lab) Source # 

Methods

showsPrec :: Int -> BasicBlock' lab -> ShowS #

show :: BasicBlock' lab -> String #

showList :: [BasicBlock' lab] -> ShowS #

brTargets :: BasicBlock' lab -> [lab] Source #

newtype GC Source #

Constructors

GC 

Fields

Instances

Show GC Source # 

Methods

showsPrec :: Int -> GC -> ShowS #

show :: GC -> String #

showList :: [GC] -> ShowS #

data Typed a Source #

Constructors

Typed 

Fields

Instances

Functor Typed Source # 

Methods

fmap :: (a -> b) -> Typed a -> Typed b #

(<$) :: a -> Typed b -> Typed a #

Foldable Typed Source # 

Methods

fold :: Monoid m => Typed m -> m #

foldMap :: Monoid m => (a -> m) -> Typed a -> m #

foldr :: (a -> b -> b) -> b -> Typed a -> b #

foldr' :: (a -> b -> b) -> b -> Typed a -> b #

foldl :: (b -> a -> b) -> b -> Typed a -> b #

foldl' :: (b -> a -> b) -> b -> Typed a -> b #

foldr1 :: (a -> a -> a) -> Typed a -> a #

foldl1 :: (a -> a -> a) -> Typed a -> a #

toList :: Typed a -> [a] #

null :: Typed a -> Bool #

length :: Typed a -> Int #

elem :: Eq a => a -> Typed a -> Bool #

maximum :: Ord a => Typed a -> a #

minimum :: Ord a => Typed a -> a #

sum :: Num a => Typed a -> a #

product :: Num a => Typed a -> a #

Traversable Typed Source # 

Methods

traverse :: Applicative f => (a -> f b) -> Typed a -> f (Typed b) #

sequenceA :: Applicative f => Typed (f a) -> f (Typed a) #

mapM :: Monad m => (a -> m b) -> Typed a -> m (Typed b) #

sequence :: Monad m => Typed (m a) -> m (Typed a) #

DefineArgs Type (Typed Value -> BB ()) Source # 

Methods

defineBody :: [Typed Ident] -> Type -> (Typed Value -> BB ()) -> LLVM ([Typed Ident], [BasicBlock])

Show a => Show (Typed a) Source # 

Methods

showsPrec :: Int -> Typed a -> ShowS #

show :: Typed a -> String #

showList :: [Typed a] -> ShowS #

IsValue a => IsValue (Typed a) Source # 

Methods

toValue :: Typed a -> Value Source #

DefineArgs (Type, Type) (Typed Value -> Typed Value -> BB ()) Source # 

Methods

defineBody :: [Typed Ident] -> (Type, Type) -> (Typed Value -> Typed Value -> BB ()) -> LLVM ([Typed Ident], [BasicBlock])

DefineArgs as k => DefineArgs ((:>) Type as) (Typed Value -> k) Source # 

Methods

defineBody :: [Typed Ident] -> (Type :> as) -> (Typed Value -> k) -> LLVM ([Typed Ident], [BasicBlock])

DefineArgs (Type, Type, Type) (Typed Value -> Typed Value -> Typed Value -> BB ()) Source # 

Methods

defineBody :: [Typed Ident] -> (Type, Type, Type) -> (Typed Value -> Typed Value -> Typed Value -> BB ()) -> LLVM ([Typed Ident], [BasicBlock])

mapMTyped :: Monad m => (a -> m b) -> Typed a -> m (Typed b) Source #

data ArithOp Source #

Constructors

Add Bool Bool
  • Integral addition.
  • First boolean flag: check for unsigned overflow.
  • Second boolean flag: check for signed overflow.
  • If the checks fail, then the result is poisoned.
FAdd

Floating point addition.

Sub Bool Bool
  • Integral subtraction.
  • First boolean flag: check for unsigned overflow.
  • Second boolean flag: check for signed overflow.
  • If the checks fail, then the result is poisoned.
FSub

Floating point subtraction.

Mul Bool Bool
  • Integral multiplication.
  • First boolean flag: check for unsigned overflow.
  • Second boolean flag: check for signed overflow.
  • If the checks fail, then the result is poisoned.
FMul

Floating point multiplication.

UDiv Bool
  • Integral unsigned division.
  • Boolean flag: check for exact result.
  • If the check fails, then the result is poisoned.
SDiv Bool
  • Integral signed division.
  • Boolean flag: check for exact result.
  • If the check fails, then the result is poisoned.
FDiv

Floating point division.

URem

Integral unsigned reminder resulting from unsigned division. Division by 0 is undefined.

SRem
  • Integral signded reminder resulting from signed division.
  • The sign of the reminder matches the divident (first parameter).
  • Division by 0 is undefined.
FRem
  • Floating point reminder resulting from floating point division.
  • The reminder has the same sign as the divident (first parameter).

data BitOp Source #

Constructors

Shl Bool Bool
  • Shift left.
  • First bool flag: check for unsigned overflow (i.e., shifted out a 1).
  • Second bool flag: check for signed overflow (i.e., shifted out something that does not match the sign bit)

    If a check fails, then the result is poisoned.

    The value of the second parameter must be strictly less than the nubmer of bits in the first parameter, otherwise the result is undefined.

Lshr Bool
  • Logical shift right.
  • The boolean is for exact check: posion the result, if we shift out a 1 bit (i.e., had to round).

The value of the second parameter must be strictly less than the nubmer of bits in the first parameter, otherwise the result is undefined.

Ashr Bool
  • Arithmetic shift right.
  • The boolean is for exact check: posion the result, if we shift out a 1 bit (i.e., had to round).

The value of the second parameter must be strictly less than the nubmer of bits in the first parameter, otherwise the result is undefined.

And 
Or 
Xor 

Instances

type Align = Int Source #

data Instr' lab Source #

Constructors

Ret (Typed (Value' lab))
  • Return from function with the given value.
  • Ends basic block.
RetVoid
  • Return from function.
  • Ends basic block.
Arith ArithOp (Typed (Value' lab)) (Value' lab)
  • Binary arithmetic operation, both operands have the same type.
  • Middle of basic block.
  • The result is the same as parameters.
Bit BitOp (Typed (Value' lab)) (Value' lab)
  • Binary bit-vector operation, both operands have the same type.
  • Middle of basic block.
  • The result is the same as parameters.
Conv ConvOp (Typed (Value' lab)) Type
  • Convert a value from one type to another.
  • Middle of basic block.
  • The result matches the 3rd parameter.
Call Bool Type (Value' lab) [Typed (Value' lab)]
  • Call a function. The boolean is tail-call hint (XXX: needs to be updated)
  • Middle of basic block.
  • The result is as indicated by the provided type.
Alloca Type (Maybe (Typed (Value' lab))) (Maybe Int)
  • Allocated space on the stack: type of elements; how many elements (1 if Nothing); required alignment.
  • Middle of basic block.
  • Returns a pointer to hold the given number of elemets.
Load (Typed (Value' lab)) (Maybe Align)
  • Read a value from the given address: address to read from; assumptions about alignment of the given pointer.
  • Middle of basic block.
  • Returns a value of type matching the pointer.
Store (Typed (Value' lab)) (Typed (Value' lab)) (Maybe Align)
  • Write a value ot memory: value to store; pointer to location where to store; assumptions about the alignment of the given pointer.
  • Middle olf basic block.
  • Effect.
ICmp ICmpOp (Typed (Value' lab)) (Value' lab)
  • Compare two integral values.
  • Middle of basic block.
  • Returns a boolean value.
FCmp FCmpOp (Typed (Value' lab)) (Value' lab)
  • Compare two floating point values.
  • Middle of basic block.
  • Returns a boolean value.
Phi Type [(Value' lab, lab)]
  • Join point for an SSA value: we get one value per predecessor basic block.
  • Middle of basic block.
  • Returns a value of the specified type.
GEP Bool (Typed (Value' lab)) [Typed (Value' lab)]
  • "Get element pointer", compute the address of a field in a structure: inbounds check (value poisoned if this fails); pointer to parent strucutre; path to a sub-component of a strucutre.
  • Middle of basic block.
  • Returns the address of the requiested member.

The types in path are the types of the index, not the fields.

The indexes are in units of a fields (i.e., the first element in a struct is field 0, the next one is 1, etc., regardless of the size of the fields in bytes).

Select (Typed (Value' lab)) (Typed (Value' lab)) (Value' lab)
  • Local if-then-else; the first argument is boolean, if true pick the 2nd argument, otherwise evaluate to the 3rd.
  • Middle of basic block.
  • Returns either the 2nd or the 3rd argument.
ExtractValue (Typed (Value' lab)) [Int32]
  • Get the value of a member of an aggregate value: the first argument is an aggregate value (not a pointer!), the second is a path of indexes, similar to the one in GEP.
  • Middle of basic block.
  • Returns the given member of the aggregate value.
InsertValue (Typed (Value' lab)) (Typed (Value' lab)) [Int32]
  • Set the value for a member of an aggregate value: the first argument is the value to insert, the second is the aggreagate value to be modified.
  • Middle of basic block.
  • Returns an updated aggregate value.
ExtractElt (Typed (Value' lab)) (Value' lab)
  • Get an element from a vector: the first argument is a vector, the second an index.
  • Middle of basic block.
  • Returns the element at the given positoin.
InsertElt (Typed (Value' lab)) (Typed (Value' lab)) (Value' lab)
  • Modify an element of a vector: the first argument is the vector, the second the value to be inserted, the third is the index where to insert the value.
  • Middle of basic block.
  • Returns an updated vector.
ShuffleVector (Typed (Value' lab)) (Value' lab) (Typed (Value' lab)) 
Jump lab
  • Jump to the given basic block.
  • Ends basic block.
Br (Typed (Value' lab)) lab lab
  • Conditional jump: if the value is true jump to the first basic block, otherwise jump to the second.
  • Ends basic block.
Invoke Type (Value' lab) [Typed (Value' lab)] lab lab 
Comment String

Comment

Unreachable

No defined sematics, we should not get to here.

Unwind 
VaArg (Typed (Value' lab)) Type 
IndirectBr (Typed (Value' lab)) [lab] 
Switch (Typed (Value' lab)) lab [(Integer, lab)]
  • Multi-way branch: the first value determines the direction of the branch, the label is a default direction, if the value does not appear in the jump table, the last argument is the jump table.
  • Ends basic block.
LandingPad Type (Typed (Value' lab)) Bool [Clause' lab] 
Resume (Typed (Value' lab)) 

Instances

Functor Instr' Source # 

Methods

fmap :: (a -> b) -> Instr' a -> Instr' b #

(<$) :: a -> Instr' b -> Instr' a #

HasLabel Instr' Source # 

Methods

relabel :: Applicative m => (Maybe Symbol -> a -> m b) -> Instr' a -> m (Instr' b) Source #

Show lab => Show (Instr' lab) Source # 

Methods

showsPrec :: Int -> Instr' lab -> ShowS #

show :: Instr' lab -> String #

showList :: [Instr' lab] -> ShowS #

data Clause' lab Source #

Constructors

Catch (Typed (Value' lab)) 
Filter (Typed (Value' lab)) 

Instances

Functor Clause' Source # 

Methods

fmap :: (a -> b) -> Clause' a -> Clause' b #

(<$) :: a -> Clause' b -> Clause' a #

HasLabel Clause' Source # 

Methods

relabel :: Applicative m => (Maybe Symbol -> a -> m b) -> Clause' a -> m (Clause' b) Source #

Show lab => Show (Clause' lab) Source # 

Methods

showsPrec :: Int -> Clause' lab -> ShowS #

show :: Clause' lab -> String #

showList :: [Clause' lab] -> ShowS #

data ICmpOp Source #

Constructors

Ieq 
Ine 
Iugt 
Iuge 
Iult 
Iule 
Isgt 
Isge 
Islt 
Isle 

Instances

data FCmpOp Source #

Instances

data Value' lab Source #

Instances

Functor Value' Source # 

Methods

fmap :: (a -> b) -> Value' a -> Value' b #

(<$) :: a -> Value' b -> Value' a #

HasLabel Value' Source # 

Methods

relabel :: Applicative m => (Maybe Symbol -> a -> m b) -> Value' a -> m (Value' b) Source #

IsValue Value Source # 

Methods

toValue :: Value -> Value Source #

DefineArgs Type (Typed Value -> BB ()) Source # 

Methods

defineBody :: [Typed Ident] -> Type -> (Typed Value -> BB ()) -> LLVM ([Typed Ident], [BasicBlock])

Show lab => Show (Value' lab) Source # 

Methods

showsPrec :: Int -> Value' lab -> ShowS #

show :: Value' lab -> String #

showList :: [Value' lab] -> ShowS #

DefineArgs (Type, Type) (Typed Value -> Typed Value -> BB ()) Source # 

Methods

defineBody :: [Typed Ident] -> (Type, Type) -> (Typed Value -> Typed Value -> BB ()) -> LLVM ([Typed Ident], [BasicBlock])

DefineArgs as k => DefineArgs ((:>) Type as) (Typed Value -> k) Source # 

Methods

defineBody :: [Typed Ident] -> (Type :> as) -> (Typed Value -> k) -> LLVM ([Typed Ident], [BasicBlock])

DefineArgs (Type, Type, Type) (Typed Value -> Typed Value -> Typed Value -> BB ()) Source # 

Methods

defineBody :: [Typed Ident] -> (Type, Type, Type) -> (Typed Value -> Typed Value -> Typed Value -> BB ()) -> LLVM ([Typed Ident], [BasicBlock])

data ValMd' lab Source #

Instances

Functor ValMd' Source # 

Methods

fmap :: (a -> b) -> ValMd' a -> ValMd' b #

(<$) :: a -> ValMd' b -> ValMd' a #

HasLabel ValMd' Source # 

Methods

relabel :: Applicative m => (Maybe Symbol -> a -> m b) -> ValMd' a -> m (ValMd' b) Source #

Show lab => Show (ValMd' lab) Source # 

Methods

showsPrec :: Int -> ValMd' lab -> ShowS #

show :: ValMd' lab -> String #

showList :: [ValMd' lab] -> ShowS #

data DebugLoc' lab Source #

Constructors

DebugLoc 

Fields

Instances

Functor DebugLoc' Source # 

Methods

fmap :: (a -> b) -> DebugLoc' a -> DebugLoc' b #

(<$) :: a -> DebugLoc' b -> DebugLoc' a #

HasLabel DebugLoc' Source # 

Methods

relabel :: Applicative m => (Maybe Symbol -> a -> m b) -> DebugLoc' a -> m (DebugLoc' b) Source #

Show lab => Show (DebugLoc' lab) Source # 

Methods

showsPrec :: Int -> DebugLoc' lab -> ShowS #

show :: DebugLoc' lab -> String #

showList :: [DebugLoc' lab] -> ShowS #

data Stmt' lab Source #

Constructors

Result Ident (Instr' lab) [(String, ValMd' lab)] 
Effect (Instr' lab) [(String, ValMd' lab)] 

Instances

Functor Stmt' Source # 

Methods

fmap :: (a -> b) -> Stmt' a -> Stmt' b #

(<$) :: a -> Stmt' b -> Stmt' a #

HasLabel Stmt' Source # 

Methods

relabel :: Applicative m => (Maybe Symbol -> a -> m b) -> Stmt' a -> m (Stmt' b) Source #

Show lab => Show (Stmt' lab) Source # 

Methods

showsPrec :: Int -> Stmt' lab -> ShowS #

show :: Stmt' lab -> String #

showList :: [Stmt' lab] -> ShowS #

stmtInstr :: Stmt' lab -> Instr' lab Source #

stmtMetadata :: Stmt' lab -> [(String, ValMd' lab)] Source #

extendMetadata :: (String, ValMd' lab) -> Stmt' lab -> Stmt' lab Source #

data ConstExpr' lab Source #

Constructors

ConstGEP Bool [Typed (Value' lab)] 
ConstConv ConvOp (Typed (Value' lab)) Type 
ConstSelect (Typed (Value' lab)) (Typed (Value' lab)) (Typed (Value' lab)) 
ConstBlockAddr Symbol lab 

Instances

Functor ConstExpr' Source # 

Methods

fmap :: (a -> b) -> ConstExpr' a -> ConstExpr' b #

(<$) :: a -> ConstExpr' b -> ConstExpr' a #

HasLabel ConstExpr' Source # 

Methods

relabel :: Applicative m => (Maybe Symbol -> a -> m b) -> ConstExpr' a -> m (ConstExpr' b) Source #

Show lab => Show (ConstExpr' lab) Source # 

Methods

showsPrec :: Int -> ConstExpr' lab -> ShowS #

show :: ConstExpr' lab -> String #

showList :: [ConstExpr' lab] -> ShowS #

data IndexResult Source #

Constructors

Invalid

An invalid use of GEP

HasType Type

A resolved type

Resolve Ident (Type -> IndexResult)

Continue, after resolving an alias

resolveGepFull Source #

Arguments

:: (Ident -> Maybe Type)

Type alias resolution

-> Type

Pointer type

-> [Typed (Value' lab)]

Path

-> Maybe Type

Type of result

Resolves the type of a GEP instruction. Type aliases are resolved using the given function. An invalid use of GEP or one relying on unknown type aliases will return Nothing

resolveGep :: Type -> [Typed (Value' lab)] -> IndexResult Source #

Resolve the type of a GEP instruction. Note that the type produced is the type of the result, not necessarily a pointer.

resolveGepBody :: Type -> [Typed (Value' lab)] -> IndexResult Source #

Resolve the type of a GEP instruction. This assumes that the input has already been processed as a pointer.