I'm not asking about compiling Rust to wasm or compiling Rust to wat.
I want my rust code to generate Wat.
I want to generate the exprs in Understanding WebAssembly text format - WebAssembly | MDN
Is there some Rust crate for generating this? To clarify: I'm not asking about parsing/loading/compilingto wasm. I literally just want to generate wat on the fly.
1 Like
What WAT code you want to generate from Rust? WAT is a textual format and you can easily write it by hand on your favorite text editor.
It looks like binaryen-sys
has a method for transforming a module AST into WAT: binaryen_sys::BinaryenModuleWriteText - Rust
It's an unsafe interface, but it's the only thing I've found that writes WAT.
1 Like
Lucet has a rust api to compile and link code.
https://crates.io/crates/lucet-wasi-sdk
Example use in their tests:
#[cfg(test)]
mod compile_and_link_tests {
use lucet_wasi_sdk::*;
use std::path::PathBuf;
use tempfile::TempDir;
fn test_file(name: &str) -> PathBuf {
let mut p = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
p.push("tests");
p.push(name);
assert!(p.exists(), "test file does not exist");
p
}
#[test]
fn compile_a() {
let tmp = TempDir::new().expect("create temporary directory");
let compiler = Compile::new(test_file("a.c"));
This file has been truncated. show original
system
Closed
August 31, 2020, 12:36am
6
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.