Browse Source

Migrating to wabt::wat2wasm (#29)

* Add test_environ_translate

* Migrating to wabt::wat2wasm
pull/35/head
Frank Rehberger 6 years ago
committed by Dan Gohman
parent
commit
ec940ee8af
  1. 3
      Cargo.toml
  2. 24
      src/main.rs

3
Cargo.toml

@ -28,13 +28,10 @@ wasmtime-obj = { path = "lib/obj" }
docopt = "1.0.1" docopt = "1.0.1"
serde = "1.0.75" serde = "1.0.75"
serde_derive = "1.0.75" serde_derive = "1.0.75"
tempdir = "*"
faerie = "0.6.0" faerie = "0.6.0"
target-lexicon = { version = "0.2.0", default-features = false } target-lexicon = { version = "0.2.0", default-features = false }
pretty_env_logger = "0.2.5" pretty_env_logger = "0.2.5"
file-per-thread-logger = "0.1.1" file-per-thread-logger = "0.1.1"
[dev-dependencies]
wabt = "0.7" wabt = "0.7"
[workspace] [workspace]

24
src/main.rs

@ -44,9 +44,6 @@ extern crate wasmtime_execute;
extern crate serde_derive; extern crate serde_derive;
extern crate file_per_thread_logger; extern crate file_per_thread_logger;
extern crate pretty_env_logger; extern crate pretty_env_logger;
extern crate tempdir;
#[cfg(test)]
extern crate wabt; extern crate wabt;
use cranelift_codegen::isa::TargetIsa; use cranelift_codegen::isa::TargetIsa;
@ -62,8 +59,7 @@ use std::io::prelude::*;
use std::io::stdout; use std::io::stdout;
use std::path::Path; use std::path::Path;
use std::path::PathBuf; use std::path::PathBuf;
use std::process::{exit, Command}; use std::process::exit;
use tempdir::TempDir;
use wasmtime_environ::{Module, ModuleEnvironment}; use wasmtime_environ::{Module, ModuleEnvironment};
use wasmtime_execute::{compile_and_link_module, execute, finish_instantiation, Instance}; use wasmtime_execute::{compile_and_link_module, execute, finish_instantiation, Instance};
@ -148,23 +144,9 @@ fn main() {
fn handle_module(args: &Args, path: PathBuf, isa: &TargetIsa) -> Result<(), String> { fn handle_module(args: &Args, path: PathBuf, isa: &TargetIsa) -> Result<(), String> {
let mut data = read_to_end(path.clone()).map_err(|err| String::from(err.description()))?; let mut data = read_to_end(path.clone()).map_err(|err| String::from(err.description()))?;
// if data is using wat-format, first convert data to wasm
if !data.starts_with(&[b'\0', b'a', b's', b'm']) { if !data.starts_with(&[b'\0', b'a', b's', b'm']) {
let tmp_dir = TempDir::new("cranelift-wasm").unwrap(); data = wabt::wat2wasm(data).map_err(|err| String::from(err.description()))?;
let file_path = tmp_dir.path().join("module.wasm");
File::create(file_path.clone()).unwrap();
Command::new("wat2wasm")
.arg(path.clone())
.arg("-o")
.arg(file_path.to_str().unwrap())
.output()
.or_else(|e| {
if let io::ErrorKind::NotFound = e.kind() {
return Err(String::from("wat2wasm not found"));
} else {
return Err(String::from(e.description()));
}
})?;
data = read_to_end(file_path).map_err(|err| String::from(err.description()))?;
} }
let mut module = Module::new(); let mut module = Module::new();
let environ = ModuleEnvironment::new(isa, &mut module); let environ = ModuleEnvironment::new(isa, &mut module);

Loading…
Cancel
Save