Documentation
¶
Index ¶
- Constants
- Variables
- type AOTService
- type Frame
- type FunctionImport
- type FunctionImportInfo
- type ImportResolver
- type Module
- func (m *Module) GenerateNEnv(config NCompileConfig) string
- func (m *Module) GetFunctionExport(key string) (int, bool)
- func (m *Module) GetGlobalExport(key string) (int, bool)
- func (m *Module) NBuildAliasDef() string
- func (m *Module) NCompile(config NCompileConfig) string
- func (m *Module) NewVirtualMachine() *VirtualMachine
- type NCompileConfig
- type NopResolver
- type Snapshot
- type VMConfig
- type VirtualMachine
- func (vm *VirtualMachine) AddAndCheckGas(delta uint64) bool
- func (vm *VirtualMachine) Execute()
- func (vm *VirtualMachine) GenerateNEnv(config NCompileConfig) string
- func (vm *VirtualMachine) GetCurrentFrame() *Frame
- func (vm *VirtualMachine) GetFunctionExport(key string) (int, bool)
- func (vm *VirtualMachine) GetGlobalExport(key string) (int, bool)
- func (vm *VirtualMachine) Ignite(functionID int, params ...int64)
- func (vm *VirtualMachine) NBuildAliasDef() string
- func (vm *VirtualMachine) NCompile(config NCompileConfig) string
- func (vm *VirtualMachine) PrintStackTrace()
- func (vm *VirtualMachine) ReadSnapshot() *Snapshot
- func (vm *VirtualMachine) Run(entryID int, params ...int64) (retVal int64, retErr error)
- func (vm *VirtualMachine) RunWithGasLimit(entryID, limit int, params ...int64) (int64, error)
- func (vm *VirtualMachine) SetAOTService(s AOTService)
- func (vm *VirtualMachine) WriteSnapshot(ss *Snapshot) error
Constants ¶
const ( // DefaultCallStackSize is the default call stack size. DefaultCallStackSize = 512 // DefaultPageSize is the linear memory page size. DefaultPageSize = 65536 // JITCodeSizeThreshold is the lower-bound code size threshold for the JIT compiler. JITCodeSizeThreshold = 30 )
Variables ¶
var LE = binary.LittleEndian
LE is a simple alias to `binary.LittleEndian`.
Functions ¶
This section is empty.
Types ¶
type AOTService ¶
type AOTService interface {
Initialize(vm *VirtualMachine)
UnsafeInvokeFunction_0(vm *VirtualMachine, name string) uint64
UnsafeInvokeFunction_1(vm *VirtualMachine, name string, p0 uint64) uint64
UnsafeInvokeFunction_2(vm *VirtualMachine, name string, p0, p1 uint64) uint64
}
type Frame ¶
type Frame struct {
FunctionID int
Code []byte
Regs []int64
Locals []int64
IP int
ReturnReg int
Continuation int32
}
Frame represents a call frame.
func (*Frame) Destroy ¶
func (f *Frame) Destroy(vm *VirtualMachine)
Destroy destroys a frame. Must be called on return.
func (*Frame) Init ¶
func (f *Frame) Init(vm *VirtualMachine, functionID int, code compiler.InterpreterCode)
Init initializes a frame. Must be called on `call` and `call_indirect`.
type FunctionImport ¶
type FunctionImport func(vm *VirtualMachine) int64
type FunctionImportInfo ¶
type FunctionImportInfo struct {
ModuleName string
FieldName string
F FunctionImport
}
type ImportResolver ¶
type ImportResolver interface {
ResolveFunc(module, field string) FunctionImport
ResolveGlobal(module, field string) int64
}
ImportResolver is an interface for allowing one to define imports to WebAssembly modules ran under a single VirtualMachine instance.
type Module ¶
type Module struct {
Config VMConfig
Module *compiler.Module
FunctionCode []compiler.InterpreterCode
FunctionImports []FunctionImportInfo
Table []uint32
Globals []int64
GasPolicy compiler.GasPolicy
ImportResolver ImportResolver
}
func NewModule ¶
func NewModule( code []byte, config VMConfig, impResolver ImportResolver, gasPolicy compiler.GasPolicy, ) (_retVM *Module, retErr error)
NewModule instantiates a module for a given WebAssembly module, with specific execution options specified under a VMConfig, and a WebAssembly module import resolver.
func (*Module) GenerateNEnv ¶
func (m *Module) GenerateNEnv(config NCompileConfig) string
func (*Module) GetFunctionExport ¶
GetFunctionExport returns the function export with the given name.
func (*Module) GetGlobalExport ¶
GetGlobalExport returns the global export with the given name.
func (*Module) NBuildAliasDef ¶
func (*Module) NCompile ¶
func (m *Module) NCompile(config NCompileConfig) string
func (*Module) NewVirtualMachine ¶
func (m *Module) NewVirtualMachine() *VirtualMachine
NewVirtualMachine instantiates a virtual machine for the module.
type NCompileConfig ¶
type NopResolver ¶
type NopResolver struct{}
NopResolver is a nil WebAssembly module import resolver.
func (*NopResolver) ResolveFunc ¶
func (r *NopResolver) ResolveFunc(module, field string) FunctionImport
func (*NopResolver) ResolveGlobal ¶
func (r *NopResolver) ResolveGlobal(module, field string) int64
type VMConfig ¶
type VMConfig struct {
EnableJIT bool
MaxMemoryPages int
MaxTableSize int
MaxValueSlots int
MaxCallStackDepth int
DefaultMemoryPages int
DefaultTableSize int
GasLimit uint64
DisableFloatingPoint bool
ReturnOnGasLimitExceeded bool
}
VMConfig denotes a set of options passed to a single VirtualMachine insta.ce
type VirtualMachine ¶
type VirtualMachine struct {
Config VMConfig
Module *compiler.Module
FunctionCode []compiler.InterpreterCode
FunctionImports []FunctionImportInfo
CallStack []Frame
CurrentFrame int
Table []uint32
Globals []int64
Memory []byte
NumValueSlots int
Yielded int64
InsideExecute bool
Delegate func()
Exited bool
ExitError interface{}
ReturnValue int64
Gas uint64
GasLimitExceeded bool
GasPolicy compiler.GasPolicy
ImportResolver ImportResolver
AOTService AOTService
StackTrace string
}
VirtualMachine is a WebAssembly execution environment.
func NewVirtualMachine ¶
func NewVirtualMachine( code []byte, config VMConfig, impResolver ImportResolver, gasPolicy compiler.GasPolicy, ) (_retVM *VirtualMachine, retErr error)
NewVirtualMachine instantiates a virtual machine for a given WebAssembly module, with specific execution options specified under a VMConfig, and a WebAssembly module import resolver.
func (*VirtualMachine) AddAndCheckGas ¶
func (vm *VirtualMachine) AddAndCheckGas(delta uint64) bool
func (*VirtualMachine) Execute ¶
func (vm *VirtualMachine) Execute()
Execute starts the virtual machines main instruction processing loop. This function may return at any point and is guaranteed to return at least once every 10000 instructions. Caller is responsible for detecting VM status in a loop.
func (*VirtualMachine) GenerateNEnv ¶
func (vm *VirtualMachine) GenerateNEnv(config NCompileConfig) string
func (*VirtualMachine) GetCurrentFrame ¶
func (vm *VirtualMachine) GetCurrentFrame() *Frame
GetCurrentFrame returns the current frame.
func (*VirtualMachine) GetFunctionExport ¶
func (vm *VirtualMachine) GetFunctionExport(key string) (int, bool)
GetFunctionExport returns the function export with the given name.
func (*VirtualMachine) GetGlobalExport ¶
func (vm *VirtualMachine) GetGlobalExport(key string) (int, bool)
GetGlobalExport returns the global export with the given name.
func (*VirtualMachine) Ignite ¶
func (vm *VirtualMachine) Ignite(functionID int, params ...int64)
Ignite initializes the first call frame.
func (*VirtualMachine) NBuildAliasDef ¶
func (vm *VirtualMachine) NBuildAliasDef() string
func (*VirtualMachine) NCompile ¶
func (vm *VirtualMachine) NCompile(config NCompileConfig) string
func (*VirtualMachine) PrintStackTrace ¶
func (vm *VirtualMachine) PrintStackTrace()
PrintStackTrace prints the entire VM stack trace for debugging.
func (*VirtualMachine) ReadSnapshot ¶
func (vm *VirtualMachine) ReadSnapshot() *Snapshot
func (*VirtualMachine) Run ¶
func (vm *VirtualMachine) Run(entryID int, params ...int64) (retVal int64, retErr error)
Run runs a WebAssembly modules function denoted by its ID with a specified set of parameters. Panics on logical errors.
func (*VirtualMachine) RunWithGasLimit ¶
func (vm *VirtualMachine) RunWithGasLimit(entryID, limit int, params ...int64) (int64, error)
RunWithGasLimit runs a WebAssembly modules function denoted by its ID with a specified set of parameters for a specified amount of instructions (also known as gas) denoted by `limit`. Panics on logical errors.
func (*VirtualMachine) SetAOTService ¶
func (vm *VirtualMachine) SetAOTService(s AOTService)
func (*VirtualMachine) WriteSnapshot ¶
func (vm *VirtualMachine) WriteSnapshot(ss *Snapshot) error