Pass enabled features (e.g. --enable-simd) on to WABT when running WAST files
This commit is contained in:
@@ -107,6 +107,11 @@ impl Context {
|
|||||||
Self::new(Box::new(Compiler::new(isa)))
|
Self::new(Box::new(Compiler::new(isa)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Retrieve the context features
|
||||||
|
pub fn features(&self) -> &Features {
|
||||||
|
&self.features
|
||||||
|
}
|
||||||
|
|
||||||
/// Construct a new instance with the given features from the current `Context`
|
/// Construct a new instance with the given features from the current `Context`
|
||||||
pub fn with_features(self, features: Features) -> Self {
|
pub fn with_features(self, features: Features) -> Self {
|
||||||
Self { features, ..self }
|
Self { features, ..self }
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ use std::io::Read;
|
|||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::{fmt, fs, io, str};
|
use std::{fmt, fs, io, str};
|
||||||
use wabt::script::{Action, Command, CommandKind, ModuleBinary, ScriptParser, Value};
|
use wabt::script::{Action, Command, CommandKind, ModuleBinary, ScriptParser, Value};
|
||||||
|
use wabt::Features as WabtFeatures;
|
||||||
use wasmtime_jit::{
|
use wasmtime_jit::{
|
||||||
ActionError, ActionOutcome, Compiler, Context, Features, InstanceHandle, InstantiationError,
|
ActionError, ActionOutcome, Compiler, Context, Features, InstanceHandle, InstantiationError,
|
||||||
RuntimeValue, UnknownInstance,
|
RuntimeValue, UnknownInstance,
|
||||||
@@ -196,17 +197,24 @@ impl WastContext {
|
|||||||
|
|
||||||
/// Run a wast script from a byte buffer.
|
/// Run a wast script from a byte buffer.
|
||||||
pub fn run_buffer(&mut self, filename: &str, wast: &[u8]) -> Result<(), WastFileError> {
|
pub fn run_buffer(&mut self, filename: &str, wast: &[u8]) -> Result<(), WastFileError> {
|
||||||
let mut parser =
|
let features: WabtFeatures = convert_features(self.context.features());
|
||||||
ScriptParser::from_str(str::from_utf8(wast).map_err(|error| WastFileError {
|
let test_filename = "test.wast"; // TODO apparently we can't use filename because this breaks the execution
|
||||||
filename: filename.to_string(),
|
let mut parser = ScriptParser::from_source_and_name_with_features(
|
||||||
line: 0,
|
str::from_utf8(wast)
|
||||||
error: WastError::Utf8(error),
|
.map_err(|error| WastFileError {
|
||||||
})?)
|
filename: filename.to_string(),
|
||||||
.map_err(|error| WastFileError {
|
line: 0,
|
||||||
filename: filename.to_string(),
|
error: WastError::Utf8(error),
|
||||||
line: 0,
|
})?
|
||||||
error: WastError::Syntax(error),
|
.as_bytes(),
|
||||||
})?;
|
test_filename,
|
||||||
|
features,
|
||||||
|
)
|
||||||
|
.map_err(|error| WastFileError {
|
||||||
|
filename: filename.to_string(),
|
||||||
|
line: 0,
|
||||||
|
error: WastError::Syntax(error),
|
||||||
|
})?;
|
||||||
|
|
||||||
while let Some(Command { kind, line }) = parser.next().expect("parser") {
|
while let Some(Command { kind, line }) = parser.next().expect("parser") {
|
||||||
match kind {
|
match kind {
|
||||||
@@ -520,3 +528,22 @@ fn read_to_end(path: &Path) -> Result<Vec<u8>, io::Error> {
|
|||||||
file.read_to_end(&mut buf)?;
|
file.read_to_end(&mut buf)?;
|
||||||
Ok(buf)
|
Ok(buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Helper to convert wasmtime features to WABT features; would be nicer as Into<WabtFeatures> but
|
||||||
|
/// wasmtime-jit does not have a wabt dependency
|
||||||
|
fn convert_features(features: &Features) -> WabtFeatures {
|
||||||
|
let mut wabt_features = WabtFeatures::new();
|
||||||
|
if features.simd {
|
||||||
|
wabt_features.enable_simd()
|
||||||
|
}
|
||||||
|
if features.multi_value {
|
||||||
|
wabt_features.enable_multi_value()
|
||||||
|
}
|
||||||
|
if features.bulk_memory {
|
||||||
|
wabt_features.enable_bulk_memory()
|
||||||
|
}
|
||||||
|
if features.threads {
|
||||||
|
wabt_features.enable_threads()
|
||||||
|
}
|
||||||
|
wabt_features
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user