Struct WatPrinterConfig

pub(crate) struct WatPrinterConfig {
    pub(crate) print_offsets: bool,
    pub(crate) print_skeleton: bool,
    pub(crate) name_unnamed: bool,
    pub(crate) fold_instructions: bool,
    pub(crate) indent_text: String,
    pub(crate) print_operand_stack: bool,
}
Expand description

Configuration used to print a WebAssembly binary.

This structure is used to control the overal structure of how wasm binaries are printed and tweaks various ways that configures the output.

Fields§

§print_offsets: bool§print_skeleton: bool§name_unnamed: bool§fold_instructions: bool§indent_text: String§print_operand_stack: bool

Implementations§

§

impl Config

pub fn new() -> Config

Creates a new Config object that’s ready to start printing wasm binaries to strings.

pub fn print_offsets(&mut self, print: bool) -> &mut Config

Whether or not to print binary offsets of each item as comments in the text format whenever a newline is printed.

pub fn print_skeleton(&mut self, print: bool) -> &mut Config

Whether or not to print only a “skeleton” which skips function bodies, data segment contents, element segment contents, etc.

pub fn name_unnamed(&mut self, enable: bool) -> &mut Config

Assign names to all unnamed items.

If enabled then any previously unnamed item will have a name synthesized that looks like $#func10 for example. The leading # indicates that it’s wasmprinter-generated. The func is the namespace of the name and provides extra context about the item when referenced. The 10 is the local index of the item.

Note that if the resulting text output is converted back to binary the resulting name custom section will not be the same as before.

pub fn fold_instructions(&mut self, enable: bool) -> &mut Config

Print instructions in folded form where possible.

This will cause printing to favor the s-expression (parenthesized) form of WebAssembly instructions. For example this output would be generated for a simple add function:

(module
    (func $foo (param i32 i32) (result i32)
        (i32.add
            (local.get 0)
            (local.get 1))
    )
)

pub fn print_operand_stack(&mut self, enable: bool) -> &mut Config

Print the operand stack types within function bodies, flagging newly pushed operands when color output is enabled. E.g.:

(module
  (type (;0;) (func))
  (func (;0;) (type 0)
    i32.const 4
    ;; [i32]
    i32.const 5
    ;; [i32 i32]
    i32.add
    ;; [i32]
    drop
    ;; []
  )
)

pub fn indent_text(&mut self, text: impl Into<String>) -> &mut Config

Select the string to use when indenting.

The indent allowed here are arbitrary and unchecked. You should enter blank text like " " or "\t", rather than something like "(;;)".

The default setting is double spaces " "

pub fn print(&self, wasm: &[u8], result: &mut impl Print) -> Result<(), Error>

Print a WebAssembly binary.

This function takes an entire wasm binary blob and prints it to the result in the WebAssembly Text Format.

pub fn offsets_and_lines<'a>( &self, wasm: &[u8], storage: &'a mut String, ) -> Result<impl Iterator<Item = (Option<usize>, &'a str)> + 'a, Error>

Get the line-by-line WAT disassembly for the given Wasm, along with the binary offsets for each line.

Trait Implementations§

§

impl Debug for Config

§

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

Formats the value using the given formatter. Read more
§

impl Default for Config

§

fn default() -> Config

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

Auto Trait Implementations§

§

impl Freeze for Config

§

impl RefUnwindSafe for Config

§

impl Send for Config

§

impl Sync for Config

§

impl Unpin for Config

§

impl UnwindSafe for Config

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.