ssa

package
v1.2.6 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2023 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ConstMap = make(map[any]*Const)

	UnDefineConst = &Const{
		user:  []User{},
		value: nil,
		typ:   []Type{BasicTypesKind[Undefine]},
		str:   "Undefine",
		Unary: 0,
	}
)
View Source
var BasicTypesKind = []BasicType{
	Number:   {Number, "number"},
	String:   {String, "string"},
	Boolean:  {Boolean, "boolean"},
	Undefine: {Undefine, "undefine"},
	Null:     {Null, "null"},
	Any:      {Any, "any"},
}
View Source
var BinaryOpcodeName = map[BinaryOpcode]string{
	OpAnd:    `and`,
	OpAndNot: `and-not`,
	OpOr:     `or`,
	OpXor:    `xor`,
	OpShl:    `shl`,
	OpShr:    `shr`,
	OpAdd:    `add`,
	OpSub:    `sub`,
	OpMod:    `mod`,
	OpMul:    `mul`,
	OpDiv:    `div`,
	OpGt:     `gt`,
	OpLt:     `lt`,
	OpLtEq:   `lt-eq`,
	OpGtEq:   `gt-eq`,
	OpNotEq:  `neq`,
	OpEq:     `eq`,
}

----------- BinOp

Functions

func CheckTransForm

func CheckTransForm(from, to Type)

func CheckUpdateType

func CheckUpdateType(address, value []Type)

func GetReg

func GetReg(I Instruction, f *Function) string

func GetTypeStr

func GetTypeStr(n Node) string

func NewBlockId

func NewBlockId() string

func ReplaceValue

func ReplaceValue(v Value, to Value)

Types

type BasicBlock

type BasicBlock struct {
	Index int
	Name  string
	// function
	Parent *Function
	// basicblock graph
	Preds, Succs []*BasicBlock

	// instruction list
	Instrs []Instruction
	Phis   []*Phi
	// contains filtered or unexported fields
}

implement Value

func (*BasicBlock) AddSucc

func (b *BasicBlock) AddSucc(succ *BasicBlock)

func (*BasicBlock) AddUser

func (b *BasicBlock) AddUser(u User)

func (*BasicBlock) GetType

func (b *BasicBlock) GetType() Types

func (*BasicBlock) GetUsers

func (b *BasicBlock) GetUsers() []User

func (*BasicBlock) GetValues

func (b *BasicBlock) GetValues() []Value

----------- BasicBlock

func (*BasicBlock) LastInst

func (b *BasicBlock) LastInst() Instruction

func (*BasicBlock) RemoveUser

func (b *BasicBlock) RemoveUser(u User)

func (*BasicBlock) Sealed

func (b *BasicBlock) Sealed()

func (*BasicBlock) SetType

func (b *BasicBlock) SetType(ts Types)

func (*BasicBlock) String

func (b *BasicBlock) String() string

----------- basic block

type BasicType

type BasicType struct {
	Kind TypeKind
	// contains filtered or unexported fields
}

func (BasicType) String

func (b BasicType) String() string

type BinOp

type BinOp struct {
	Op   BinaryOpcode
	X, Y Value
	// contains filtered or unexported fields
}

----------- BinOp

func (*BinOp) AddUser

func (b *BinOp) AddUser(u User)

func (*BinOp) AddValue

func (b *BinOp) AddValue(v Value)

func (*BinOp) GetBlock

func (a *BinOp) GetBlock() *BasicBlock

implement instruction

func (*BinOp) GetParent

func (a *BinOp) GetParent() *Function

func (*BinOp) GetType

func (a *BinOp) GetType() Types

func (*BinOp) GetUsers

func (b *BinOp) GetUsers() []User

func (*BinOp) GetValues

func (b *BinOp) GetValues() []Value

func (*BinOp) InferenceType

func (b *BinOp) InferenceType()

func (BinOp) NewError

func (an BinOp) NewError(kind ErrorKind, format string, arg ...any)

func (*BinOp) Pos

func (a *BinOp) Pos() string

func (*BinOp) RemoveUser

func (b *BinOp) RemoveUser(u User)

func (*BinOp) ReplaceValue

func (b *BinOp) ReplaceValue(v Value, to Value)

----------- BinOp

func (*BinOp) SetType

