WABT bindings for Rust
Rust bindings for WABT.
Usage
Add this to your Cargo.toml
:
[]
= "0.9.0"
Use cases
Assemble a given program in WebAssembly text format (aka wat) and translate it into binary.
extern crate wabt;
use wat2wasm;
or disassemble a wasm binary into the text format.
extern crate wabt;
use wasm2wat;
wabt
can be also used for parsing the official testsuite scripts.
use ;
let wast = r#"
;; Define anonymous module with function export named `sub`.
(module
(func (export "sub") (param $x i32) (param $y i32) (result i32)
;; return x - y;
(i32.sub
(get_local $x) (get_local $y)
)
)
)
;; Assert that invoking export `sub` with parameters (8, 3)
;; should return 5.
(assert_return
(invoke "sub"
(i32.const 8) (i32.const 3)
)
(i32.const 5)
)
"#;
let mut parser = from_str?;
while let Some = parser.next?
Alternatives
You might find wat
or wast
crate useful if you only want to parse .wat
or .wast
source. The advantage of using them is that
they are implemented completely in Rust. Moreover, wast
among other things
allows you to add your own extensions to WebAssembly text format.
For print the text representation of a wasm binary, wasmprinter
can work better for you, since it is implemented completely in Rust.