ssa

package
v1.2.7-sp1 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2023 License: AGPL-3.0 Imports: 7 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 = 4
)

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

func DeleteInst(i Instruction)

func EmitBefore

func EmitBefore(before, inst Instruction)

func EmitInst

func EmitInst(i Instruction)

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 NewBlockId

func NewBlockId() string

func NewNode

func NewNode() anNode

func ReplaceValue

func ReplaceValue(v Value, to Value)

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

func (a *Assert) GetParent() *Function

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) 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
	Instrs []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) GetParent

func (a *BinOp) GetParent() *Function

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

	// caller
	// caller Value
	// ~ drop error
	IsDropError 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, isDropError bool, 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) GetParent

func (a *Call) GetParent() *Function

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

func NewConst(i any) *Const

func NewConstWithUnary

func NewConstWithUnary(i any, un int) *Const

create 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) GetParent

func (a *ConstInst) GetParent() *Function

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

func (a *ErrorHandler) GetParent() *Function

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

	// capture by other function
	OutCapture bool

	Update []Value // value
	// contains filtered or unexported fields
}

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

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

func (a *Field) GetParent() *Function

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) 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` hanlder, 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
	CurrtenPos   *Position   // current position in source code
	// 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) 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) BuildLoop added in v1.2.8

func (b *FunctionBuilder) BuildLoop() *LoopBuilder

func (*FunctionBuilder) BuildValueFromAny added in v1.2.8

func (b *FunctionBuilder) BuildValueFromAny(libname, 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) *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) (key, field, ok Value)

func (*FunctionBuilder) EmitNextOnly added in v1.2.8

func (f *FunctionBuilder) EmitNextOnly(iter Value) *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) 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) Value

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 feild

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

func (b FunctionBuilder) HandlerEllipsis()

function param

func (*FunctionBuilder) IfBuilder

func (b *FunctionBuilder) IfBuilder() *IfBuilder

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) 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() *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

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)

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

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

func (*FunctionBuilder) WithExternInstance

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

type FunctionType added in v1.2.8

type FunctionType struct {
	Name       string
	ReturnType Type
	Parameter  []Type
	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) 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 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 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) GetParent

func (a *If) GetParent() *Function

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

func (i *IfBuilder) AddChild(child *IfBuilder)

func (*IfBuilder) ElifBranch

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

func (*IfBuilder) ElseBranch

func (i *IfBuilder) ElseBranch(body func())

func (*IfBuilder) Finish added in v1.2.8

func (i *IfBuilder) Finish()

func (*IfBuilder) IfBranch

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

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
}

type InstructionValue

type InstructionValue interface {
	Instruction
	Value

	// variable
	GetVariable() string
	SetVariable(string)
}

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

func (a *Jump) GetParent() *Function

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

func (a *Loop) GetParent() *Function

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

func (lb *LoopBuilder) BuildCondtion(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) GetParent

func (a *Make) GetParent() *Function

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) 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
	// contains filtered or unexported fields
}

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

func NewNext added in v1.2.8

func NewNext(iter Value, 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) GetParent

func (a *Next) GetParent() *Function

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

	Combination bool
	// 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 (*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) GetParent

func (a *Panic) GetParent() *Function

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

func (a *Phi) GetParent() *Function

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

func (a *Recover) GetParent() *Function

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

func (a *Return) GetParent() *Function

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

func (a *Switch) GetParent() *Function

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

func (a *TypeCast) GetParent() *Function

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) 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 golnag
	Null         //
	Any          // any type
	ChanTypeKind
	ErrorType
	ObjectTypeKind
	InterfaceTypeKind
	FunctionTypeKind
)

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

func (a *UnOp) GetParent() *Function

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

func (a *Undefine) GetParent() *Function

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)

----------- undifne

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

func (a *Update) GetParent() *Function

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

type Value

type Value interface {
	Node

	// user
	AddUser(User)
	RemoveUser(User)

	// type
	SetType(Type)
}

func CalcBianry

func CalcBianry(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