func (a *BinOp) SetType(ts Types)

func (*BinOp) String

func (b *BinOp) String() string

type BinaryOpcode

type BinaryOpcode int
const (
	// Binary
	OpShl    BinaryOpcode = iota // <<
	OpShr                        // >>
	OpAnd                        // &
	OpAndNot                     // &^
	OpOr                         // |
	OpXor                        // ^
	OpAdd                        // +
	OpSub                        // -
	OpMul                        // *
	OpDiv                        // /
	OpMod                        // %
	OpGt                         // >
	OpLt                         // <
	OpGtEq                       // >=
	OpLtEq                       // <=
	OpEq                         // ==
	OpNotEq                      // != <>
)

type Builder

type Builder interface {
	Build()
}

type Call

type Call struct {

	// for call function
	Method Value
	Args   []Value
	// contains filtered or unexported fields
}

----------- Call call instruction call method function with args as argument

func (*Call) AddUser

func (c *Call) AddUser(u User)

func (*Call) AddValue

func (c *Call) AddValue(v Value)

func (*Call) GetBlock

func (a *Call) GetBlock() *BasicBlock

implement instruction

func (*Call) GetParent

func (a *Call) GetParent() *Function

func (*Call) GetType

func (a *Call) GetType() Types

func (*Call) GetUsers

func (c *Call) GetUsers() []User

func (*Call) GetValues

func (c *Call) GetValues() []Value

func (*Call) InferenceType

func (c *Call) InferenceType()

func (Call) NewError

func (an Call) NewError(kind ErrorKind, format string, arg ...any)

func (*Call) Pos

func (a *Call) Pos() string

func (*Call) RemoveUser

func (c *Call) RemoveUser(u User)

func (*Call) ReplaceValue

func (c *Call) ReplaceValue(v Value, to Value)

----------- Call

func (*Call) SetType

func (a *Call) SetType(ts Types)

func (*Call) String

func (c *Call) String() string

----------- Call

type ChanType

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

====================== chan type

func NewChanType

func NewChanType(elem Types) *ChanType

func (ChanType) String

func (c ChanType) String() string

type Const

type Const struct {

	// other
	Unary int
	// contains filtered or unexported fields
}

----------- Const only Value

func NewConst

func NewConst(i any) *Const

func NewConstWithUnary

func NewConstWithUnary(i any, un int) *Const

create const

func (*Const) AddUser

func (c *Const) AddUser(u User)

func (Const) GetType

func (c Const) GetType() Types

get type

func (*Const) GetUsers

func (c *Const) GetUsers() []User

func (*Const) GetValues

func (c *Const) GetValues() []Value

----------- Const

func (*Const) RemoveUser

func (c *Const) RemoveUser(u User)

func (*Const) SetType

func (c *Const) SetType(ts Types)

func (Const) String

func (c Const) String() string

----------- const

type ErrorKind

type ErrorKind int
const (
	Info ErrorKind = iota
	Warn
	Error
)

type Field

type Field struct {

	// field
	Key Value
	I   Value

	// capture by other function
	OutCapture bool
	// contains filtered or unexported fields
}

instruction ----------- Field

func (*Field) AddUser

func (f *Field) AddUser(u User)

func (*Field) AddValue

func (f *Field) AddValue(v Value)

func (*Field) Assign

func (field *Field) Assign(v Value, f *FunctionBuilder)

--------------- point variable to value `f.symbol[variable]value` --------------- it's memory address, not SSA value

func (*Field) GetBlock

func (a *Field) GetBlock() *BasicBlock

implement instruction

func (*Field) GetLastValue

func (f *Field) GetLastValue() Value

func (*Field) GetParent

func (a *Field) GetParent() *Function

func (*Field) GetType

func (a *Field) GetType() Types

func (*Field) GetUsers

func (f *Field) GetUsers() []User

func (*Field) GetValue

func (f *Field) GetValue(_ *FunctionBuilder) Value

func (*Field) GetValues

func (f *Field) GetValues() []Value

func (*Field) InferenceType

func (f *Field) InferenceType()

func (Field) NewError

func (an Field) NewError(kind ErrorKind, format string, arg ...any)

func (*Field) Pos

func (a *Field) Pos() string

func (*Field) RemoveUser

func (f *Field) RemoveUser(u User)

