ir2

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package ir2 contains an Intermediate Representation (IR) in Static Single Assignment (SSA) form.

  • Each Program contains a list of Packages.
  • Packages are a list of Globals, TypeDefs and Funcs.
  • Each Func is a list of Blocks.
  • Blocks have a list of Instrs.
  • Instrs Def (define) Values, and have Values as Args.
  • Values can be constants, types, temps, registers, memory locations, etc.

Note: Unlike other SSA representations, this representation separates the concept of instructions from the concept of values. This allows an instruction to define multiple values. This is handy to avoid needing tuples and unpacking tuples to handle instructions (like function calls) that return multiple values.

Index

Constants

This section is empty.

Variables

View Source
var Placeholder ident = idFor(ValuePlaceholder, -1)

Placeholder is an invalid ID meant to signal a place that needs to be filled

Functions

func BoolValue added in v0.1.3

func BoolValue(c Const) (bool, bool)

BoolValue returns a bool for a BoolConst

func Int64Value added in v0.1.3

func Int64Value(c Const) (int64, bool)

Int64Value returns an int64 for an IntConst

func IntValue added in v0.1.3

func IntValue(c Const) (int, bool)

IntValue returns an int for an IntConst

func StringValue added in v0.1.3

func StringValue(c Const) (string, bool)

StringValue return a string for a StringConst

Types

type Block

type Block struct {
	User
	// contains filtered or unexported fields
}

Block is a collection of Instrs which is a basic block in a control flow graph. The last Instr of a block must be a control flow Instr. A block may begin with one or more Phi Instrs, and all Phis should be at the start of the Block. Blocks can have Preds and Succs for the blocks that come before or after in the control flow graph respectively.

func (*Block) AddPred added in v0.1.3

func (blk *Block) AddPred(pred *Block)

AddPred adds the Block to the predecessor list

func (*Block) AddSucc added in v0.1.3

func (blk *Block) AddSucc(succ *Block)

AddSucc adds the Block to the successor list

func (Block) BlockIn added in v0.1.4

func (id Block) BlockIn(fn *Func) *Block

BlockIn returns the Block in the Func or nil if this ID is not for a Block

func (*Block) Control added in v0.1.3

func (blk *Block) Control() *Instr

Control returns the last instruction, which should be a control flow instruction

func (*Block) Emit added in v0.1.3

func (blk *Block) Emit(out io.Writer, dec Decorator)

func (*Block) Func added in v0.1.3

func (blk *Block) Func() *Func

Func returns the containing Func

func (Block) IDNum added in v0.1.4

func (id Block) IDNum() int

IDNum returns the ID number for the ID

func (Block) IDString added in v0.1.4

func (id Block) IDString() string

IDString returns the ID string

func (*Block) InsertInstr added in v0.1.3

func (blk *Block) InsertInstr(i int, instr *Instr)

InsertInstr inserts the instruction at the ith position. -1 means append it.

func (*Block) Instr added in v0.1.3

func (blk *Block) Instr(i int) *Instr

Instr returns the ith Instr in the list

func (Block) InstrIn added in v0.1.4

func (id Block) InstrIn(fn *Func) *Instr

InstrIn returns the Instr in the Func or nil if this ID is not for a Instr

func (*Block) InstrIter added in v0.1.3

func (blk *Block) InstrIter() *BlockIter

InstrIter will return an Iter which iterates over every instruction in this block.

func (Block) IsBlock added in v0.1.4

func (id Block) IsBlock() bool

IsBlock returns if ID points to a Block

func (Block) IsInstr added in v0.1.4

func (id Block) IsInstr() bool

IsInstr returns if ID points to a Instr

func (Block) IsValue added in v0.1.4

func (id Block) IsValue() bool

IsValue returns if ID points to a Value

func (*Block) NumInstrs added in v0.1.3

func (blk *Block) NumInstrs() int

NumInstrs returns the number of instructions

