ssaapi

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: AGPL-3.0 Imports: 21 Imported by: 0

README

SSA API

do ssa api can do anything?

the ssa api is designed for auditing and analysis, not for optimization.

optimization should be handled in Lower-IR.

Verify Case Suite

the cases for verifying ssa api should be careful code.

u can test any language feature in ssa api;

  1. rename test
  2. scope test
  3. if statement test
  4. if statement test: phi
  5. switch statement test
  6. switch statement test: phi
  7. loop statement test
  8. loop statement test: phi
  9. loop statement test: phi t2=phi(t1, t2)
  10. function test
  11. function test: formal parameter analysis
  12. function test: the N-th formal parameter analysis
  13. function test: return value analysis
  14. function test: closure
  15. function test: free-value
  16. function test: cross
  17. function test: recursive
  18. function test: recursive loop phi
  19. function test: maskable free-value
  20. classless test: static member call
  21. classless test: dynamic member call
  22. classless test: static member call: phi
  23. classless test: dynamic member call: phi
  24. dynamic member convert to static member: collapsed literal
  25. classless test and closure: multi-returns value to static member
  26. function test: maskable membered free-value
  27. function test: multi-returns value to value in function defs
  28. classless test: container assigned in closure

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Exports = map[string]any{
	"Parse": Parse,

	"withLanguage":    WithLanguage,
	"withExternLib":   WithExternLib,
	"withExternValue": WithExternValue,
	"withDataBase":    WithDataBase,

	"Javascript": JS,
	"Yak":        Yak,
	"PHP":        PHP,
	"Java":       JAVA,
}
View Source
var (
	LanguageBuilders = map[Language]Build{
		Yak:  yak2ssa.Build,
		JS:   js2ssa.Build,
		PHP:  php2ssa.Build,
		JAVA: java2ssa.Build,
	}
)

Functions

func GetBareNode added in v1.2.9

func GetBareNode(v *Value) ssa.Value

GetBareNode get ssa.Value from ssaapi.Value only use this function in golang

func GetBareType added in v1.2.9

func GetBareType(typ *Type) ssa.Type

func TypeCompare added in v1.2.9

func TypeCompare(t1, t2 *Type) bool

func ValueCompare added in v1.2.9

func ValueCompare(v1, v2 *Value) bool

Types

type AnalyzeContext added in v1.3.0

type AnalyzeContext struct {
	// Self
	Self *Value
	// contains filtered or unexported fields
}

func NewAnalyzeContext added in v1.3.0

func NewAnalyzeContext(opt ...OperationOption) *AnalyzeContext

func (*AnalyzeContext) GetCurrentCall added in v1.3.0

func (g *AnalyzeContext) GetCurrentCall() *Value

func (*AnalyzeContext) GetCurrentObject added in v1.3.2

func (g *AnalyzeContext) GetCurrentObject() (*Value, *Value, *Value)

func (*AnalyzeContext) IsExistedInCallStack added in v1.3.0

func (a *AnalyzeContext) IsExistedInCallStack(i *Value) bool

func (*AnalyzeContext) PopCall added in v1.3.0

func (a *AnalyzeContext) PopCall() *Value

func (*AnalyzeContext) PopObject added in v1.3.2

func (g *AnalyzeContext) PopObject() (*Value, *Value, *Value)

func (*AnalyzeContext) PushCall added in v1.3.0

func (a *AnalyzeContext) PushCall(i *Value) error

func (*AnalyzeContext) PushObject added in v1.3.2

func (g *AnalyzeContext) PushObject(obj, key, member *Value) error

func (*AnalyzeContext) TheCallShouldBeVisited added in v1.3.0

func (a *AnalyzeContext) TheCallShouldBeVisited(i *Value) bool

func (*AnalyzeContext) TheMemberShouldBeVisited added in v1.3.2

func (g *AnalyzeContext) TheMemberShouldBeVisited(member *Value) bool

