Move get_module_info into the Engine

This commit is contained in:
Felix Schütt
2023-01-19 19:43:01 +01:00
parent af67c86621
commit b26b48794c
3 changed files with 14 additions and 30 deletions

View File

@@ -56,19 +56,8 @@ impl Artifact {
data: &[u8],
tunables: &dyn Tunables,
) -> Result<Self, CompileError> {
let artifact = Self::get_artifact_build(engine, data, tunables)?;
let mut inner_engine = engine.inner_mut();
Self::from_parts(&mut inner_engine, artifact)
}
#[cfg(feature = "compiler")]
fn get_artifact_build(
engine: &Engine,
data: &[u8],
tunables: &dyn Tunables,
) -> Result<ArtifactBuild, CompileError> {
let environ = ModuleEnvironment::new();
let mut inner_engine = engine.inner_mut();
let translation = environ.translate(data).map_err(CompileError::Wasm)?;
let module = translation.module;
let memory_styles: PrimaryMap<MemoryIndex, MemoryStyle> = module
@@ -90,18 +79,7 @@ impl Artifact {
table_styles,
)?;
Ok(artifact)
}
/// Compile a data buffer into a `ArtifactBuild`, which may then be instantiated.
#[cfg(feature = "compiler")]
pub fn get_module_info(
engine: &Engine,
data: &[u8],
tunables: &dyn Tunables,
) -> Result<ModuleInfo, CompileError> {
let artifact = Self::get_artifact_build(engine, data, tunables)?;
Ok(artifact.create_module_info())
Self::from_parts(&mut inner_engine, artifact)
}
/// Compile a data buffer into a `ArtifactBuild`, which may then be instantiated.

View File

@@ -74,6 +74,15 @@ impl Engine {
}
}
/// Returns only the `ModuleInfo` given a `wasm` byte slice
#[cfg(feature = "compiler")]
pub fn get_module_info(data: &[u8]) -> Result<ModuleInfo, CompileError> {
// this is from `artifact_builder.rs`
let environ = crate::ModuleEnvironment::new();
let translation = environ.translate(data).map_err(CompileError::Wasm)?;
Ok(translation.module)
}
/// Returns the name of this engine
pub fn name(&self) -> &str {
self.name.as_str()