func (*Block) NumPreds added in v0.1.3

func (blk *Block) NumPreds() int

NumPreds is the number of predecessors

func (*Block) NumSuccs added in v0.1.3

func (blk *Block) NumSuccs() int

NumSuccs returns the number of successors

func (Block) ObjectKind added in v0.1.4

func (id Block) ObjectKind() ObjectKind

ObjectKind returns the kind of object the ID is for

func (*Block) Pred added in v0.1.3

func (blk *Block) Pred(i int) *Block

Pred returns the ith predecessor

func (*Block) RemoveInstr added in v0.1.3

func (blk *Block) RemoveInstr(inst *Instr)

RemoveInstr removes the Instr from the list

func (*Block) String added in v0.1.3

func (blk *Block) String() string

func (*Block) Succ added in v0.1.3

func (blk *Block) Succ(i int) *Block

Succ returns the ith successor

func (*Block) SwapInstr added in v0.1.3

func (blk *Block) SwapInstr(a *Instr, b *Instr)

SwapInstr swaps two instructions

func (blk *Block) Unlink()

Unlink removes the Block from the pred/succ lists of surrounding Blocks

func (Block) ValueIn added in v0.1.4

func (id Block) ValueIn(fn *Func) *Value

ValueIn returns the Value in the Func or nil if this ID is not for a Value

type BlockIter added in v0.1.3

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

BlockIter is an iterator that iterates over instructions in a Block

func (*BlockIter) Block added in v0.1.3

func (it *BlockIter) Block() *Block

Block returns the current block

func (*BlockIter) BlockIndex added in v0.1.3

func (it *BlockIter) BlockIndex() int

BlockIndex returns the index of the Block within the Func

func (*BlockIter) Changed added in v0.1.3

func (it *BlockIter) Changed()

Changed forces `HasChanged()` to return true

func (*BlockIter) HasChanged added in v0.1.3

func (it *BlockIter) HasChanged() bool

HasChanged returns true if `Changed()` was called, or one of the mutation methods

func (*BlockIter) HasNext added in v0.1.3

func (it *BlockIter) HasNext() bool

HasNext returns whether Next() will succeed

func (*BlockIter) HasPrev added in v0.1.3

func (it *BlockIter) HasPrev() bool

HasPrev returns whether Prev() will succeed

func (*BlockIter) Insert added in v0.1.3

func (it *BlockIter) Insert(op Op, typ types.Type, args ...interface{}) *Instr

Insert inserts an instruction at the cursor position and increments the position

func (*BlockIter) Instr added in v0.1.3

func (it *BlockIter) Instr() *Instr

Instr returns the current instruction

func (*BlockIter) InstrIndex added in v0.1.3

func (it *BlockIter) InstrIndex() int

InstrIndex returns the index of the current instruction in the Block

func (*BlockIter) Last added in v0.1.4

func (it *BlockIter) Last() bool

Last fast forwards to the end of the block

func (*BlockIter) Next added in v0.1.3

func (it *BlockIter) Next() bool

Next increments the position and returns whether that was successful

func (*BlockIter) Prev added in v0.1.3

func (it *BlockIter) Prev() bool

Prev decrements the position and returns whether that was successful

func (*BlockIter) Remove added in v0.1.3

func (it *BlockIter) Remove() *Instr

Remove will remove the instruction at the current position and decrement the position, returning the removed instruction. NOTE: this only removes the instruction from the Block, it does not Unlink() it from any uses.

func (*BlockIter) Update added in v0.1.3

func (it *BlockIter) Update(op Op, typ types.Type, args ...interface{}) *Instr

Update updates the instruction at the cursor position

type Const added in v0.1.3

type Const interface {
	Location() Location
	Kind() ConstKind
	String() string
	// contains filtered or unexported methods
}

Const is a constant value of some sort

func ConstFor added in v0.1.3

func ConstFor(v interface{}) Const

Return a Const for a value