func (*Field) ReplaceValue

func (f *Field) ReplaceValue(v, to Value)

----------- Field

func (*Field) SetType

func (a *Field) SetType(ts Types)

func (*Field) String

func (f *Field) String() string

----------- Field

type Function

type Function struct {
	Name string

	// package
	Package *Package

	Param  []*Parameter
	Return []*Return

	// type
	ParamTyp  []Types
	ReturnTyp []Types

	// BasicBlock list
	Blocks     []*BasicBlock
	EnterBlock *BasicBlock
	ExitBlock  *BasicBlock

	// anonymous function in this function
	AnonFuncs []*Function

	FreeValues []Value // the value, captured variable form parent-function,

	Pos *Position // current position
	// contains filtered or unexported fields
}

implement Value

func NewFunctionDefine

func NewFunctionDefine(name string, ParamTyp, ReturnTyp []Types, hasEllipsis bool) *Function

just create a function define, only function parameter type \ return type \ ellipsis

func (*Function) AddUser

func (f *Function) AddUser(u User)

func (*Function) DisAsm

func (f *Function) DisAsm(flag FunctionAsmFlag) string

func (*Function) Finish

func (f *Function) Finish()

current function finish

func (*Function) GetParent

func (f *Function) GetParent() *Function

func (*Function) GetSymbol

func (f *Function) GetSymbol() *Interface

func (*Function) GetType

func (f *Function) GetType() Types

func (*Function) GetUsers

func (f *Function) GetUsers() []User

func (*Function) GetValues

func (f *Function) GetValues() []Value

----------- Function

func (*Function) InspectVariable

func (f *Function) InspectVariable(varName string) *InspectVariableResult

func (*Function) NewBasicBlock

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

func (*Function) NewBasicBlockUnSealed

func (f *Function) NewBasicBlockUnSealed(name string) *BasicBlock

func (*Function) NewErrorWithPos

func (f *Function) NewErrorWithPos(kind ErrorKind, Pos *Position, format string, arg ...any)

func (*Function) NewParam

func (f *Function) NewParam(name string)

func (*Function) RemoveUser

func (f *Function) RemoveUser(u User)

func (*Function) ReturnValue

func (f *Function) ReturnValue() []Value

func (*Function) SetReg

func (f *Function) SetReg(i Instruction)

func (*Function) SetType

func (f *Function) SetType(ts Types)

func (*Function) String

func (f *Function) String() string

implement value

func (*Function) WriteVariable

func (f *Function) WriteVariable(variable string, value Value)

--------------- `f.currentDef` hanlder, read && write

type FunctionAsmFlag

type FunctionAsmFlag int
const (
	DisAsmDefault FunctionAsmFlag = 1 << iota
	DisAsmWithoutSource
)

type FunctionBuilder

type FunctionBuilder struct {
	*Function

	CurrentBlock *BasicBlock // current block to build
	// contains filtered or unexported fields
}

Function builder API

func NewBuilder

func NewBuilder(f *Function, next *FunctionBuilder) *FunctionBuilder

func (*FunctionBuilder) AddDefer

func (b *FunctionBuilder) AddDefer(call *Call)

add current function defer function

func (*FunctionBuilder) BuildFreeValue

func (f *FunctionBuilder) BuildFreeValue(variable string) Value

func (*FunctionBuilder) CanBuildFreeValue

func (b *FunctionBuilder) CanBuildFreeValue(variable string) bool

func (*FunctionBuilder) CreateInterfaceWithVs

func (b *FunctionBuilder) CreateInterfaceWithVs(keys []Value, vs []Value) *Interface

func (*FunctionBuilder) EmitArith

func (f *FunctionBuilder) EmitArith(op BinaryOpcode, x, y Value) *BinOp

func (*FunctionBuilder) EmitCall

func (f *FunctionBuilder) EmitCall(c *Call) *Call

func (*FunctionBuilder) EmitField

func (f *FunctionBuilder) EmitField(i Value, key Value) *Field

func (*FunctionBuilder) EmitIf

func (f *FunctionBuilder) EmitIf(cond Value) *If

func (*FunctionBuilder) EmitInterfaceBuildWithType

func (f *FunctionBuilder) EmitInterfaceBuildWithType(typ Types, Len, Cap Value) *Interface

