Misc improvements

This commit is contained in:
Syrus
2020-06-11 14:25:13 -07:00
parent afc7e0f0b9
commit bf03c734fc
9 changed files with 98 additions and 77 deletions

View File

@@ -33,11 +33,6 @@ pub enum IoCompileError {
pub struct Module {
store: Store,
artifact: Arc<dyn Artifact>,
#[cfg(feature = "wat")]
#[doc(hidden)]
// If the module was compiled from a wat file.
pub from_wat: bool,
}
impl Module {
@@ -103,20 +98,12 @@ impl Module {
#[allow(unreachable_code)]
pub fn new(store: &Store, bytes: impl AsRef<[u8]>) -> Result<Module, CompileError> {
#[cfg(feature = "wat")]
{
let might_be_wat = !bytes.as_ref().starts_with(b"\0asm");
let bytes = wat::parse_bytes(bytes.as_ref()).map_err(|e| {
CompileError::Wasm(WasmError::Generic(format!(
"Error when converting wat: {}",
e
)))
})?;
let mut module = Module::from_binary(store, bytes.as_ref())?;
// We can assume it was a wat file if is not "wasm" looking
// and the previous step succeeded.
module.from_wat = might_be_wat;
return Ok(module);
}
let bytes = wat::parse_bytes(bytes.as_ref()).map_err(|e| {
CompileError::Wasm(WasmError::Generic(format!(
"Error when converting wat: {}",
e
)))
})?;
Module::from_binary(store, bytes.as_ref())
}
@@ -266,8 +253,6 @@ impl Module {
Module {
store: store.clone(),
artifact,
#[cfg(feature = "wat")]
from_wat: false,
}
}