type ConstKind added in v0.1.3

type ConstKind uint8

ConstKind is a kind of constant

const (
	// no const, or not a const
	NotConst ConstKind = iota

	// nil, which is different than no const at all
	NilConst

	// non-numeric values
	BoolConst
	StringConst

	// numeric values
	IntConst

	// funcs and globals
	FuncConst
	GlobalConst
)

type CrossBlockIter added in v0.1.3

type CrossBlockIter struct {
	BlockIter
	// contains filtered or unexported fields
}

func (*CrossBlockIter) HasNext added in v0.1.3

func (it *CrossBlockIter) HasNext() bool

HasNext returns whether Next() will succeed

func (*CrossBlockIter) HasPrev added in v0.1.3

func (it *CrossBlockIter) HasPrev() bool

HasPrev returns whether Prev() will succeed

func (*CrossBlockIter) Last added in v0.1.4

func (it *CrossBlockIter) Last() bool

Last fast forwards to the end of the func

func (*CrossBlockIter) Next added in v0.1.3

func (it *CrossBlockIter) Next() bool

Next increments the position and returns whether that was successful

func (*CrossBlockIter) Prev added in v0.1.3

func (it *CrossBlockIter) Prev() bool

Prev decrements the position and returns whether that was successful

type Decorator added in v0.1.3

type Decorator interface {
	Begin(out io.Writer, what interface{})
	End(out io.Writer, what interface{})

	BeginLabel(out io.Writer, what interface{})
	EndLabel(out io.Writer, what interface{})

	WrapLabel(str string, what interface{}) string
	WrapRef(str string, what interface{}) string
	WrapType(str string) string
	WrapOp(str string, what Op) string
	SSAForm() bool
}

type Func

type Func struct {
	Name     string
	FullName string
	Sig      *types.Signature

	Referenced bool
	NumCalls   int
	// contains filtered or unexported fields
}

Func is a collection of Blocks, which comprise a function or method in a Program.

func FuncValue added in v0.1.3

func FuncValue(c Const) (*Func, bool)

FuncValue returns a *Func for a FuncConst

func (*Func) Block added in v0.1.3

func (fn *Func) Block(i int) *Block

Block returns the ith Block

func (*Func) BlockForID added in v0.1.3

func (fn *Func) BlockForID(b ident) *Block

BlockForID returns a Block by ID

func (*Func) BlockIndex added in v0.1.3

func (fn *Func) BlockIndex(blk *Block) int

BlockIndex returns the index of the Block in the list

func (*Func) Emit added in v0.1.3

func (fn *Func) Emit(out io.Writer, dec Decorator)

func (*Func) HasPlaceholders added in v0.1.3

func (fn *Func) HasPlaceholders() bool

HasPlaceholders returns whether there are unresolved placeholders or not

func (*Func) InsertBlock added in v0.1.3

func (fn *Func) InsertBlock(i int, blk *Block)

InsertBlock inserts the block at the specific location in the list

func (*Func) InstrForID added in v0.1.3

func (fn *Func) InstrForID(i ident) *Instr

InstrForID returns the Instr for the ID

func (*Func) InstrIter added in v0.1.3

func (fn *Func) InstrIter() *CrossBlockIter

InstrIter returns an iterator that will iterate over every block and instruction in the func.

func (*Func) LongString added in v0.1.3

func (fn *Func) LongString() string

func (*Func) NewBlock added in v0.1.3

func (fn *Func) NewBlock() *Block

NewBlock adds a new block

func (*Func) NewInstr added in v0.1.3

func (fn *Func) NewInstr(op Op, typ types.Type, args ...interface{}) *Instr

NewInstr creates an unbound Instr

func (*Func) NewValue added in v0.1.3

func (fn *Func) NewValue(typ types.Type) *Value

NewValue creates a new Value of type typ

func (*Func) NumBlocks added in v0.1.3

func (fn *Func) NumBlocks() int

