WasmModule
data class WasmModule
Fields
| Name | Description |
|---|---|
val identifier: Label?
|
|
val types: List<Type>
|
|
val imports: List<Import>
|
|
val functions: List<WasmFunction>
|
|
val tables: List<Table>
|
|
val memories: List<Memory>
|
|
val globals: List<Global>
|
|
val exports: List<Export>
|
|
val start: StartFunction?
|
|
val elements: List<ElementSegment>
|
|
val data: List<DataSegment>
|
Constructors
<init>
constructor(identifier: Label?, types: List<Type>, imports: List<Import>, functions: List<WasmFunction>, tables: List<Table>, memories: List<Memory>, globals: List<Global>, exports: List<Export>, start: StartFunction?, elements: List<ElementSegment>, data: List<DataSegment>)
Represents a WebAssembly module.
From the docs:
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.
Parameters
| Name | Description |
|---|---|
identifier: Label?
|
|
types: List<Type>
|
|
imports: List<Import>
|
|
functions: List<WasmFunction>
|
|
tables: List<Table>
|
|
memories: List<Memory>
|
|
globals: List<Global>
|
|
exports: List<Export>
|
|
start: StartFunction?
|
|
elements: List<ElementSegment>
|
|
data: List<DataSegment>
|
Extensions
allocate
fun WasmModule.allocate(validationContext: Module, memoryProvider: MemoryProvider, externalValues: List<ImportExtern<Address>>, store: Store): ModuleAllocationResult
Instantiates a WasmModule into a ModuleInstance given a Store.
From the docs:
- Let
modulebe the module to allocate andexternval*_imthe vector of external values providing the module’s imports, andval*the initialization values of the module’s globals. For each function
func_iinmodule.funcs, do:- Let
funcaddr_ibe the function address resulting from allocatingfunc_ifor the module instancemoduleinstdefined below.
- Let
For each table
table_iinmodule.tables, do:- Let
tableaddr_ibe the table address resulting from allocatingtable_i.type.
- Let
For each memory
mem_iinmodule.mems, do:- Let
memaddr_ibe the memory address resulting from allocatingmem_i.type.
- Let
For each global
global_iinmodule.globals, do:- Let
globaladdr_ibe the global address resulting from allocatingglobal_i.typewith initializer valueval*[i].
- Let
- Let
funcaddr*be the the concatenation of the function addressesfuncaddr_iin index order. - Let
tableaddr*be the the concatenation of the table addressestableaddr_iin index order. - Let
memaddr*be the the concatenation of the memory addressesmemaddr_iin index order. - Let
globaladdr*be the the concatenation of the global addressesglobaladdr_iin index order. - Let
funcaddr*_modbe the list of function addresses extracted fromexternval*_im, concatenated withfuncaddr*. - Let
tableaddr*_modbe the list of table addresses extracted fromexternval*_im, concatenated withtableaddr*. - Let
memaddr*_modbe the list of memory addresses extracted fromexternval*_im, concatenated withmemaddr*. - Let
globaladdr*_modbe the list of global addresses extracted fromexternval*_im, concatenated withglobaladdr*. For each export
export_iinmodule.exports, do:- If
export_iis a function export for function indexx, then letexternval_ibe the external valuefunc (funcaddr*_mod[x]). - Else, if
export_iis a table export for table indexx, then letexternval_ibe the external valuetable (tableaddr*_mod[x]). - Else, if
export_iis a memory export for memory indexx, then letexternval_ibe the external valuemem (memaddr*_mod[x]). - Else, if
export_iis a global export for global indexx, then letexternval_ibe the external valueglobal (globaladdr*_mod[x]). - Let
exportinst_ibe the export instance{name (export_i.name), value externval_i}.
- If
- Let
exportinst*be the the concatenation of the export instancesexportinst_iin index order. - Let
moduleinstbe the module instance{ types (module.types), funcaddrs funcaddr*_mod, tableaddrs tableaddr*_mod, memaddrs memaddr*_mod, globaladdrs globaladdr*_mod, exports exportinst* }. - Return
moduleinst.
Receiver
| Name | Description |
|---|---|
WasmModule
|
Parameters
| Name | Description |
|---|---|
validationContext: Module
|
|
memoryProvider: MemoryProvider
|
|
externalValues: List<ImportExtern<Address>>
|
|
store: Store
|
ReturnValue
| Name | Description |
|---|---|
ModuleAllocationResult
|
collectImportExterns
fun WasmModule.collectImportExterns(): List<ImportExtern<Address>>
Transforms a WasmModule's raw list of Imports into ImportExterns.
Receiver
| Name | Description |
|---|---|
WasmModule
|
ReturnValue
| Name | Description |
|---|---|
List<ImportExtern<Address>>
|
validate
fun WasmModule.validate(context: Module): Module
Validates a WasmModule.
This is the main entry point into the validation process.
Receiver
| Name | Description |
|---|---|
WasmModule
|
Parameters
| Name | Description |
|---|---|
context: Module
|
ReturnValue
| Name | Description |
|---|---|
Module
|
Represents a WebAssembly module.
From the docs:
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.