Use wabt, and make the wasm subcommand optional. (#347)

* Use wabt for wasm testing.

* Use wabt in cton-util.

* Make the wasm subcommand optional.
This commit is contained in:
Ram
2018-05-25 01:23:00 +10:00
committed by Dan Gohman
parent b855184ae1
commit 4afb28ef59
6 changed files with 48 additions and 74 deletions

View File

@@ -9,14 +9,11 @@ use cretonne_codegen::print_errors::{pretty_error, pretty_verifier_error};
use cretonne_codegen::settings::FlagsOrIsa;
use cretonne_wasm::{translate_module, DummyEnvironment, ModuleEnvironment};
use std::error::Error;
use std::fs::File;
use std::io;
use std::path::Path;
use std::path::PathBuf;
use std::process::Command;
use tempdir::TempDir;
use term;
use utils::{parse_sets_and_isa, read_to_end};
use wabt::wat2wasm;
macro_rules! vprintln {
($x: expr, $($tts:tt)*) => {
@@ -85,23 +82,12 @@ fn handle_module(
let mut data = read_to_end(path.clone()).map_err(|err| {
String::from(err.description())
})?;
if !data.starts_with(&[b'\0', b'a', b's', b'm']) {
let tmp_dir = TempDir::new("cretonne-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 = match wat2wasm(&data) {
Ok(data) => data,
Err(e) => return Err(String::from(e.description())),
};
}
let mut dummy_environ = DummyEnvironment::with_flags(fisa.flags.clone());