* Switch lightbeam from `wabt` to `wast` Switch from a C++-based `*.wat` parser to a Rust-based parser * Remove unneeded `wabt` dev-dependency from wasmtime-api * Rewrite `wasmtime-wast` crate with `wast-parser` This commit moves the `wasmtime-wast` crate off the `wabt` crate on to the `wast-parser` crate which is a Rust implementation of a `*.wast` and `*.wat` parser. The intention here is to continue to reduce the amount of C++ required to build wasmtime! * Use new `wat` and `wast` crate names
34 lines
1.2 KiB
Rust
34 lines
1.2 KiB
Rust
extern crate alloc;
|
|
|
|
use alloc::rc::Rc;
|
|
use core::cell::RefCell;
|
|
use cranelift_codegen::settings;
|
|
use cranelift_codegen::settings::Configurable;
|
|
use std::collections::HashMap;
|
|
use std::path::PathBuf;
|
|
use wasmtime_jit::{instantiate, CompilationStrategy, Compiler, NullResolver};
|
|
|
|
const PATH_MODULE_RS2WASM_ADD_FUNC: &str = r"filetests/rs2wasm-add-func.wat";
|
|
|
|
/// Simple test reading a wasm-file and translating to binary representation.
|
|
#[test]
|
|
fn test_environ_translate() {
|
|
let path = PathBuf::from(PATH_MODULE_RS2WASM_ADD_FUNC);
|
|
let data = wat::parse_file(path).expect("expecting valid wat-file");
|
|
assert!(data.len() > 0);
|
|
|
|
let mut flag_builder = settings::builder();
|
|
flag_builder.enable("enable_verifier").unwrap();
|
|
|
|
let isa_builder = cranelift_native::builder().unwrap_or_else(|_| {
|
|
panic!("host machine is not a supported target");
|
|
});
|
|
let isa = isa_builder.finish(settings::Flags::new(flag_builder));
|
|
|
|
let mut resolver = NullResolver {};
|
|
let mut compiler = Compiler::new(isa, CompilationStrategy::Auto);
|
|
let global_exports = Rc::new(RefCell::new(HashMap::new()));
|
|
let instance = instantiate(&mut compiler, &data, &mut resolver, global_exports, false);
|
|
assert!(instance.is_ok());
|
|
}
|