func (*FunctionBuilder) EmitInterfaceSlice

func (f *FunctionBuilder) EmitInterfaceSlice(i *Interface, low, high, max Value) *Interface

func (*FunctionBuilder) EmitJump

func (f *FunctionBuilder) EmitJump(to *BasicBlock) *Jump

func (*FunctionBuilder) EmitReturn

func (f *FunctionBuilder) EmitReturn(vs []Value) *Return

func (*FunctionBuilder) EmitSwitch

func (f *FunctionBuilder) EmitSwitch(cond Value, defaultb *BasicBlock, label []SwitchLabel) *Switch

func (*FunctionBuilder) Finish

func (b *FunctionBuilder) Finish()

finish current function builder

func (*FunctionBuilder) GetBreak

func (b *FunctionBuilder) GetBreak() *BasicBlock

get target feild

func (*FunctionBuilder) GetContinue

func (b *FunctionBuilder) GetContinue() *BasicBlock

func (*FunctionBuilder) GetFallthrough

func (b *FunctionBuilder) GetFallthrough() *BasicBlock

func (FunctionBuilder) GetParentBuilder

func (b FunctionBuilder) GetParentBuilder() *FunctionBuilder

get parent function

func (FunctionBuilder) HandlerEllipsis

func (b FunctionBuilder) HandlerEllipsis()

function param

func (*FunctionBuilder) MapBlockSymbolTable

func (b *FunctionBuilder) MapBlockSymbolTable(text string) string

use block symbol table map variable -> variable+blockid

func (*FunctionBuilder) NewCall

func (f *FunctionBuilder) NewCall(target Value, args []Value, isDropError bool) *Call

func (*FunctionBuilder) NewError

func (b *FunctionBuilder) NewError(kind ErrorKind, format string, arg ...any)

func (*FunctionBuilder) NewField

func (b *FunctionBuilder) NewField(key string) *Field

func (*FunctionBuilder) NewFunc

func (b *FunctionBuilder) NewFunc() *Function

new function

func (*FunctionBuilder) PopBlockSymbolTable

func (b *FunctionBuilder) PopBlockSymbolTable()

func (*FunctionBuilder) PopFunction

func (b *FunctionBuilder) PopFunction() *FunctionBuilder

func (*FunctionBuilder) PopTarget

func (b *FunctionBuilder) PopTarget() bool

func (*FunctionBuilder) PushBlockSymbolTable

func (b *FunctionBuilder) PushBlockSymbolTable()

block symboltable stack

func (*FunctionBuilder) PushFunction

func (b *FunctionBuilder) PushFunction(newfunc *Function) *FunctionBuilder

func (*FunctionBuilder) PushTarget

func (b *FunctionBuilder) PushTarget(_break, _continue, _fallthrough *BasicBlock)

target stack

func (*FunctionBuilder) ReadField

func (b *FunctionBuilder) ReadField(key string) *Field

func (*FunctionBuilder) ReadVariable

func (b *FunctionBuilder) ReadVariable(variable string) Value

func (*FunctionBuilder) SetPosition

func (b *FunctionBuilder) SetPosition(pos *Position) *Position

handler position: set new position and return original position for backup

type IdentifierLV

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

--------------- only point variable to value with `f.currentDef` --------------- is SSA value

func NewIndentifierLV

func NewIndentifierLV(variable string) *IdentifierLV

func (*IdentifierLV) Assign

func (i *IdentifierLV) Assign(v Value, f *FunctionBuilder)

func (*IdentifierLV) GetValue

func (i *IdentifierLV) GetValue(f *FunctionBuilder) Value

type If

type If struct {
	Cond  Value
	True  *BasicBlock
	False *BasicBlock
	// contains filtered or unexported fields
}

----------- IF The If instruction transfers control to one of the two successors of its owning block, depending on the boolean Cond: the first if true, the second if false.

func (*If) AddFalse

func (i *If) AddFalse(f *BasicBlock)

func (*If) AddTrue

func (i *If) AddTrue(t *BasicBlock)

func (*If) AddValue

func (i *If) AddValue(v Value)

func (*If) GetBlock

func (a *If) GetBlock() *BasicBlock

implement instruction

func (*If) GetParent

func (a *If) GetParent() *Function

func (*If) GetType

func (a *If) GetType() Types

