diff --git a/cranelift/src/clif-util.rs b/cranelift/src/clif-util.rs index 8077cf9b23..19402d4bff 100755 --- a/cranelift/src/clif-util.rs +++ b/cranelift/src/clif-util.rs @@ -104,7 +104,13 @@ fn add_print_flag<'a>() -> clap::Arg<'a, 'a> { fn add_debug_flag<'a>() -> clap::Arg<'a, 'a> { Arg::with_name("debug") .short("d") - .help("enable debug output on stderr/stdout") + .help("Enable debug output on stderr/stdout") +} + +fn add_enable_simd_flag<'a>() -> clap::Arg<'a, 'a> { + Arg::with_name("enable-simd") + .long("enable-simd") + .help("Enable WASM's SIMD operations") } /// Returns a vector of clap value options and changes these options into a vector of strings @@ -137,6 +143,7 @@ fn add_wasm_or_compile<'a>(cmd: &str) -> clap::App<'a, 'a> { .arg(add_target_flag()) .arg(add_input_file_arg()) .arg(add_debug_flag()) + .arg(add_enable_simd_flag()) } fn handle_debug_flag(debug: bool) { @@ -296,6 +303,7 @@ fn main() { rest_cmd.is_present("print-size"), rest_cmd.is_present("time-passes"), rest_cmd.is_present("value-ranges"), + rest_cmd.is_present("enable-simd"), ) }; diff --git a/cranelift/src/wasm.rs b/cranelift/src/wasm.rs index f6b2036d57..cc55238822 100644 --- a/cranelift/src/wasm.rs +++ b/cranelift/src/wasm.rs @@ -19,7 +19,7 @@ use cranelift_wasm::{translate_module, DummyEnvironment, FuncIndex, ReturnMode}; use std::path::Path; use std::path::PathBuf; use term; -use wabt::wat2wasm; +use wabt::{wat2wasm_with_features, Features}; macro_rules! vprintln { ($x: expr, $($tts:tt)*) => { @@ -49,6 +49,7 @@ pub fn run( flag_print_size: bool, flag_report_times: bool, flag_calc_value_ranges: bool, + flag_enable_simd: bool, ) -> Result<(), String> { let parsed = parse_sets_and_triple(flag_set, flag_triple)?; @@ -64,6 +65,7 @@ pub fn run( flag_print_disasm, flag_report_times, flag_calc_value_ranges, + flag_enable_simd, &path.to_path_buf(), &name, parsed.as_fisa(), @@ -81,6 +83,7 @@ fn handle_module( flag_print_disasm: bool, flag_report_times: bool, flag_calc_value_ranges: bool, + flag_enable_simd: bool, path: &PathBuf, name: &str, fisa: FlagsOrIsa, @@ -97,7 +100,11 @@ fn handle_module( let mut module_binary = read_to_end(path.clone()).map_err(|err| err.to_string())?; if !module_binary.starts_with(&[b'\0', b'a', b's', b'm']) { - module_binary = match wat2wasm(&module_binary) { + let mut features = Features::new(); + if flag_enable_simd { + features.enable_simd(); + } + module_binary = match wat2wasm_with_features(&module_binary, features) { Ok(data) => data, Err(e) => return Err(e.to_string()), }; diff --git a/cranelift/wasm/tests/wasm_testsuite.rs b/cranelift/wasm/tests/wasm_testsuite.rs index 6b16f69791..fd46458d53 100644 --- a/cranelift/wasm/tests/wasm_testsuite.rs +++ b/cranelift/wasm/tests/wasm_testsuite.rs @@ -53,6 +53,8 @@ fn read_file(path: &Path) -> io::Result> { } fn handle_module(path: &Path, flags: &Flags, return_mode: ReturnMode) { + let mut features = Features::new(); + features.enable_all(); let data = match path.extension() { None => { panic!("the file extension is not wasm or wat"); @@ -61,8 +63,6 @@ fn handle_module(path: &Path, flags: &Flags, return_mode: ReturnMode) { Some("wasm") => read_file(path).expect("error reading wasm file"), Some("wat") => { let wat = read_file(path).expect("error reading wat file"); - let mut features = Features::new(); - features.enable_all(); match wat2wasm_with_features(&wat, features) { Ok(wasm) => wasm, Err(e) => {