Struct walrus::ModuleConfig

source ·
pub struct ModuleConfig { /* private fields */ }
Expand description

Configuration for a Module which currently affects parsing.

Implementations§

source§

impl ModuleConfig

source

pub fn new() -> ModuleConfig

Creates a fresh new configuration with default settings.

source

pub fn generate_dwarf(&mut self, generate: bool) -> &mut ModuleConfig

Sets a flag to whether DWARF debug sections are generated for this module.

By default this flag is false. Note that any emitted DWARF is currently wildly incorrect and buggy, and is also larger than the wasm itself!

source

pub fn generate_name_section(&mut self, generate: bool) -> &mut ModuleConfig

Sets a flag to whether the custom “name” section is generated for this module.

The “name” section contains symbol names for the module, functions, and locals. When enabled, stack traces will use these names, instead of wasm-function[123].

By default this flag is true.

source

pub fn generate_synthetic_names_for_anonymous_items( &mut self, generate: bool ) -> &mut ModuleConfig

Sets a flag to whether synthetic debugging names are generated for anonymous locals/functions/etc when parsing and running passes for this module.

By default this flag is false, and it will generate quite a few names if enabled!

source

pub fn strict_validate(&mut self, strict: bool) -> &mut ModuleConfig

Indicates whether the module, after parsing, performs strict validation of the wasm module to adhere with the current version of the wasm specification.

This can be expensive for some modules and strictly isn’t required to create a Module from a wasm file. This includes checks such as “atomic instructions require a shared memory”.

By default this flag is true

source

pub fn generate_producers_section( &mut self, generate: bool ) -> &mut ModuleConfig

Indicates whether the module will have the “producers” custom section which preserves the original producers and also includes walrus.

This is generally used for telemetry in browsers, but for otherwise tiny wasm binaries can add some size to the binary.

By default this flag is true

source

pub fn only_stable_features(&mut self, only: bool) -> &mut ModuleConfig

Indicates whether this module is allowed to use only stable WebAssembly features or not.

This is currently used to disable some validity checks required by the WebAssembly specification. It’s not religiously adhered to throughout the codebase, even if set to true some unstable features may still be allowed.

By default this flag is false

source

pub fn on_parse<F>(&mut self, f: F) -> &mut ModuleConfigwhere F: Fn(&mut Module, &IndicesToIds) -> Result<()> + Send + Sync + 'static,

Provide a function that is invoked after successfully parsing a module, and gets access to data structures that only exist at parse time, such as the map from indices in the original Wasm to the new walrus IDs.

This is a good place to parse custom sections that reference things by index.

This will never be invoked for modules that are created from scratch, and are not parsed from an existing Wasm binary.

Note that only one on_parse function may be registered and subsequent registrations will override the old ones.

Note that cloning a ModuleConfig will result in a config that does not have an on_parse function, even if the original did.

source

pub fn on_instr_loc<F>(&mut self, f: F) -> &mut ModuleConfigwhere F: Fn(&usize) -> InstrLocId + Send + Sync + 'static,

Provide a function that is invoked on source location ID step.

Note that cloning a ModuleConfig will result in a config that does not have an on_instr_loc function, even if the original did.

source

pub fn preserve_code_transform(&mut self, preserve: bool) -> &mut ModuleConfig

Sets a flag to whether code transform is preverved during parsing.

By default this flag is false.

source

pub fn parse(&self, wasm: &[u8]) -> Result<Module>

Parses an in-memory WebAssembly file into a Module using this configuration.

source

pub fn parse_file<P>(&self, path: P) -> Result<Module>where P: AsRef<Path>,

Parses a WebAssembly file into a Module using this configuration.

Trait Implementations§

source§

impl Clone for ModuleConfig

source§

fn clone(&self) -> ModuleConfig

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for ModuleConfig

source§

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

Formats the value using the given formatter. Read more
source§

impl Default for ModuleConfig

source§

fn default() -> ModuleConfig

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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 Twhere U: TryFrom<T>,

§

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.