func (*AnalyzeContext) ThePhiShouldBeVisited added in v1.3.0

func (a *AnalyzeContext) ThePhiShouldBeVisited(i *Value) bool

ThePhiShouldBeVisited is used to check whether the phi should be visited

func (*AnalyzeContext) VisitPhi added in v1.3.0

func (a *AnalyzeContext) VisitPhi(i *Value)

type Build added in v1.3.2

type Build func(string, bool, *ssa.FunctionBuilder) error

type ContextID added in v1.3.2

type ContextID string
var (
	ANALYZE_RUNTIME_CTX_TOPDEF_CALL_ENTRY             ContextID = "call_entry"
	ANALYZE_RUNTIME_CTX_TOPDEF_CALL_ENTRY_TRACE_INDEX ContextID = "call_entry_trace_idx"
)

type DominatorForest added in v1.3.1

type DominatorForest struct {
	Trees []*DominatorTree
}

type DominatorTree added in v1.3.1

type DominatorTree *omap.OrderedMap[int, *Value]

type Language

type Language string
const (
	Yak  Language = "yak"
	JS   Language = "js"
	PHP  Language = "php"
	JAVA Language = "java"
)

type OperationConfig added in v1.3.1

type OperationConfig struct {
	// 限制递归深度,每一次递归核心函数,计数器都会加一
	// 上下文计数器受到这个限制
	MaxDepth int
	MinDepth int

	// Hook
	HookEveryNode func(*Value) error
}

func NewOperations added in v1.3.1

func NewOperations(opt ...OperationOption) *OperationConfig

type OperationOption added in v1.3.1

type OperationOption func(*OperationConfig)

func WithDepthLimit added in v1.3.1

func WithDepthLimit(depth int) OperationOption

func WithHookEveryNode added in v1.3.1

func WithHookEveryNode(hookNode func(*Value) error) OperationOption

func WithMaxDepth added in v1.3.1

func WithMaxDepth(maxDepth int) OperationOption

func WithMinDepth added in v1.3.1

func WithMinDepth(minDepth int) OperationOption

type Option

type Option func(*config)

func WithDataBase added in v1.3.2

func WithDataBase(name string) Option

save to database, please set the program name

func WithDefineFunc added in v1.3.1

func WithDefineFunc(table map[string]any) Option

func WithExternInfo added in v1.3.0

func WithExternInfo(info string) Option

func WithExternLib

func WithExternLib(name string, table map[string]any) Option

func WithExternMethod added in v1.2.9

func WithExternMethod(b ssa.MethodBuilder) Option

func WithExternValue

func WithExternValue(table map[string]any) Option

func WithFeedCode added in v1.3.1

func WithFeedCode(b ...bool) Option

func WithIgnoreSyntaxError added in v1.3.0

func WithIgnoreSyntaxError(b ...bool) Option

func WithLanguage

func WithLanguage(language Language) Option

type Program

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

func NewProgram

func NewProgram(prog *ssa.Program) *Program

func Parse

func Parse(code string, opts ...Option) (*Program, error)

func (*Program) AddConfig added in v1.3.1

func (p *Program) AddConfig(c *config)

func (*Program) Feed added in v1.3.1

func (p *Program) Feed(code string)

func (*Program) GetAllSymbols added in v1.3.0

func (p *Program) GetAllSymbols() map[string]Values

func (*Program) GetClassMember added in v1.3.2

func (p *Program) GetClassMember(className string, key string) *Value

func (*Program) GetErrors added in v1.3.0

func (p *Program) GetErrors() ssa.SSAErrors

func (*Program) GetInstructionById added in v1.3.0

func (p *Program) GetInstructionById(id int64) ssa.Instruction

func (*Program) GetValueById added in v1.3.0

func (p *Program) GetValueById(id int64) (*Value, error)

func (*Program) GetValueByIdMust added in v1.3.0