func (*If) GetUsers

func (i *If) GetUsers() []User

func (*If) GetValues

func (i *If) GetValues() []Value

func (*If) InferenceType

func (i *If) InferenceType()

func (If) NewError

func (an If) NewError(kind ErrorKind, format string, arg ...any)

func (*If) Pos

func (a *If) Pos() string

func (*If) ReplaceValue

func (i *If) ReplaceValue(v Value, to Value)

----------- IF

func (*If) SetType

func (a *If) SetType(ts Types)

func (*If) String

func (i *If) String() string

----------- IF

type InspectVariableResult

type InspectVariableResult struct {
	VariableName   string
	ProbablyTypes  []string
	ProbablyValues []string
}

func (*InspectVariableResult) Merge

type Instruction

type Instruction interface {
	GetParent() *Function
	GetBlock() *BasicBlock

	String() string

	// pos
	Pos() string
}

type Interface

type Interface struct {

	// when slice or map
	Len, Cap Value
	// contains filtered or unexported fields
}

----------- Interface instruction + value + user

func (*Interface) AddUser

func (i *Interface) AddUser(u User)

func (*Interface) AddValue

func (i *Interface) AddValue(_ Value)

func (*Interface) GetBlock

func (a *Interface) GetBlock() *BasicBlock

implement instruction

func (*Interface) GetParent

func (a *Interface) GetParent() *Function

func (*Interface) GetType

func (a *Interface) GetType() Types

func (*Interface) GetUsers

func (i *Interface) GetUsers() []User

func (*Interface) GetValues

func (i *Interface) GetValues() []Value

func (*Interface) InferenceType

func (i *Interface) InferenceType()

func (Interface) NewError

func (an Interface) NewError(kind ErrorKind, format string, arg ...any)

func (*Interface) Pos

func (a *Interface) Pos() string

func (*Interface) RemoveUser

func (i *Interface) RemoveUser(u User)

func (*Interface) ReplaceValue

func (i *Interface) ReplaceValue(v, to Value)

----------- Interface

func (*Interface) SetType

func (a *Interface) SetType(ts Types)

func (*Interface) String

func (i *Interface) String() string

----------- Interface

type InterfaceType

type InterfaceType struct {
	Kind InterfaceTypeKind
	Key  []Value

	Field []Types
	// contains filtered or unexported fields
}

func NewInterfaceType

func NewInterfaceType() *InterfaceType

func NewMapType

func NewMapType(key, field Types) *InterfaceType

func NewSliceType

func NewSliceType(elem Types) *InterfaceType

for slice build

func (*InterfaceType) AddField

func (s *InterfaceType) AddField(key Value, field Types)

for struct build

func (*InterfaceType) GetField

func (s *InterfaceType) GetField(key Value) Types

func (InterfaceType) String

func (itype InterfaceType) String() string

func (*InterfaceType) Transform

func (s *InterfaceType) Transform()

===================== transform

type InterfaceTypeKind

type InterfaceTypeKind int

==================== interface type

const (
	Slice InterfaceTypeKind = iota
	Map
	Struct
)

type Jump

type Jump struct {
	To *BasicBlock
	// contains filtered or unexported fields
}

----------- Jump The Jump instruction transfers control to the sole successor of its owning block.

the block containing Jump instruction only have one successor block

func (*Jump) GetBlock

func (a *Jump) GetBlock() *BasicBlock

implement instruction

func (*Jump) GetParent

func (a *Jump) GetParent() *Function

func (*Jump) GetType

func (a *Jump) GetType() Types

func (Jump) NewError

func (an Jump) NewError(kind ErrorKind, format string, arg ...any)

func (*Jump) Pos

func (a *Jump) Pos() string

func (*Jump) SetType

func (a *Jump) SetType(ts Types)

func (*Jump) String

func (j *Jump) String() string

----------- Jump

type LeftValue

type LeftValue interface {
	Assign(Value, *FunctionBuilder)
	GetValue(*FunctionBuilder) Value
}

--------------- for assign

type Node

type Node interface {
	String() string

	GetType() Types

	GetUsers() []User
	GetValues() []Value
}

TODO data flow graph node

type Package

type Package struct {
	Name string
	// point to program
	Prog *Program
	// function list
	Funcs []*Function
}

