ssa

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WriteFunction

func WriteFunction(b *strings.Builder, f *Function)

Types

type Arithmetic

type Arithmetic struct {
	Op  string
	Lhs Value
	Rhs Value
}

func (Arithmetic) String

func (s Arithmetic) String() string

type Assign

type Assign struct {
	Lhs Value
	Rhs Value
	// contains filtered or unexported fields
}

func (*Assign) Block

func (v *Assign) Block() *BasicBlock

func (*Assign) Parent

func (v *Assign) Parent() *Function

func (*Assign) Referrers

func (v *Assign) Referrers() *[]Instruction

func (*Assign) String

func (v *Assign) String() string

type AttrGet

type AttrGet struct {
	Object Value
	Key    Value
}

func (AttrGet) String

func (s AttrGet) String() string

type BasicBlock

type BasicBlock struct {
	Index   int    // index of this block within Parent().Blocks
	Comment string // optional label; no semantic significance

	Instrs       []Instruction // instructions in order
	Preds, Succs []*BasicBlock // predecessors and successors
	// contains filtered or unexported fields
}

func (*BasicBlock) Dominates

func (b *BasicBlock) Dominates(c *BasicBlock) bool

Dominates reports whether b dominates c.

func (*BasicBlock) Dominees

func (b *BasicBlock) Dominees() []*BasicBlock

Dominees returns the list of blocks that b immediately dominates: its children in the dominator tree.

func (*BasicBlock) Idom

func (b *BasicBlock) Idom() *BasicBlock

Idom returns the block that immediately dominates b: its parent in the dominator tree, if any. Neither the entry node (b.Index==0) nor recover node (b==b.Parent().Recover()) have a parent.

func (*BasicBlock) Parent

func (b *BasicBlock) Parent() *Function

Parent returns the function that contains block b.

func (*BasicBlock) String

func (b *BasicBlock) String() string

String returns a human-readable label of this block. It is not guaranteed unique within the function.

func (*BasicBlock) ToAst

func (b *BasicBlock) ToAst(dom domFrontier) (chunk ast.Chunk)

type Call

type Call struct {
	Args   []Value
	Func   Value
	Method string
	Recv   Value
	// contains filtered or unexported fields
}

func (*Call) Block

func (v *Call) Block() *BasicBlock

func (*Call) Parent

func (v *Call) Parent() *Function

func (*Call) Referrers

func (v *Call) Referrers() *[]Instruction

func (Call) String

func (s Call) String() string

func (*Call) Value

func (s *Call) Value() *Call

type CompoundAssign

type CompoundAssign struct {
	Op  string
	Lhs Value
	Rhs Value
	// contains filtered or unexported fields
}

func (*CompoundAssign) Block

func (v *CompoundAssign) Block() *BasicBlock

func (*CompoundAssign) Parent

func (v *CompoundAssign) Parent() *Function

func (*CompoundAssign) Referrers

func (v *CompoundAssign) Referrers() *[]Instruction

func (*CompoundAssign) String

func (v *CompoundAssign) String() string

type Concat

type Concat struct {
	Lhs Value
	Rhs Value
}

func (Concat) String

func (s Concat) String() string

type False

type False struct{}

func (False) String

func (s False) String() string

type Field

type Field struct {
	Key   Value
	Value Value
}

type Function

type Function struct {
	Name      string
	Params    []*Local // function parameters; for methods, includes receiver
	Locals    []*Local
	UpValues  []*Local
	Functions []*Function   // nested functions defined inside this one
	Blocks    []*BasicBlock // basic blocks of the function; nil => external
	VarArg    bool
	// contains filtered or unexported fields
}

func Build

func Build(chunk ast.Chunk) *Function

func (*Function) Chunk

func (f *Function) Chunk() (chunk ast.Chunk)

func (*Function) DomPreorder

func (f *Function) DomPreorder() []*BasicBlock

DomPreorder returns a new slice containing the blocks of f in dominator tree preorder.

func (*Function) EmitAssign

func (f *Function) EmitAssign(lhs Value, rhs Value)

func (*Function) NewBasicBlock

func (f *Function) NewBasicBlock(comment string) *BasicBlock

NewBasicBlock adds to f a new basic block and returns it. It does not automatically become the current block for subsequent calls to emit. comment is an optional string for more readable debugging output.

func (*Function) Operands

func (v *Function) Operands(rands []*Value) []*Value

Non-Instruction Values: func (v *Const) Operands(rands []*Value) []*Value { return rands }

func (*Function) Parent

func (v *Function) Parent() *Function

