WasmModule

WasmModule

data class WasmModule

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.

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:

  1. Let module be the module to allocate and externval*_im the vector of external values providing the module’s imports, and val* the initialization values of the module’s globals.
  2. For each function func_i in module.funcs, do:

    • Let funcaddr_i be the function address resulting from allocating func_i for the module instance moduleinst defined below.
  3. For each table table_i in module.tables, do:

    • Let tableaddr_i be the table address resulting from allocating table_i.type.
  4. For each memory mem_i in module.mems, do:

    • Let memaddr_i be the memory address resulting from allocating mem_i.type.
  5. For each global global_i in module.globals, do:

    • Let globaladdr_i be the global address resulting from allocating global_i.type with initializer value val*[i].
  6. Let funcaddr* be the the concatenation of the function addresses funcaddr_i in index order.
  7. Let tableaddr* be the the concatenation of the table addresses tableaddr_i in index order.
  8. Let memaddr* be the the concatenation of the memory addresses memaddr_i in index order.
  9. Let globaladdr* be the the concatenation of the global addresses globaladdr_i in index order.
  10. Let funcaddr*_mod be the list of function addresses extracted from externval*_im, concatenated with funcaddr*.
  11. Let tableaddr*_mod be the list of table addresses extracted from externval*_im, concatenated with tableaddr*.
  12. Let memaddr*_mod be the list of memory addresses extracted from externval*_im, concatenated with memaddr*.
  13. Let globaladdr*_mod be the list of global addresses extracted from externval*_im, concatenated with globaladdr*.
  14. For each export export_i in module.exports, do:

    • If export_i is a function export for function index x, then let externval_i be the external value func (funcaddr*_mod[x]).
    • Else, if export_i is a table export for table index x, then let externval_i be the external value table (tableaddr*_mod[x]).
    • Else, if export_i is a memory export for memory index x, then let externval_i be the external value mem (memaddr*_mod[x]).
    • Else, if export_i is a global export for global index x, then let externval_i be the external value global (globaladdr*_mod[x]).
    • Let exportinst_i be the export instance {name (export_i.name), value externval_i}.
  15. Let exportinst* be the the concatenation of the export instances exportinst_i in index order.
  16. Let moduleinst be the module instance { types (module.types), funcaddrs funcaddr*_mod, tableaddrs tableaddr*_mod, memaddrs memaddr*_mod, globaladdrs globaladdr*_mod, exports exportinst* }.
  17. 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