pub struct Module<'a> {
pub span: Span,
pub id: Option<Id<'a>>,
pub name: Option<NameAnnotation<'a>>,
pub kind: ModuleKind<'a>,
}
Expand description
A parsed WebAssembly core module.
Fields
span: Span
Where this module
was defined
id: Option<Id<'a>>
An optional identifier this module is known by
name: Option<NameAnnotation<'a>>
An optional @name
annotation for this module
kind: ModuleKind<'a>
What kind of module this was parsed as.
Implementations
sourceimpl<'a> Module<'a>
impl<'a> Module<'a>
sourcepub fn resolve(&mut self) -> Result<Names<'a>, Error>
pub fn resolve(&mut self) -> Result<Names<'a>, Error>
Performs a name resolution pass on this Module
, resolving all
symbolic names to indices.
The WAT format contains a number of shorthands to make it easier to
write, such as inline exports, inline imports, inline type definitions,
etc. Additionally it allows using symbolic names such as $foo
instead
of using indices. This module will postprocess an AST to remove all of
this syntactic sugar, preparing the AST for binary emission. This is
where expansion and name resolution happens.
This function will mutate the AST of this Module
and replace all
Index
arguments with Index::Num
. This will
also expand inline exports/imports listed on fields and handle various
other shorthands of the text format.
If successful the AST was modified to be ready for binary encoding. A
Names
structure is also returned so if you’d like to do your own
name lookups on the result you can do so as well.
Errors
If an error happens during resolution, such a name resolution error or items are found in the wrong order, then an error is returned.
sourcepub fn encode(&mut self) -> Result<Vec<u8>, Error>
pub fn encode(&mut self) -> Result<Vec<u8>, Error>
Encodes this Module
to its binary form.
This function will take the textual representation in Module
and
perform all steps necessary to convert it to a binary WebAssembly
module, suitable for writing to a *.wasm
file. This function may
internally modify the Module
, for example:
-
Name resolution is performed to ensure that
Index::Id
isn’t present anywhere in the AST. -
Inline shorthands such as imports/exports/types are all expanded to be dedicated fields of the module.
-
Module fields may be shuffled around to preserve index ordering from expansions.
After all of this expansion has happened the module will be converted to
its binary form and returned as a Vec<u8>
. This is then suitable to
hand off to other wasm runtimes and such.
Errors
This function can return an error for name resolution errors and other expansion-related errors.
Trait Implementations
Auto Trait Implementations
impl<'a> RefUnwindSafe for Module<'a>
impl<'a> Send for Module<'a>
impl<'a> Sync for Module<'a>
impl<'a> Unpin for Module<'a>
impl<'a> UnwindSafe for Module<'a>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more