ssa

package
v0.0.0-...-563a209 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 16, 2016 License: LGPL-3.0 Imports: 7 Imported by: 5

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func BlockTrace

func BlockTrace(block *Block) string

func EscapeString

func EscapeString(str string) string

func FunctionTrace

func FunctionTrace(function *Function) string

func GlobalTrace

func GlobalTrace(global *Global) string

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 ValueIdentifier(val Value) string

func ValueString

func ValueString(val Value) string

Types

type Alloc

type Alloc struct {
	NameHandler
	ReferenceHandler
	BlockHandler
	// contains filtered or unexported fields
}

func (Alloc) IsTerminating

func (_ Alloc) IsTerminating() bool

func (Alloc) String

func (v Alloc) String() string

func (Alloc) Type

func (v Alloc) Type() types.Type

type BinOp

type BinOp struct {
	BlockHandler
	NameHandler
	ReferenceHandler
	// contains filtered or unexported fields
}

func (BinOp) BinOpType

func (v BinOp) BinOpType() BinOpType

func (BinOp) IsTerminating

func (_ BinOp) IsTerminating() bool

func (BinOp) String

func (v BinOp) String() string

func (BinOp) Type

func (v BinOp) Type() types.Type

type BinOpType

type BinOpType int
const (
	// Integer arithmetic
	BinOpAdd BinOpType = iota
	BinOpSub
	BinOpMul
	BinOpSDiv
	BinOpUDiv
	BinOpSRem
	BinOpURem

	// Float arithmetic
	BinOpFAdd
	BinOpFSub
	BinOpFMul
	BinOpFDiv
	BinOpFRem

	// Bitwise
	BinOpShl
	BinOpLShr
	BinOpAShr
	BinOpAnd
	BinOpOr
	BinOpXor
)

func (BinOpType) String

func (i BinOpType) String() string

type Block

type Block struct {
	ReferenceHandler
	NameHandler
	// contains filtered or unexported fields
}

func (Block) FirstInstr

func (v Block) FirstInstr() Instruction

func (Block) Function

func (v Block) Function() *Function

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) IsEntry

func (v *Block) IsEntry() bool

func (Block) LastInstr

func (v Block) LastInstr() Instruction

func (Block) NumInstrs

func (v Block) NumInstrs() int

func (Block) String

func (v Block) String() string

func (Block) Type

func (_ Block) Type() types.Type

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

func (_ Br) IsTerminating() bool

func (Br) String

func (v Br) String() string

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

func NewBuilder

func NewBuilder() *Builder

func (*Builder) CreateAlloc

func (v *Builder) CreateAlloc(typ types.Type, name string) *Alloc

func (*Builder) CreateBinOp

func (v *Builder) CreateBinOp(x, y Value, binOpType BinOpType, name string) *BinOp

func (*Builder) CreateBr

func (v *Builder) CreateBr(target *Block) *Br

func (*Builder) CreateCall

func (v *Builder) CreateCall(fn *Function, args []Value, name string) *Call

func (*Builder) CreateCondBr

func (v *Builder) CreateCondBr(cond Value, trueTarget, falseTarget *Block) *CondBr

func (*Builder) CreateConvert

func (v *Builder) CreateConvert(x Value, target types.Type, convertType ConvertType, name string) *Convert

func (*Builder) CreateGEP

func (v *Builder) CreateGEP(value Value, indexes []Value, name string) *GEP

func (*Builder) CreateICmp

func (v *Builder) CreateICmp(x, y Value, predicate IntPredicate, name string) *ICmp

func (*Builder) CreateLoad

func (v *Builder) CreateLoad(location Value, name string) *Load

func (*Builder) CreatePhi

func (v *Builder) CreatePhi(t types.Type, name string) *Phi

func (*Builder) CreateRet

func (v *Builder) CreateRet(returnValue Value) *Ret

func (*Builder) CreateStore

func (v *Builder) CreateStore(location, value Value) *Store

func (*Builder) CreateUnreachable

func (v *Builder) CreateUnreachable() *Unreachable

func (*Builder) SetInsertAfterInstr

func (v *Builder) SetInsertAfterInstr(i Instruction)

func (*Builder) SetInsertAtBlockEnd

func (v *Builder) SetInsertAtBlockEnd(b *Block)

func (*Builder) SetInsertAtBlockStart

func (v *Builder) SetInsertAtBlockStart(b *Block)

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

func (_ Call) IsTerminating() bool

func (Call) String

func (v Call) String() string

func (Call) Type

