ModuleValidator
object ModuleValidator
Methods
visit
fun visit(node: WasmModule, context: Module): Module
Validates the given node, and if necessary: its children (recursively, using other ValidationVisitor instances).
Parameters
Name | Description |
---|---|
node: WasmModule
|
|
context: Module
|
ReturnValue
Name | Description |
---|---|
Module
|
Validator of WasmModules.
From the docs:
Modules are classified by their mapping from the external types of their imports to those of their exports.
A module is entirely closed, that is, its components can only refer to definitions that appear in the module itself. Consequently, no initial context is required. Instead, the context
C
for validation of the module’s content is constructed from the definitions in the module.KWasm Note: The validation context will be passed to the ModuleValidator
module
be the module to validate.Let
C
be a context where:C.types
ismodule.types
,C.funcs
isfuncs(it*)
concatenated withft*
, with the import’s external typesit*
and the internal function typesft*
as determined below,C.tables
istables(it*)
concatenated withtt*
, with the import’s external typesit*
and the internal table typestt*
as determined below,C.mems
ismems(it*)
concatenated withmt*
, with the import’s external typesit*
and the internal memory typesmt*
as determined below,C.globals
isglobals(it*)
concatenated withgt*
, with the import’s external typesit*
and the internal global typesgt*
as determined below,C.locals
is empty,C.labels
is empty,C.return
is empty.C′
be the context whereC′.globals
is the sequenceglobals(it*)
and all other fields are empty.C
:functype_i
inmodule.types
, the function typefunctype_i
must be valid.func_i
inmodule.funcs
, the definitionfunc_i
must be valid with a function typeft_i
.table_i
inmodule.tables
, the definitiontable_i
must be valid with a table typett_i
.mem_i
inmodule.mems
, the definitionmem_i
must be valid with a memory typemt_i
.global_i
inmodule.globals:
Under the contextC′
, the definitionglobal_i
must be valid with a global typegt_i
.elem_i
inmodule.elem
, the segmentelem_i
must be valid.data_i
inmodule.data
, the segmentdata_i
must be valid.module.start
is non-empty, thenmodule.start
must be valid.import_i
inmodule.imports
, the segmentimport_i
must be valid with an external typeit_i
.export_i
inmodule.exports
, the segmentexport_i
must be valid with external typeet_i
.C.tables
must not be larger than1
.C.mems
must not be larger than1
.export_i.name
must be different.ft*
be the concatenation of the internal function typesft_i
, in index order.tt*
be the concatenation of the internal table typestt_i
, in index order.mt*
be the concatenation of the internal memory typesmt_i
, in index order.gt*
be the concatenation of the internal global typesgt_i
, in index order.it*
be the concatenation of external typesit_i
of the imports, in index order.et*
be the concatenation of external typeset_i
of the exports, in index order.it* => et*
.