func (*Package) NewFunction

func (p *Package) NewFunction(name string) *Function

func (*Package) NewFunctionWithParent

func (p *Package) NewFunctionWithParent(name string, parent *Function) *Function

type Parameter

type Parameter struct {
	Func *Function
	// contains filtered or unexported fields
}

----------- Parameter

func (*Parameter) AddUser

func (p *Parameter) AddUser(u User)

func (*Parameter) GetType

func (p *Parameter) GetType() Types

func (*Parameter) GetUsers

func (p *Parameter) GetUsers() []User

func (*Parameter) GetValues

func (p *Parameter) GetValues() []Value

----------- param

func (*Parameter) RemoveUser

func (p *Parameter) RemoveUser(u User)

func (*Parameter) SetType

func (p *Parameter) SetType(ts Types)

func (*Parameter) String

func (p *Parameter) String() string

----------- Parameter

type Phi

type Phi struct {
	Edge []Value // edge[i] from phi.Block.Preds[i]
	// contains filtered or unexported fields
}

----------- Phi

func NewPhi

func NewPhi(f *Function, block *BasicBlock, variable string) *Phi

func (*Phi) AddUser

func (p *Phi) AddUser(u User)

func (*Phi) AddValue

func (p *Phi) AddValue(v Value)

func (*Phi) Build

func (phi *Phi) Build() Value

func (*Phi) GetBlock

func (a *Phi) GetBlock() *BasicBlock

implement instruction

func (*Phi) GetParent

func (a *Phi) GetParent() *Function

func (*Phi) GetType

func (a *Phi) GetType() Types

func (*Phi) GetUsers

func (p *Phi) GetUsers() []User

func (*Phi) GetValues

func (p *Phi) GetValues() []Value

func (*Phi) InferenceType

func (phi *Phi) InferenceType()

func (*Phi) Name

func (phi *Phi) Name() string

func (Phi) NewError

func (an Phi) NewError(kind ErrorKind, format string, arg ...any)

func (*Phi) Pos

func (a *Phi) Pos() string

func (*Phi) RemoveUser

func (p *Phi) RemoveUser(u User)

func (*Phi) ReplaceValue

func (p *Phi) ReplaceValue(v Value, to Value)

----------- Phi

func (*Phi) SetType

func (a *Phi) SetType(ts Types)

func (*Phi) String

func (p *Phi) String() string

----------- Phi

type Position

type Position struct {
	// SourceCodeFilePath *string
	SourceCode  string
	StartLine   int
	StartColumn int
	EndLine     int
	EndColumn   int
}

func (*Position) String

func (p *Position) String() string

type Program

type Program struct {
	// package list
	Packages []*Package
	// contains filtered or unexported fields
}

func NewProgram

func NewProgram() *Program

func (*Program) Build

func (prog *Program) Build(b Builder)

build enter pointer front implement `Builder`

func (*Program) GetErrors

func (prog *Program) GetErrors() SSAErrors

func (*Program) InspectVariable

func (p *Program) InspectVariable(varName string) *InspectVariableResult

func (*Program) NewPackage

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

func (*Program) Show

func (p *Program) Show()

func (*Program) ShowWithSource

func (p *Program) ShowWithSource()

type Return

type Return struct {
	Results []Value
	// contains filtered or unexported fields
}

----------- Return The Return instruction returns values and control back to the calling function.

func (*Return) AddValue

func (r *Return) AddValue(v Value)

func (*Return) GetBlock

func (a *Return) GetBlock() *BasicBlock

implement instruction

func (*Return) GetParent

func (a *Return) GetParent() *Function

func (*Return) GetType

func (a *Return) GetType() Types

func (*Return) GetUsers

func (r *Return) GetUsers() []User

func (*Return) GetValues

func (r *Return) GetValues() []Value

func (*Return) InferenceType

func (r *Return) InferenceType()

func (Return) NewError

func (an Return) NewError(kind ErrorKind, format string, arg ...any)

func (*Return) Pos

func (a *Return) Pos() string

func (*Return) ReplaceValue

func (r *Return) ReplaceValue(v Value, to Value)

----------- Return

func (*Return) SetType

func (a *Return) SetType(ts Types)

func (*Return) String

func (r *Return) String() string

----------- Return

type SSAError

