Skip to content

Commit

Permalink
Improved store returned data
Browse files Browse the repository at this point in the history
  • Loading branch information
syrusakbary committed Jun 4, 2020
1 parent 80c6b5c commit 78ef13a
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 64 deletions.
19 changes: 9 additions & 10 deletions src/commands/compile.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::store::StoreOptions;
use crate::store::{EngineType, StoreOptions};
use crate::warning;
use anyhow::{Context, Result};
use std::path::PathBuf;
Expand All @@ -21,7 +21,7 @@ pub struct Compile {
target_triple: Option<Triple>,

#[structopt(flatten)]
compiler: StoreOptions,
store: StoreOptions,

#[structopt(short = "m", multiple = true)]
cpu_features: Vec<CpuFeature>,
Expand All @@ -47,15 +47,15 @@ impl Compile {
} else {
Target::default()
};
let (store, engine_name, compiler_name) =
self.compiler.get_store_for_target(target.clone())?;
let (store, engine_type, compiler_type) =
self.store.get_store_for_target(target.clone())?;
let output_filename = self
.output
.file_stem()
.map(|osstr| osstr.to_string_lossy().to_string())
.unwrap_or_default();
let recommended_extension = match engine_name.as_ref() {
"native" => {
let recommended_extension = match engine_type {
EngineType::Native => {
// TODO: Match it depending on the `BinaryFormat` instead of the
// `OperatingSystem`.
match target.triple().operating_system {
Expand All @@ -65,8 +65,7 @@ impl Compile {
_ => "so",
}
}
"jit" => "wjit",
_ => "?",
EngineType::JIT => "wjit",
};
match self.output.extension() {
Some(ext) => {
Expand All @@ -78,8 +77,8 @@ impl Compile {
warning!("the output file has no extension. We recommend using `{}.{}` for the chosen target", &output_filename, &recommended_extension)
}
}
println!("Engine: {}", engine_name);
println!("Compiler: {}", compiler_name);
println!("Engine: {}", engine_type.to_string());
println!("Compiler: {}", compiler_type.to_string());
println!("Target: {}", target.triple());
let module = Module::from_file(&store, &self.path)?;
let _ = module.serialize_to_file(&self.output)?;
Expand Down
4 changes: 2 additions & 2 deletions src/commands/inspect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub struct Inspect {
path: PathBuf,

#[structopt(flatten)]
compiler: StoreOptions,
store: StoreOptions,
}

impl Inspect {
Expand All @@ -23,7 +23,7 @@ impl Inspect {
.context(format!("failed to inspect `{}`", self.path.display()))
}
fn inner_execute(&self) -> Result<()> {
let (store, _engine_name, _compiler_name) = self.compiler.get_store()?;
let (store, _engine_type, _compiler_type) = self.store.get_store()?;
let module_contents = std::fs::read(&self.path)?;
let module = Module::new(&store, &module_contents)?;
println!("Type: {}", if module.from_wat { "wat" } else { "wasm" });
Expand Down
7 changes: 4 additions & 3 deletions src/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub struct Run {
cache_key: Option<String>,

#[structopt(flatten)]
compiler: StoreOptions,
store: StoreOptions,

#[cfg(feature = "wasi")]
#[structopt(flatten)]
Expand Down Expand Up @@ -153,14 +153,15 @@ impl Run {
return Ok(module);
}
}
let (store, engine_name, compiler_name) = self.compiler.get_store()?;
let (store, engine_type, compiler_type) = self.store.get_store()?;
// We try to get it from cache, in case caching is enabled
// and the file length is greater than 4KB.
// For files smaller than 4KB caching is not worth,
// as it takes space and the speedup is minimal.
let mut module =
if cfg!(feature = "cache") && !self.disable_cache && contents.len() > 0x1000 {
let mut cache = self.get_cache(engine_name, compiler_name)?;
let mut cache =
self.get_cache(engine_type.to_string(), compiler_type.to_string())?;
// Try to get the hash from the provided `--cache-key`, otherwise
// generate one from the provided file `.wasm` contents.
let hash = self
Expand Down
4 changes: 2 additions & 2 deletions src/commands/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub struct Validate {
path: PathBuf,

#[structopt(flatten)]
compiler: StoreOptions,
store: StoreOptions,
}

impl Validate {
Expand All @@ -22,7 +22,7 @@ impl Validate {
.context(format!("failed to validate `{}`", self.path.display()))
}
fn inner_execute(&self) -> Result<()> {
let (store, _engine_name, _compiler_name) = self.compiler.get_store()?;
let (store, _engine_type, _compiler_type) = self.store.get_store()?;
let module_contents = std::fs::read(&self.path)?;
Module::validate(&store, &module_contents)?;
eprintln!("Validation passed for `{}`.", self.path.display());
Expand Down
4 changes: 2 additions & 2 deletions src/commands/wast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub struct Wast {
path: PathBuf,

#[structopt(flatten)]
compiler: StoreOptions,
store: StoreOptions,

#[structopt(short, long)]
/// A flag to indicate wast stop at the first error or continue.
Expand All @@ -27,7 +27,7 @@ impl Wast {
.context(format!("failed to test the wast `{}`", self.path.display()))
}
fn inner_execute(&self) -> Result<()> {
let (store, _engine_name, _compiler_name) = self.compiler.get_store()?;
let (store, _engine_name, _compiler_name) = self.store.get_store()?;
let mut wast = WastSpectest::new_with_spectest(store);
wast.fail_fast = self.fail_fast;
wast.run_file(&self.path).with_context(|| "tests failed")?;
Expand Down
Loading

0 comments on commit 78ef13a

Please sign in to comment.