func (p *Program) GetValueByIdMust(id int64) *Value

func (*Program) IsNil added in v1.2.9

func (p *Program) IsNil() bool

func (*Program) Ref

func (p *Program) Ref(name string) Values

func (*Program) Show added in v1.3.0

func (p *Program) Show() *Program

type Type added in v1.2.9

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

func FuncOf added in v1.2.9

func FuncOf(name string, args, ret []*Type, isVariadic bool) *Type

func MapOf added in v1.2.9

func MapOf(key, value *Type) *Type

func NewType added in v1.2.9

func NewType(t ssa.Type) *Type

func SliceOf added in v1.2.9

func SliceOf(t *Type) *Type

func (*Type) Compare added in v1.2.9

func (t *Type) Compare(t2 *Type) bool

func (*Type) String added in v1.2.9

func (t *Type) String() string

type Value

type Value struct {
	EffectOn Values
	DependOn Values
	// contains filtered or unexported fields
}

func FullUseDefChain added in v1.3.1

func FullUseDefChain(value *Value, opts ...OperationOption) *Value

func NewValue

func NewValue(n ssa.Value) *Value

func (*Value) AnalyzeDepth added in v1.3.1

func (v *Value) AnalyzeDepth() int

func (*Value) AppendDependOn added in v1.3.1

func (v *Value) AppendDependOn(i *Value) *Value

func (*Value) AppendEffectOn added in v1.3.1

func (v *Value) AppendEffectOn(i *Value) *Value

func (*Value) Backtrack added in v1.3.1

func (v *Value) Backtrack() *omap.OrderedMap[string, *Value]

func (*Value) Compare added in v1.2.9

func (v *Value) Compare(other *Value) bool

func (*Value) Dot added in v1.3.1

func (v *Value) Dot() string

func (*Value) FlexibleDepends added in v1.3.1

func (v *Value) FlexibleDepends() *Value

FlexibleDepends is used to get all the dependencies of the value e.g: a = b + c; d = a + e; the e is not filled in the depends of a, but call FlexibleDepends will get it

func (*Value) GetAllMember added in v1.3.1

func (v *Value) GetAllMember() Values

GetAllMember get all member of object

func (*Value) GetBlock

func (v *Value) GetBlock() *Value

func (*Value) GetBottomUses added in v1.3.0

func (v *Value) GetBottomUses(opt ...OperationOption) Values

func (*Value) GetCallArgs added in v1.3.0

func (v *Value) GetCallArgs() Values

func (*Value) GetCallReturns added in v1.3.0

func (v *Value) GetCallReturns() Values

func (*Value) GetCalledBy added in v1.3.0

func (v *Value) GetCalledBy() Values

GetCalledBy desc all of 'Users' is Call

func (*Value) GetCallee added in v1.3.0

func (v *Value) GetCallee() *Value

GetCallee desc any of 'Users' is Call

func (*Value) GetConst added in v1.2.9

func (v *Value) GetConst() *ssa.Const

func (*Value) GetConstValue added in v1.2.9

func (v *Value) GetConstValue() any

for const instruction

func (*Value) GetContextValue added in v1.3.0

func (v *Value) GetContextValue(i ContextID) (*Value, bool)

GetContextValue can handle context

func (*Value) GetDepth added in v1.3.1

func (v *Value) GetDepth() int

func (*Value) GetFunction

func (v *Value) GetFunction() *Value

func (*Value) GetId added in v1.3.0

func (v *Value) GetId() int64

func (*Value) GetKey added in v1.3.1

func (v *Value) GetKey() *Value

GetKey get key of member

func (*Value) GetMember added in v1.3.1

func (v *Value) GetMember(value *Value) *Value

GetMember get member of object by key

func (*Value) GetName added in v1.3.0

func (i *Value) GetName() string

func (*Value) GetObject added in v1.3.1

func (v *Value) GetObject() *Value

