Documentation ¶
Overview ¶
Package wasmer is a Go library to run WebAssembly binaries.
Index ¶
- Constants
- func LimitMaxUnbound() uint32
- func ValidateModule(store *Store, bytes []byte) error
- func Wat2Wasm(wat string) ([]byte, error)
- type Config
- type CpuFeatures
- type Engine
- type Error
- type ExportType
- type Exports
- func (self *Exports) Get(name string) (*Extern, error)
- func (self *Exports) GetFunction(name string) (NativeFunction, error)
- func (self *Exports) GetGlobal(name string) (*Global, error)
- func (self *Exports) GetMemory(name string) (*Memory, error)
- func (self *Exports) GetRawFunction(name string) (*Function, error)
- func (self *Exports) GetTable(name string) (*Table, error)
- func (self *Exports) GetWasiStartFunction() (NativeFunction, error)
- type Extern
- type ExternKind
- type ExternType
- type Frame
- type Function
- type FunctionEnvironment
- type FunctionType
- type Global
- type GlobalMutability
- type GlobalType
- type ImportObject
- type ImportType
- type Instance
- type IntoExtern
- type IntoExternType
- type Limits
- type Memory
- type MemoryType
- type Module
- type NativeFunction
- type Pages
- type Store
- type Table
- type TableSize
- type TableType
- type Target
- type Trap
- type TrapError
- type Triple
- type Value
- type ValueKind
- type ValueType
- type WasiEnvironment
- type WasiStateBuilder
- type WasiVersion
Constants ¶
const ( FUNCTION = ExternKind(C.WASM_EXTERN_FUNC) GLOBAL = ExternKind(C.WASM_EXTERN_GLOBAL) TABLE = ExternKind(C.WASM_EXTERN_TABLE) MEMORY = ExternKind(C.WASM_EXTERN_MEMORY) )
const ( IMMUTABLE = GlobalMutability(C.WASM_CONST) MUTABLE = GlobalMutability(C.WASM_VAR) )
const ( I32 = ValueKind(C.WASM_I32) I64 = ValueKind(C.WASM_I64) F32 = ValueKind(C.WASM_F32) F64 = ValueKind(C.WASM_F64) AnyRef = ValueKind(C.WASM_ANYREF) FuncRef = ValueKind(C.WASM_FUNCREF) )
const ( WASI_VERSION_LATEST = WasiVersion(C.LATEST) WASI_VERSION_SNAPSHOT0 = WasiVersion(C.SNAPSHOT0) WASI_VERSION_SNAPSHOT1 = WasiVersion(C.SNAPSHOT1) WASI_VERSION_INVALID = WasiVersion(C.INVALID_VERSION) )
const WasmMaxPages = uint(0x10000)
const WasmMinPages = uint(0x100)
const WasmPageSize = uint(0x10000)
Variables ¶
This section is empty.
Functions ¶
func LimitMaxUnbound ¶
func LimitMaxUnbound() uint32
func ValidateModule ¶
ValidateModule validates a new Module against the given Store.
It takes two arguments, the Store and the Wasm module as an byte array of WAT code..
wasmBytes := []byte(`...`) engine := wasmer.NewEngine() store := wasmer.NewStore(engine) err := wasmer.ValidateModule(store, wasmBytes)
func Wat2Wasm ¶
Wat2Wasm parsers a string as either WAT code or a binary Wasm module.
⚠️ This is not part of the standard Wasm C API. It is Wasmer specific.
wat := "(module)" wasm, _ := Wat2Wasm(wat) engine := wasmer.NewEngine() store := wasmer.NewStore(engine) module, _ := wasmer.NewModule(store, wasmBytes)
Types ¶
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
func NewConfig ¶
func NewConfig() *Config
NewConfig instantiates and returns a new Config.
config := NewConfig()
func (*Config) UseCraneliftCompiler ¶
func (self *Config) UseCraneliftCompiler()
UseCraneliftCompiler sets the compiler to Cranelift in the configuration.
config := NewConfig() config.UseCraneliftCompiler()
func (*Config) UseJITEngine ¶
func (self *Config) UseJITEngine()
UseJITEngine sets the engine to JIT in the configuration.
config := NewConfig() config.UseJITEngine()
func (*Config) UseLLVMCompiler ¶
func (self *Config) UseLLVMCompiler()
UseLLVMCompiler sets the compiler to LLVM in the configuration.
config := NewConfig() config.UseLLVMCompiler()
func (*Config) UseNativeEngine ¶
func (self *Config) UseNativeEngine()
UseNativeEngine sets the engine to Native in the configuration.
config := NewConfig() config.UseNativeEngine()
type CpuFeatures ¶
type CpuFeatures struct {
// contains filtered or unexported fields
}
func NewCpuFeatures ¶
func NewCpuFeatures() *CpuFeatures
func (*CpuFeatures) Add ¶
func (self *CpuFeatures) Add(feature string) error
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
func NewEngine ¶
func NewEngine() *Engine
NewEngine instantiates and returns a new Engine with the default configuration.
engine := NewEngine()
func NewEngineWithConfig ¶
NewEngineWithConfig instantiates and returns a new Engine with the given configuration.
config := NewConfig() engine := NewEngineWithConfig(config)
func NewJITEngine ¶
func NewJITEngine() *Engine
NewJITEngine instantiates and returns a new JIT engine.
engine := NewJITEngine()
func NewNativeEngine ¶
func NewNativeEngine() *Engine
NewNativeEngine instantiates and returns a new Native engine.
engine := NewNativeEngine()
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error represents a Wasmer runtime error.
type ExportType ¶
type ExportType struct {
// contains filtered or unexported fields
}
func NewExportType ¶
func NewExportType(name string, ty IntoExternType) *ExportType
NewExportType instantiates a new ExportType with a name and an extern type.
ℹ️ An extern type is anything implementing IntoExternType: FunctionType, GlobalType, MemoryType, TableType.
valueType := NewValueType(I32) globalType := NewGlobalType(valueType, CONST) exportType := NewExportType("a_global", globalType)
func (*ExportType) Name ¶
func (self *ExportType) Name() string
Name returns the name of the export type.
exportType := NewExportType("a_global", globalType) exportType.Name() // "global"
func (*ExportType) Type ¶
func (self *ExportType) Type() *ExternType
Type returns the type of the export type.
exportType := NewExportType("a_global", globalType) exportType.Type() // ExternType
type Exports ¶
type Exports struct {
// contains filtered or unexported fields
}
func (*Exports) Get ¶
Get retrieves and returns an Extern by its name.
❗️ If the name does not refer to an existing export, Get will return an Error.
instance, _ := NewInstance(module, NewImportObject()) extern, error := instance.Exports.Get("an_export")
func (*Exports) GetFunction ¶
func (self *Exports) GetFunction(name string) (NativeFunction, error)
GetFunction retrieves a exported function by its name and returns it as a native Go function.
❗️ If the name does not refer to an existing export, GetFunction will return an Error.
⚠️ If the export is not a function, GetFunction will return nil as its result.
instance, _ := NewInstance(module, NewImportObject()) exportedFunc, error := instance.Exports.GetFunction("an_exported_function") if error != nil && exportedFunc != nil { exportedFunc() }
func (*Exports) GetGlobal ¶
GetGlobal retrieves and returns a exported Global by its name.
❗️ If the name does not refer to an existing export, GetGlobal will return an Error.
⚠️ If the export is not a global, GetGlobal will return nil as a result.
instance, _ := NewInstance(module, NewImportObject()) exportedGlobal, error := instance.Exports.GetGlobal("an_exported_global")
func (*Exports) GetMemory ¶
GetMemory retrieves and returns a exported Memory by its name.
❗️ If the name does not refer to an existing export, GetMemory will return an Error.
⚠️ If the export is not a memory, GetMemory will return nil as a result.
instance, _ := NewInstance(module, NewImportObject()) exportedMemory, error := instance.Exports.GetMemory("an_exported_memory")
func (*Exports) GetRawFunction ¶
GetRawFunction retrieves and returns a exported Function by its name.
❗️ If the name does not refer to an existing export, GetRawFunction will return an Error.
⚠️ If the export is not a function, GetRawFunction will return nil as its result.
instance, _ := NewInstance(module, NewImportObject()) exportedFunc, error := instance.Exports.GetRawFunction("an_exported_function") if error != nil && exportedFunc != nil { exportedFunc.Call() }
func (*Exports) GetTable ¶
GetTable retrieves and returns a exported Table by its name.
❗️ If the name does not refer to an existing export, GetTable will return an Error.
⚠️ If the export is not a table, GetTable will return nil as a result.
instance, _ := NewInstance(module, NewImportObject()) exportedTable, error := instance.Exports.GetTable("an_exported_table")
func (*Exports) GetWasiStartFunction ¶
func (self *Exports) GetWasiStartFunction() (NativeFunction, error)
type Extern ¶
type Extern struct {
// contains filtered or unexported fields
}
func (*Extern) IntoExtern ¶
func (*Extern) IntoFunction ¶
IntoFunction converts the Extern into a Function.
⚠️ If the Extern is not a Function, IntoFunction will return nil as its result.
function, _ := instance.Exports.GetFunction("exported_function") extern = function.IntoExtern() _ := extern.IntoFunction()
func (*Extern) IntoGlobal ¶
IntoGlobal converts the Extern into a Global.
⚠️ If the Extern is not a Global, IntoGlobal will return nil as its result.
global, _ := instance.Exports.GetGlobal("exported_global") extern = global.IntoExtern() _ := extern.IntoGlobal()
func (*Extern) IntoMemory ¶
IntoMemory converts the Extern into a Memory.
⚠️ If the Extern is not a Memory, IntoMemory will return nil as its result.
memory, _ := instance.Exports.GetMemory("exported_memory") extern = memory.IntoExtern() _ := extern.IntoMemory()
func (*Extern) IntoTable ¶
IntoTable converts the Extern into a Table.
⚠️ If the Extern is not a Table, IntoTable will return nil as its result.
table, _ := instance.Exports.GetTable("exported_table") extern = table.IntoExtern() _ := extern.IntoTable()
func (*Extern) Kind ¶
func (self *Extern) Kind() ExternKind
Kind returns the Extern's ExternKind.
global, _ := instance.Exports.GetGlobal("exported_global") _ = global.IntoExtern().Kind()
func (*Extern) Type ¶
func (self *Extern) Type() *ExternType
Type returns the Extern's ExternType.
global, _ := instance.Exports.GetGlobal("exported_global") _ = global.IntoExtern().Type()
type ExternKind ¶
type ExternKind C.wasm_externkind_t
func (ExternKind) String ¶
func (self ExternKind) String() string
String returns the ExternKind as a string.
FUNCTION.String() // "func" GLOBAL.String() // "global" TABLE.String() // "table" MEMORY.String() // "memory"
type ExternType ¶
type ExternType struct {
// contains filtered or unexported fields
}
ExternType classifies imports and external values with their respective types.
See also ¶
Specification: https://webassembly.github.io/spec/core/syntax/types.html#external-types
func (*ExternType) IntoFunctionType ¶
func (self *ExternType) IntoFunctionType() *FunctionType
IntoFunctionType converts the ExternType into a FunctionType.
⚠️ If the ExternType is not a FunctionType, IntoFunctionType will return nil as its result.
function, _ := instance.Exports.GetFunction("exported_function") externType = function.IntoExtern().Type() _ := externType.IntoFunctionType()
func (*ExternType) IntoGlobalType ¶
func (self *ExternType) IntoGlobalType() *GlobalType
IntoGlobalType converts the ExternType into a GlobalType.
⚠️ If the ExternType is not a GlobalType, IntoGlobalType will return nil as its result.
global, _ := instance.Exports.GetGlobal("exported_global") externType = global.IntoExtern().Type() _ := externType.IntoGlobalType()
func (*ExternType) IntoMemoryType ¶
func (self *ExternType) IntoMemoryType() *MemoryType
IntoMemoryType converts the ExternType into a MemoryType.
⚠️ If the ExternType is not a MemoryType, IntoMemoryType will return nil as its result.
memory, _ := instance.Exports.GetMemory("exported_memory") externType = memory.IntoExtern().Type() _ := externType.IntoMemoryType()
func (*ExternType) IntoTableType ¶
func (self *ExternType) IntoTableType() *TableType
IntoTableType converts the ExternType into a TableType.
⚠️ If the ExternType is not a TableType, IntoTableType will return nil as its result.
table, _ := instance.Exports.GetTable("exported_table") externType = table.IntoExtern().Type() _ := externType.IntoTableType()
func (*ExternType) Kind ¶
func (self *ExternType) Kind() ExternKind
Kind returns the ExternType's ExternKind
global, _ := instance.Exports.GetGlobal("exported_global") extern = global.IntoExtern() _ = extern.Kind()
type Frame ¶
type Frame struct {
// contains filtered or unexported fields
}
func (*Frame) FunctionIndex ¶
func (*Frame) FunctionOffset ¶
func (*Frame) ModuleOffset ¶
type Function ¶
type Function struct {
// contains filtered or unexported fields
}
func NewFunction ¶
NewGlobal instantiates a new Global in the given Store.
It takes three arguments, the Store, the FunctionType and the definition for the Function.
The function definition must be a native Go function with a Value array as its single argument. The function must return a Value array or an error.
⚠️ Even if the function does not take any argument (or use any argument) it must receive a Value array
as its single argument. At runtime, this array will be empty. The same applies to the result. hostFunction := wasmer.NewFunction( store, wasmer.NewFunctionType(wasmer.NewValueTypes(), wasmer.NewValueTypes(wasmer.I32)), func(args []wasmer.Value) ([]wasmer.Value, error) { return []wasmer.Value{wasmer.NewI32(42)}, nil }, )
func (*Function) Call ¶
Call will call the Function and return its results as native Go values.
function, _ := instance.Exports.GetFunction("exported_function") _ = function.Call(1, 2, 3)
func (*Function) IntoExtern ¶
IntoExtern converts the Function into an Extern.
function, _ := instance.Exports.GetFunction("exported_function") extern := function.IntoExtern()
func (*Function) Native ¶
func (self *Function) Native() NativeFunction
Native will turn the Function into a native Go function that can be then called.
function, _ := instance.Exports.GetFunction("exported_function") nativeFunction = function.Native() _ = nativeFunction(1, 2, 3)
func (*Function) ParameterArity ¶
ParameterArity returns the number of arguments the Function expects as per its definition.
function, _ := instance.Exports.GetFunction("exported_function") arity := function.ParameterArity()
func (*Function) ResultArity ¶
ParameterArity returns the number of results the Function will return.
function, _ := instance.Exports.GetFunction("exported_function") arity := function.ResultArity()
func (*Function) Type ¶
func (self *Function) Type() *FunctionType
Type returns the Function's FunctionType.
function, _ := instance.Exports.GetFunction("exported_function") ty := function.Type()
type FunctionEnvironment ¶
type FunctionEnvironment struct {
// contains filtered or unexported fields
}
type FunctionType ¶
type FunctionType struct {
// contains filtered or unexported fields
}
FunctionType classifies the signature of functions, mapping a vector of parameters to a vector of results. They are also used to classify the inputs and outputs of instructions.
See also ¶
Specification: https://webassembly.github.io/spec/core/syntax/types.html#function-types
func NewFunctionType ¶
func NewFunctionType(params []*ValueType, results []*ValueType) *FunctionType
NewFunctionType instantiates a new FunctionType from two ValueType arrays: the parameters and the results.
params := wasmer.NewValueTypes() results := wasmer.NewValueTypes(wasmer.I32) functionType := wasmer.NewFunctionType(params, results)
func (*FunctionType) IntoExternType ¶
func (self *FunctionType) IntoExternType() *ExternType
IntoExternType converts the FunctionType into an ExternType.
function, _ := instance.Exports.GetFunction("exported_function") functionType := function.Type() externType = functionType.IntoExternType()
func (*FunctionType) Params ¶
func (self *FunctionType) Params() []*ValueType
Params returns the parameters definitions from the FunctionType as a ValueType array
params := wasmer.NewValueTypes() results := wasmer.NewValueTypes(wasmer.I32) functionType := wasmer.NewFunctionType(params, results) paramsValueTypes = functionType.Params()
func (*FunctionType) Results ¶
func (self *FunctionType) Results() []*ValueType
Results returns the results definitions from the FunctionType as a ValueType array
params := wasmer.NewValueTypes() results := wasmer.NewValueTypes(wasmer.I32) functionType := wasmer.NewFunctionType(params, results) resultsValueTypes = functionType.Results()
type Global ¶
type Global struct {
// contains filtered or unexported fields
}
Global stores a single value of the given GlobalType.
See also ¶
https://webassembly.github.io/spec/core/syntax/modules.html#globals
func NewGlobal ¶
func NewGlobal(store *Store, ty *GlobalType, value Value) *Global
NewGlobal instantiates a new Global in the given Store.
It takes three arguments, the Store, the GlobalType and the Value for the Global.
valueType := NewValueType(I32) globalType := NewGlobalType(valueType, CONST) global := NewGlobal(store, globalType, NewValue(42, I32))
func (*Global) Get ¶
Get returns the Global's value as a native Go value.
global, _ := instance.Exports.GetGlobal("exported_global") value, _ := global.Get()
func (*Global) IntoExtern ¶
IntoExtern converts the Global into an Extern.
global, _ := instance.Exports.GetGlobal("exported_global") extern := global.IntoExtern()
func (*Global) Set ¶
Set sets the Global's value.
It takes two arguments, the Global's value as a native Go value and the value's ValueKind.
global, _ := instance.Exports.GetGlobal("exported_global") _ = global.Set(1, I32)
func (*Global) Type ¶
func (self *Global) Type() *GlobalType
Type returns the Global's GlobalType.
global, _ := instance.Exports.GetGlobal("exported_global") ty := global.Type()
type GlobalMutability ¶
type GlobalMutability C.wasm_mutability_t
func (GlobalMutability) String ¶
func (self GlobalMutability) String() string
String returns the GlobalMutability as a string.
IMMUTABLE.String() // "const" MUTABLE.String() // "var"
type GlobalType ¶
type GlobalType struct {
// contains filtered or unexported fields
}
GlobalType classifies global variables, which hold a value and can either be mutable or immutable.
See also ¶
Specification: https://webassembly.github.io/spec/core/syntax/types.html#global-types
func NewGlobalType ¶
func NewGlobalType(valueType *ValueType, mutability GlobalMutability) *GlobalType
NewGlobalType instantiates a new GlobalType from a ValueType and a GlobalMutability
valueType := NewValueType(I32) globalType := NewGlobalType(valueType, IMMUTABLE)
func (*GlobalType) IntoExternType ¶
func (self *GlobalType) IntoExternType() *ExternType
IntoExternType converts the GlobalType into an ExternType.
valueType := NewValueType(I32) globalType := NewGlobalType(valueType, IMMUTABLE) externType = globalType.IntoExternType()
func (*GlobalType) Mutability ¶
func (self *GlobalType) Mutability() GlobalMutability
Mutability returns the GlobalType's GlobalMutability
valueType := NewValueType(I32) globalType := NewGlobalType(valueType, IMMUTABLE) globalType.Mutability().String() // "const"
func (*GlobalType) ValueType ¶
func (self *GlobalType) ValueType() *ValueType
ValueType returns the GlobalType's ValueType
valueType := NewValueType(I32) globalType := NewGlobalType(valueType, IMMUTABLE) globalType.ValueType().Kind().String() // "i32"
type ImportObject ¶
type ImportObject struct {
// contains filtered or unexported fields
}
func NewImportObject ¶
func NewImportObject() *ImportObject
NewImportObject instantiates a new empty ImportObject.
imports := NewImportObject()
func (*ImportObject) ContainsNamespace ¶
func (self *ImportObject) ContainsNamespace(name string) bool
ContainsNamespace returns true if the ImportObject contains the given namespace (or module name)
imports := NewImportObject() _ = imports.ContainsNamespace("env") // false
func (*ImportObject) Register ¶
func (self *ImportObject) Register(namespaceName string, namespace map[string]IntoExtern)
Register registers a namespace (or module name) in the ImportObject.
It takes two arguments: the namespace name and a map with imports names as key and externs as values.
ℹ️ An extern is anything implementing IntoExtern: Function, Global, Memory, Table.
imports := NewImportObject() importObject.Register( "env", map[string]wasmer.IntoExtern{ "host_function": hostFunction, "host_global": hostGlobal, }, )
ℹ️ The namespace (or module name) may be empty:
imports := NewImportObject() importObject.Register( "", map[string]wasmer.IntoExtern{ "host_function": hostFunction, "host_global": hostGlobal, }, )
type ImportType ¶
type ImportType struct {
// contains filtered or unexported fields
}
func NewImportType ¶
func NewImportType(module string, name string, ty IntoExternType) *ImportType
NewImportType instantiates a new ImportType with a module name (or namespace), a name and an extern type.
ℹ️ An extern type is anything implementing IntoExternType: FunctionType, GlobalType, MemoryType, TableType.
valueType := NewValueType(I32) globalType := NewGlobalType(valueType, CONST) importType := NewImportType("ns", "host_global", globalType)
func (*ImportType) Module ¶
func (self *ImportType) Module() string
Module returns the ImportType's module name (or namespace).
valueType := NewValueType(I32) globalType := NewGlobalType(valueType, CONST) importType := NewImportType("ns", "host_global", globalType) _ = importType.Module()
func (*ImportType) Name ¶
func (self *ImportType) Name() string
Name returns the ImportType's name.
valueType := NewValueType(I32) globalType := NewGlobalType(valueType, CONST) importType := NewImportType("ns", "host_global", globalType) _ = importType.Name()
func (*ImportType) Type ¶
func (self *ImportType) Type() *ExternType
Type returns the ImportType's type as an ExternType.
valueType := NewValueType(I32) globalType := NewGlobalType(valueType, CONST) importType := NewImportType("ns", "host_global", globalType) _ = importType.Type()
type Instance ¶
type Instance struct { Exports *Exports // contains filtered or unexported fields }
func NewInstance ¶
func NewInstance(module *Module, imports *ImportObject) (*Instance, error)
NewInstance instantiates a new Instance.
It takes two arguments, the Module and an ImportObject.
⚠️ Instantiating a module may return TrapError if the module's start function traps.
wasmBytes := []byte(`...`) engine := wasmer.NewEngine() store := wasmer.NewStore(engine) module, err := wasmer.NewModule(store, wasmBytes) importObject := wasmer.NewImportObject() instance, err := wasmer.NewInstance(module, importObject)
type IntoExtern ¶
type IntoExtern interface {
IntoExtern() *Extern
}
type IntoExternType ¶
type IntoExternType interface {
IntoExternType() *ExternType
}
type Limits ¶
type Limits struct {
// contains filtered or unexported fields
}
Limits classify the size range of resizeable storage associated with memory types and table types.
See also ¶
Specification: https://webassembly.github.io/spec/core/syntax/types.html#limits
func NewLimits ¶
NewLimits instantiates a new Limits which describes the Memory used. The minimum and maximum parameters are "number of memory pages".
ℹ️ Each page is 64 KiB in size.
⚠️ You cannot Memory.Grow the Memory beyond the maximum defined here.
type Memory ¶
type Memory struct {
// contains filtered or unexported fields
}
Memory is a vector of raw uninterpreted bytes.
See also ¶
Specification: https://webassembly.github.io/spec/core/syntax/modules.html#memories
func NewMemory ¶
func NewMemory(store *Store, ty *MemoryType) *Memory
NewMemory instantiates a new Memory in the given Store.
It takes two arguments, the Store and the MemoryType for the Memory.
memory := wasmer.NewFunction( store, wasmer.NewMemoryType(wasmer.NewLimits(1, 4)), )
func (*Memory) Data ¶
Data returns the Memory's contents as an byte array.
memory, _ := instance.Exports.GetMemory("exported_memory") data := memory.Data()
func (*Memory) DataSize ¶
Size returns the Memory's size as a number of bytes.
memory, _ := instance.Exports.GetMemory("exported_memory") size := memory.DataSize()
func (*Memory) Grow ¶
Grow grows the Memory's size by a given number of Pages (the delta).
memory, _ := instance.Exports.GetMemory("exported_memory") grown := memory.Grow(2)
func (*Memory) IntoExtern ¶
IntoExtern converts the Memory into an Extern.
memory, _ := instance.Exports.GetMemory("exported_memory") extern := memory.IntoExtern()
func (*Memory) Size ¶
Size returns the Memory's size as Pages.
memory, _ := instance.Exports.GetMemory("exported_memory") size := memory.Size()
func (*Memory) Type ¶
func (self *Memory) Type() *MemoryType
Type returns the Memory's MemoryType.
memory, _ := instance.Exports.GetMemory("exported_memory") ty := memory.Type()
type MemoryType ¶
type MemoryType struct {
// contains filtered or unexported fields
}
MemoryType classifies linear memories and their size range.
See also ¶
Specification: https://webassembly.github.io/spec/core/syntax/types.html#memory-types
func NewMemoryType ¶
func NewMemoryType(limits *Limits) *MemoryType
NewMemoryType instantiates a new MemoryType given some Limits.
limits := NewLimits(1, 4) memoryType := NewMemoryType(limits)
func (*MemoryType) IntoExternType ¶
func (self *MemoryType) IntoExternType() *ExternType
IntoExternType converts the MemoryType into an ExternType.
limits := NewLimits(1, 4) memoryType := NewMemoryType(limits) externType = memoryType.IntoExternType()
func (*MemoryType) Limits ¶
func (self *MemoryType) Limits() *Limits
Limits returns the MemoryType's Limits.
limits := NewLimits(1, 4) memoryType := NewMemoryType(limits) _ = memoryType.Limits()
type Module ¶
type Module struct {
// contains filtered or unexported fields
}
Module contains stateless WebAssembly code that has already been compiled and can be instantiated multiple times.
WebAssembly programs are organized into modules, which are the unit of deployment, loading, and compilation. A module collects definitions for types, functions, tables, memories, and globals. In addition, it can declare imports and exports and provide initialization logic in the form of data and element segments or a start function.
See also ¶
Specification: https://webassembly.github.io/spec/core/syntax/modules.html#modules
func DeserializeModule ¶
DeserializeModule deserializes an byte array to a Module.
wasmBytes := []byte(`...`) engine := wasmer.NewEngine() store := wasmer.NewStore(engine) module, _ := wasmer.NewModule(store, wasmBytes) bytes := module.Serialize() //... deserializedModule := wasmer.DeserializeModule(store, bytes)
func NewModule ¶
NewModule instantiates a new Module with the given Store.
It takes two arguments, the Store and the Wasm module as a byte array of WAT code.
wasmBytes := []byte(`...`) engine := wasmer.NewEngine() store := wasmer.NewStore(engine) module, err := wasmer.NewModule(store, wasmBytes)
func (*Module) Exports ¶
func (self *Module) Exports() []*ExportType
Exports returns the Module's exports as an ExportType array.
wasmBytes := []byte(`...`) engine := wasmer.NewEngine() store := wasmer.NewStore(engine) module, _ := wasmer.NewModule(store, wasmBytes) exports := module.Exports()
func (*Module) Imports ¶
func (self *Module) Imports() []*ImportType
Imports returns the Module's imports as an ImportType array.
wasmBytes := []byte(`...`) engine := wasmer.NewEngine() store := wasmer.NewStore(engine) module, _ := wasmer.NewModule(store, wasmBytes) imports := module.Imports()
func (*Module) Name ¶
Name returns the Module's name.
⚠️ This is not part of the standard Wasm C API. It is Wasmer specific.
wasmBytes := []byte(`...`) engine := wasmer.NewEngine() store := wasmer.NewStore(engine) module, _ := wasmer.NewModule(store, wasmBytes) name := module.Name()
type NativeFunction ¶
type NativeFunction = func(...interface{}) (interface{}, error)
type Pages ¶
type Pages C.wasm_memory_pages_t
type Store ¶
type Store struct { Engine *Engine // contains filtered or unexported fields }
Store represents all global state that can be manipulated by WebAssembly programs. It consists of the runtime representation of all instances of functions, tables, memories, and globals that have been allocated during the life time of the abstract machine.
The Store holds the Engine (that is — amongst many things — used to compile the Wasm bytes into a valid module artifact).
See also ¶
Specification: https://webassembly.github.io/spec/core/exec/runtime.html#store
type Table ¶
type Table struct {
// contains filtered or unexported fields
}
A table instance is the runtime representation of a table. It holds a vector of function elements and an optional maximum size, if one was specified in the table type at the table’s definition site.
See also ¶
Specification: https://webassembly.github.io/spec/core/exec/runtime.html#table-instances
func (*Table) IntoExtern ¶
IntoExtern converts the Table into an Extern.
table, _ := instance.Exports.GetTable("exported_table") extern := table.IntoExtern()
type TableSize ¶
type TableSize C.wasm_table_size_t
type TableType ¶
type TableType struct {
// contains filtered or unexported fields
}
TableType classifies tables over elements of element types within a size range.
See also ¶
Specification: https://webassembly.github.io/spec/core/syntax/types.html#table-types
func NewTableType ¶
NewTableType instantiates a new TableType given a ValueType and some Limits.
valueType := NewValueType(I32) limits := NewLimits(1, 4) tableType := NewTableType(valueType, limits) _ = tableType.IntoExternType()
func (*TableType) IntoExternType ¶
func (self *TableType) IntoExternType() *ExternType
IntoExternType converts the TableType into an ExternType.
valueType := NewValueType(I32) limits := NewLimits(1, 4) tableType := NewTableType(valueType, limits) _ = tableType.IntoExternType()
type Target ¶
type Target struct {
// contains filtered or unexported fields
}
func NewTarget ¶
func NewTarget(triple *Triple, cpuFeatures *CpuFeatures) *Target
type TrapError ¶
type TrapError struct {
// contains filtered or unexported fields
}
TrapError represents a trap produced during Wasm execution.
See also ¶
Specification: https://webassembly.github.io/spec/core/intro/overview.html#trap
type Triple ¶
type Triple struct {
// contains filtered or unexported fields
}
func NewTripleFromHost ¶
func NewTripleFromHost() *Triple
type Value ¶
type Value struct {
// contains filtered or unexported fields
}
func NewF32 ¶
func NewF32(value interface{}) Value
NewF32 instantiates a new F32 Value with the given value.
⚠️ If a Wasm value cannot be created from the given value, NewF32 will panic.
value := NewF32(4.2)
func NewF64 ¶
func NewF64(value interface{}) Value
NewF64 instantiates a new F64 Value with the given value.
⚠️ If a Wasm value cannot be created from the given value, NewF64 will panic.
value := NewF64(4.2)
func NewI32 ¶
func NewI32(value interface{}) Value
NewI32 instantiates a new I32 Value with the given value.
⚠️ If a Wasm value cannot be created from the given value, NewI32 will panic.
value := NewI32(42)
func NewI64 ¶
func NewI64(value interface{}) Value
NewI64 instantiates a new I64 Value with the given value.
⚠️ If a Wasm value cannot be created from the given value, NewI64 will panic.
value := NewI64(42)
func NewValue ¶
NewValue instantiates a new Value with the given value and ValueKind.
⚠️ If a Wasm value cannot be created from the given value, NewValue will panic.
value := NewValue(42, I32)
func (*Value) F32 ¶
F32 returns the Value's value as a native Go float32.
value := NewF32(4.2) _ = value.F32()
func (*Value) F64 ¶
F64 returns the Value's value as a native Go float64.
value := NewF64(4.2) _ = value.F64()
func (*Value) I32 ¶
I32 returns the Value's value as a native Go int32.
value := NewI32(42) _ = value.I32()
func (*Value) I64 ¶
I64 returns the Value's value as a native Go int64.
value := NewI64(42) _ = value.I64()
type ValueKind ¶
type ValueKind C.wasm_valkind_t
func (ValueKind) IsNumber ¶
IsNumber returns true if the ValueKind is a number type.
I32.IsNumber() // true I64.IsNumber() // true F32.IsNumber() // true F64.IsNumber() // true AnyRef.IsNumber() // false FuncRef.IsNumber() // false
func (ValueKind) IsReference ¶
IsReference returns true if the ValueKind is a reference.
I32.IsReference() // false I64.IsReference() // false F32.IsReference() // false F64.IsReference() // false AnyRef.IsReference() // true FuncRef.IsReference() // true
type ValueType ¶
type ValueType struct {
// contains filtered or unexported fields
}
ValueType classifies the individual values that WebAssembly code can compute with and the values that a variable accepts.
func NewValueType ¶
NewValueType instantiates a new ValueType given a ValueKind.
valueType := NewValueType(I32)
func NewValueTypes ¶
NewValueTypes instantiates a new ValueType array from a list of ValueKind. Not that the list may be empty.
valueTypes := NewValueTypes(I32, I64, F32)
ℹ️ NewValueTypes is specifically designed to help you declare function types:
functionType := NewFunctionType(NewValueTypes(), NewValueTypes(I32))
type WasiEnvironment ¶
type WasiEnvironment struct {
// contains filtered or unexported fields
}
func (*WasiEnvironment) GenerateImportObject ¶
func (self *WasiEnvironment) GenerateImportObject(store *Store, module *Module) (*ImportObject, error)
type WasiStateBuilder ¶
type WasiStateBuilder struct {
// contains filtered or unexported fields
}
func NewWasiStateBuilder ¶
func NewWasiStateBuilder(programName string) *WasiStateBuilder
type WasiVersion ¶
type WasiVersion C.wasi_version_t
func GetWasiVersion ¶
func GetWasiVersion(module *Module) WasiVersion
func (WasiVersion) String ¶
func (self WasiVersion) String() string
Source Files ¶
- cgo.go
- config.go
- engine.go
- error.go
- exports.go
- exporttype.go
- extern.go
- externtype.go
- function.go
- functiontype.go
- global.go
- globaltype.go
- import_object.go
- importtype.go
- instance.go
- limits.go
- memory.go
- memorytype.go
- module.go
- name.go
- pages.go
- store.go
- table.go
- tabletype.go
- target.go
- trap.go
- value.go
- valuetype.go
- wasi.go
- wasmer.go
- wat.go