type SSAError struct {
	Pos     *Position
	Message string
	Kind    ErrorKind
}

func (SSAError) String

func (err SSAError) String() string

type SSAErrors

type SSAErrors []*SSAError

func (SSAErrors) String

func (errs SSAErrors) String() string

type Switch

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

func (*Switch) AddValue

func (sw *Switch) AddValue(v Value)

func (*Switch) GetBlock

func (a *Switch) GetBlock() *BasicBlock

implement instruction

func (*Switch) GetParent

func (a *Switch) GetParent() *Function

func (*Switch) GetType

func (a *Switch) GetType() Types

func (*Switch) GetUsers

func (sw *Switch) GetUsers() []User

func (*Switch) GetValues

func (sw *Switch) GetValues() []Value

func (*Switch) InferenceType

func (sw *Switch) InferenceType()

func (Switch) NewError

func (an Switch) NewError(kind ErrorKind, format string, arg ...any)

func (*Switch) Pos

func (a *Switch) Pos() string

func (*Switch) ReplaceValue

func (sw *Switch) ReplaceValue(v Value, to Value)

----------- Switch

func (*Switch) SetType

func (a *Switch) SetType(ts Types)

func (*Switch) String

func (sw *Switch) String() string

----------- Switch

type SwitchLabel

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

----------- Switch

func NewSwitchLabel

func NewSwitchLabel(v Value, dest *BasicBlock) SwitchLabel

type Type

type Type interface {
	String() string
}

func GetType

func GetType(i any) Type

func GetTypeByStr

func GetTypeByStr(typ string) Type

type TypeKind

type TypeKind int

basic type

const (
	Number TypeKind = iota
	String
	Boolean
	Undefine // undefine is nil in golnag
	Null     //
	Any      // any type
)

type Types

type Types []Type // each value can have multiple type possible

func ParseTypesFromValues

func ParseTypesFromValues(vs []Value) Types

func (Types) Compare

func (org Types) Compare(typs Types) bool

return true if org != typs return false if org == typs

func (Types) String

func (t Types) String() string

type UnOp

type UnOp struct {
	Op UnaryOpcode
	X  Value
	// contains filtered or unexported fields
}

func (*UnOp) GetBlock

func (a *UnOp) GetBlock() *BasicBlock

implement instruction

func (*UnOp) GetParent

func (a *UnOp) GetParent() *Function

func (*UnOp) GetType

func (a *UnOp) GetType() Types

func (UnOp) NewError

func (an UnOp) NewError(kind ErrorKind, format string, arg ...any)

func (*UnOp) Pos

func (a *UnOp) Pos() string

func (*UnOp) SetType

func (a *UnOp) SetType(ts Types)

type UnaryOpcode

type UnaryOpcode int
const (
	OpNot UnaryOpcode = iota
	OpPlus
	OpNeg
	OpChan
)

type Update

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

----------- Update

func (*Update) AddUser

func (s *Update) AddUser(u User)

func (*Update) AddValue

func (s *Update) AddValue(_ Value)

func (*Update) GetBlock

func (a *Update) GetBlock() *BasicBlock

implement instruction

func (*Update) GetParent

func (a *Update) GetParent() *Function

func (*Update) GetType

func (a *Update) GetType() Types

func (*Update) GetUsers

func (s *Update) GetUsers() []User

func (*Update) GetValues

func (s *Update) GetValues() []Value

func (*Update) InferenceType

func (u *Update) InferenceType()

func (Update) NewError

func (an Update) NewError(kind ErrorKind, format string, arg ...any)

func (*Update) Pos

func (a *Update) Pos() string

func (*Update) RemoveUser

func (s *Update) RemoveUser(u User)

func (*Update) ReplaceValue

func (s *Update) ReplaceValue(v, to Value)

----------- Update

func (*Update) SetType

func (a *Update) SetType(ts Types)

func (*Update) String

func (s *Update) String() string

----------- Update

type User

type User interface {
	Node

	String() string

	GetValues() []Value
	AddValue(Value)

	ReplaceValue(Value, Value)

	// inference type
	InferenceType()
}

type Value

type Value interface {
	Node

	String() string

	GetUsers() []User
	AddUser(User)
	RemoveUser(User)

	SetType(Types)
}

Jump to

Keyboard shortcuts

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