NumBlocks returns the number of Blocks

func (*Func) Package added in v0.1.3

func (fn *Func) Package() *Package

Package returns the Func's Package

func (*Func) PlaceholderFor added in v0.1.3

func (fn *Func) PlaceholderFor(label string) *Value

PlaceholderFor creates a special placeholder value that can be later resolved with a different value. This is useful for marking and resolving forward references.

func (*Func) PlaceholderLabels added in v0.1.3

func (fn *Func) PlaceholderLabels() []string

PlaceholderLabels returns a sorted list of placeholder labels

func (*Func) RemoveBlock added in v0.1.3

func (fn *Func) RemoveBlock(blk *Block)

RemoveBlock removes the Block from the list but does not remove it from succ/pred lists. See blk.Unlink()

func (*Func) ResolvePlaceholder added in v0.1.3

func (fn *Func) ResolvePlaceholder(label string, value *Value)

ResolvePlaceholder removes the placeholder from the list, replacing its uses with the specified value

func (*Func) ValueFor added in v0.1.3

func (fn *Func) ValueFor(typ types.Type, v interface{}) *Value

ValueFor looks up an existing Value

func (*Func) ValueForID added in v0.1.3

func (fn *Func) ValueForID(v ident) *Value

ValueForID returns the Value for the ID

type Global added in v0.1.3

type Global struct {
	Name       string
	FullName   string
	Type       types.Type
	Referenced bool

	// initial value
	Value Const
	// contains filtered or unexported fields
}

Global is a global variable or literal stored in memory

func GlobalValue added in v0.1.3

func GlobalValue(c Const) (*Global, bool)

GlobalValue returns a *Func for a GlobalConst

func (*Global) Emit added in v0.1.3

func (glob *Global) Emit(out io.Writer, dec Decorator)

func (*Global) Package added in v0.1.3

func (glob *Global) Package() *Package

func (*Global) String added in v0.1.3

func (glob *Global) String() string

type Instr

type Instr struct {
	User
	Op

	Pos token.Pos
	// contains filtered or unexported fields
}

Instr is an instruction that may define one or more Values, and take as args (operands) one or more Values.

func (Instr) BlockIn added in v0.1.4

func (id Instr) BlockIn(fn *Func) *Block

BlockIn returns the Block in the Func or nil if this ID is not for a Block

func (*Instr) Emit added in v0.1.3

func (in *Instr) Emit(out io.Writer, dec Decorator)

func (Instr) IDNum added in v0.1.4

func (id Instr) IDNum() int

IDNum returns the ID number for the ID

func (Instr) IDString added in v0.1.4

func (id Instr) IDString() string

IDString returns the ID string

func (*Instr) Index added in v0.1.3

func (in *Instr) Index() int

Index returns the index in the Block's Instr list

func (Instr) InstrIn added in v0.1.4

func (id Instr) InstrIn(fn *Func) *Instr

InstrIn returns the Instr in the Func or nil if this ID is not for a Instr

func (Instr) IsBlock added in v0.1.4

func (id Instr) IsBlock() bool

IsBlock returns if ID points to a Block

func (Instr) IsInstr added in v0.1.4

func (id Instr) IsInstr() bool

IsInstr returns if ID points to a Instr

func (Instr) IsValue added in v0.1.4

func (id Instr) IsValue() bool

IsValue returns if ID points to a Value

func (*Instr) LineNo added in v0.1.4

func (in *Instr) LineNo() int

func (*Instr) LongString added in v0.1.3

func (in *Instr) LongString() string

func (*Instr) MoveAfter added in v0.1.3

func (in *Instr) MoveAfter(other *Instr)

MoveAfter moves this instruction after other

func (*Instr) MoveBefore added in v0.1.3

func (in *Instr) MoveBefore(other *Instr)

MoveBefore moves this instruction before other

func (Instr) ObjectKind added in v0.1.4

func (id Instr) ObjectKind() ObjectKind

