Skip to main content

Module

Struct Module 

Source
pub struct Module<'a> {
Show 13 fields pub sections: Vec<RawSection<'a>>, pub types: Vec<FuncType>, pub imports: Vec<Import>, pub exports: Vec<Export>, pub functions: Vec<TypeIdx>, pub tables: Vec<TableType>, pub elements: Vec<ElementSegment<'a>>, pub globals: Vec<Global<'a>>, pub memories: Vec<MemType>, pub data: Vec<DataSegment<'a>>, pub start: Option<FuncIdx>, pub data_count: Option<u32>, pub codes: Vec<CodeBody<'a>>,
}
Expand description

A parsed WASM module. Contains the raw section data segmented by type.

At Phase 0, section bodies are stored as raw bytes. Later phases will parse type entries, imports, function bodies, etc.

Fields§

§sections: Vec<RawSection<'a>>

All sections in the order they appeared, as raw byte spans.

§types: Vec<FuncType>

Decoded function signatures from the type section.

§imports: Vec<Import>

Imported items declared by the module.

§exports: Vec<Export>

Exported items declared by the module.

§functions: Vec<TypeIdx>

Type indices for module-defined (non-imported) functions.

§tables: Vec<TableType>

Defined tables from the table section.

§elements: Vec<ElementSegment<'a>>

Defined element segments from the element section.

§globals: Vec<Global<'a>>

Defined globals from the global section.

§memories: Vec<MemType>

Defined memories from the memory section.

§data: Vec<DataSegment<'a>>

Defined data segments from the data section.

§start: Option<FuncIdx>

Optional declared start function.

§data_count: Option<u32>

Optional declared data count.

§codes: Vec<CodeBody<'a>>

Function bodies from the code section.

Implementations§

Source§

impl<'a> Module<'a>

Source

pub fn decode(bytes: &'a [u8]) -> Result<Self, DecodeError>

Decode a WASM binary into a Module.

This validates the preamble (magic + version), parses section boundaries, and checks section ordering. It does NOT validate section contents.

Source

pub fn section(&self, id: SectionId) -> Option<&RawSection<'a>>

Get the first section with the given ID, if present.

Source

pub fn types(&self) -> &[FuncType]

Function signatures declared in the type section.

Source

pub fn imports(&self) -> &[Import]

Imported items declared by the module.

Source

pub fn exports(&self) -> &[Export]

Exported items declared by the module.

Source

pub fn functions(&self) -> &[TypeIdx]

Type indices for module-defined functions.

Source

pub fn tables(&self) -> &[TableType]

Defined tables from the table section.

Source

pub fn elements(&self) -> &[ElementSegment<'a>]

Defined element segments from the element section.

Source

pub fn imported_function_count(&self) -> usize

Number of imported functions in the function index space.

Source

pub fn globals(&self) -> &[Global<'a>]

Defined globals from the global section.

Source

pub fn memories(&self) -> &[MemType]

Defined memories from the memory section.

Source

pub fn data(&self) -> &[DataSegment<'a>]

Defined data segments from the data section.

Source

pub fn start(&self) -> Option<FuncIdx>

Declared start function, if present.

Source

pub fn data_count(&self) -> Option<u32>

Declared data count, if present.

Source

pub fn codes(&self) -> &[CodeBody<'a>]

Function bodies from the code section.

Source

pub fn custom_sections(&self) -> impl Iterator<Item = &RawSection<'a>>

Iterate over all custom sections.

Source

pub fn section_summary(&self) -> Vec<(SectionId, usize, usize)>

Summary of the module’s section layout for display.

Source§

impl<'a> Module<'a>

Source

pub fn lower(&self) -> Result<RegModule, LowerError>

Validate and lower this module into Baedeker register IR.

Source§

impl<'a> Module<'a>

Source

pub fn validate(&self) -> Result<(), ValidationError>

Validate the currently decoded subset of the module.

Trait Implementations§

Source§

impl<'a> Debug for Module<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Module<'a>

§

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> UnsafeUnpin for Module<'a>

§

impl<'a> UnwindSafe for Module<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.