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
module
be the module to allocate andexternval*_im
the vector of external values providing the module’s imports, andval*
the initialization values of the module’s globals. For each function
func_i
inmodule.funcs
, do:- Let
funcaddr_i
be the function address resulting from allocatingfunc_i
for the module instancemoduleinst
defined below.
- Let
For each table
table_i
inmodule.tables
, do:- Let
tableaddr_i
be the table address resulting from allocatingtable_i.type
.
- Let
For each memory
mem_i
inmodule.mems
, do:- Let
memaddr_i
be the memory address resulting from allocatingmem_i.type
.
- Let
For each global
global_i
inmodule.globals
, do:- Let
globaladdr_i
be the global address resulting from allocatingglobal_i.type
with initializer valueval*[i]
.
- Let
- Let
funcaddr*
be the the concatenation of the function addressesfuncaddr_i
in index order. - Let
tableaddr*
be the the concatenation of the table addressestableaddr_i
in index order. - Let
memaddr*
be the the concatenation of the memory addressesmemaddr_i
in index order. - Let
globaladdr*
be the the concatenation of the global addressesglobaladdr_i
in index order. - Let
funcaddr*_mod
be the list of function addresses extracted fromexternval*_im
, concatenated withfuncaddr*
. - Let
tableaddr*_mod
be the list of table addresses extracted fromexternval*_im
, concatenated withtableaddr*
. - Let
memaddr*_mod
be the list of memory addresses extracted fromexternval*_im
, concatenated withmemaddr*
. - Let
globaladdr*_mod
be the list of global addresses extracted fromexternval*_im
, concatenated withglobaladdr*
. For each export
export_i
inmodule.exports
, do:- If
export_i
is a function export for function indexx
, then letexternval_i
be the external valuefunc (funcaddr*_mod[x])
. - Else, if
export_i
is a table export for table indexx
, then letexternval_i
be the external valuetable (tableaddr*_mod[x])
. - Else, if
export_i
is a memory export for memory indexx
, then letexternval_i
be the external valuemem (memaddr*_mod[x])
. - Else, if
export_i
is a global export for global indexx
, then letexternval_i
be the external valueglobal (globaladdr*_mod[x])
. - Let
exportinst_i
be the export instance{name (export_i.name), value externval_i}
.
- If
- Let
exportinst*
be the the concatenation of the export instancesexportinst_i
in index order. - Let
moduleinst
be 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.