ssautil

package
v1.3.4-alpha7 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ForEachCapturedVariable

func ForEachCapturedVariable[T versionedValue](
	scope ScopedVersionedTableIF[T],
	base ScopedVersionedTableIF[T],
	handler CaptureVariableHandler[T],
)

ForEachCapturedVariable call the handler for each captured by base scope Variable

func RegisterLazyInstructionBuilder added in v1.3.3

func RegisterLazyInstructionBuilder(builder func(id int64) (SSAValue, error))

Types

type CaptureVariableHandler

type CaptureVariableHandler[T versionedValue] func(string, VersionedIF[T])

capture variable

type FileDescriptor added in v1.3.3

type FileDescriptor struct {
	FileName string
	Info     fs.FileInfo
}

type GlobalIndexFetcher

type GlobalIndexFetcher func() int

for builder

type IfStmt

type IfStmt[T versionedValue] struct {
	BodyScopes []ScopedVersionedTableIF[T]
	// contains filtered or unexported fields
}

IfStmt represents an if statement.

func NewIfStmt

func NewIfStmt[T versionedValue](global ScopedVersionedTableIF[T]) *IfStmt[T]

NewIfStmt creates a new IfStmt with the given global scope.

IfStmt will handle if-stmt scope.
API:
	* BuildItem(condition fun(scope), body func(scope)):
		build if item using the provided Condition and Body functions.
	* BuildElse(elseBody func(scope)):
		set the else function for the IfStmt.
	* BuildFinish(mergeHandler func(name string, t []T) T):
		build the IfStmt finish, using the provided mergeHandler function create Phi.
IfStmt will build this scope when this method call

func (*IfStmt[T]) BuildElse

func (i *IfStmt[T]) BuildElse(elseBody func(ScopedVersionedTableIF[T]) ScopedVersionedTableIF[T])

SetElse sets the else function for the IfStmt.

func (*IfStmt[T]) BuildFinish

func (i *IfStmt[T]) BuildFinish(
	mergeHandler MergeHandle[T],
) ScopedVersionedTableIF[T]

Build builds the IfStmt using the provided mergeHandler function.

func (*IfStmt[T]) BuildItem

func (i *IfStmt[T]) BuildItem(Condition func(ScopedVersionedTableIF[T]), Body func(ScopedVersionedTableIF[T]) ScopedVersionedTableIF[T])

BuildItem build the if item using the provided Condition and Body functions.

type LabelTarget

type LabelTarget[T versionedValue] interface {
	Break(from ScopedVersionedTableIF[T])
	Continue(from ScopedVersionedTableIF[T])
	FallThough(from ScopedVersionedTableIF[T])
}

type LoopStmt

type LoopStmt[T versionedValue] struct {
	MergeToEnd   []ScopedVersionedTableIF[T] // break, merge phi in exit
	MergeToLatch []ScopedVersionedTableIF[T] // continue, merge phi in latch

	ThirdBuilder func(ScopedVersionedTableIF[T]) // third
	// contains filtered or unexported fields
}

LoopStmt represents a loop statement.

func NewLoopStmt

func NewLoopStmt[T versionedValue](global ScopedVersionedTableIF[T], NewPhi func(string) T) *LoopStmt[T]

NewLoopStmt creates a new LoopStmt with the given global scope.

func (*LoopStmt[T]) Break

func (l *LoopStmt[T]) Break(from ScopedVersionedTableIF[T])

func (*LoopStmt[T]) Build

func (l *LoopStmt[T]) Build(
	SpinHandler SpinHandle[T],
	mergeLatch MergeHandle[T],
	mergeEnd MergeHandle[T],
) ScopedVersionedTableIF[T]

Build builds the LoopStmt using the provided NewPhi and SpinHandler functions.

func (*LoopStmt[T]) Continue

func (l *LoopStmt[T]) Continue(from ScopedVersionedTableIF[T])

func (*LoopStmt[T]) FallThough

func (l *LoopStmt[T]) FallThough(from ScopedVersionedTableIF[T])

func (*LoopStmt[T]) SetBody

func (l *LoopStmt[T]) SetBody(f func(ScopedVersionedTableIF[T]) ScopedVersionedTableIF[T])

SetBody sets the body function for the LoopStmt.

func (*LoopStmt[T]) SetCondition

func (l *LoopStmt[T]) SetCondition(f func(ScopedVersionedTableIF[T]))

SetCondition sets the condition function for the LoopStmt.

func (*LoopStmt[T]) SetFirst

func (l *LoopStmt[T]) SetFirst(f func(ScopedVersionedTableIF[T]))

SetFirst sets the first function for the LoopStmt.

func (*LoopStmt[T]) SetThird

func (l *LoopStmt[T]) SetThird(f func(ScopedVersionedTableIF[T]))

SetThird sets the third function for the LoopStmt.

type MergeHandle

type MergeHandle[T comparable] func(string, []T) T

MergeHandle handler Merge Value generate Phi

type PackageLoader added in v1.3.3

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

func NewPackageLoader added in v1.3.3

func NewPackageLoader(opts ...PackageLoaderOption) *PackageLoader

func (*PackageLoader) AddIncludePath added in v1.3.3

func (p *PackageLoader) AddIncludePath(s ...string)

func (*PackageLoader) AddPackagePath added in v1.3.3

func (p *PackageLoader) AddPackagePath(path []string)

func (*PackageLoader) DirPath added in v1.3.3

func (p *PackageLoader) DirPath(wantPath string, once bool) (string, error)

func (*PackageLoader) FilePath added in v1.3.3

func (p *PackageLoader) FilePath(wantPath string, once bool) (string, error)

func (*PackageLoader) GetCurrentPath added in v1.3.3

func (p *PackageLoader) GetCurrentPath() string

func (*PackageLoader) GetFilesysFileSystem

func (p *PackageLoader) GetFilesysFileSystem() filesys.FileSystem

func (*PackageLoader) GetPackagePath added in v1.3.3

func (p *PackageLoader) GetPackagePath() []string

func (*PackageLoader) LoadDirectoryPackage added in v1.3.3

func (p *PackageLoader) LoadDirectoryPackage(packageName string, once bool) (chan FileDescriptor, error)

func (*PackageLoader) LoadFilePackage added in v1.3.3

func (p *PackageLoader) LoadFilePackage(packageName string, once bool) (string, *memedit.MemEditor, error)

func (*PackageLoader) SetCurrentPath added in v1.3.3

func (p *PackageLoader) SetCurrentPath(currentPath string)

type PackageLoaderOption added in v1.3.3

type PackageLoaderOption func(*PackageLoader)

func WithCurrentPath added in v1.3.3

func WithCurrentPath(path string) PackageLoaderOption

func WithFileSystem added in v1.3.3

func WithFileSystem(fs filesys.FileSystem) PackageLoaderOption

func WithIncludePath added in v1.3.3

func WithIncludePath(paths ...string) PackageLoaderOption

type SSAValue

type SSAValue interface {
	IsUndefined() bool
	SelfDelete()
	GetId() int64
}

func NewLazyInstruction added in v1.3.3

func NewLazyInstruction(id int64) (SSAValue, error)

type ScopedVersionedTable

type ScopedVersionedTable[T versionedValue] struct {
	// contains filtered or unexported fields
}

func NewRootVersionedTable

func NewRootVersionedTable[T versionedValue](
	programName string,
	newVersioned VersionedBuilder[T],
	fetcher ...func() int,
) *ScopedVersionedTable[T]

func NewScope

func NewScope[T versionedValue](
	programName string,
	fetcher func() int,
	newVersioned VersionedBuilder[T],
	parent ScopedVersionedTableIF[T],
) *ScopedVersionedTable[T]

func (*ScopedVersionedTable[T]) AssignVariable

func (scope *ScopedVersionedTable[T]) AssignVariable(variable VersionedIF[T], value T)

---------------- Assign

func (*ScopedVersionedTable[T]) Compare

func (s *ScopedVersionedTable[T]) Compare(other ScopedVersionedTableIF[T]) bool

func (*ScopedVersionedTable[T]) CoverBy

func (base *ScopedVersionedTable[T]) CoverBy(scope ScopedVersionedTableIF[T])

func (*ScopedVersionedTable[T]) CreateSubScope

func (v *ScopedVersionedTable[T]) CreateSubScope() ScopedVersionedTableIF[T]

func (*ScopedVersionedTable[T]) CreateVariable

func (v *ScopedVersionedTable[T]) CreateVariable(name string, isLocal bool) VersionedIF[T]

func (*ScopedVersionedTable[T]) ForEachCapturedVariable

func (ps *ScopedVersionedTable[T]) ForEachCapturedVariable(handler CaptureVariableHandler[T])

func (*ScopedVersionedTable[T]) GetCaptured added in v1.3.3

func (s *ScopedVersionedTable[T]) GetCaptured() *omap.OrderedMap[string, VersionedIF[T]]

func (*ScopedVersionedTable[T]) GetIncomingPhi added in v1.3.3

func (s *ScopedVersionedTable[T]) GetIncomingPhi() *omap.OrderedMap[string, VersionedIF[T]]

func (*ScopedVersionedTable[T]) GetParent

func (v *ScopedVersionedTable[T]) GetParent() ScopedVersionedTableIF[T]

func (*ScopedVersionedTable[T]) GetPersistentId added in v1.3.3

func (s *ScopedVersionedTable[T]) GetPersistentId() int64

func (*ScopedVersionedTable[T]) GetPersistentProgramName added in v1.3.3

func (s *ScopedVersionedTable[T]) GetPersistentProgramName() string

func (*ScopedVersionedTable[T]) GetScopeLevel

func (s *ScopedVersionedTable[T]) GetScopeLevel() int

use for up lever

func (*ScopedVersionedTable[T]) GetThis

func (v *ScopedVersionedTable[T]) GetThis() ScopedVersionedTableIF[T]

func (*ScopedVersionedTable[T]) GetValues added in v1.3.3

func (*ScopedVersionedTable[T]) GetVariable added in v1.3.3

func (s *ScopedVersionedTable[T]) GetVariable() *omap.OrderedMap[T, []VersionedIF[T]]

func (*ScopedVersionedTable[T]) GetVariableFromValue

func (scope *ScopedVersionedTable[T]) GetVariableFromValue(value T) VersionedIF[T]

func (*ScopedVersionedTable[T]) IsRoot

func (v *ScopedVersionedTable[T]) IsRoot() bool

func (*ScopedVersionedTable[T]) IsSameOrSubScope

func (s *ScopedVersionedTable[T]) IsSameOrSubScope(other ScopedVersionedTableIF[T]) bool

IsSubScope check if the scope is sub scope of the other

func (*ScopedVersionedTable[T]) Merge

func (base *ScopedVersionedTable[T]) Merge(
	hasSelf bool,
	merge MergeHandle[T],
	subScopes ...ScopedVersionedTableIF[T],
)

Merge merge the sub-scope to current scope, if hasSelf is true: the current scope will be merged to the result

func (*ScopedVersionedTable[T]) ReadValue

func (v *ScopedVersionedTable[T]) ReadValue(name string) (t T)

func (*ScopedVersionedTable[T]) ReadVariable

func (scope *ScopedVersionedTable[T]) ReadVariable(name string) VersionedIF[T]

func (*ScopedVersionedTable[T]) SaveToDatabase added in v1.3.3

func (s *ScopedVersionedTable[T]) SaveToDatabase() error

func (*ScopedVersionedTable[T]) SetCapturedVariable

func (scope *ScopedVersionedTable[T]) SetCapturedVariable(name string, ver VersionedIF[T])

func (*ScopedVersionedTable[T]) SetParent added in v1.3.3

func (v *ScopedVersionedTable[T]) SetParent(parent ScopedVersionedTableIF[T])

func (*ScopedVersionedTable[T]) SetParentId added in v1.3.3

func (s *ScopedVersionedTable[T]) SetParentId(i int64)

func (*ScopedVersionedTable[T]) SetPersistentId added in v1.3.3

func (s *ScopedVersionedTable[T]) SetPersistentId(i int64)

func (*ScopedVersionedTable[T]) SetPersistentNode added in v1.3.3

func (s *ScopedVersionedTable[T]) SetPersistentNode(i *ssadb.IrScopeNode)

func (*ScopedVersionedTable[T]) SetScopeLevel added in v1.3.3

func (s *ScopedVersionedTable[T]) SetScopeLevel(i int)

func (*ScopedVersionedTable[T]) SetSpin

func (s *ScopedVersionedTable[T]) SetSpin(create func(string) T)

func (*ScopedVersionedTable[T]) SetSpinRaw added in v1.3.3

func (s *ScopedVersionedTable[T]) SetSpinRaw(b bool)

func (*ScopedVersionedTable[T]) SetThis

func (v *ScopedVersionedTable[T]) SetThis(scope ScopedVersionedTableIF[T])

func (*ScopedVersionedTable[T]) ShouldSaveToDatabase added in v1.3.3

func (s *ScopedVersionedTable[T]) ShouldSaveToDatabase() bool

func (*ScopedVersionedTable[T]) Spin

