Documentation ¶
Overview ¶
Procedures required for working with SSA IR: - finding all references to a specified value - changing the value a reference refers to - replacing all references to a value with another value
Index ¶
- func BlockTrace(block *Block) string
- func EscapeString(str string) string
- func FunctionTrace(function *Function) string
- func GlobalTrace(global *Global) string
- func InstrName(instr Instruction) string
- func InstrTrace(instr Instruction) string
- func ReplaceAllValueReferences(original, replacement Value)
- func ReplaceOperandFromIndex(instr Instruction, opIndex int, newOp Value)
- func ReplaceOperandFromValue(instr Instruction, value *Value, newValue Value)
- func ValueIdentifier(val Value) string
- func ValueString(val Value) string
- type Alloc
- type BinOp
- type BinOpType
- type Block
- func (v Block) FirstInstr() Instruction
- func (v Block) Function() *Function
- func (v Block) InstrAtIndex(i int) Instruction
- func (v Block) InstrIndex(needle Instruction) int
- func (v Block) Instrs() []Instruction
- func (v *Block) IsEntry() bool
- func (v Block) LastInstr() Instruction
- func (v Block) NumInstrs() int
- func (v Block) String() string
- func (_ Block) Type() types.Type
- type BlockHandler
- type Br
- type Builder
- func (v *Builder) CreateAlloc(typ types.Type, name string) *Alloc
- func (v *Builder) CreateBinOp(x, y Value, binOpType BinOpType, name string) *BinOp
- func (v *Builder) CreateBr(target *Block) *Br
- func (v *Builder) CreateCall(fn *Function, args []Value, name string) *Call
- func (v *Builder) CreateCondBr(cond Value, trueTarget, falseTarget *Block) *CondBr
- func (v *Builder) CreateConvert(x Value, target types.Type, convertType ConvertType, name string) *Convert
- func (v *Builder) CreateGEP(value Value, indexes []Value, name string) *GEP
- func (v *Builder) CreateICmp(x, y Value, predicate IntPredicate, name string) *ICmp
- func (v *Builder) CreateLoad(location Value, name string) *Load
- func (v *Builder) CreatePhi(t types.Type, name string) *Phi
- func (v *Builder) CreateRet(returnValue Value) *Ret
- func (v *Builder) CreateStore(location, value Value) *Store
- func (v *Builder) CreateUnreachable() *Unreachable
- func (v *Builder) SetInsertAfterInstr(i Instruction)
- func (v *Builder) SetInsertAtBlockEnd(b *Block)
- func (v *Builder) SetInsertAtBlockStart(b *Block)
- func (v *Builder) SetInsertBeforeInstr(i Instruction)
- type Call
- type CondBr
- type Convert
- type ConvertType
- type FloatLiteral
- type Function
- func (v *Function) AddBlockAtEnd(name string) *Block
- func (v *Function) AddBlockAtStart(name string) *Block
- func (v Function) Blocks() []*Block
- func (v Function) EntryBlock() *Block
- func (v Function) IsPrototype() bool
- func (v Function) Parameters() []*Parameter
- func (v Function) SignatureString() string
- func (v Function) String() string
- func (v Function) Type() types.Type
- func (v *Function) UpdateNames()
- type GEP
- type Global
- type ICmp
- type Initialiser
- type Instruction
- type IntLiteral
- type IntPredicate
- type Literal
- type LiteralInitialiser
- type Load
- type Module
- func (v Module) FunctionNamed(name string) *Function
- func (v Module) Functions() []*Function
- func (v Module) GlobalNamed(name string) *Global
- func (v Module) Globals() []*Global
- func (v Module) Name() string
- func (v *Module) NewFunction(typ *types.Signature, name string) *Function
- func (v *Module) NewGlobal(typ types.Type, init Initialiser, name string) *Global
- func (v *Module) NewGlobalString(val string, nullTerminate bool, name string) *Global
- func (v *Module) String() string
- func (v *Module) UpdateNames()
- type NameHandler
- type Parameter
- type Phi
- type ReferenceHandler
- type Ret
- type Store
- type StringLiteral
- type Unreachable
- type Value
- type ZeroInitialiser
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BlockTrace ¶
func EscapeString ¶
func FunctionTrace ¶
func GlobalTrace ¶
func InstrName ¶
func InstrName(instr Instruction) string
func InstrTrace ¶
func InstrTrace(instr Instruction) string
func ReplaceAllValueReferences ¶
func ReplaceAllValueReferences(original, replacement Value)
Make sure references are not out-of-date when calling this function.
func ReplaceOperandFromIndex ¶
func ReplaceOperandFromIndex(instr Instruction, opIndex int, newOp Value)
func ReplaceOperandFromValue ¶
func ReplaceOperandFromValue(instr Instruction, value *Value, newValue Value)
func ValueIdentifier ¶
func ValueString ¶
Types ¶
type Alloc ¶
type Alloc struct { NameHandler ReferenceHandler BlockHandler // contains filtered or unexported fields }
func (Alloc) IsTerminating ¶
type BinOp ¶
type BinOp struct { BlockHandler NameHandler ReferenceHandler // contains filtered or unexported fields }
func (BinOp) IsTerminating ¶
type Block ¶
type Block struct { ReferenceHandler NameHandler // contains filtered or unexported fields }
func (Block) FirstInstr ¶
func (v Block) FirstInstr() Instruction
func (Block) InstrAtIndex ¶
func (v Block) InstrAtIndex(i int) Instruction
Returns nil for index out of range.
func (Block) InstrIndex ¶
func (v Block) InstrIndex(needle Instruction) int
func (Block) Instrs ¶
func (v Block) Instrs() []Instruction
func (Block) LastInstr ¶
func (v Block) LastInstr() Instruction
type BlockHandler ¶
type BlockHandler struct {
// contains filtered or unexported fields
}
func (BlockHandler) Block ¶
func (v BlockHandler) Block() *Block
type Br ¶
type Br struct { BlockHandler // contains filtered or unexported fields }
func (Br) IsTerminating ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
func NewBuilder ¶
func NewBuilder() *Builder
func (*Builder) CreateBinOp ¶
func (*Builder) CreateCall ¶
func (*Builder) CreateCondBr ¶
func (*Builder) CreateConvert ¶
func (*Builder) CreateICmp ¶
func (v *Builder) CreateICmp(x, y Value, predicate IntPredicate, name string) *ICmp
func (*Builder) CreateStore ¶
func (*Builder) CreateUnreachable ¶
func (v *Builder) CreateUnreachable() *Unreachable
func (*Builder) SetInsertAfterInstr ¶
func (v *Builder) SetInsertAfterInstr(i Instruction)
func (*Builder) SetInsertAtBlockEnd ¶
func (*Builder) SetInsertAtBlockStart ¶
func (*Builder) SetInsertBeforeInstr ¶
func (v *Builder) SetInsertBeforeInstr(i Instruction)
type Call ¶
type Call struct { NameHandler ReferenceHandler BlockHandler // contains filtered or unexported fields }
func (Call) IsTerminating ¶
type CondBr ¶
type CondBr struct { BlockHandler // contains filtered or unexported fields }
func (CondBr) IsTerminating ¶
type Convert ¶
type Convert struct { NameHandler BlockHandler ReferenceHandler // contains filtered or unexported fields }
func (Convert) ConvertType ¶
func (v Convert) ConvertType() ConvertType
func (Convert) IsTerminating ¶
type ConvertType ¶
type ConvertType int
const ( // Integer ConvertSExt ConvertType = iota ConvertZExt ConvertTrunc // Pointer ConvertBitcast // Float ConvertFExt ConvertFTrunc // Float-Integer ConvertFToUI ConvertFToSI ConvertUIToF ConvertSIToF // Pointer-Integer ConvertPtrToInt ConvertIntToPtr )
func (ConvertType) String ¶
func (i ConvertType) String() string
type FloatLiteral ¶
type FloatLiteral struct { ReferenceHandler // contains filtered or unexported fields }
func NewFloat32Literal ¶
func NewFloat32Literal(value float32) *FloatLiteral
func NewFloat64Literal ¶
func NewFloat64Literal(value float64) *FloatLiteral
func (FloatLiteral) Float64 ¶
func (v FloatLiteral) Float64() float64
Use for display purposes only, can be inaccurate!
func (FloatLiteral) LiteralValue ¶
func (v FloatLiteral) LiteralValue() interface{}
func (FloatLiteral) Name ¶
func (v FloatLiteral) Name() string
func (FloatLiteral) SetName ¶
func (_ FloatLiteral) SetName(_ string)
func (FloatLiteral) Type ¶
func (v FloatLiteral) Type() types.Type
type Function ¶
type Function struct { NameHandler ReferenceHandler // contains filtered or unexported fields }
func (*Function) AddBlockAtEnd ¶
func (*Function) AddBlockAtStart ¶
func (Function) EntryBlock ¶
func (Function) IsPrototype ¶
func (Function) Parameters ¶
func (Function) SignatureString ¶
func (*Function) UpdateNames ¶
func (v *Function) UpdateNames()
type GEP ¶
type GEP struct { NameHandler ReferenceHandler BlockHandler // contains filtered or unexported fields }
Note: for int literals accessing structs, the int type will be ignored, ie. no overflow/underflow will occur due to the int type.
func (GEP) IsTerminating ¶
type Global ¶
type Global struct { ReferenceHandler NameHandler // contains filtered or unexported fields }
func (Global) Initialiser ¶
func (v Global) Initialiser() Initialiser
func (*Global) SetInitialiser ¶
func (v *Global) SetInitialiser(init Initialiser)
type ICmp ¶
type ICmp struct { BlockHandler NameHandler ReferenceHandler // contains filtered or unexported fields }
func (ICmp) IsTerminating ¶
func (ICmp) Predicate ¶
func (v ICmp) Predicate() IntPredicate
type Initialiser ¶
type Initialiser interface { Initialiser() String() string }
type Instruction ¶
type IntLiteral ¶
type IntLiteral struct { ReferenceHandler // contains filtered or unexported fields }
func NewIntLiteral ¶
func NewIntLiteral(value uint64, typ *types.Int) *IntLiteral
func (IntLiteral) LiteralValue ¶
func (v IntLiteral) LiteralValue() interface{}
func (IntLiteral) Name ¶
func (v IntLiteral) Name() string
func (IntLiteral) SetName ¶
func (_ IntLiteral) SetName(_ string)
func (IntLiteral) Type ¶
func (v IntLiteral) Type() types.Type
type IntPredicate ¶
type IntPredicate int
const ( IntEQ IntPredicate = iota // equal IntNEQ // not equal IntUGT // unsigned greater than IntUGE // unsigned greater or equal IntULT // unsigned less than IntULE // unsigned less or equal IntSGT // signed greater than IntSGE // signed greater or equal IntSLT // signed less than IntSLE // signed less or equal )
func (IntPredicate) String ¶
func (i IntPredicate) String() string
type LiteralInitialiser ¶
type LiteralInitialiser struct {
// contains filtered or unexported fields
}
Used for literals as initialisers
func NewLiteralInitialiser ¶
func NewLiteralInitialiser(lit Literal) *LiteralInitialiser
TODO reference handling?
func (LiteralInitialiser) Initialiser ¶
func (_ LiteralInitialiser) Initialiser()
func (LiteralInitialiser) Literal ¶
func (v LiteralInitialiser) Literal() Literal
func (LiteralInitialiser) String ¶
func (v LiteralInitialiser) String() string
type Load ¶
type Load struct { NameHandler ReferenceHandler BlockHandler // contains filtered or unexported fields }
func (Load) IsTerminating ¶
type Module ¶
type Module struct {
// contains filtered or unexported fields
}
func (Module) FunctionNamed ¶
func (Module) GlobalNamed ¶
func (*Module) NewFunction ¶
Created a new function with the specified type and name then inserts it into the module, returning the new function afterwards. If a function with the same name already exists, does nothing and returns nil.
func (*Module) NewGlobalString ¶
Convenience method
func (*Module) UpdateNames ¶
func (v *Module) UpdateNames()
type NameHandler ¶
type NameHandler struct {
// contains filtered or unexported fields
}
func (NameHandler) Name ¶
func (v NameHandler) Name() string
func (*NameHandler) SetName ¶
func (v *NameHandler) SetName(name string)
type Parameter ¶
type Parameter struct { ReferenceHandler NameHandler // contains filtered or unexported fields }
type Phi ¶
type Phi struct { ReferenceHandler BlockHandler NameHandler // contains filtered or unexported fields }
func (*Phi) AddIncoming ¶
func (Phi) IsTerminating ¶
func (Phi) NumIncoming ¶
func (*Phi) RemoveIncoming ¶
type ReferenceHandler ¶
type ReferenceHandler struct {
// contains filtered or unexported fields
}
func (ReferenceHandler) References ¶
func (v ReferenceHandler) References() []Instruction
type Ret ¶
type Ret struct { BlockHandler // contains filtered or unexported fields }
func (Ret) IsTerminating ¶
type Store ¶
type Store struct { BlockHandler // contains filtered or unexported fields }
func (Store) IsTerminating ¶
type StringLiteral ¶
type StringLiteral struct { ReferenceHandler // contains filtered or unexported fields }
func NewStringLiteral ¶
func NewStringLiteral(value string, appendNullByte bool) *StringLiteral
func (StringLiteral) LiteralValue ¶
func (v StringLiteral) LiteralValue() interface{}
func (StringLiteral) Name ¶
func (v StringLiteral) Name() string
func (StringLiteral) SetName ¶
func (_ StringLiteral) SetName(string)
func (StringLiteral) Type ¶
func (v StringLiteral) Type() types.Type
type Unreachable ¶
type Unreachable struct {
BlockHandler
}
Unreachable is an instruction used as a terminating instruction for a block that control should never reach the end of. It is used to satisfy the validator. Implementation is undefined.
func (Unreachable) IsTerminating ¶
func (_ Unreachable) IsTerminating() bool
func (Unreachable) String ¶
func (_ Unreachable) String() string
type Value ¶
type Value interface { Type() types.Type Name() string // is empty for unset name SetName(string) // Duplicates may exist if the value is referenced more than once in an instruction. References() []Instruction // contains filtered or unexported methods }
func GetOperands ¶
func GetOperands(instr Instruction) []Value
type ZeroInitialiser ¶
type ZeroInitialiser struct{}
Used to zero out a global as an initialiser
func NewZeroInitialiser ¶
func NewZeroInitialiser() *ZeroInitialiser
func (ZeroInitialiser) Initialiser ¶
func (_ ZeroInitialiser) Initialiser()
func (ZeroInitialiser) String ¶
func (_ ZeroInitialiser) String() string