I write my first wasm implementation for my programming language. The output of the WAT using wasm2wat
is:
(module
(type (;0;) (func (result i64)))
(func $add (type 1) (param i64 i64) (result i64)
local.get 0
local.get 1
i64.add
return)
(export "add" (func $add)))
I want to test this using assert
inside my rust code. What is the best way to do that? Is there any library that I can use?
Currently, I use walrus' emit_wasm()
to produce wasm buffer.
I would take a look at https://docs.wasmtime.dev/lang-rust.html: it has an example of how to embed Wasmtime in your Rust program and call your add
function`.
Thank you for the link. I have seen it but it seems we should have .wat
file first to do that. What I want is more like my_language -> wasm -> wat
or my_language -> wat
but in buffer. Similar to what emit_wasm()
function does, but to produce wat
based on wasm spec.
Are you looking for Module::new
? I guess you could use Module::from_binary
directly if you already have the compiled Wasm bytes available.
You can use the wasmprinter
crate to disassemble a wasm buffer into wat: https://docs.rs/wasmprinter/0.2.25/wasmprinter/
Andrew Brown said:
Are you looking for
Module::new
? I guess you could useModule::from_binary
directly if you already have the compiled Wasm bytes available.
Yes, thank for the suggestion.
@_fitzgen (he/him)|253990 said:
You can use the
wasmprinter
crate to disassemble a wasm buffer into wat: https://docs.rs/wasmprinter/0.2.25/wasmprinter/
thanks, I'll look into it.
Last updated: Dec 23 2024 at 12:05 UTC