From ec940ee8af74f2d7d59af156c90a3a3a888699e4 Mon Sep 17 00:00:00 2001 From: Frank Rehberger Date: Fri, 30 Nov 2018 17:44:44 +0100 Subject: [PATCH] Migrating to wabt::wat2wasm (#29) * Add test_environ_translate * Migrating to wabt::wat2wasm --- Cargo.toml | 3 --- src/main.rs | 24 +++--------------------- 2 files changed, 3 insertions(+), 24 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7e6a30ab8e..c15d39019a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,13 +28,10 @@ wasmtime-obj = { path = "lib/obj" } docopt = "1.0.1" serde = "1.0.75" serde_derive = "1.0.75" -tempdir = "*" faerie = "0.6.0" target-lexicon = { version = "0.2.0", default-features = false } pretty_env_logger = "0.2.5" file-per-thread-logger = "0.1.1" - -[dev-dependencies] wabt = "0.7" [workspace] diff --git a/src/main.rs b/src/main.rs index d4b3b5aa60..63bb9bdaa9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -44,9 +44,6 @@ extern crate wasmtime_execute; extern crate serde_derive; extern crate file_per_thread_logger; extern crate pretty_env_logger; -extern crate tempdir; - -#[cfg(test)] extern crate wabt; use cranelift_codegen::isa::TargetIsa; @@ -62,8 +59,7 @@ use std::io::prelude::*; use std::io::stdout; use std::path::Path; use std::path::PathBuf; -use std::process::{exit, Command}; -use tempdir::TempDir; +use std::process::exit; use wasmtime_environ::{Module, ModuleEnvironment}; 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> { 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']) { - let tmp_dir = TempDir::new("cranelift-wasm").unwrap(); - 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()))?; + data = wabt::wat2wasm(data).map_err(|err| String::from(err.description()))?; } let mut module = Module::new(); let environ = ModuleEnvironment::new(isa, &mut module);