ObjectKind returns the kind of object the ID is for

func (*Instr) Update added in v0.1.3

func (in *Instr) Update(op Op, typ types.Type, args ...interface{})

Update changes the op, type and number of defs and the args

func (Instr) ValueIn added in v0.1.4

func (id Instr) ValueIn(fn *Func) *Value

ValueIn returns the Value in the Func or nil if this ID is not for a Value

type Iter added in v0.1.3

type Iter interface {
	// Instr returns the current instruction
	Instr() *Instr

	// InstrIndex returns the index of the current instruction in the Block
	InstrIndex() int

	// Block returns the current block
	Block() *Block

	// BlockIndex returns the index of the Block within the Func
	BlockIndex() int

	// HasNext returns whether Next() will succeed
	HasNext() bool

	// Next increments the position and returns whether that was successful
	Next() bool

	// HasPrev returns whether Prev() will succeed
	HasPrev() bool

	// Prev decrements the position and returns whether that was successful
	Prev() bool

	// Last fast forwards to the end
	Last() bool

	// Insert inserts an instruction at the cursor position and increments the position
	Insert(op Op, typ types.Type, args ...interface{}) *Instr

	// Remove will remove the instruction at the current position and decrement the position,
	// returning the removed instruction.
	// NOTE: this only removes the instruction from the Block, it does not Unlink() it from
	// any uses.
	Remove() *Instr

	// Update updates the instruction at the cursor position
	Update(op Op, typ types.Type, args ...interface{}) *Instr

	// HasChanged returns true if `Changed()` was called, or one of the mutation methods
	HasChanged() bool

	// Changed forces `HasChanged()` to return true
	Changed()
}

Iter is a iterator over instructions

type Location added in v0.1.4

type Location uint8

Location is the location of a Value

const (
	InTemp Location = iota
	InConst
	InReg

	// Param slots are an area of the stack for func parameters.
	// Specifically, they are in the caller's arg slot area.
	InParamSlot

	// Arg slots are an area of the stack reserved for call arguments.
	InArgSlot

	// Spill slots are an area of the stack reserved for register spills.
	InSpillSlot
)

type ObjectKind added in v0.1.4

type ObjectKind uint8
const (
	UnknownObject ObjectKind = iota
	BlockObject
	InstrObject
	ValueObject
	ValuePlaceholder
)

type Op added in v0.1.3

type Op interface {
	String() string
	IsCall() bool
	IsCompare() bool
	IsCopy() bool
	IsCommutative() bool
	IsSink() bool
}

Op describes an operation (instruction) type

type Package

type Package struct {
	Type *types.Package

	Name string
	Path string
	// contains filtered or unexported fields
}

Package is a collection of Funcs and Globals which comprise a part of a program.

func (*Package) Emit added in v0.1.3

func (pkg *Package) Emit(out io.Writer, dec Decorator)

func (*Package) Func added in v0.1.3

func (pkg *Package) Func(name string) *Func

Func finds a func by either Name or FullName

func (*Package) Funcs added in v0.1.3

func (pkg *Package) Funcs() []*Func

Funcs returns a copy of the func list

func (*Package) Global added in v0.1.3

func (pkg *Package) Global(name string) *Global

Global finds the Global by Name or FullName

func (*Package) Globals added in v0.1.3

func (pkg *Package) Globals() []*Global

Globals returns a copy of the global list

func (*Package) NewFunc added in v0.1.3

func (pkg *Package) NewFunc(name string, sig *types.Signature) *Func

NewFunc adds a func to the list

func (*Package) NewGlobal added in v0.1.3

func (pkg *Package) NewGlobal(name string, typ types.Type) *Global

NewGlobal adds a global to the list

func (*Package) NewStringLiteral added in v0.1.3

func (pkg *Package) NewStringLiteral(funcname, str string) *Global

NewStringLiteral creates a global with a string literal value

