Expand description
WebAssembly model of modules and their segments.
StructsΒ§
- Custom
- Custom sections have the id 0. They are intended to be used for debugging information or third-party extensions, and are ignored by the WebAssembly semantics. Their contents consist of a name further identifying the custom section, followed by an uninterpreted sequence of bytes for custom use.
- Data
- The initial contents of a memory are zero bytes. Data segments can be used to initialize a range of memory from a static vector of bytes. Like element segments, data segments have a mode that identifies them as either passive or active. A passive data segmentβs contents can be copied into a memory using the ππΎππππ.ππππ instruction. An active data segment copies its contents into a memory during instantiation, as specified by a memory index and a constant expression defining an offset into that memory. Data segments are referenced through data indices.
- Element
- The initial contents of a table is uninitialized. Element segments can be used to initialize a subrange of a table from a static vector of elements. Each element segment defines a reference type and a corresponding list of constant element expressions. Element segments have a mode that identifies them as either passive, active, or declarative. A passive element segmentβs elements can be copied to a table using the ππΊπ»π πΎ.ππππ instruction. An active element segment copies its elements into a table during instantiation, as specified by a table index and a constant expression defining an offset into that table. A declarative element segment is not available at runtime but merely serves to forward-declare references that are formed in code with instructions like ππΎπΏ.πΏπππΌ. The ππΏπΏππΎπ is given by a constant expression. Element segments are referenced through element indices.
- Export
- The πΎππππππ component of a module defines a set of exports that become accessible to the host environment once the module has been instantiated. Each export is labeled by a unique name. Exportable definitions are functions, tables, memories, and globals, which are referenced through a respective descriptor.
- Function
- The ππππΎ of a function declares its signature by reference to a type defined in the module. The parameters of the function are referenced through 0-based local indices in the functionβs body; they are mutable. The π ππΌπΊπ π 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. The π»ππ½π is an instruction sequence that upon termination must produce a stack matching the function typeβs result type.
- Global
- 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.
- Import
- Each import is labeled by a two-level name space, consisting of a πππ½ππ πΎ name and a ππΊππΎ 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.
- Memory
- A memory is a vector of raw uninterpreted bytes. The πππ size in the limits of the memory type specifies the initial size of that memory, while its ππΊπ, 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.
- Module
- 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 in the form of data and element segments, or a start function. Each of the vectors β and thus the entire module β may be empty.
- Module
Builder - A builder pattern for
Modules. The builder performs minimal validation when using theadd_*family of methods. The builder validates that the added element would not exceed the maximum size of a u32. No other validations are performed. - Start
- The πππΊππ component of a module declares the function index of a start function that is automatically invoked when the module is instantiated, after tables and memories have been initialized. start::={πΏπππΌ funcidx}
- Table
- A table is a vector of opaque values of a particular reference type. The πππ size in the limits of the table type specifies the initial size of that table, while its ππΊπ, 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.
EnumsΒ§
- Data
Mode - Like element segments, data segments have a mode that identifies them as either passive or active.
- Element
Mode - Element segments have a mode that identifies them as either passive, active, or declarative.
- Export
Description - Exportable definitions are functions, tables, memories, and globals, which are referenced through a respective descriptor.
- Import
Description - Each import is specified by a descriptor with a respective type that a definition provided during instantiation is required to match.
- Module
Section - The binary encoding of modules is organized into sections. Most sections correspond to one component of a module record, except that function definitions are split into two sections, separating their type declarations in the function section from their bodies in the code section.
TraitsΒ§
- Element
Initializer - Supported types for initializing an element component.