Skip to content
This repository was archived by the owner on Jun 26, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cranelift-wasm/tests/wasm_testsuite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ fn read_file(path: &Path) -> io::Result<Vec<u8>> {
}

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");
Expand All @@ -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) => {
Expand Down
10 changes: 9 additions & 1 deletion src/clif-util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this different from --set=enable_simd=true?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--set=enable_simd=true will set the flags for the TargetIsa whereas this one is used for telling wabt that we want to parse WASM and not fail on SIMD operators.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, of course. Maybe the string could say "Enable wasm SIMD operations" then?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


/// Returns a vector of clap value options and changes these options into a vector of strings
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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"),
)
};

Expand Down
11 changes: 9 additions & 2 deletions src/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)*) => {
Expand Down Expand Up @@ -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)?;

Expand All @@ -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(),
Expand All @@ -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,
Expand All @@ -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()),
};
Expand Down