GetObject get object of member

func (*Value) GetOpcode added in v1.2.9

func (v *Value) GetOpcode() ssa.Opcode

func (*Value) GetOperand

func (i *Value) GetOperand(index int) *Value

func (*Value) GetOperands

func (i *Value) GetOperands() Values

func (*Value) GetParameter

func (v *Value) GetParameter(i int) *Value

func (*Value) GetParameters added in v1.2.9

func (v *Value) GetParameters() Values

func (*Value) GetRange added in v1.3.1

func (v *Value) GetRange() *ssa.Range

func (*Value) GetReachable

func (v *Value) GetReachable() *Value

func (*Value) GetReturn

func (v *Value) GetReturn() Values

func (*Value) GetSelf added in v1.2.9

func (v *Value) GetSelf() *Value

func (*Value) GetTopDefs added in v1.3.0

func (i *Value) GetTopDefs(opt ...OperationOption) Values

GetTopDefs desc all of 'Defs' is not used by any other value

func (*Value) GetType added in v1.2.9

func (v *Value) GetType() *Type

func (*Value) GetTypeKind added in v1.2.9

func (v *Value) GetTypeKind() ssa.TypeKind

func (*Value) GetUser

func (i *Value) GetUser(index int) *Value

func (*Value) GetUsers

func (i *Value) GetUsers() Values

func (*Value) GetVerboseName added in v1.3.1

func (i *Value) GetVerboseName() string

func (*Value) HasOperands

func (i *Value) HasOperands() bool

func (*Value) HasUsers

func (i *Value) HasUsers() bool

func (*Value) InMainFunction

func (v *Value) InMainFunction() bool

func (*Value) IsAssert

func (v *Value) IsAssert() bool

func (*Value) IsBasicBlock

func (v *Value) IsBasicBlock() bool

func (*Value) IsBinOp

func (v *Value) IsBinOp() bool

func (*Value) IsCall

func (v *Value) IsCall() bool

func (*Value) IsCalled added in v1.3.0

func (v *Value) IsCalled() bool

IsCalled desc any of 'Users' is Call

func (*Value) IsConstInst

func (v *Value) IsConstInst() bool

func (*Value) IsErrorHandler

func (v *Value) IsErrorHandler() bool

func (*Value) IsExternLib added in v1.3.1

func (v *Value) IsExternLib() bool

IsExternLib desc if the value is extern lib

extern-lib is a special value that is used to represent the external library

code := `a = fmt.Println`
fmt := prog.Ref("fmt") // extern-lib
fmt.GetOperands() // Values // [Function-Println]

func (*Value) IsFunction

func (v *Value) IsFunction() bool

func (*Value) IsIf

func (v *Value) IsIf() bool

func (*Value) IsJump

func (v *Value) IsJump() bool

func (*Value) IsLoop

func (v *Value) IsLoop() bool

func (*Value) IsMake

func (v *Value) IsMake() bool

func (*Value) IsMember added in v1.3.1

func (v *Value) IsMember() bool

IsMember desc if the value is member of some object

func (*Value) IsModifySelf added in v1.2.9

func (v *Value) IsModifySelf() bool

func (*Value) IsNext

func (v *Value) IsNext() bool

func (*Value) IsObject added in v1.3.1

func (v *Value) IsObject() bool

IsObject desc if the value is object

func (*Value) IsPanic

func (v *Value) IsPanic() bool

func (*Value) IsParameter added in v1.2.9

func (v *Value) IsParameter() bool

func (*Value) IsPhi

func (v *Value) IsPhi() bool

func (*Value) IsReachable

func (v *Value) IsReachable() int

if condition is true : 1 reach if condition is false : -1 unreachable if condition need calc: 0 unknown

func (*Value) IsRecover

func (v *Value) IsRecover() bool

func (*Value) IsReturn

func (v *Value) IsReturn() bool

func (*Value) IsSwitch