func (*Package) NewTypeDef added in v0.1.3

func (pkg *Package) NewTypeDef(name string, typ types.Type) *TypeDef

NewTypeDef adds a typedef to the list

func (*Package) Program added in v0.1.3

func (pkg *Package) Program() *Program

Program that the package belongs to

func (*Package) TypeDef added in v0.1.3

func (pkg *Package) TypeDef(name string) *TypeDef

TypeDef finds a func by either Name or FullName

func (*Package) TypeDefs added in v0.1.3

func (pkg *Package) TypeDefs() []*TypeDef

TypeDefs returns a copy of the func list

type Program added in v0.1.3

type Program struct {
	FileSet *token.FileSet
	// contains filtered or unexported fields
}

Program is a collection of packages, which comprise a whole program.

func (*Program) AddPackage added in v0.1.3

func (prog *Program) AddPackage(pkg *Package)

AddPackage adds a package to the list

func (*Program) Emit added in v0.1.3

func (prog *Program) Emit(out io.Writer, dec Decorator)

func (*Program) Func added in v0.1.3

func (prog *Program) Func(name string) *Func

Func searches each package for a func

func (*Program) Global added in v0.1.3

func (prog *Program) Global(name string) *Global

Global searches each package for a global

func (*Program) Package added in v0.1.3

func (prog *Program) Package(name string) *Package

Package finds a package first by full name, then if there is no match, by short name.

func (*Program) Packages added in v0.1.3

func (prog *Program) Packages() []*Package

Packages returns a copy of the package list

func (*Program) StringLiteral added in v0.1.3

func (prog *Program) StringLiteral(str string, fullname string) *Global

type SSAString added in v0.1.3

type SSAString struct{}

SSAString emits a plain string in SSA form

func (SSAString) Begin added in v0.1.3

func (ss SSAString) Begin(out io.Writer, what interface{})

func (SSAString) BeginLabel added in v0.1.4

func (ss SSAString) BeginLabel(out io.Writer, what interface{})

func (SSAString) End added in v0.1.3

func (ss SSAString) End(out io.Writer, what interface{})

func (SSAString) EndLabel added in v0.1.4

func (ss SSAString) EndLabel(out io.Writer, what interface{})

func (SSAString) SSAForm added in v0.1.3

func (ss SSAString) SSAForm() bool

func (SSAString) WrapLabel added in v0.1.3

func (ss SSAString) WrapLabel(str string, what interface{}) string

func (SSAString) WrapOp added in v0.1.3

func (ss SSAString) WrapOp(str string, what Op) string

func (SSAString) WrapRef added in v0.1.3

func (ss SSAString) WrapRef(str string, what interface{}) string

func (SSAString) WrapType added in v0.1.3

func (ss SSAString) WrapType(str string) string

type TypeDef added in v0.1.3

type TypeDef struct {
	Name       string
	Referenced bool

	Type types.Type
	// contains filtered or unexported fields
}

TypeDef is a type definition

func (*TypeDef) Emit added in v0.1.3

func (td *TypeDef) Emit(out io.Writer, dec Decorator)

type User added in v0.1.4

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

User uses and defines Values. Blocks and Instrs are Users.

func (*User) AddDef added in v0.1.4

func (use *User) AddDef(val *Value) *Value

AddDef adds a Value definition

func (*User) Arg added in v0.1.4

func (use *User) Arg(i int) *Value

Arg returns the ith argument

func (*User) ArgIndex added in v0.1.4

func (use *User) ArgIndex(arg *Value) int

ArgIndex returns the index of the arg, or -1 if not found

func (*User) Args added in v0.1.4

func (use *User) Args() []*Value

Args returns a copy of the arguments

func (*User) Block added in v0.1.4

func (use *User) Block() *Block

Block returns either the User Block or parent Block

func (User) BlockIn added in v0.1.4

func (id User) BlockIn(fn *Func) *Block

BlockIn returns the Block in the Func or nil if this ID is not for a Block