func (*Function) Referrers

func (v *Function) Referrers() *[]Instruction

func (*Function) StartBody

func (f *Function) StartBody()

StartBody initializes the function prior to generating SSA code for its body. Precondition: f.Type() already set.

func (*Function) String

func (f *Function) String() string

func (*Function) Syntax

func (f *Function) Syntax() *ast.FunctionExpr

type GenericFor

type GenericFor struct {
	Locals []Value
	Values []Value
	// contains filtered or unexported fields
}

func (*GenericFor) Block

func (v *GenericFor) Block() *BasicBlock

func (*GenericFor) Parent

func (v *GenericFor) Parent() *Function

func (*GenericFor) Referrers

func (v *GenericFor) Referrers() *[]Instruction

func (*GenericFor) String

func (v *GenericFor) String() string

type Global

type Global struct {
	Comment string
	Value   Value
}

func (*Global) String

func (v *Global) String() string

type If

type If struct {
	Cond Value
	// contains filtered or unexported fields
}

func (*If) Block

func (v *If) Block() *BasicBlock

func (*If) Parent

func (v *If) Parent() *Function

func (*If) Referrers

func (v *If) Referrers() *[]Instruction

func (*If) String

func (s *If) String() string

type Instruction

type Instruction interface {
	String() string
	Parent() *Function
	Block() *BasicBlock
	// contains filtered or unexported methods
}

type Jump

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

func (*Jump) Block

func (v *Jump) Block() *BasicBlock

func (*Jump) Parent

func (v *Jump) Parent() *Function

func (*Jump) Referrers

func (v *Jump) Referrers() *[]Instruction

func (*Jump) String

func (s *Jump) String() string

type Local

type Local struct {
	Comment string
	Value   Value
	Num     int
	// contains filtered or unexported fields
}

func (*Local) Name

func (v *Local) Name() string

func (v *Function) Name() string { return fmt.Sprintf("func:%d", v.num) }

func (*Local) String

func (s *Local) String() string

type Logic

type Logic struct {
	Op  string
	Lhs Value
	Rhs Value
}

func (Logic) String

func (s Logic) String() string

type Nil

type Nil struct{}

func (Nil) String

func (s Nil) String() string

type Node

type Node interface {
	// Common methods:
	String() string
	Parent() *Function

	// Partial methods:
	Operands(rands []*Value) []*Value // nil for non-Instructions
	Referrers() *[]Instruction        // nil for non-Values
}

type Number

type Number struct {
	Value float64
}

func (Number) String

func (s Number) String() string

type NumberFor

type NumberFor struct {
	Local Value
	Init  Value
	Limit Value
	Step  Value
	// contains filtered or unexported fields
}

func (*NumberFor) Block

func (v *NumberFor) Block() *BasicBlock

func (*NumberFor) Parent

func (v *NumberFor) Parent() *Function

func (*NumberFor) Referrers

func (v *NumberFor) Referrers() *[]Instruction

func (*NumberFor) String

func (v *NumberFor) String() string

type Phi

type Phi struct {
	Comment string  // a hint as to its purpose
	Edges   []Value // Edges[i] is value for Block().Preds[i]
	// contains filtered or unexported fields
}

func (*Phi) Block

func (v *Phi) Block() *BasicBlock

func (*Phi) Operands

func (v *Phi) Operands(rands []*Value) []*Value

func (*Phi) Parent

func (v *Phi) Parent() *Function

func (*Phi) Referrers

func (v *Phi) Referrers() *[]Instruction

func (*Phi) String

func (v *Phi) String() string

type Relation

type Relation struct {
	Op  string
	Lhs Value
	Rhs Value
}

func (Relation) String

func (s Relation) String() string

type Return

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

func (*Return) Block

func (v *Return) Block() *BasicBlock

func (*Return) Parent

func (v *Return) Parent() *Function

func (*Return) Referrers

func (v *Return) Referrers() *[]Instruction

func (*Return) String

func (s *Return) String() string

type Scope

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

type String

type String struct {
	Value string
}

func (String) String

func (s String) String() string

type Table

type Table struct {
	Fields []*Field
}

func (Table) String

func (s Table) String() string

type True

type True struct{}

func (True) String

func (s True) String() string

type Unary

type Unary struct {
	Op    string
	Value Value
}

func (Unary) String

func (s Unary) String() string

type Value

type Value interface {
	String() string
}

type VarArg

type VarArg struct{}

func (VarArg) String

func (s VarArg) String() string

type Variable

type Variable interface {
	String() string
}

Jump to

Keyboard shortcuts

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