func (v *Value) IsSwitch() bool

func (*Value) IsTypeCast

func (v *Value) IsTypeCast() bool

func (*Value) IsTypeValue

func (v *Value) IsTypeValue() bool

func (*Value) IsUnOp

func (v *Value) IsUnOp() bool

func (*Value) IsUndefined

func (v *Value) IsUndefined() bool

func (*Value) LoadFullUseDefChain added in v1.3.1

func (v *Value) LoadFullUseDefChain() *Value

func (*Value) NewError added in v1.2.9

func (v *Value) NewError(tag, msg string)

func (*Value) NewWarn added in v1.2.9

func (v *Value) NewWarn(tag, msg string)

func (*Value) RecursiveDepends added in v1.3.1

func (v *Value) RecursiveDepends(h func(value *Value) error)

RecursiveDepends is used to get all the dependencies of the value

func (*Value) RecursiveDependsAndEffects added in v1.3.1

func (v *Value) RecursiveDependsAndEffects(h func(value *Value) error)

func (*Value) RecursiveEffects added in v1.3.1

func (v *Value) RecursiveEffects(h func(value *Value) error)

RecursiveEffects is used to get all the effects of the value

func (*Value) SetContextValue added in v1.3.0

func (v *Value) SetContextValue(i ContextID, values *Value) *Value

func (*Value) SetDepth added in v1.3.1

func (v *Value) SetDepth(i int)

func (*Value) ShortString added in v1.3.1

func (v *Value) ShortString() string

func (*Value) Show

func (i *Value) Show()

func (*Value) ShowBacktrack added in v1.3.1

func (v *Value) ShowBacktrack()

func (*Value) ShowDot added in v1.3.1

func (v *Value) ShowDot() *Value

func (*Value) ShowUseDefChain

func (v *Value) ShowUseDefChain()

func (*Value) ShowWithSource

func (i *Value) ShowWithSource()

func (*Value) String

func (v *Value) String() string

func (*Value) StringWithSource

func (i *Value) StringWithSource() string

type Values

type Values []*Value

func FindFlexibleCommonDepends added in v1.3.1

func FindFlexibleCommonDepends(val Values) Values

func FindStrictCommonDepends added in v1.3.1

func FindStrictCommonDepends(val Values) Values

func (Values) AppendDependOn added in v1.3.1

func (i Values) AppendDependOn(v *Value) Values

func (Values) AppendEffectOn added in v1.3.1

func (i Values) AppendEffectOn(v *Value) Values

func (Values) Filter added in v1.2.9

func (v Values) Filter(f func(*Value) bool) Values

func (Values) Flat added in v1.3.0

func (v Values) Flat(f func(*Value) Values) Values

func (Values) FlexibleDepends added in v1.3.1

func (v Values) FlexibleDepends() Values

func (Values) ForEach

func (v Values) ForEach(f func(*Value)) Values

func (Values) FullUseDefChain added in v1.3.1

func (v Values) FullUseDefChain(h func(*Value))

func (Values) Get

func (v Values) Get(i int) *Value

func (Values) GetBottomUses added in v1.3.1

func (v Values) GetBottomUses() Values

func (Values) GetOperands added in v1.3.1

func (v Values) GetOperands() Values

func (Values) GetTopDefs added in v1.3.0

func (v Values) GetTopDefs(opts ...OperationOption) Values

func (Values) GetUsers added in v1.2.9

func (v Values) GetUsers() Values

func (Values) Ref

func (value Values) Ref(name string) Values

func (Values) Show

func (v Values) Show(b ...bool) Values

func (Values) ShowDot added in v1.3.1

func (V Values) ShowDot() Values

func (Values) ShowWithSource

func (v Values) ShowWithSource(b ...bool) Values

func (Values) String added in v1.3.0

func (v Values) String() string

func (Values) StringEx

func (v Values) StringEx(flag int) string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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