kwasm.ast.module

Kwasm.ast.module

package kwasm.ast.module

Classes

Name Description
data class DataSegment

From the docs:

The initial contents of a memory are zero-valued bytes. The data component of a module defines a vector of data segments that initialize a range of memory, at a given offset, with a static vector of bytes.


data ::= { data memidx, offset expr, init vec(byte)}

The offset is given by a constant expression.

Note: In the current version of WebAssembly, at most one memory is allowed in a module. Consequently, the only valid memidx is 0.

data class ElementSegment

Representation of an element segment for a table.

From the docs:

The initial contents of a table is uninitialized. The elem component of a module defines a vector of element segments that initialize a subrange of a table, at a given offset, from a static vector of elements.


elem ::= {table tableidx, offset expr, init vec(funcidx)}

The offset is given by a constant expression.

Note: In the current version of WebAssembly, at most one table is allowed in a module. Consequently, the only valid tableidx is 0.

data class Export

Defines an export for a WasmModule.

From the docs:

The exports component of a module defines a set of exports that become accessible to the host environment once the module has been instantiated.


export     ::= {name name, desc exportdesc}
exportdesc ::= func funcidx
table tableidx
mem memidx
global globalidx

Each export is labeled by a unique name. Exportable definitions are functions, tables, memories, and globals, which are referenced through a respective descriptor.

sealed class ExportDescriptor

See Export.

data class Global

Represents a global in a WasmModule.

From the docs:


global ::= {type globaltype, init expr}

Each global stores a single value of the given global type. Its 𝗍𝗒𝗉𝖾 also specifies whether a global is immutable or mutable. Moreover, each global is initialized with an 𝗂𝗇𝗂𝗍 value given by a constant initializer expression.

Globals are referenced through global indices, starting with the smallest index not referencing a global import.

data class Import

Represents an import for a WasmModule.

From the docs:

The imports component of a module defines a set of imports that are required for instantiation.


import     ::= {module name, name name, desc importdesc}
importdesc ::= func typeidx
table tabletype
mem memtype
global globaltype

Each import is labeled by a two-level name space, consisting of a module name and a name for an entity within that module. Importable definitions are functions, tables, memories, and globals. Each import is specified by a descriptor with a respective type that a definition provided during instantiation is required to match.

Every import defines an index in the respective index space. In each index space, the indices of imports go before the first index of any definition contained in the module itself.

sealed class ImportDescriptor

See Import.

sealed class Index

Reference to an indexed AstNode in the AST.

From the docs:


typeidx(I)     ::= x:u32   => x
v:id    => x (if I.types[x] = v)
funcidx(I)     ::= x:u32   => x
v:id    => x (if I.funcs[x] = v)
tableidx(I)    ::= x:u32   => x
v:id    => x (if I.tables[x] = v)
memidx(I)      ::= x:u32   => x
v:id    => x (if I.mems[x] = v)
globalidx(I)   ::= x:u32   => x
v:id    => x (if I.globals[x] = v)
lacalidx(I)    ::= x:u32   => x
v:id    => x (if I.locals[x] = v)
labelidx(I)    ::= l:u32   => l
v:id    => l (if I.labels[l] = v)

data class Local

Represents a mutable local value for a WasmFunction.

From the docs:

The locals declare a vector of mutable local variables and their types. These variables are referenced through local indices in the function’s body. The index of the first local is the smallest index not referencing a parameter.

data class Memory

Represents a memory instance in a WasmModule.

From the docs:

The mems component of a module defines a vector of linear memories (or memories for short) as described by their memory type:


mem    ::=

A memory is a vector of raw uninterpreted bytes. The min size in the limits of the memory type specifies the initial size of that memory, while its max, if present, restricts the size to which it can grow later. Both are in units of page size.

Memories can be initialized through data segments.

Memories are referenced through memory indices, starting with the smallest index not referencing a memory import. Most constructs implicitly reference memory index 0.

Note: In the current version of WebAssembly, at most one memory may be defined or imported in a single module, and all constructs implicitly reference this memory 0. This restriction may be lifted in future versions.

data class Offset

Container for an Expression which resolves to a memory offset.

data class StartFunction

Identifies the entry point for a WasmModule.

Note: At most one start function may occur in a module

data class Table

Represents a table in a WasmModule.

From the docs:

The tables component of a module defines a vector of tables described by their table type:


table ::=

A table is a vector of opaque values of a particular table element type. The min size in the limits of the table type specifies the initial size of that table, while its max, if present, restricts the size to which it can grow later.

Tables can be initialized through element segments.

Tables are referenced through table indices, starting with the smallest index not referencing a table import. Most constructs implicitly reference table index 0.

Note:** In the current version of WebAssembly, at most one table may be defined or imported in a single module, and all constructs implicitly reference this table 0. This restriction may be lifted in future versions.

data class Type

A possibly-identified FunctionType.

data class TypeUse

Represents a reference to a Type definition.

From the docs:

It may optionally be augmented by explicit inlined parameter and result declarations. That allows binding symbolic identifiers to name the local indices of parameters. If inline declarations are given, then their types must match the referenced function type.


typeuse(I) ::=
β€˜(’ β€˜type’ x:typeidx(I) β€˜)’
=> x,Iβ€² (if I.typedefs[x] = [t^n_1] -> [t*^2] ∧ Iβ€² = {locals (Ο΅)^n})
β€˜(’ β€˜type’ x:typeidx(I) β€˜)’ (t_1:param)* (t_2:result)*
=> x,Iβ€² (if I.typedefs[x] = [t*_1] -> [t*_2] ∧ Iβ€² = {locals id(param)*} well-formed)

Note: Both productions overlap for the case that the function type is [] -> []. However, in that case, they also produce the same results, so that the choice is immaterial. The well-formedness condition on Iβ€² ensures that the parameters do not contain duplicate identifier.

A typeuse may also be replaced entirely by inline parameter and result declarations. In that case, a type index is automatically inserted:


(t_1:param)* (t_2:result)* ≑ β€˜(’ β€˜type' x β€˜)’ param* result*

where x is the smallest existing type index whose definition in the current module is the function type [t*_1] -> [t*_2]. If no such index exists, then a new type definition of the form β€˜(’ β€˜type’ β€˜(’ β€˜func’ param* result β€˜)’ β€˜)’ is inserted at the end of the module.

Abbreviations are expanded in the order they appear, such that previously inserted type definitions are reused by consecutive expansions.

data class WasmFunction

Encapsulates a function within a 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.