func (v Call) Type() types.Type

type CondBr

type CondBr struct {
	BlockHandler
	// contains filtered or unexported fields
}

func (CondBr) IsTerminating

func (_ CondBr) IsTerminating() bool

func (CondBr) String

func (v CondBr) String() string

type Convert

type Convert struct {
	NameHandler
	BlockHandler
	ReferenceHandler
	// contains filtered or unexported fields
}

func (Convert) ConvertType

func (v Convert) ConvertType() ConvertType

func (Convert) IsTerminating

func (_ Convert) IsTerminating() bool

func (Convert) String

func (v Convert) String() string

func (Convert) Type

func (v Convert) Type() types.Type

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 (v *Function) AddBlockAtEnd(name string) *Block

func (*Function) AddBlockAtStart

func (v *Function) AddBlockAtStart(name string) *Block

func (Function) Blocks

func (v Function) Blocks() []*Block

func (Function) EntryBlock

func (v Function) EntryBlock() *Block

func (Function) IsPrototype

func (v Function) IsPrototype() bool

func (Function) Parameters

func (v Function) Parameters() []*Parameter

func (Function) SignatureString

func (v Function) SignatureString() string

func (Function) String

func (v Function) String() string

func (Function) Type

func (v Function) Type() types.Type

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

func (_ GEP) IsTerminating() bool

func (GEP) String

func (v GEP) String() string

func (*GEP) Type

func (v *GEP) Type() types.Type

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)

func (*Global) String

func (v *Global) String() string

func (Global) Type

func (v Global) Type() types.Type

type ICmp

type ICmp struct {
	BlockHandler
	NameHandler
	ReferenceHandler
	// contains filtered or unexported fields
}

func (ICmp) IsTerminating

func (_ ICmp) IsTerminating() bool

func (ICmp) Predicate

func (v ICmp) Predicate() IntPredicate

func (ICmp) String

func (v ICmp) String() string

func (ICmp) Type

func (_ ICmp) Type() types.Type

type Initialiser

type Initialiser interface {
	Initialiser()
	String() string
}

type Instruction

type Instruction interface {
	// Returns the textual IR representation of the instruction.
	// If the instruction is also a value, the name of the value is not included in the string.
	String() string

	IsTerminating() bool

	Block() *Block
	// contains filtered or unexported methods
}

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 Literal

type Literal interface {
	Value
	LiteralValue() interface{}
}

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

func (_ Load) IsTerminating() bool

func (Load) String

func (v Load) String() string

func (Load) Type

func (v Load) Type() types.Type

type Module

type Module struct {
	// contains filtered or unexported fields
}

func NewModule

func NewModule(name string) *Module

func (Module) FunctionNamed

func (v Module) FunctionNamed(name string) *Function

func (Module) Functions

func (v Module) Functions() []*Function

func (Module) GlobalNamed

func (v Module) GlobalNamed(name string) *Global

func (Module) Globals

func (v Module) Globals() []*Global

func (Module) Name

func (v Module) Name() string

func (*Module) NewFunction

func (v *Module) NewFunction(typ *types.Signature, name string) *Function

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) NewGlobal

func (v *Module) NewGlobal(typ types.Type, init Initialiser, name string) *Global

func (*Module) NewGlobalString

func (v *Module) NewGlobalString(val string, nullTerminate bool, name string) *Global

Convenience method

func (*Module) String

func (v *Module) String() string

Automatically calls UpdateNames

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
}

func (Parameter) Type

func (v Parameter) Type() types.Type

type Phi

type Phi struct {
	ReferenceHandler
	BlockHandler
	NameHandler
	// contains filtered or unexported fields
}

func (*Phi) AddIncoming

func (v *Phi) AddIncoming(val Value, block *Block)

func (Phi) GetIncoming

func (v Phi) GetIncoming(index int) (Value, *Block)

func (Phi) IsTerminating

func (_ Phi) IsTerminating() bool

func (Phi) NumIncoming

func (v Phi) NumIncoming() int

func (*Phi) RemoveIncoming

func (v *Phi) RemoveIncoming(index int)

func (Phi) String

func (v Phi) String() string

func (Phi) Type

func (v Phi) Type() types.Type

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

func (_ Ret) IsTerminating() bool

func (Ret) String

func (v Ret) String() string

type Store

type Store struct {
	BlockHandler
	// contains filtered or unexported fields
}

func (Store) IsTerminating

func (_ Store) IsTerminating() bool

func (Store) String

func (v Store) String() string

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL