wazevoapi

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2023 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// FunctionInstanceSize is the size of wazevo.functionInstance.
	FunctionInstanceSize = 24
	// FunctionInstanceExecutableOffset is an offset of `executable` field in wazevo.functionInstance
	FunctionInstanceExecutableOffset = 0
	// FunctionInstanceModuleContextOpaquePtrOffset is an offset of `moduleContextOpaquePtr` field in wazevo.functionInstance
	FunctionInstanceModuleContextOpaquePtrOffset = 8
	// FunctionInstanceTypeIDOffset is an offset of `typeID` field in wazevo.functionInstance
	FunctionInstanceTypeIDOffset = 16
)
View Source
const ExitCodeMask = 0xff

Variables

View Source
var ExecutionContextOffsets = ExecutionContextOffsetData{
	ExitCodeOffset:                          0,
	CallerModuleContextPtr:                  8,
	OriginalFramePointer:                    16,
	OriginalStackPointer:                    24,
	GoReturnAddress:                         32,
	StackBottomPtr:                          40,
	GoCallReturnAddress:                     48,
	StackPointerBeforeGrow:                  56,
	StackGrowRequiredSize:                   64,
	MemoryGrowTrampolineAddress:             72,
	StackGrowCallSequenceAddress:            80,
	SavedRegistersBegin:                     96,
	GoFunctionCallCalleeModuleContextOpaque: 1120,
	GoFunctionCallStackBegin:                1128,
}

Functions

func GoFunctionIndexFromExitCode

func GoFunctionIndexFromExitCode(exitCode ExitCode) int

Types

type ExecutionContextOffsetData

type ExecutionContextOffsetData struct {
	// ExitCodeOffset is an offset of `exitCode` field in wazevo.executionContext
	ExitCodeOffset Offset
	// CallerModuleContextPtr is an offset of `callerModuleContextPtr` field in wazevo.executionContext
	CallerModuleContextPtr Offset
	// CallerModuleContextPtr is an offset of `originalFramePointer` field in wazevo.executionContext
	OriginalFramePointer Offset
	// OriginalStackPointer is an offset of `originalStackPointer` field in wazevo.executionContext
	OriginalStackPointer Offset
	// GoReturnAddress is an offset of `goReturnAddress` field in wazevo.executionContext
	GoReturnAddress Offset
	// StackBottomPtr is an offset of `stackBottomPtr` field in wazevo.executionContext
	StackBottomPtr Offset
	// GoCallReturnAddress is an offset of `goCallReturnAddress` field in wazevo.executionContext
	GoCallReturnAddress Offset
	// GoCallReturnAddress is an offset of `stackPointerBeforeGoCall` field in wazevo.executionContext
	StackPointerBeforeGrow Offset
	// StackGrowRequiredSize is an offset of `stackGrowRequiredSize` field in wazevo.executionContext
	StackGrowRequiredSize Offset
	// MemoryGrowTrampolineAddress is an offset of `memoryGrowTrampolineAddress` field in wazevo.executionContext
	MemoryGrowTrampolineAddress Offset
	// StackGrowCallSequenceAddress is an offset of `stackGrowCallSequenceAddress` field in wazevo.executionContext
	StackGrowCallSequenceAddress Offset
	// GoCallReturnAddress is an offset of the first element of `savedRegisters` field in wazevo.executionContext
	SavedRegistersBegin Offset
	// GoFunctionCallCalleeModuleContextOpaque is an offset of `goFunctionCallCalleeModuleContextOpaque` field in wazevo.executionContext
	GoFunctionCallCalleeModuleContextOpaque Offset
	// GoFunctionCallStackBegin is an offset of the first element of `goFunctionCallStack` field in wazevo.executionContext
	GoFunctionCallStackBegin Offset
}

ExecutionContextOffsetData allows the compilers to get the information about offsets to the fields of wazevo.executionContext, which are necessary for compiling various instructions. This is globally unique.

type ExitCode

type ExitCode uint32

ExitCode is an exit code of an execution of a function.

const (
	ExitCodeOK ExitCode = iota
	ExitCodeGrowStack
	ExitCodeGrowMemory
	ExitCodeUnreachable
	ExitCodeMemoryOutOfBounds
	// ExitCodeCallGoModuleFunction is an exit code for a call to an api.GoModuleFunction.
	ExitCodeCallGoModuleFunction
	// ExitCodeCallGoFunction is an exit code for a call to an api.GoFunction.
	ExitCodeCallGoFunction
	ExitCodeTableOutOfBounds
	ExitCodeIndirectCallNullPointer
	ExitCodeIndirectCallTypeMismatch
)

func ExitCodeCallGoFunctionWithIndex

func ExitCodeCallGoFunctionWithIndex(index int) ExitCode

func ExitCodeCallGoModuleFunctionWithIndex

func ExitCodeCallGoModuleFunctionWithIndex(index int) ExitCode

func (ExitCode) String

func (e ExitCode) String() string

String implements fmt.Stringer.

type ModuleContextOffsetData

type ModuleContextOffsetData struct {
	TotalSize int
	ModuleInstanceOffset,
	LocalMemoryBegin,
	ImportedMemoryBegin,
	ImportedFunctionsBegin,
	GlobalsBegin,
	TypeIDs1stElement,
	TablesBegin Offset
}

ModuleContextOffsetData allows the compilers to get the information about offsets to the fields of wazevo.moduleContextOpaque, This is unique per module.

func NewModuleContextOffsetData

func NewModuleContextOffsetData(m *wasm.Module) ModuleContextOffsetData

NewModuleContextOffsetData creates a ModuleContextOffsetData determining the structure of moduleContextOpaque for the given Module. The structure is described in the comment of wazevo.moduleContextOpaque.

func (*ModuleContextOffsetData) GlobalInstanceOffset

func (m *ModuleContextOffsetData) GlobalInstanceOffset(i wasm.Index) Offset

GlobalInstanceOffset returns an offset of the i-th global instance.

func (*ModuleContextOffsetData) ImportedFunctionOffset

func (m *ModuleContextOffsetData) ImportedFunctionOffset(i wasm.Index) (
	executableOffset, moduleCtxOffset, typeIDOffset Offset,
)

ImportedFunctionOffset returns an offset of the i-th imported function. Each item is stored as wazevo.functionInstance whose size matches FunctionInstanceSize.

func (*ModuleContextOffsetData) LocalMemoryBase

func (m *ModuleContextOffsetData) LocalMemoryBase() Offset

LocalMemoryBase returns an offset of the first byte of the local memory.

func (*ModuleContextOffsetData) LocalMemoryLen

func (m *ModuleContextOffsetData) LocalMemoryLen() Offset

LocalMemoryLen returns an offset of the length of the local memory buffer.

func (*ModuleContextOffsetData) TableOffset

func (m *ModuleContextOffsetData) TableOffset(tableIndex int) Offset

TableOffset returns an offset of the i-th table instance.

type Offset

type Offset int32

Offset represents an offset of a field of a struct.

func (Offset) I64

func (o Offset) I64() int64

I64 encodes an Offset as int64 for convenience.

func (Offset) U32

func (o Offset) U32() uint32

U32 encodes an Offset as uint32 for convenience.

func (Offset) U64

func (o Offset) U64() uint64

U64 encodes an Offset as int64 for convenience.

type Pool

type Pool[T any] struct {
	// contains filtered or unexported fields
}

Pool is a pool of T that can be allocated and reset. This is useful to avoid unnecessary allocations.

func NewPool

func NewPool[T any]() Pool[T]

NewPool returns a new Pool.

func (*Pool[T]) Allocate

func (p *Pool[T]) Allocate() *T

Allocate allocates a new T from the pool.

func (*Pool[T]) Allocated

func (p *Pool[T]) Allocated() int

Allocated returns the number of allocated T currently in the pool.

func (*Pool[T]) Reset

func (p *Pool[T]) Reset()

Reset resets the pool.

func (*Pool[T]) View

func (p *Pool[T]) View(i int) *T

View returns the pointer to i-th item from the pool.

Jump to

Keyboard shortcuts

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