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

@@ -1,5 +1,5 @@
#![deny(trivial_numeric_casts, unused_extern_crates)]
#![warn(unused_import_braces, unstable_features)]
#![deny(trivial_numeric_casts)]
#![warn(unused_import_braces, unstable_features, unused_extern_crates)]
#![cfg_attr(feature="cargo-clippy", warn(
float_arithmetic,
mut_mut,
@@ -10,17 +10,25 @@
use_self,
))]
#[macro_use]
extern crate cfg_if;
extern crate cretonne_codegen;
extern crate cretonne_filetests;
extern crate cretonne_reader;
extern crate cretonne_wasm;
extern crate docopt;
extern crate filecheck;
#[macro_use]
extern crate serde_derive;
extern crate tempdir;
extern crate term;
extern crate capstone;
extern crate term;
cfg_if! {
if #[cfg(feature = "wasm")] {
extern crate cretonne_wasm;
extern crate wabt;
mod wasm;
}
}
use cretonne_codegen::{timing, VERSION};
use docopt::Docopt;
@@ -32,7 +40,6 @@ mod compile;
mod print_cfg;
mod rsfilecheck;
mod utils;
mod wasm;
const USAGE: &str = "
Cretonne code generator utility
@@ -114,7 +121,8 @@ fn cton_util() -> CommandResult {
&args.flag_isa,
)
} else if args.cmd_wasm {
wasm::run(
#[cfg(feature = "wasm")]
let result = wasm::run(
args.arg_file,
args.flag_verbose,
args.flag_just_decode,
@@ -123,7 +131,14 @@ fn cton_util() -> CommandResult {
&args.flag_set,
&args.flag_isa,
args.flag_print_size,
)
);
#[cfg(not(feature = "wasm"))]
let result = Err(
"Error: cton-util was compiled without wasm support.".to_owned(),
);
result
} else {
// Debugging / shouldn't happen with proper command line handling above.
Err(format!("Unhandled args: {:?}", args))

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());