func (s *ScopedVersionedTable[T]) Spin(
	header, latch ScopedVersionedTableIF[T],
	handler SpinHandle[T],
)

this handler merge [origin, last] to phi

type ScopedVersionedTableIF

type ScopedVersionedTableIF[T versionedValue] interface {
	// Read Variable by name
	ReadVariable(name string) VersionedIF[T]
	// read value by name
	ReadValue(name string) T

	// create variable, if isLocal is true, the variable is local
	CreateVariable(name string, isLocal bool) VersionedIF[T]

	// assign a value to the variable
	AssignVariable(VersionedIF[T], T)

	GetVariableFromValue(T) VersionedIF[T]

	// this scope
	SetThis(ScopedVersionedTableIF[T])
	GetThis() ScopedVersionedTableIF[T]

	// create sub scope
	CreateSubScope() ScopedVersionedTableIF[T]
	// get scope level, each scope has a level, the root scope is 0, the sub scope is {parent-scope.level + 1}
	GetScopeLevel() int
	GetParent() ScopedVersionedTableIF[T]
	SetParent(ScopedVersionedTableIF[T])

	IsSameOrSubScope(ScopedVersionedTableIF[T]) bool
	Compare(ScopedVersionedTableIF[T]) bool

	// use in ssautil, handle inner member
	ForEachCapturedVariable(CaptureVariableHandler[T])
	SetCapturedVariable(string, VersionedIF[T])

	// use in phi
	CoverBy(ScopedVersionedTableIF[T])
	Merge(bool, MergeHandle[T], ...ScopedVersionedTableIF[T])
	Spin(ScopedVersionedTableIF[T], ScopedVersionedTableIF[T], SpinHandle[T])
	SetSpin(func(string) T)

	// db
	SaveToDatabase() error
	GetPersistentId() int64
	SetPersistentId(i int64)
	SetPersistentNode(*ssadb.IrScopeNode)

	GetPersistentProgramName() string
}

ScopedVersionedTableIF is the interface for scope versioned table

func BuildSyntaxBlock

func BuildSyntaxBlock[T versionedValue](
	global ScopedVersionedTableIF[T],
	buildBody func(ScopedVersionedTableIF[T]) ScopedVersionedTableIF[T],
) ScopedVersionedTableIF[T]

BuildSyntaxBlock builds a syntax block using the provided scope and buildBody function.

if this scope finish this program

* BuildBody should return true

* this function will return true

type SpinHandle

type SpinHandle[T comparable] func(string, T, T, T) map[string]T

SpinHandle for Loop Spin Phi

type SwitchStmt

type SwitchStmt[T versionedValue] struct {
	AutoBreak bool
	// contains filtered or unexported fields
}

func NewSwitchStmt

func NewSwitchStmt[T versionedValue](global ScopedVersionedTableIF[T], AutoBreak bool) *SwitchStmt[T]

func (*SwitchStmt[T]) Break

func (s *SwitchStmt[T]) Break(from ScopedVersionedTableIF[T])

func (*SwitchStmt[T]) Build

func (s *SwitchStmt[T]) Build(merge func(string, []T) T) ScopedVersionedTableIF[T]

func (*SwitchStmt[T]) BuildBody

func (s *SwitchStmt[T]) BuildBody(
	body func(ScopedVersionedTableIF[T]) ScopedVersionedTableIF[T],
	merge func(string, []T) T,
)

func (*SwitchStmt[T]) Continue

func (s *SwitchStmt[T]) Continue(from ScopedVersionedTableIF[T])

func (*SwitchStmt[T]) FallThough

func (s *SwitchStmt[T]) FallThough(from ScopedVersionedTableIF[T])

type TryStmt

type TryStmt[T versionedValue] struct {
	ErrorName string
	// contains filtered or unexported fields
}

func NewTryStmt

func NewTryStmt[T versionedValue](
	global ScopedVersionedTableIF[T],
	mergeHandler MergeHandle[T],
) *TryStmt[T]

func (*TryStmt[T]) AddCache

func (t *TryStmt[T]) AddCache(build func(ScopedVersionedTableIF[T]) ScopedVersionedTableIF[T])

func (*TryStmt[T]) Build

func (t *TryStmt[T]) Build() ScopedVersionedTableIF[T]

func (*TryStmt[T]) CreateFinally

func (t *TryStmt[T]) CreateFinally() ScopedVersionedTableIF[T]

func (*TryStmt[T]) SetError