func (*User) Def added in v0.1.4

func (use *User) Def(i int) *Value

Def returns the ith Value defined

func (*User) Defs added in v0.1.4

func (use *User) Defs() []*Value

Defs returns a copy of the list of Values defined by this user

func (*User) Func added in v0.1.4

func (use *User) Func() *Func

Func returns the containing function

func (User) IDNum added in v0.1.4

func (id User) IDNum() int

IDNum returns the ID number for the ID

func (User) IDString added in v0.1.4

func (id User) IDString() string

IDString returns the ID string

func (*User) InsertArg added in v0.1.4

func (use *User) InsertArg(i int, arg *Value)

InsertArg inserts the Value in the argument list at position i, or appending if i is -1

func (*User) Instr added in v0.1.4

func (use *User) Instr() *Instr

Instr returns either the Instr or an empty Instr to cut down on having to check IsInstr() everywhere.

func (User) InstrIn added in v0.1.4

func (id User) InstrIn(fn *Func) *Instr

InstrIn returns the Instr in the Func or nil if this ID is not for a Instr

func (User) IsBlock added in v0.1.4

func (id User) IsBlock() bool

IsBlock returns if ID points to a Block

func (User) IsInstr added in v0.1.4

func (id User) IsInstr() bool

IsInstr returns if ID points to a Instr

func (User) IsValue added in v0.1.4

func (id User) IsValue() bool

IsValue returns if ID points to a Value

func (*User) NumArgs added in v0.1.4

func (use *User) NumArgs() int

NumArgs returns the number of arguments

func (*User) NumDefs added in v0.1.4

func (use *User) NumDefs() int

NumDefs returns the number of Values defined

func (User) ObjectKind added in v0.1.4

func (id User) ObjectKind() ObjectKind

ObjectKind returns the kind of object the ID is for

func (*User) RemoveArg added in v0.1.4

func (use *User) RemoveArg(arg *Value)

RemoveArg removes the value from the arguments list

func (*User) ReplaceArg added in v0.1.4

func (use *User) ReplaceArg(i int, arg *Value)

ReplaceArg replaces the ith argument with the value specified. Will call InsertArg instead if i == NumArgs().

func (User) ValueIn added in v0.1.4

func (id User) ValueIn(fn *Func) *Value

ValueIn returns the Value in the Func or nil if this ID is not for a Value

type Value

type Value struct {

	// Type is the type of the Value
	Type types.Type
	// contains filtered or unexported fields
}

Value is a single value that may be stored in a single place. This may be a constant or variable, stored in a temp, register or on the stack.

func (*Value) ArgSlot added in v0.1.4

func (val *Value) ArgSlot() int

ArgSlot returns which arg slot the Value is in, or -1 if not in a arg slot.

func (Value) BlockIn added in v0.1.4

func (id Value) BlockIn(fn *Func) *Block

BlockIn returns the Block in the Func or nil if this ID is not for a Block

func (*Value) Const added in v0.1.3

func (val *Value) Const() Const

Const returns the constant value of the Value or NotConst if not constant.

func (*Value) Def added in v0.1.3

func (val *Value) Def() *User

Def returns the Instr defining the Value, or nil if it's not defined

func (*Value) Func added in v0.1.3

func (val *Value) Func() *Func

Func returns the containing Func.

func (Value) IDNum added in v0.1.4

func (id Value) IDNum() int

IDNum returns the ID number for the ID

func (Value) IDString added in v0.1.4

func (id Value) IDString() string

IDString returns the ID string

func (*Value) InArgSlot added in v0.1.4

func (val *Value) InArgSlot() bool

InArgSlot returns whether the value in one of the arg slots on the stack.

func (*Value) InParamSlot added in v0.1.4

func (val *Value) InParamSlot() bool

InParamSlot returns whether the value in one of the param slots on the stack.

func (*Value) InReg added in v0.1.4

