ssa

package
v1.2.7-sp3 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2023 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// loop
	LoopHeader = "loop.header"
	LoopBody   = "loop.body"
	LoopExit   = "loop.exit"
	LoopLatch  = "loop.latch"

	// if
	IfDone  = "if.done"
	IfTrue  = "if.true"
	IfFalse = "if.false"
	IfElif  = "if.elif"
)
View Source
const (
	MAXTYPELEVEL = 15
)

Variables

View Source
var BasicTypes = []*BasicType{
	Number:       {Number, "number", make(map[string]*FunctionType, 0)},
	String:       {String, "string", make(map[string]*FunctionType, 0)},
	Boolean:      {Boolean, "boolean", make(map[string]*FunctionType, 0)},
	UndefineType: {UndefineType, "undefine", make(map[string]*FunctionType, 0)},
	Null:         {Null, "null", make(map[string]*FunctionType, 0)},
	Any:          {Any, "any", make(map[string]*FunctionType, 0)},
	ErrorType:    {ErrorType, "error", make(map[string]*FunctionType, 0)},
}
View Source
var BinaryOpcodeName = map[BinaryOpcode]string{
	OpLogicAnd: `&&`,
	OpLogicOr:  `||`,

	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`,
	OpIn:     `in`,
	OpSend:   `send`,
}

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

View Source
var (
	ConstMap = make(map[any]*Const)
)
View Source
var NextType = NewObjectType()
View Source
var UnaryOpcodeName = map[UnaryOpcode]string{
	OpNone:       ``,
	OpNot:        `not`,
	OpPlus:       `plus`,
	OpNeg:        `neg`,
	OpChan:       `chan`,
	OpBitwiseNot: `bitwise-not`,
}

----------- UnOp

Functions

func AddUser

func AddUser(v Value, u User)

func AddValue

func AddValue(user User, v Value)

func BindingNotFound added in v1.2.8

func BindingNotFound(v string) string

func DeleteInst added in v1.2.8

func DeleteInst(i Instruction)

func EmitAfter

func EmitAfter(after, inst Instruction)

func EmitBefore

func EmitBefore(before, inst Instruction)

func EmitInst

func EmitInst(i Instruction)

func GetIdByBlockSymbolTable added in v1.2.8

func GetIdByBlockSymbolTable(id string, symbolEnter *blockSymbolTable) string

func GetTypeStr

func GetTypeStr(n Node) string

func HasUser

func HasUser(n Node) bool

func Insert

func Insert(i Instruction, b *BasicBlock)

func IsConst added in v1.3.1

func IsConst(v Value) bool

func IsField

func IsField(v Value) bool

func IsObject

func IsObject(v Value) bool

func NewNode

func NewNode() anNode

func ReplaceValue

func ReplaceValue(v Value, to Value)

func ReplaceValueInRange

func ReplaceValueInRange(v Value, to Value, inRange func(Instruction) bool)

Types

type AliasType added in v1.2.8

type AliasType struct {
	Name string
	// contains filtered or unexported fields
}

====================== alias type

func NewAliasType added in v1.2.8

func NewAliasType(name string, elem Type) *AliasType

func (*AliasType) GetMethod added in v1.2.8

func (a *AliasType) GetMethod(id string) *FunctionType

func (*AliasType) GetTypeKind added in v1.2.8

func (a *AliasType) GetTypeKind() TypeKind

func (*AliasType) RawString added in v1.2.8

func (a *AliasType) RawString() string

func (*AliasType) SetMethod added in v1.2.8

func (a *AliasType) SetMethod(m map[string]*FunctionType)

func (*AliasType) String added in v1.2.8

func (a *AliasType) String() string

type Assert added in v1.2.8

type Assert struct {
	Cond     Value
	Msg      string
	MsgValue Value
	// contains filtered or unexported fields
}

----------- assert

func NewAssert added in v1.2.8

func NewAssert(cond, msgValue Value, msg string, block *BasicBlock) *Assert

func (*Assert) AddValue

func (a *Assert) AddValue(v Value)

func (*Assert) GetBlock added in v1.2.8

func (a *Assert) GetBlock() *BasicBlock

implement instruction

func (*Assert) GetLeftPosition added in v1.2.8

func (a *Assert) GetLeftPosition() *Position

func (*Assert) GetParent

func (a *Assert) GetParent() *Function

func (*Assert) GetPosition added in v1.2.8

func (a *Assert) GetPosition() *Position

func (*Assert) GetSymbolTable added in v1.2.8

func (a *Assert) GetSymbolTable() *blockSymbolTable

func (*Assert) GetType

func (a *Assert) GetType() Type

func (*Assert) GetUsers added in v1.2.8

func (a *Assert) GetUsers() []User

func (*Assert) GetValues added in v1.2.8

func (a *Assert) GetValues() []Value

----------- Assert

func (*Assert) GetVariable added in v1.2.8

func (a *Assert) GetVariable() string

func (Assert) NewError added in v1.2.8

func (an Assert) NewError(kind ErrorKind, tag ErrorTag, format string, arg ...any)

func (*Assert) Pos

func (a *Assert) Pos() string

func (*Assert) RemoveValue

func (a *Assert) RemoveValue(v Value)

func (*Assert) ReplaceValue added in v1.2.8

func (a *Assert) ReplaceValue(v, to Value)

func (*Assert) SetLeftPosition

func (a *Assert) SetLeftPosition(pos *Position)

func (*Assert) SetPosition added in v1.2.8

func (a *Assert) SetPosition(pos *Position)

func (*Assert) SetSymbolTable added in v1.2.8

func (a *Assert) SetSymbolTable(symbolTable *blockSymbolTable)

func (*Assert) SetType

func (a *Assert) SetType(ts Type)

func (*Assert) SetVariable added in v1.2.8

func (a *Assert) SetVariable(name string)

func (*Assert) String added in v1.2.8

func (a *Assert) String() string

type BasicBlock

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

	/*
		if Condition == true: this block reach
	*/
	Condition Value

	// instruction list
	Insts []Instruction
	Phis  []*Phi

	// error catch
	Handler *ErrorHandler

	Skip bool // for phi build, avoid recursive
	// 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) GetBlock added in v1.2.8

func (b *BasicBlock) GetBlock(name string) *BasicBlock

func (*BasicBlock) GetType

func (b *BasicBlock) GetType() Type

func (*BasicBlock) GetUsers

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

func (*BasicBlock) GetValues

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

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

func (*BasicBlock) IsBlock added in v1.2.8

func (b *BasicBlock) IsBlock(name string) bool

func (*BasicBlock) LastInst

func (b *BasicBlock) LastInst() Instruction

func (*BasicBlock) NewError added in v1.2.8

func (b *BasicBlock) NewError(kind ErrorKind, tag ErrorTag, format string, arg ...any)

func (*BasicBlock) Reachable added in v1.2.8

func (b *BasicBlock) Reachable() int

func (*BasicBlock) RemoveUser

func (b *BasicBlock) RemoveUser(u User)

func (*BasicBlock) Sealed

func (b *BasicBlock) Sealed()

func (*BasicBlock) SetPosition added in v1.2.8

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

func (*BasicBlock) SetType

func (b *BasicBlock) SetType(ts Type)

func (*BasicBlock) String

func (b *BasicBlock) String() string

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

type BasicType

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

func (*BasicType) GetMethod added in v1.2.8

func (b *BasicType) GetMethod(id string) *FunctionType

func (*BasicType) GetTypeKind added in v1.2.8

func (b *BasicType) GetTypeKind() TypeKind

func (*BasicType) RawString added in v1.2.8

func (b *BasicType) RawString() string

func (*BasicType) SetMethod added in v1.2.8

func (b *BasicType) SetMethod(method map[string]*FunctionType)

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 NewBinOpOnly added in v1.2.8

func NewBinOpOnly(op BinaryOpcode, x, y Value, block *BasicBlock) *BinOp

func (*BinOp) AddUser

func (n *BinOp) AddUser(u User)

func (*BinOp) AddValue

func (n *BinOp) AddValue(v Value)

func (*BinOp) GetBlock

func (a *BinOp) GetBlock() *BasicBlock

implement instruction

func (*BinOp) GetLeftPosition added in v1.2.8

func (a *BinOp) GetLeftPosition() *Position

func (*BinOp) GetParent

func (a *BinOp) GetParent() *Function

func (*BinOp) GetPosition added in v1.2.8

func (a *BinOp) GetPosition() *Position

func (*BinOp) GetSymbolTable added in v1.2.8

func (a *BinOp) GetSymbolTable() *blockSymbolTable

func (*BinOp) GetType

func (a *BinOp) GetType() Type

func (*BinOp) GetUsers

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

func (*BinOp) GetValues

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

func (*BinOp) GetVariable added in v1.2.8

func (a *BinOp) GetVariable() string

func (BinOp) NewError

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

func (*BinOp) Pos

func (a *BinOp) Pos() string

func (*BinOp) RemoveUser

func (n *BinOp) RemoveUser(u User)

func (*BinOp) RemoveValue

func (n *BinOp) RemoveValue(v Value)

func (*BinOp) ReplaceValue

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

// ----------- BinOp

func (*BinOp) SetLeftPosition

func (a *BinOp) SetLeftPosition(pos *Position)

func (*BinOp) SetPosition added in v1.2.8

func (a *BinOp) SetPosition(pos *Position)

func (*BinOp) SetSymbolTable added in v1.2.8

func (a *BinOp) SetSymbolTable(symbolTable *blockSymbolTable)

func (*BinOp) SetType

func (a *BinOp) SetType(ts Type)

func (*BinOp) SetVariable added in v1.2.8

func (a *BinOp) SetVariable(name string)

func (*BinOp) String

func (b *BinOp) String() string

type BinaryOpcode

type BinaryOpcode int
const (
	// Binary
	OpShl BinaryOpcode = iota // <<

	OpLogicAnd // &&
	OpLogicOr  // ||

	OpShr    // >>
	OpAnd    // &
	OpAndNot // &^
	OpOr     // |
	OpXor    // ^
	OpAdd    // +
	OpSub    // -
	OpDiv    // /
	OpMod    // %
	// mul
	OpMul // *

	// boolean opcode
	OpGt    // >
	OpLt    // <
	OpGtEq  // >=
	OpLtEq  // <=
	OpEq    // ==
	OpNotEq // != <>
	OpIn    //  a in b

	OpSend // <-
)

type Builder

type Builder interface {
	Build()
}

type Call

type Call struct {

	// for call function
	Method Value
	Args   []Value

	// go function
	Async bool

	Unpack bool

	// caller
	// caller Value
	// ~ drop error
	IsDropError bool
	IsEllipsis  bool
	// contains filtered or unexported fields
}

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

func NewCall added in v1.2.8

func NewCall(target Value, args, binding []Value, block *BasicBlock) *Call

func (*Call) AddUser

func (n *Call) AddUser(u User)

func (*Call) AddValue

func (n *Call) AddValue(v Value)

func (*Call) GetBlock

func (a *Call) GetBlock() *BasicBlock

implement instruction

func (*Call) GetLeftPosition added in v1.2.8

func (a *Call) GetLeftPosition() *Position

func (*Call) GetParent

func (a *Call) GetParent() *Function

func (*Call) GetPosition added in v1.2.8

func (a *Call) GetPosition() *Position

func (*Call) GetSymbolTable added in v1.2.8

func (a *Call) GetSymbolTable() *blockSymbolTable

func (*Call) GetType

func (a *Call) GetType() Type

func (*Call) GetUsers

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

func (*Call) GetValues

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

func (*Call) GetVariable added in v1.2.8

func (a *Call) GetVariable() string

func (*Call) HandleFreeValue added in v1.2.8

func (c *Call) HandleFreeValue(fvs map[string]bool)

func (Call) NewError

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

func (*Call) Pos

func (a *Call) Pos() string

func (*Call) RemoveUser

func (n *Call) RemoveUser(u User)

func (*Call) RemoveValue

func (n *Call) RemoveValue(v Value)

func (*Call) ReplaceValue

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

// ----------- Call

func (*Call) SetLeftPosition

func (a *Call) SetLeftPosition(pos *Position)

func (*Call) SetPosition added in v1.2.8

func (a *Call) SetPosition(pos *Position)

func (*Call) SetSymbolTable added in v1.2.8

func (a *Call) SetSymbolTable(symbolTable *blockSymbolTable)

func (*Call) SetType

func (a *Call) SetType(ts Type)

func (*Call) SetVariable added in v1.2.8

func (a *Call) SetVariable(name string)

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 Type) *ChanType

func (*ChanType) GetMethod added in v1.2.8

func (c *ChanType) GetMethod(id string) *FunctionType

func (*ChanType) GetTypeKind added in v1.2.8

func (c *ChanType) GetTypeKind() TypeKind

func (ChanType) RawString added in v1.2.8

func (c ChanType) RawString() string

func (*ChanType) SetMethod added in v1.2.8

func (c *ChanType) SetMethod(m map[string]*FunctionType)

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 CalcConstBinary added in v1.2.8

func CalcConstBinary(x, y *Const, op BinaryOpcode) *Const

func CalcConstUnary added in v1.2.8

func CalcConstUnary(x *Const, op UnaryOpcode) *Const

OpNone UnaryOpcode = iota OpNot // ! OpPlus // + OpNeg // - OpChan // ->

func NewAny added in v1.2.8

func NewAny() *Const

func NewConst

func NewConst(i any) *Const

func NewConstWithUnary

func NewConstWithUnary(i any, un int) *Const

create const

func NewNil added in v1.2.8

func NewNil() *Const

func ToConst added in v1.2.8

func ToConst(v Value) *Const

func (*Const) AddUser

func (n *Const) AddUser(u User)

func (*Const) AddValue

func (n *Const) AddValue(v Value)

func (*Const) Boolean added in v1.2.8

func (c *Const) Boolean() bool

func (*Const) Float added in v1.2.8

func (c *Const) Float() float64

func (*Const) GetType

func (c *Const) GetType() Type

get type

func (*Const) GetTypeKind added in v1.2.8

func (c *Const) GetTypeKind() TypeKind

func (*Const) GetUsers

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

func (*Const) GetValues

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

func (*Const) IsBoolean added in v1.2.8

func (c *Const) IsBoolean() bool

func (*Const) IsFloat added in v1.2.8

func (c *Const) IsFloat() bool

func (*Const) IsNumber added in v1.2.8

func (c *Const) IsNumber() bool

func (*Const) IsString added in v1.2.8

func (c *Const) IsString() bool

func (*Const) Number added in v1.2.8

func (c *Const) Number() int64

func (*Const) RemoveUser

func (n *Const) RemoveUser(u User)

func (*Const) RemoveValue

func (n *Const) RemoveValue(v Value)

func (*Const) SetType

func (c *Const) SetType(ts Type)

func (Const) String

func (c Const) String() string

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

func (*Const) VarString added in v1.2.8

func (c *Const) VarString() string

type ConstInst added in v1.2.8

type ConstInst struct {
	*Const
	// contains filtered or unexported fields
}

----------- Const ConstInst also have block pointer, which block set this const to variable

func NewConstInst added in v1.2.8

func NewConstInst(c *Const, block *BasicBlock) *ConstInst

func (ConstInst) AddUser added in v1.2.8

func (n ConstInst) AddUser(u User)

func (ConstInst) AddValue

func (n ConstInst) AddValue(v Value)

func (*ConstInst) GetBlock added in v1.2.8

func (a *ConstInst) GetBlock() *BasicBlock

implement instruction

func (*ConstInst) GetLeftPosition added in v1.2.8

func (a *ConstInst) GetLeftPosition() *Position

func (*ConstInst) GetParent

func (a *ConstInst) GetParent() *Function

func (*ConstInst) GetPosition added in v1.2.8

func (a *ConstInst) GetPosition() *Position

func (*ConstInst) GetSymbolTable added in v1.2.8

func (a *ConstInst) GetSymbolTable() *blockSymbolTable

func (*ConstInst) GetType added in v1.2.8

func (c *ConstInst) GetType() Type

func (ConstInst) GetUsers added in v1.2.8

func (n ConstInst) GetUsers() []User

func (ConstInst) GetValues added in v1.2.8

func (n ConstInst) GetValues() []Value

func (*ConstInst) GetVariable added in v1.2.8

func (a *ConstInst) GetVariable() string

func (ConstInst) NewError added in v1.2.8

func (an ConstInst) NewError(kind ErrorKind, tag ErrorTag, format string, arg ...any)

func (*ConstInst) Pos

func (a *ConstInst) Pos() string

func (ConstInst) RemoveUser added in v1.2.8

func (n ConstInst) RemoveUser(u User)

func (ConstInst) RemoveValue

func (n ConstInst) RemoveValue(v Value)

func (*ConstInst) ReplaceValue added in v1.3.0

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

----------- ConstInst

func (*ConstInst) SetLeftPosition

func (a *ConstInst) SetLeftPosition(pos *Position)

func (*ConstInst) SetPosition added in v1.2.8

func (a *ConstInst) SetPosition(pos *Position)

func (*ConstInst) SetSymbolTable added in v1.2.8

func (a *ConstInst) SetSymbolTable(symbolTable *blockSymbolTable)

func (*ConstInst) SetType added in v1.2.8

func (c *ConstInst) SetType(ts Type)

func (*ConstInst) SetVariable added in v1.2.8

func (a *ConstInst) SetVariable(name string)

func (*ConstInst) String added in v1.2.8

func (c *ConstInst) String() string

----------- const instruction

type ErrorHandler added in v1.2.8

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

------------- ErrorHandler

func NewErrorHandler added in v1.2.8

func NewErrorHandler(try, catch, block *BasicBlock) *ErrorHandler

func (*ErrorHandler) AddDone added in v1.2.8

func (e *ErrorHandler) AddDone(d *BasicBlock)

func (*ErrorHandler) AddFinal added in v1.2.8

func (e *ErrorHandler) AddFinal(f *BasicBlock)

func (*ErrorHandler) GetBlock added in v1.2.8

func (a *ErrorHandler) GetBlock() *BasicBlock

implement instruction

func (*ErrorHandler) GetLeftPosition added in v1.2.8

func (a *ErrorHandler) GetLeftPosition() *Position

func (*ErrorHandler) GetParent

func (a *ErrorHandler) GetParent() *Function

func (*ErrorHandler) GetPosition added in v1.2.8

func (a *ErrorHandler) GetPosition() *Position

func (*ErrorHandler) GetSymbolTable added in v1.2.8

func (a *ErrorHandler) GetSymbolTable() *blockSymbolTable

func (*ErrorHandler) GetType

func (a *ErrorHandler) GetType() Type

func (*ErrorHandler) GetVariable added in v1.2.8

func (a *ErrorHandler) GetVariable() string

func (ErrorHandler) NewError added in v1.2.8

func (an ErrorHandler) NewError(kind ErrorKind, tag ErrorTag, format string, arg ...any)

func (*ErrorHandler) Pos

func (a *ErrorHandler) Pos() string

func (*ErrorHandler) SetLeftPosition

func (a *ErrorHandler) SetLeftPosition(pos *Position)

func (*ErrorHandler) SetPosition added in v1.2.8

func (a *ErrorHandler) SetPosition(pos *Position)

func (*ErrorHandler) SetSymbolTable added in v1.2.8

func (a *ErrorHandler) SetSymbolTable(symbolTable *blockSymbolTable)

func (*ErrorHandler) SetType

func (a *ErrorHandler) SetType(ts Type)

func (*ErrorHandler) SetVariable added in v1.2.8

func (a *ErrorHandler) SetVariable(name string)

func (*ErrorHandler) String added in v1.2.8

func (e *ErrorHandler) String() string

type ErrorKind

type ErrorKind int
const (
	Warn ErrorKind = iota
	Error
)

type ErrorTag added in v1.2.8

type ErrorTag string
const (
	SSATAG ErrorTag = "ssa"
)

type Field

type Field struct {

	// field
	Key Value
	Obj User

	// Method or Field
	IsMethod bool

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

instruction ----------- Field use-chain: interface(user) -> *field(self) -> multiple update(value) -> value

func GetField added in v1.2.8

func GetField(u User, key Value) *Field

func GetFields added in v1.2.8

func GetFields(u User) []*Field

func NewFieldOnly added in v1.2.8

func NewFieldOnly(key Value, obj User, block *BasicBlock) *Field

func ToField added in v1.2.8

func ToField(v Value) *Field

func (*Field) AddUser

func (n *Field) AddUser(u User)

func (*Field) AddValue

func (n *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) GetLeftPosition added in v1.2.8

func (a *Field) GetLeftPosition() *Position

func (*Field) GetParent

func (a *Field) GetParent() *Function

func (*Field) GetPosition added in v1.2.8

func (a *Field) GetPosition() *Position

func (*Field) GetSymbolTable added in v1.2.8

func (a *Field) GetSymbolTable() *blockSymbolTable

func (*Field) GetType

func (a *Field) GetType() Type

func (*Field) GetUsers

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

func (*Field) GetValue

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

func (*Field) GetValues

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

func (*Field) GetVariable added in v1.2.8

func (a *Field) GetVariable() string

func (Field) NewError

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

func (*Field) Pos

func (a *Field) Pos() string

func (*Field) RemoveUser

func (n *Field) RemoveUser(u User)

func (*Field) RemoveValue

func (n *Field) RemoveValue(v Value)

func (*Field) ReplaceValue

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

// ----------- Field

func (*Field) SetLeftPosition

func (a *Field) SetLeftPosition(pos *Position)

func (*Field) SetPosition added in v1.2.8

func (a *Field) SetPosition(pos *Position)

func (*Field) SetSymbolTable added in v1.2.8

func (a *Field) SetSymbolTable(symbolTable *blockSymbolTable)

func (*Field) SetType

func (a *Field) SetType(ts Type)

func (*Field) SetVariable added in v1.2.8

func (a *Field) SetVariable(name string)

func (*Field) String

func (f *Field) String() string

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

type Function

type Function struct {
	Name string

	Type *FunctionType

	// package
	Package *Package

	Param  []*Parameter
	Return []*Return

	// 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

	// for instruction
	InstReg map[Instruction]string // instruction -> virtual register
	// contains filtered or unexported fields
}

implement Value

func NewFunctionWithType added in v1.2.8

func NewFunctionWithType(name string, typ *FunctionType) *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() *Make

func (*Function) GetType

func (f *Function) GetType() Type

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, tag ErrorTag, 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) ReplaceSymbolTable

func (f *Function) ReplaceSymbolTable(v InstructionValue, to Value)

func (*Function) ReturnValue

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

func (*Function) SetReg

func (f *Function) SetReg(i Instruction)

func (*Function) SetType

func (f *Function) SetType(t Type)

func (*Function) String

func (f *Function) String() string

implement value

func (*Function) WriteSymbolTable

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

func (*Function) WriteVariable

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

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

type FunctionAsmFlag

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

type FunctionBuilder

type FunctionBuilder struct {
	*Function

	CurrentBlock *BasicBlock // current block to build
	CurrentPos   *Position   // current position in source code
	// contains filtered or unexported fields
}

Function builder API

func NewBuilder

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

func (*FunctionBuilder) AddDefer

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

add current function defer function

func (*FunctionBuilder) AddSubFunction added in v1.2.8

func (b *FunctionBuilder) AddSubFunction(builder func())

sub-function builder

func (*FunctionBuilder) BuildFreeValue

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

func (*FunctionBuilder) BuildIf added in v1.2.8

func (b *FunctionBuilder) BuildIf() *IfBuilder

func (*FunctionBuilder) BuildLoop added in v1.2.8

func (b *FunctionBuilder) BuildLoop() *LoopBuilder

func (*FunctionBuilder) BuildValueFromAny added in v1.2.8

func (b *FunctionBuilder) BuildValueFromAny(id string, v any) (value Value)

func (*FunctionBuilder) CanBuildFreeValue

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

func (*FunctionBuilder) CoverReflectFunctionType added in v1.2.8

func (f *FunctionBuilder) CoverReflectFunctionType(itype reflect.Type, level int) *FunctionType

func (*FunctionBuilder) CreateInterfaceWithVs

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

func (*FunctionBuilder) EmitAssert added in v1.2.8

func (f *FunctionBuilder) EmitAssert(cond, msgValue Value, msg string) *Assert

func (*FunctionBuilder) EmitBinOp added in v1.2.8

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

func (*FunctionBuilder) EmitCall

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

func (*FunctionBuilder) EmitConstInst added in v1.2.8

func (f *FunctionBuilder) EmitConstInst(c *Const) *ConstInst

func (*FunctionBuilder) EmitErrorHandler added in v1.2.8

func (f *FunctionBuilder) EmitErrorHandler(try, catch *BasicBlock) *ErrorHandler

func (*FunctionBuilder) EmitField

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

func (*FunctionBuilder) EmitFieldMust added in v1.2.8

func (f *FunctionBuilder) EmitFieldMust(i User, key Value) *Field

func (*FunctionBuilder) EmitIf

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

func (*FunctionBuilder) EmitJump

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

func (*FunctionBuilder) EmitLoop added in v1.2.8

func (f *FunctionBuilder) EmitLoop(body, exit *BasicBlock, cond Value) *Loop

func (*FunctionBuilder) EmitMakeBuildWithType added in v1.2.8

func (f *FunctionBuilder) EmitMakeBuildWithType(typ Type, Len, Cap Value) *Make

func (*FunctionBuilder) EmitMakeSlice added in v1.2.8

func (f *FunctionBuilder) EmitMakeSlice(i User, low, high, max Value) *Make

func (*FunctionBuilder) EmitMakeWithoutType added in v1.2.8

func (f *FunctionBuilder) EmitMakeWithoutType(Len, Cap Value) *Make

func (*FunctionBuilder) EmitNext added in v1.2.8

func (f *FunctionBuilder) EmitNext(iter Value, isIn bool) (key, field, ok Value)

func (*FunctionBuilder) EmitNextOnly added in v1.2.8

func (f *FunctionBuilder) EmitNextOnly(iter Value, isIn bool) *Next

func (*FunctionBuilder) EmitPanic added in v1.2.8

func (f *FunctionBuilder) EmitPanic(info Value) *Panic

func (*FunctionBuilder) EmitRecover added in v1.2.8

func (f *FunctionBuilder) EmitRecover() *Recover

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) EmitTypeCast added in v1.2.8

func (f *FunctionBuilder) EmitTypeCast(v Value, typ Type) *TypeCast

func (*FunctionBuilder) EmitTypeValue added in v1.2.8

func (f *FunctionBuilder) EmitTypeValue(typ Type) *TypeValue

func (*FunctionBuilder) EmitUnOp added in v1.2.8

func (f *FunctionBuilder) EmitUnOp(op UnaryOpcode, v Value) Value

func (*FunctionBuilder) EmitUndefine added in v1.2.8

func (f *FunctionBuilder) EmitUndefine(name string) *Undefine

func (*FunctionBuilder) EmitUpdate added in v1.2.8

func (f *FunctionBuilder) EmitUpdate(address User, v Value) *Update

func (*FunctionBuilder) Finish

func (b *FunctionBuilder) Finish()

finish current function builder

func (*FunctionBuilder) GetBreak

func (b *FunctionBuilder) GetBreak() *BasicBlock

get target field

func (*FunctionBuilder) GetContinue

func (b *FunctionBuilder) GetContinue() *BasicBlock

func (*FunctionBuilder) GetFallthrough

func (b *FunctionBuilder) GetFallthrough() *BasicBlock

func (*FunctionBuilder) GetField

func (b *FunctionBuilder) GetField(i User, key Value, create bool) *Field

func (*FunctionBuilder) GetIdByBlockSymbolTable added in v1.2.8

func (b *FunctionBuilder) GetIdByBlockSymbolTable(id string) string

func (FunctionBuilder) GetParentBuilder

func (b FunctionBuilder) GetParentBuilder() *FunctionBuilder

get parent function

func (*FunctionBuilder) GetVariableBefore

func (f *FunctionBuilder) GetVariableBefore(name string, before Instruction) Value

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) NewBlockId added in v1.2.8

func (b *FunctionBuilder) NewBlockId() string

func (*FunctionBuilder) NewCall

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

func (*FunctionBuilder) NewCaptureField added in v1.2.8

func (b *FunctionBuilder) NewCaptureField(text string) *Field

func (*FunctionBuilder) NewError

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

func (*FunctionBuilder) NewField

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

func (*FunctionBuilder) NewFunc

func (b *FunctionBuilder) NewFunc(name string) (*Function, *blockSymbolTable)

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 symbol-table stack

func (*FunctionBuilder) PushFunction

func (b *FunctionBuilder) PushFunction(newFunc *Function, symbol *blockSymbolTable, block *BasicBlock) *FunctionBuilder

function stack

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, create bool) (ret Value)

* first check builder.currentDef

* if block sealed; just create a phi * if len(block.preds) == 0: undefine * if len(block.preds) == 1: just recursive * if len(block.preds) > 1: create phi and builder

func (*FunctionBuilder) ReplaceVariable

func (b *FunctionBuilder) ReplaceVariable(variable string, v, to Value)

func (*FunctionBuilder) SetPosition

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

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

func (*FunctionBuilder) TryBuildExternLib

func (b *FunctionBuilder) TryBuildExternLib(name string) func(string) Value

func (*FunctionBuilder) TryBuildExternValue added in v1.2.8

func (b *FunctionBuilder) TryBuildExternValue(id string) Value

func (*FunctionBuilder) WithExternLib added in v1.2.8

func (b *FunctionBuilder) WithExternLib(lib map[string]map[string]any)

func (*FunctionBuilder) WithExternValue added in v1.2.8

func (b *FunctionBuilder) WithExternValue(vs map[string]any)

type FunctionType added in v1.2.8

type FunctionType struct {
	Name       string
	ReturnType Type
	Parameter  Types
	FreeValue  map[string]bool
	IsVariadic bool
}

func NewFunctionType added in v1.2.8

func NewFunctionType(name string, Parameter []Type, ReturnType []Type, IsVariadic bool) *FunctionType

func (*FunctionType) GetMethod added in v1.2.8

func (f *FunctionType) GetMethod(string) *FunctionType

func (*FunctionType) GetTypeKind added in v1.2.8

func (s *FunctionType) GetTypeKind() TypeKind

func (*FunctionType) RawString added in v1.2.8

func (s *FunctionType) RawString() string

func (*FunctionType) SetFreeValue added in v1.2.8

func (s *FunctionType) SetFreeValue(fv map[string]bool)

func (*FunctionType) SetMethod added in v1.2.8

func (f *FunctionType) SetMethod(m map[string]*FunctionType)

func (*FunctionType) SetName added in v1.2.8

func (s *FunctionType) SetName(name string)

func (*FunctionType) String added in v1.2.8

func (s *FunctionType) String() string

type IdentifierLV

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

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

func NewIdentifierLV added in v1.2.8

func NewIdentifierLV(variable string, pos *Position) *IdentifierLV

func (*IdentifierLV) Assign

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

func (*IdentifierLV) GetPosition added in v1.2.8

func (i *IdentifierLV) GetPosition() *Position

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 NewIf added in v1.2.8

func NewIf(cond Value, block *BasicBlock) *If

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) GetLeftPosition added in v1.2.8

func (a *If) GetLeftPosition() *Position

func (*If) GetParent

func (a *If) GetParent() *Function

func (*If) GetPosition added in v1.2.8

func (a *If) GetPosition() *Position

func (*If) GetSymbolTable added in v1.2.8

func (a *If) GetSymbolTable() *blockSymbolTable

func (*If) GetType

func (a *If) GetType() Type

func (*If) GetUsers

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

func (*If) GetValues

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

func (*If) GetVariable added in v1.2.8

func (a *If) GetVariable() string

func (If) NewError

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

func (*If) Pos

func (a *If) Pos() string

func (*If) RemoveValue

func (i *If) RemoveValue(v Value)

func (*If) ReplaceValue

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

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

func (*If) SetLeftPosition

func (a *If) SetLeftPosition(pos *Position)

func (*If) SetPosition added in v1.2.8

func (a *If) SetPosition(pos *Position)

func (*If) SetSymbolTable added in v1.2.8

func (a *If) SetSymbolTable(symbolTable *blockSymbolTable)

func (*If) SetType

func (a *If) SetType(ts Type)

func (*If) SetVariable added in v1.2.8

func (a *If) SetVariable(name string)

func (*If) String

func (i *If) String() string

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

type IfBuilder added in v1.2.8

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

func (*IfBuilder) BuildChild added in v1.2.8

func (i *IfBuilder) BuildChild(child *IfBuilder)

func (*IfBuilder) BuildCondition added in v1.2.8

func (i *IfBuilder) BuildCondition(condition func() Value)

func (*IfBuilder) BuildElif added in v1.2.8

func (i *IfBuilder) BuildElif(condition func() Value, body func())

func (*IfBuilder) BuildFalse added in v1.2.8

func (i *IfBuilder) BuildFalse(body func())

func (*IfBuilder) BuildTrue added in v1.2.8

func (i *IfBuilder) BuildTrue(body func())

func (*IfBuilder) Finish added in v1.2.8

func (i *IfBuilder) Finish()

type InspectVariableResult

type InspectVariableResult struct {
	VariableName string
	// values         []Value
	ProbablyTypes  []string
	ProbablyValues []string
	MustTypes      []string
	MustValue      []string
}

func (*InspectVariableResult) Merge

type Instruction

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

	String() string

	// error
	NewError(ErrorKind, ErrorTag, string, ...any)

	// pos
	Pos() string

	GetPosition() *Position
	SetPosition(pos *Position)
	SetSymbolTable(*blockSymbolTable)
	GetSymbolTable() *blockSymbolTable
}

type InstructionValue

type InstructionValue interface {
	Instruction
	Value

	// variable
	GetVariable() string
	SetVariable(string)
	SetLeftPosition(*Position)
	GetLeftPosition() *Position
}

both instruction and value

type InterfaceType

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

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

func NewInterfaceType

func NewInterfaceType(name string) *InterfaceType

func (*InterfaceType) GetMethod added in v1.2.8

func (i *InterfaceType) GetMethod(id string) *FunctionType

func (*InterfaceType) GetTypeKind added in v1.2.8

func (i *InterfaceType) GetTypeKind() TypeKind

func (*InterfaceType) RawString added in v1.2.8

func (i *InterfaceType) RawString() string

func (*InterfaceType) SetMethod added in v1.2.8

func (i *InterfaceType) SetMethod(m map[string]*FunctionType)

func (*InterfaceType) String

func (i *InterfaceType) String() string

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 NewJump added in v1.2.8

func NewJump(to *BasicBlock, block *BasicBlock) *Jump

func (*Jump) GetBlock

func (a *Jump) GetBlock() *BasicBlock

implement instruction

func (*Jump) GetLeftPosition added in v1.2.8

func (a *Jump) GetLeftPosition() *Position

func (*Jump) GetParent

func (a *Jump) GetParent() *Function

func (*Jump) GetPosition added in v1.2.8

func (a *Jump) GetPosition() *Position

func (*Jump) GetSymbolTable added in v1.2.8

func (a *Jump) GetSymbolTable() *blockSymbolTable

func (*Jump) GetType

func (a *Jump) GetType() Type

func (*Jump) GetVariable added in v1.2.8

func (a *Jump) GetVariable() string

func (Jump) NewError

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

func (*Jump) Pos

func (a *Jump) Pos() string

func (*Jump) SetLeftPosition

func (a *Jump) SetLeftPosition(pos *Position)

func (*Jump) SetPosition added in v1.2.8

func (a *Jump) SetPosition(pos *Position)

func (*Jump) SetSymbolTable added in v1.2.8

func (a *Jump) SetSymbolTable(symbolTable *blockSymbolTable)

func (*Jump) SetType

func (a *Jump) SetType(ts Type)

func (*Jump) SetVariable added in v1.2.8

func (a *Jump) SetVariable(name string)

func (*Jump) String

func (j *Jump) String() string

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

type LeftValue

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

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

type Loop added in v1.2.8

type Loop struct {
	Body, Exit *BasicBlock

	Init, Cond, Step Value
	Key              *Phi
	// contains filtered or unexported fields
}

----------- For for loop

func NewLoop added in v1.2.8

func NewLoop(block *BasicBlock, cond Value) *Loop

func (*Loop) AddValue

func (l *Loop) AddValue(v Value)

func (*Loop) Finish added in v1.2.8

func (l *Loop) Finish(init, step []Value)

func (*Loop) GetBlock added in v1.2.8

func (a *Loop) GetBlock() *BasicBlock

implement instruction

func (*Loop) GetLeftPosition added in v1.2.8

func (a *Loop) GetLeftPosition() *Position

func (*Loop) GetParent

func (a *Loop) GetParent() *Function

func (*Loop) GetPosition added in v1.2.8

func (a *Loop) GetPosition() *Position

func (*Loop) GetSymbolTable added in v1.2.8

func (a *Loop) GetSymbolTable() *blockSymbolTable

func (*Loop) GetType

func (a *Loop) GetType() Type

func (*Loop) GetUsers added in v1.2.8

func (l *Loop) GetUsers() []User

func (*Loop) GetValues added in v1.2.8

func (l *Loop) GetValues() []Value

func (*Loop) GetVariable added in v1.2.8

func (a *Loop) GetVariable() string

func (Loop) NewError added in v1.2.8

func (an Loop) NewError(kind ErrorKind, tag ErrorTag, format string, arg ...any)

func (*Loop) Pos

func (a *Loop) Pos() string

func (*Loop) RemoveValue

func (l *Loop) RemoveValue(v Value)

func (*Loop) ReplaceValue added in v1.2.8

func (l *Loop) ReplaceValue(v Value, to Value)

----------- Loop

func (*Loop) SetLeftPosition

func (a *Loop) SetLeftPosition(pos *Position)

func (*Loop) SetPosition added in v1.2.8

func (a *Loop) SetPosition(pos *Position)

func (*Loop) SetSymbolTable added in v1.2.8

func (a *Loop) SetSymbolTable(symbolTable *blockSymbolTable)

func (*Loop) SetType

func (a *Loop) SetType(ts Type)

func (*Loop) SetVariable added in v1.2.8

func (a *Loop) SetVariable(name string)

func (*Loop) String added in v1.2.8

func (l *Loop) String() string

----------- Loop

type LoopBuilder added in v1.2.8

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

func (*LoopBuilder) BuildBody added in v1.2.8

func (lb *LoopBuilder) BuildBody(f func())

func (*LoopBuilder) BuildCondition added in v1.2.8

func (lb *LoopBuilder) BuildCondition(f func() Value)

func (*LoopBuilder) BuildFirstExpr added in v1.2.8

func (lb *LoopBuilder) BuildFirstExpr(f func() []Value)

func (*LoopBuilder) BuildThird added in v1.2.8

func (lb *LoopBuilder) BuildThird(f func() []Value)

func (*LoopBuilder) Finish added in v1.2.8

func (lb *LoopBuilder) Finish()

type Make added in v1.2.8

type Make struct {
	IsNew bool

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

----------- Make instruction + value + user use-chain: *interface(self) -> multiple field(value)

func NewMake added in v1.2.8

func NewMake(parentI User, typ Type, low, high, step, Len, Cap Value, block *BasicBlock) *Make

func ToObject added in v1.2.8

func ToObject(v Value) *Make

func (*Make) AddUser added in v1.2.8

func (n *Make) AddUser(u User)

func (*Make) AddValue

func (n *Make) AddValue(v Value)

func (*Make) GetBlock added in v1.2.8

func (a *Make) GetBlock() *BasicBlock

implement instruction

func (*Make) GetLeftPosition added in v1.2.8

func (a *Make) GetLeftPosition() *Position

func (*Make) GetParent

func (a *Make) GetParent() *Function

func (*Make) GetPosition added in v1.2.8

func (a *Make) GetPosition() *Position

func (*Make) GetSymbolTable added in v1.2.8

func (a *Make) GetSymbolTable() *blockSymbolTable

func (*Make) GetType added in v1.2.8

func (a *Make) GetType() Type

func (*Make) GetUsers added in v1.2.8

func (n *Make) GetUsers() []User

func (*Make) GetValues added in v1.2.8

func (n *Make) GetValues() []Value

func (*Make) GetVariable added in v1.2.8

func (a *Make) GetVariable() string

func (Make) NewError added in v1.2.8

func (an Make) NewError(kind ErrorKind, tag ErrorTag, format string, arg ...any)

func (*Make) Pos

func (a *Make) Pos() string

func (*Make) RemoveUser added in v1.2.8

func (n *Make) RemoveUser(u User)

func (*Make) RemoveValue

func (n *Make) RemoveValue(v Value)

func (*Make) ReplaceValue added in v1.2.8

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

// ----------- Interface

func (*Make) SetLeftPosition

func (a *Make) SetLeftPosition(pos *Position)

func (*Make) SetPosition added in v1.2.8

func (a *Make) SetPosition(pos *Position)

func (*Make) SetSymbolTable added in v1.2.8

func (a *Make) SetSymbolTable(symbolTable *blockSymbolTable)

func (*Make) SetType added in v1.2.8

func (a *Make) SetType(ts Type)

func (*Make) SetVariable added in v1.2.8

func (a *Make) SetVariable(name string)

func (*Make) String added in v1.2.8

func (i *Make) String() string

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

type Next added in v1.2.8

type Next struct {
	Iter   Value
	InNext bool // "in" grammar
	// contains filtered or unexported fields
}

------------- Next

func NewNext added in v1.2.8

func NewNext(iter Value, isIn bool, block *BasicBlock) *Next

func (*Next) AddUser added in v1.2.8

func (n *Next) AddUser(u User)

func (*Next) AddValue

func (n *Next) AddValue(v Value)

func (*Next) GetBlock added in v1.2.8

func (a *Next) GetBlock() *BasicBlock

implement instruction

func (*Next) GetLeftPosition added in v1.2.8

func (a *Next) GetLeftPosition() *Position

func (*Next) GetParent

func (a *Next) GetParent() *Function

func (*Next) GetPosition added in v1.2.8

func (a *Next) GetPosition() *Position

func (*Next) GetSymbolTable added in v1.2.8

func (a *Next) GetSymbolTable() *blockSymbolTable

func (*Next) GetType added in v1.2.8

func (a *Next) GetType() Type

func (*Next) GetUsers added in v1.2.8

func (n *Next) GetUsers() []User

func (*Next) GetValues added in v1.2.8

func (n *Next) GetValues() []Value

func (*Next) GetVariable added in v1.2.8

func (a *Next) GetVariable() string

func (Next) NewError added in v1.2.8

func (an Next) NewError(kind ErrorKind, tag ErrorTag, format string, arg ...any)

func (*Next) Pos

func (a *Next) Pos() string

func (*Next) RemoveUser added in v1.2.8

func (n *Next) RemoveUser(u User)

func (*Next) RemoveValue

func (n *Next) RemoveValue(v Value)

func (*Next) ReplaceValue added in v1.2.8

func (n *Next) ReplaceValue(v, to Value)

// ----------- Next

func (*Next) SetLeftPosition

func (a *Next) SetLeftPosition(pos *Position)

func (*Next) SetPosition added in v1.2.8

func (a *Next) SetPosition(pos *Position)

func (*Next) SetSymbolTable added in v1.2.8

func (a *Next) SetSymbolTable(symbolTable *blockSymbolTable)

func (*Next) SetType added in v1.2.8

func (a *Next) SetType(ts Type)

func (*Next) SetVariable added in v1.2.8

func (a *Next) SetVariable(name string)

func (*Next) String added in v1.2.8

func (n *Next) String() string

type Node

type Node interface {
	String() string

	GetType() Type

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

data flow graph node

type ObjectKind added in v1.2.8

type ObjectKind int

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

const (
	None ObjectKind = iota
	Slice
	Map
	Struct
)

type ObjectType added in v1.2.8

type ObjectType struct {
	Name string
	Kind ObjectKind
	Len  int
	Key  []Value

	FieldTypes []Type

	AnonymousField []*ObjectType

	Combination  bool // function multiple return will combined to struct
	VariadicPara bool // function last variadic parameter will become slice

	KeyTyp    Type
	FieldType Type
	// contains filtered or unexported fields
}

func NewMapType

func NewMapType(key, field Type) *ObjectType

func NewObjectType added in v1.2.8

func NewObjectType() *ObjectType

func NewSliceType

func NewSliceType(elem Type) *ObjectType

for slice build

func NewStructType added in v1.2.8

func NewStructType() *ObjectType

func (*ObjectType) AddField added in v1.2.8

func (s *ObjectType) AddField(key Value, field Type)

for struct build

func (*ObjectType) Finish added in v1.2.8

func (s *ObjectType) Finish()

===================== Finish simply

func (*ObjectType) GetField added in v1.2.8

func (s *ObjectType) GetField(key Value) (Type, Type)

return (field-type, key-type)

func (*ObjectType) GetMethod added in v1.2.8

func (i *ObjectType) GetMethod(id string) *FunctionType

func (*ObjectType) GetTypeKind added in v1.2.8

func (i *ObjectType) GetTypeKind() TypeKind

func (ObjectType) RawString added in v1.2.8

func (itype ObjectType) RawString() string

func (*ObjectType) SetMethod added in v1.2.8

func (i *ObjectType) SetMethod(m map[string]*FunctionType)

func (*ObjectType) SetName added in v1.2.8

func (i *ObjectType) SetName(name string)

func (ObjectType) String added in v1.2.8

func (itype ObjectType) String() string

type Package

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

func NewPackage added in v1.2.8

func NewPackage(name string) *Package

func (*Package) NewFunction

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

func (*Package) NewFunctionWithParent

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

type Panic added in v1.2.8

type Panic struct {
	Info Value
	// contains filtered or unexported fields
}

-------------- PANIC

func (*Panic) AddUser added in v1.2.8

func (n *Panic) AddUser(u User)

func (*Panic) AddValue

func (n *Panic) AddValue(v Value)

func (*Panic) GetBlock added in v1.2.8

func (a *Panic) GetBlock() *BasicBlock

implement instruction

func (*Panic) GetLeftPosition added in v1.2.8

func (a *Panic) GetLeftPosition() *Position

func (*Panic) GetParent

func (a *Panic) GetParent() *Function

func (*Panic) GetPosition added in v1.2.8

func (a *Panic) GetPosition() *Position

func (*Panic) GetSymbolTable added in v1.2.8

func (a *Panic) GetSymbolTable() *blockSymbolTable

func (*Panic) GetType added in v1.2.8

func (a *Panic) GetType() Type

func (*Panic) GetUsers added in v1.2.8

func (n *Panic) GetUsers() []User

func (*Panic) GetValues added in v1.2.8

func (n *Panic) GetValues() []Value

func (*Panic) GetVariable added in v1.2.8

func (a *Panic) GetVariable() string

func (Panic) NewError added in v1.2.8

func (an Panic) NewError(kind ErrorKind, tag ErrorTag, format string, arg ...any)

func (*Panic) Pos

func (a *Panic) Pos() string

func (*Panic) RemoveUser added in v1.2.8

func (n *Panic) RemoveUser(u User)

func (*Panic) RemoveValue

func (n *Panic) RemoveValue(v Value)

func (*Panic) ReplaceValue added in v1.2.8

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

------------- PANIC

func (*Panic) SetLeftPosition

func (a *Panic) SetLeftPosition(pos *Position)

func (*Panic) SetPosition added in v1.2.8

func (a *Panic) SetPosition(pos *Position)

func (*Panic) SetSymbolTable added in v1.2.8

func (a *Panic) SetSymbolTable(symbolTable *blockSymbolTable)

func (*Panic) SetType added in v1.2.8

func (a *Panic) SetType(ts Type)

func (*Panic) SetVariable added in v1.2.8

func (a *Panic) SetVariable(name string)

func (*Panic) String added in v1.2.8

func (p *Panic) String() string

type Parameter

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

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

func NewParam added in v1.2.8

func NewParam(variable string, isFreeValue bool, fun *Function) *Parameter

func (*Parameter) AddUser

func (n *Parameter) AddUser(u User)

func (*Parameter) AddValue

func (n *Parameter) AddValue(v Value)

func (*Parameter) GetType

func (p *Parameter) GetType() Type

func (*Parameter) GetUsers

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

func (*Parameter) GetValues

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

func (*Parameter) RemoveUser

func (n *Parameter) RemoveUser(u User)

func (*Parameter) RemoveValue

func (n *Parameter) RemoveValue(v Value)

func (*Parameter) ReplaceValue added in v1.3.1

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

// ----------- param

func (*Parameter) SetType

func (p *Parameter) SetType(ts Type)

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(block *BasicBlock, variable string, create bool) *Phi

func (*Phi) AddEdge added in v1.2.8

func (p *Phi) AddEdge(v Value)

func (*Phi) AddUser

func (n *Phi) AddUser(u User)

func (*Phi) AddValue

func (n *Phi) AddValue(v Value)

func (*Phi) Build

func (phi *Phi) Build() Value

func (*Phi) GetBlock

func (a *Phi) GetBlock() *BasicBlock

implement instruction

func (*Phi) GetLeftPosition added in v1.2.8

func (a *Phi) GetLeftPosition() *Position

func (*Phi) GetParent

func (a *Phi) GetParent() *Function

func (*Phi) GetPosition added in v1.2.8

func (a *Phi) GetPosition() *Position

func (*Phi) GetSymbolTable added in v1.2.8

func (a *Phi) GetSymbolTable() *blockSymbolTable

func (*Phi) GetType

func (a *Phi) GetType() Type

func (*Phi) GetUsers

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

func (*Phi) GetValues

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

func (*Phi) GetVariable added in v1.2.8

func (a *Phi) GetVariable() string

func (*Phi) Name

func (phi *Phi) Name() string

func (Phi) NewError

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

func (*Phi) Pos

func (a *Phi) Pos() string

func (*Phi) RemoveUser

func (n *Phi) RemoveUser(u User)

func (*Phi) RemoveValue

func (n *Phi) RemoveValue(v Value)

func (*Phi) Replace added in v1.2.8

func (phi *Phi) Replace(to Value)

func (*Phi) ReplaceValue

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

// ----------- Phi

func (*Phi) SetLeftPosition

func (a *Phi) SetLeftPosition(pos *Position)

func (*Phi) SetPosition added in v1.2.8

func (a *Phi) SetPosition(pos *Position)

func (*Phi) SetSymbolTable added in v1.2.8

func (a *Phi) SetSymbolTable(symbolTable *blockSymbolTable)

func (*Phi) SetType

func (a *Phi) SetType(ts Type)

func (*Phi) SetVariable added in v1.2.8

func (a *Phi) SetVariable(name string)

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) AddPackage added in v1.2.8

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

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) InspectVariableLast added in v1.2.8

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

func (*Program) Show

func (p *Program) Show()

func (*Program) ShowWithSource

func (p *Program) ShowWithSource()

type Recover added in v1.2.8

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

--------------- RECOVER

func (*Recover) AddUser added in v1.2.8

func (n *Recover) AddUser(u User)

func (*Recover) AddValue

func (n *Recover) AddValue(v Value)

func (*Recover) GetBlock added in v1.2.8

func (a *Recover) GetBlock() *BasicBlock

implement instruction

func (*Recover) GetLeftPosition added in v1.2.8

func (a *Recover) GetLeftPosition() *Position

func (*Recover) GetParent

func (a *Recover) GetParent() *Function

func (*Recover) GetPosition added in v1.2.8

func (a *Recover) GetPosition() *Position

func (*Recover) GetSymbolTable added in v1.2.8

func (a *Recover) GetSymbolTable() *blockSymbolTable

func (*Recover) GetType added in v1.2.8

func (a *Recover) GetType() Type

func (*Recover) GetUsers added in v1.2.8

func (n *Recover) GetUsers() []User

func (*Recover) GetValues added in v1.2.8

func (n *Recover) GetValues() []Value

func (*Recover) GetVariable added in v1.2.8

func (a *Recover) GetVariable() string

func (Recover) NewError added in v1.2.8

func (an Recover) NewError(kind ErrorKind, tag ErrorTag, format string, arg ...any)

func (*Recover) Pos

func (a *Recover) Pos() string

func (*Recover) RemoveUser added in v1.2.8

func (n *Recover) RemoveUser(u User)

func (*Recover) RemoveValue

func (n *Recover) RemoveValue(v Value)

func (*Recover) ReplaceValue added in v1.3.1

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

---------- RECOVER

func (*Recover) SetLeftPosition

func (a *Recover) SetLeftPosition(pos *Position)

func (*Recover) SetPosition added in v1.2.8

func (a *Recover) SetPosition(pos *Position)

func (*Recover) SetSymbolTable added in v1.2.8

func (a *Recover) SetSymbolTable(symbolTable *blockSymbolTable)

func (*Recover) SetType added in v1.2.8

func (a *Recover) SetType(ts Type)

func (*Recover) SetVariable added in v1.2.8

func (a *Recover) SetVariable(name string)

func (*Recover) String added in v1.2.8

func (r *Recover) String() string

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 NewReturn added in v1.2.8

func NewReturn(vs []Value, block *BasicBlock) *Return

func (*Return) AddValue

func (r *Return) AddValue(v Value)

func (*Return) GetBlock

func (a *Return) GetBlock() *BasicBlock

implement instruction

func (*Return) GetLeftPosition added in v1.2.8

func (a *Return) GetLeftPosition() *Position

func (*Return) GetParent

func (a *Return) GetParent() *Function

func (*Return) GetPosition added in v1.2.8

func (a *Return) GetPosition() *Position

func (*Return) GetSymbolTable added in v1.2.8

func (a *Return) GetSymbolTable() *blockSymbolTable

func (*Return) GetType

func (a *Return) GetType() Type

func (*Return) GetUsers

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

func (*Return) GetValues

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

func (*Return) GetVariable added in v1.2.8

func (a *Return) GetVariable() string

func (Return) NewError

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

func (*Return) Pos

func (a *Return) Pos() string

func (*Return) RemoveValue

func (r *Return) RemoveValue(v Value)

func (*Return) ReplaceValue

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

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

func (*Return) SetLeftPosition

func (a *Return) SetLeftPosition(pos *Position)

func (*Return) SetPosition added in v1.2.8

func (a *Return) SetPosition(pos *Position)

func (*Return) SetSymbolTable added in v1.2.8

func (a *Return) SetSymbolTable(symbolTable *blockSymbolTable)

func (*Return) SetType

func (a *Return) SetType(ts Type)

func (*Return) SetVariable added in v1.2.8

func (a *Return) SetVariable(name string)

func (*Return) String

func (r *Return) String() string

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

type SSAError

type SSAError struct {
	Pos *Position

	Message string
	Kind    ErrorKind
	// contains filtered or unexported fields
}

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 {
	Cond         Value
	DefaultBlock *BasicBlock

	Label []SwitchLabel
	// contains filtered or unexported fields
}

func NewSwitch added in v1.2.8

func NewSwitch(cond Value, defaultb *BasicBlock, label []SwitchLabel, block *BasicBlock) *Switch

func (*Switch) AddValue

func (sw *Switch) AddValue(v Value)

func (*Switch) GetBlock

func (a *Switch) GetBlock() *BasicBlock

implement instruction

func (*Switch) GetLeftPosition added in v1.2.8

func (a *Switch) GetLeftPosition() *Position

func (*Switch) GetParent

func (a *Switch) GetParent() *Function

func (*Switch) GetPosition added in v1.2.8

func (a *Switch) GetPosition() *Position

func (*Switch) GetSymbolTable added in v1.2.8

func (a *Switch) GetSymbolTable() *blockSymbolTable

func (*Switch) GetType

func (a *Switch) GetType() Type

func (*Switch) GetUsers

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

func (*Switch) GetValues

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

func (*Switch) GetVariable added in v1.2.8

func (a *Switch) GetVariable() string

func (Switch) NewError

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

func (*Switch) Pos

func (a *Switch) Pos() string

func (*Switch) RemoveValue

func (sw *Switch) RemoveValue(v Value)

func (*Switch) ReplaceValue

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

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

func (*Switch) SetLeftPosition

func (a *Switch) SetLeftPosition(pos *Position)

func (*Switch) SetPosition added in v1.2.8

func (a *Switch) SetPosition(pos *Position)

func (*Switch) SetSymbolTable added in v1.2.8

func (a *Switch) SetSymbolTable(symbolTable *blockSymbolTable)

func (*Switch) SetType

func (a *Switch) SetType(ts Type)

func (*Switch) SetVariable added in v1.2.8

func (a *Switch) SetVariable(name string)

func (*Switch) String

func (sw *Switch) String() string

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

type SwitchLabel

type SwitchLabel struct {
	Value Value
	Dest  *BasicBlock
}

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

func NewSwitchLabel

func NewSwitchLabel(v Value, dest *BasicBlock) SwitchLabel

type Type

type Type interface {
	String() string
	RawString() string
	GetTypeKind() TypeKind

	// set/get method
	SetMethod(map[string]*FunctionType)
	GetMethod(id string) *FunctionType
}

func CalculateType added in v1.2.8

func CalculateType(ts []Type) Type

func GetType

func GetType(i any) Type

func GetTypeByStr

func GetTypeByStr(typ string) Type

type TypeCast added in v1.2.8

type TypeCast struct {
	Value Value
	// contains filtered or unexported fields
}

----------- Type-cast cast value -> type

func NewTypeCast added in v1.2.8

func NewTypeCast(typ Type, v Value, block *BasicBlock) *TypeCast

func (*TypeCast) AddUser added in v1.2.8

func (n *TypeCast) AddUser(u User)

func (*TypeCast) AddValue

func (n *TypeCast) AddValue(v Value)

func (*TypeCast) GetBlock added in v1.2.8

func (a *TypeCast) GetBlock() *BasicBlock

implement instruction

func (*TypeCast) GetLeftPosition added in v1.2.8

func (a *TypeCast) GetLeftPosition() *Position

func (*TypeCast) GetParent

func (a *TypeCast) GetParent() *Function

func (*TypeCast) GetPosition added in v1.2.8

func (a *TypeCast) GetPosition() *Position

func (*TypeCast) GetSymbolTable added in v1.2.8

func (a *TypeCast) GetSymbolTable() *blockSymbolTable

func (*TypeCast) GetType added in v1.2.8

func (a *TypeCast) GetType() Type

func (*TypeCast) GetUsers added in v1.2.8

func (n *TypeCast) GetUsers() []User

func (*TypeCast) GetValues added in v1.2.8

func (n *TypeCast) GetValues() []Value

func (*TypeCast) GetVariable added in v1.2.8

func (a *TypeCast) GetVariable() string

func (TypeCast) NewError added in v1.2.8

func (an TypeCast) NewError(kind ErrorKind, tag ErrorTag, format string, arg ...any)

func (*TypeCast) Pos

func (a *TypeCast) Pos() string

func (*TypeCast) RemoveUser added in v1.2.8

func (n *TypeCast) RemoveUser(u User)

func (*TypeCast) RemoveValue

func (n *TypeCast) RemoveValue(v Value)

func (*TypeCast) ReplaceValue added in v1.2.8

func (t *TypeCast) ReplaceValue(v, to Value)

// ----------- Typecast

func (*TypeCast) SetLeftPosition

func (a *TypeCast) SetLeftPosition(pos *Position)

func (*TypeCast) SetPosition added in v1.2.8

func (a *TypeCast) SetPosition(pos *Position)

func (*TypeCast) SetSymbolTable added in v1.2.8

func (a *TypeCast) SetSymbolTable(symbolTable *blockSymbolTable)

func (*TypeCast) SetType added in v1.2.8

func (a *TypeCast) SetType(ts Type)

func (*TypeCast) SetVariable added in v1.2.8

func (a *TypeCast) SetVariable(name string)

func (*TypeCast) String added in v1.2.8

func (t *TypeCast) String() string

type TypeKind

type TypeKind int

basic type

const (
	Number TypeKind = iota
	String
	Boolean
	UndefineType // undefine is nil in golang
	Null         //
	Any          // any type
	ChanTypeKind
	ErrorType
	ObjectTypeKind
	InterfaceTypeKind
	FunctionTypeKind
)

type TypeValue added in v1.2.8

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

------------- type value

func NewTypeValue added in v1.2.8

func NewTypeValue(typ Type, block *BasicBlock) *TypeValue

func (*TypeValue) AddUser added in v1.2.8

func (n *TypeValue) AddUser(u User)

func (*TypeValue) AddValue

func (n *TypeValue) AddValue(v Value)

func (*TypeValue) GetBlock added in v1.2.8

func (a *TypeValue) GetBlock() *BasicBlock

implement instruction

func (*TypeValue) GetLeftPosition added in v1.2.8

func (a *TypeValue) GetLeftPosition() *Position

func (*TypeValue) GetParent

func (a *TypeValue) GetParent() *Function

func (*TypeValue) GetPosition added in v1.2.8

func (a *TypeValue) GetPosition() *Position

func (*TypeValue) GetSymbolTable added in v1.2.8

func (a *TypeValue) GetSymbolTable() *blockSymbolTable

func (*TypeValue) GetType added in v1.2.8

func (a *TypeValue) GetType() Type

func (*TypeValue) GetUsers added in v1.2.8

func (n *TypeValue) GetUsers() []User

func (*TypeValue) GetValues added in v1.2.8

func (n *TypeValue) GetValues() []Value

func (*TypeValue) GetVariable added in v1.2.8

func (a *TypeValue) GetVariable() string

func (TypeValue) NewError added in v1.2.8

func (an TypeValue) NewError(kind ErrorKind, tag ErrorTag, format string, arg ...any)

func (*TypeValue) Pos

func (a *TypeValue) Pos() string

func (*TypeValue) RemoveUser added in v1.2.8

func (n *TypeValue) RemoveUser(u User)

func (*TypeValue) RemoveValue

func (n *TypeValue) RemoveValue(v Value)

func (TypeValue) ReplaceValue added in v1.3.1

func (t TypeValue) ReplaceValue(v, to Value)

------------ type value

func (*TypeValue) SetLeftPosition

func (a *TypeValue) SetLeftPosition(pos *Position)

func (*TypeValue) SetPosition added in v1.2.8

func (a *TypeValue) SetPosition(pos *Position)

func (*TypeValue) SetSymbolTable added in v1.2.8

func (a *TypeValue) SetSymbolTable(symbolTable *blockSymbolTable)

func (*TypeValue) SetType added in v1.2.8

func (a *TypeValue) SetType(ts Type)

func (*TypeValue) SetVariable added in v1.2.8

func (a *TypeValue) SetVariable(name string)

func (*TypeValue) String added in v1.2.8

func (t *TypeValue) String() string

type Types

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

func (Types) Compare

func (org Types) Compare(typs Types) bool

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

func (Types) Contains added in v1.2.8

func (t Types) Contains(typ Types) bool

func (Types) Equal added in v1.2.8

func (t Types) Equal(typs Types) bool

func (Types) IsType added in v1.2.8

func (t Types) IsType(kind TypeKind) bool

func (Types) String

func (t Types) String() string

type UnOp

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

func NewUnOpOnly added in v1.2.8

func NewUnOpOnly(op UnaryOpcode, x Value, block *BasicBlock) *UnOp

func (*UnOp) AddUser added in v1.2.8

func (n *UnOp) AddUser(u User)

func (*UnOp) AddValue

func (n *UnOp) AddValue(v Value)

func (*UnOp) GetBlock

func (a *UnOp) GetBlock() *BasicBlock

implement instruction

func (*UnOp) GetLeftPosition added in v1.2.8

func (a *UnOp) GetLeftPosition() *Position

func (*UnOp) GetParent

func (a *UnOp) GetParent() *Function

func (*UnOp) GetPosition added in v1.2.8

func (a *UnOp) GetPosition() *Position

func (*UnOp) GetSymbolTable added in v1.2.8

func (a *UnOp) GetSymbolTable() *blockSymbolTable

func (*UnOp) GetType

func (a *UnOp) GetType() Type

func (*UnOp) GetUsers added in v1.2.8

func (n *UnOp) GetUsers() []User

func (*UnOp) GetValues added in v1.2.8

func (n *UnOp) GetValues() []Value

func (*UnOp) GetVariable added in v1.2.8

func (a *UnOp) GetVariable() string

func (UnOp) NewError

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

func (*UnOp) Pos

func (a *UnOp) Pos() string

func (*UnOp) RemoveUser added in v1.2.8

func (n *UnOp) RemoveUser(u User)

func (*UnOp) RemoveValue

func (n *UnOp) RemoveValue(v Value)

func (*UnOp) ReplaceValue added in v1.2.8

func (u *UnOp) ReplaceValue(v Value, to Value)

func (*UnOp) SetLeftPosition

func (a *UnOp) SetLeftPosition(pos *Position)

func (*UnOp) SetPosition added in v1.2.8

func (a *UnOp) SetPosition(pos *Position)

func (*UnOp) SetSymbolTable added in v1.2.8

func (a *UnOp) SetSymbolTable(symbolTable *blockSymbolTable)

func (*UnOp) SetType

func (a *UnOp) SetType(ts Type)

func (*UnOp) SetVariable added in v1.2.8

func (a *UnOp) SetVariable(name string)

func (*UnOp) String added in v1.2.8

func (u *UnOp) String() string

type UnaryOpcode

type UnaryOpcode int
const (
	OpNone       UnaryOpcode = iota
	OpNot                    // !
	OpPlus                   // +
	OpNeg                    // -
	OpChan                   // <-
	OpBitwiseNot             // ^
)

type Undefine

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

func NewUndefine

func NewUndefine(name string, block *BasicBlock) *Undefine

func (*Undefine) AddUser

func (n *Undefine) AddUser(u User)

func (*Undefine) AddValue

func (n *Undefine) AddValue(v Value)

func (*Undefine) GetBlock

func (a *Undefine) GetBlock() *BasicBlock

implement instruction

func (*Undefine) GetLeftPosition

func (a *Undefine) GetLeftPosition() *Position

func (*Undefine) GetParent

func (a *Undefine) GetParent() *Function

func (*Undefine) GetPosition

func (a *Undefine) GetPosition() *Position

func (*Undefine) GetSymbolTable

func (a *Undefine) GetSymbolTable() *blockSymbolTable

func (*Undefine) GetType

func (a *Undefine) GetType() Type

func (*Undefine) GetUsers

func (n *Undefine) GetUsers() []User

func (*Undefine) GetValues

func (n *Undefine) GetValues() []Value

func (*Undefine) GetVariable

func (a *Undefine) GetVariable() string

func (Undefine) NewError

func (an Undefine) NewError(kind ErrorKind, tag ErrorTag, format string, arg ...any)

func (*Undefine) Pos

func (a *Undefine) Pos() string

func (*Undefine) RemoveUser

func (n *Undefine) RemoveUser(u User)

func (*Undefine) RemoveValue

func (n *Undefine) RemoveValue(v Value)

func (*Undefine) ReplaceValue

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

----------- undefine

func (*Undefine) SetLeftPosition

func (a *Undefine) SetLeftPosition(pos *Position)

func (*Undefine) SetPosition

func (a *Undefine) SetPosition(pos *Position)

func (*Undefine) SetSymbolTable

func (a *Undefine) SetSymbolTable(symbolTable *blockSymbolTable)

func (*Undefine) SetType

func (a *Undefine) SetType(ts Type)

func (*Undefine) SetVariable

func (a *Undefine) SetVariable(name string)

func (*Undefine) String

func (u *Undefine) String() string

----------- undefine

type Update

type Update struct {
	Value   Value
	Address User
	// contains filtered or unexported fields
}

----------- Update use-chain: field(user) -> *update -> value

func NewUpdate added in v1.2.8

func NewUpdate(address User, v Value, block *BasicBlock) *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) GetLeftPosition added in v1.2.8

func (a *Update) GetLeftPosition() *Position

func (*Update) GetParent

func (a *Update) GetParent() *Function

func (*Update) GetPosition added in v1.2.8

func (a *Update) GetPosition() *Position

func (*Update) GetSymbolTable added in v1.2.8

func (a *Update) GetSymbolTable() *blockSymbolTable

func (*Update) GetType

func (a *Update) GetType() Type

func (*Update) GetUsers

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

func (*Update) GetValues

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

func (*Update) GetVariable added in v1.2.8

func (a *Update) GetVariable() string

func (Update) NewError

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

func (*Update) Pos

func (a *Update) Pos() string

func (*Update) RemoveUser

func (s *Update) RemoveUser(u User)

func (*Update) RemoveValue

func (s *Update) RemoveValue(_ Value)

func (*Update) ReplaceValue

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

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

func (*Update) SetLeftPosition

func (a *Update) SetLeftPosition(pos *Position)

func (*Update) SetPosition added in v1.2.8

func (a *Update) SetPosition(pos *Position)

func (*Update) SetSymbolTable added in v1.2.8

func (a *Update) SetSymbolTable(symbolTable *blockSymbolTable)

func (*Update) SetType

func (a *Update) SetType(ts Type)

func (*Update) SetVariable added in v1.2.8

func (a *Update) SetVariable(name string)

func (*Update) String

func (s *Update) String() string

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

type User

type User interface {
	Node

	AddValue(Value)
	RemoveValue(Value)

	ReplaceValue(Value, Value)
}

func GetUser

func GetUser(v Value) []User

func GetUserOnly

func GetUserOnly(n Node) []User

get user without object

type Value

type Value interface {
	Node

	// user
	AddUser(User)
	RemoveUser(User)

	// type
	SetType(Type)
}

func CalcBinary added in v1.2.8

func CalcBinary(b *BinOp) Value

func CalcConstBinarySide added in v1.2.8

func CalcConstBinarySide(c *Const, v Value, op BinaryOpcode) Value

func HandlerBinOp added in v1.2.8

func HandlerBinOp(b *BinOp) Value

func HandlerUnOp added in v1.2.8

func HandlerUnOp(u *UnOp) Value

func NewBinOp added in v1.2.8

func NewBinOp(op BinaryOpcode, x, y Value, block *BasicBlock) Value

func NewUnOp added in v1.2.8

func NewUnOp(op UnaryOpcode, x Value, block *BasicBlock) Value

Jump to

Keyboard shortcuts

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