func (t *TryStmt[T]) SetError(name string)

func (*TryStmt[T]) SetFinal

func (t *TryStmt[T]) SetFinal(build func() ScopedVersionedTableIF[T])

func (*TryStmt[T]) SetTryBody

func (t *TryStmt[T]) SetTryBody(body func(ScopedVersionedTableIF[T]) ScopedVersionedTableIF[T])

type Versioned

type Versioned[T versionedValue] struct {
	Value T
	// contains filtered or unexported fields
}

func (*Versioned[T]) Assign

func (v *Versioned[T]) Assign(val T) error

func (*Versioned[T]) CanCaptureInScope

func (v *Versioned[T]) CanCaptureInScope(base ScopedVersionedTableIF[T]) bool

func (*Versioned[T]) CaptureInScope

func (v *Versioned[T]) CaptureInScope(base ScopedVersionedTableIF[T]) (VersionedIF[T], bool)

func (*Versioned[T]) GetCaptured

func (v *Versioned[T]) GetCaptured() VersionedIF[T]

func (*Versioned[T]) GetGlobalIndex

func (v *Versioned[T]) GetGlobalIndex() int

func (*Versioned[T]) GetId added in v1.3.3

func (v *Versioned[T]) GetId() int64

func (*Versioned[T]) GetLocal

func (v *Versioned[T]) GetLocal() bool

func (*Versioned[T]) GetName

func (v *Versioned[T]) GetName() string

func (*Versioned[T]) GetRootVersion

func (v *Versioned[T]) GetRootVersion() VersionedIF[T]

func (*Versioned[T]) GetScope

func (v *Versioned[T]) GetScope() ScopedVersionedTableIF[T]

func (*Versioned[T]) GetValue

func (v *Versioned[T]) GetValue() (ret T)

func (*Versioned[T]) GetVersion

func (v *Versioned[T]) GetVersion() int

func (*Versioned[T]) IsNil

func (v *Versioned[T]) IsNil() bool

func (*Versioned[T]) IsRoot

func (v *Versioned[T]) IsRoot() bool

func (*Versioned[T]) MarshalJSON added in v1.3.3

func (v *Versioned[T]) MarshalJSON() ([]byte, error)

func (*Versioned[T]) Replace

func (v *Versioned[T]) Replace(val, to T)

func (*Versioned[T]) SetCaptured

func (v *Versioned[T]) SetCaptured(capture VersionedIF[T])

func (*Versioned[T]) SetScope added in v1.3.3

func (v *Versioned[T]) SetScope(s ScopedVersionedTableIF[T])

func (*Versioned[T]) SetVersion

func (v *Versioned[T]) SetVersion(version int)

func (*Versioned[T]) String

func (v *Versioned[T]) String() string

func (*Versioned[T]) UnmarshalJSON added in v1.3.3

func (v *Versioned[T]) UnmarshalJSON(raw []byte) error

type VersionedBuilder

type VersionedBuilder[T versionedValue] func(globalIndex int, name string, local bool, scope ScopedVersionedTableIF[T]) VersionedIF[T]

type VersionedIF

type VersionedIF[T versionedValue] interface {
	// value
	// IsNil return true if the variable is nil
	IsNil() bool
	GetValue() T

	// Replace
	Replace(T, T)
	// Assign assign a value to the variable
	Assign(T) error

	// show, string and name
	String() string
	GetName() string

	// version
	SetVersion(int)
	GetVersion() int

	// local
	GetLocal() bool

	// capture
	CaptureInScope(ScopedVersionedTableIF[T]) (VersionedIF[T], bool)
	CanCaptureInScope(ScopedVersionedTableIF[T]) bool
	// capture variable
	SetCaptured(VersionedIF[T]) // this capture will set self, when variable create.
	GetCaptured() VersionedIF[T]

	// scope
	GetScope() ScopedVersionedTableIF[T]
	SetScope(ScopedVersionedTableIF[T])

	// version and root
	GetGlobalIndex() int // global id
	GetRootVersion() VersionedIF[T]
	IsRoot() bool
	GetId() int64
	MarshalJSON() ([]byte, error)
	UnmarshalJSON([]byte) error
}

VersionedIF is an interface for versioned variable, scope will use this interface

func NewVersioned

func NewVersioned[T versionedValue](globalIndex int, name string, local bool, scope ScopedVersionedTableIF[T]) VersionedIF[T]

Jump to

Keyboard shortcuts

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