Use --enable-simd to control whether SIMD is enabled in the wasmparser.

Before this change, 'wasmer run --backend=llvm some-simd.wasm' would run without complaint.

Also, note that the flag is not part of the cache key, so after any successful run, we can run it again without passing the flag.
This commit is contained in:
Nick Lewycky 2019-07-27 11:13:13 -07:00 committed by Nick Lewycky
parent 514eb70194
commit 86316c474a
3 changed files with 13 additions and 8 deletions

View File

@ -1,6 +1,6 @@
use crate::{ use crate::{
backend::RunnableModule, backend::RunnableModule,
backend::{Backend, CacheGen, Compiler, CompilerConfig, Token}, backend::{Backend, CacheGen, Compiler, CompilerConfig, Features, Token},
cache::{Artifact, Error as CacheError}, cache::{Artifact, Error as CacheError},
error::{CompileError, CompileResult}, error::{CompileError, CompileResult},
module::{ModuleInfo, ModuleInner}, module::{ModuleInfo, ModuleInner},
@ -137,12 +137,12 @@ impl<
} }
} }
pub fn default_validating_parser_config() -> wasmparser::ValidatingParserConfig { pub fn validating_parser_config(features: &Features) -> wasmparser::ValidatingParserConfig {
wasmparser::ValidatingParserConfig { wasmparser::ValidatingParserConfig {
operator_config: wasmparser::OperatorValidatorConfig { operator_config: wasmparser::OperatorValidatorConfig {
enable_threads: false, enable_threads: false,
enable_reference_types: false, enable_reference_types: false,
enable_simd: true, enable_simd: features.simd,
enable_bulk_memory: false, enable_bulk_memory: false,
enable_multi_value: false, enable_multi_value: false,
}, },
@ -150,9 +150,9 @@ pub fn default_validating_parser_config() -> wasmparser::ValidatingParserConfig
} }
} }
fn validate(bytes: &[u8]) -> CompileResult<()> { fn validate(bytes: &[u8], features: &Features) -> CompileResult<()> {
let mut parser = let mut parser =
wasmparser::ValidatingParser::new(bytes, Some(default_validating_parser_config())); wasmparser::ValidatingParser::new(bytes, Some(validating_parser_config(features)));
loop { loop {
let state = parser.read(); let state = parser.read();
match *state { match *state {
@ -180,7 +180,7 @@ impl<
_: Token, _: Token,
) -> CompileResult<ModuleInner> { ) -> CompileResult<ModuleInner> {
if requires_pre_validation(MCG::backend_id()) { if requires_pre_validation(MCG::backend_id()) {
validate(wasm)?; validate(wasm, &compiler_config.features)?;
} }
let mut mcg = MCG::new(); let mut mcg = MCG::new();

View File

@ -85,8 +85,10 @@ pub fn read_module<
custom_sections: HashMap::new(), custom_sections: HashMap::new(),
})); }));
let mut parser = let mut parser = wasmparser::ValidatingParser::new(
wasmparser::ValidatingParser::new(wasm, Some(default_validating_parser_config())); wasm,
Some(validating_parser_config(&compiler_config.features)),
);
let mut namespace_builder = Some(StringTableBuilder::new()); let mut namespace_builder = Some(StringTableBuilder::new());
let mut name_builder = Some(StringTableBuilder::new()); let mut name_builder = Some(StringTableBuilder::new());

View File

@ -440,6 +440,9 @@ fn execute_wasm(options: &Run) -> Result<(), String> {
CompilerConfig { CompilerConfig {
symbol_map: em_symbol_map, symbol_map: em_symbol_map,
track_state, track_state,
features: Features {
simd: options.features.simd || options.features.all,
},
..Default::default() ..Default::default()
}, },
&*compiler, &*compiler,