[go: up one dir, main page]

Struct Wasm2Wat

Source
pub struct Wasm2Wat { /* private fields */ }
Expand description

A builder for converting wasm binary to wasm text format.

§Examples

extern crate wabt;
use wabt::Wasm2Wat;

fn main() {
    let wasm_text = Wasm2Wat::new()
        .fold_exprs(true)
        .inline_export(true)
        .convert(
            &[
                0, 97, 115, 109, // \0ASM - magic
                1, 0, 0, 0       //  0x01 - version
            ]
        ).unwrap();

}

Implementations§

Source§

impl Wasm2Wat

Source

pub fn new() -> Wasm2Wat

Create Wasm2Wat with default configuration.

Source

pub fn features(&mut self, features: Features) -> &mut Wasm2Wat

Support for pre-standard features.

Source

pub fn read_debug_names(&mut self, read_debug_names: bool) -> &mut Wasm2Wat

Read debug names in the binary file.

false by default.

Source

pub fn fold_exprs(&mut self, fold_exprs: bool) -> &mut Wasm2Wat

Write folded expressions where possible.

Example of folded code (if true):

(module
    (func (param i32 i32) (result i32)
        (i32.add ;; Add loaded arguments
            (get_local 0) ;; Load first arg
            (get_local 1) ;; Load second arg
        )
    )
)

Example of straight code (if false):

(module
    (func (param i32 i32) (result i32)
        get_local 0 ;; Load first arg
        get_local 1 ;; Load second arg
        i32.add     ;; Add loaded arguments
    )
)

false by default.

Source

pub fn inline_export(&mut self, inline_export: bool) -> &mut Wasm2Wat

Write all exports inline.

Example of code with inline exports (if true):

(module
(func $addTwo (export "addTwo") (param $p0 i32) (param $p1 i32) (result i32)
  (i32.add
    (get_local $p0)
    (get_local $p1))))

Example of code with separate exports (if false):

(module
  (func $addTwo (param $p0 i32) (param $p1 i32) (result i32)
    (i32.add
      (get_local $p0)
      (get_local $p1)))
  (export "addTwo" (func $addTwo)))

false by default.

Source

pub fn convert<S: AsRef<[u8]>>(&self, wasm: S) -> Result<WabtBuf, Error>

Perform conversion.

Auto Trait Implementations§

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> FromBits<T> for T

Source§

fn from_bits(other: T) -> T

Convert other to Self, preserving bitwise representation
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.