func (val *Value) InReg() bool

InReg indicates if the Value is in a register.

func (*Value) InSpillSlot added in v0.1.4

func (val *Value) InSpillSlot() bool

InSpillSlot returns whether the value in one of the spill slots on the stack.

func (*Value) InTemp added in v0.1.4

func (val *Value) InTemp() bool

InTemp indicates the value is in a temp.

func (Value) InstrIn added in v0.1.4

func (id Value) InstrIn(fn *Func) *Instr

InstrIn returns the Instr in the Func or nil if this ID is not for a Instr

func (Value) IsBlock added in v0.1.4

func (id Value) IsBlock() bool

IsBlock returns if ID points to a Block

func (*Value) IsConst added in v0.1.4

func (val *Value) IsConst() bool

IsConst returns if the Value is constant.

func (*Value) IsDefinedByOp added in v0.1.4

func (val *Value) IsDefinedByOp(op Op) bool

func (Value) IsInstr added in v0.1.4

func (id Value) IsInstr() bool

IsInstr returns if ID points to a Instr

func (Value) IsValue added in v0.1.4

func (id Value) IsValue() bool

IsValue returns if ID points to a Value

func (*Value) NumUses added in v0.1.3

func (val *Value) NumUses() int

NumUses returns the number of uses

func (Value) ObjectKind added in v0.1.4

func (id Value) ObjectKind() ObjectKind

ObjectKind returns the kind of object the ID is for

func (*Value) ParamSlot added in v0.1.4

func (val *Value) ParamSlot() int

ParamSlot returns which param slot the Value is in, or -1 if not in a param slot.

func (*Value) Reg added in v0.1.3

func (val *Value) Reg() reg.Reg

Reg returns which register the Value is in, otherwise reg.None if its not in a register.

func (*Value) ReplaceUsesWith added in v0.1.3

func (val *Value) ReplaceUsesWith(other *Value)

ReplaceUsesWith will go through each use of val and replace it with other. Does not modify any definitions.

func (*Value) SetArgSlot added in v0.1.4

func (val *Value) SetArgSlot(slot int)

SetArgSlot puts the Value in the specified arg slot on the stack.

func (*Value) SetConst added in v0.1.4

func (val *Value) SetConst(con Const)

SetConst makes the Value the specified constant.

func (*Value) SetParamSlot added in v0.1.4

func (val *Value) SetParamSlot(slot int)

SetParamSlot puts the Value in the specified param slot on the stack.

func (*Value) SetReg added in v0.1.4

func (val *Value) SetReg(reg reg.Reg)

SetReg puts the value in the specified register.

func (*Value) SetSpillSlot added in v0.1.4

func (val *Value) SetSpillSlot(slot int)

SetSpillSlot puts the Value in the specified spill slot on the stack.

func (*Value) SetTemp added in v0.1.4

func (val *Value) SetTemp()

SetTemp turns the value into a temp.

func (*Value) SpillSlot added in v0.1.4

func (val *Value) SpillSlot() int

SpillSlot returns which spill slot the Value is in, or -1 if not in a spill slot.

func (*Value) String added in v0.1.3

func (val *Value) String() string

func (*Value) Temp added in v0.1.4

func (val *Value) Temp() ident

Temp returns which temp if the value is in a temp.

func (*Value) Use added in v0.1.3

func (val *Value) Use(i int) *User

Use returns the ith Instr using this Value

func (Value) ValueIn added in v0.1.4

func (id Value) ValueIn(fn *Func) *Value

ValueIn returns the Value in the Func or nil if this ID is not for a Value

Directories

Path Synopsis
experimental simplified type system Defintions: - A `byte` is the smallest addressable unit in the CPU, this does not need to be 8 bits, though it usually is.
experimental simplified type system Defintions: - A `byte` is the smallest addressable unit in the CPU, this does not need to be 8 bits, though it usually is.

Jump to

Keyboard shortcuts

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