From b26b48794cc7b00bb5f939dfdf40bba94e9ba86c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 19 Jan 2023 19:43:01 +0100 Subject: [PATCH] Move get_module_info into the Engine --- lib/cli/src/commands/create_exe.rs | 11 ++++------- lib/compiler/src/engine/artifact.rs | 24 +----------------------- lib/compiler/src/engine/inner.rs | 9 +++++++++ 3 files changed, 14 insertions(+), 30 deletions(-) diff --git a/lib/cli/src/commands/create_exe.rs b/lib/cli/src/commands/create_exe.rs index 80d72eb56..7eb6f0362 100644 --- a/lib/cli/src/commands/create_exe.rs +++ b/lib/cli/src/commands/create_exe.rs @@ -224,7 +224,7 @@ impl CreateExe { return Err(anyhow::anyhow!("input path cannot be a directory")); } - let (store, compiler_type) = self.compiler.get_store_for_target(target.clone())?; + let (_, compiler_type) = self.compiler.get_store_for_target(target.clone())?; println!("Compiler: {}", compiler_type.to_string()); println!("Target: {}", target.triple()); @@ -273,7 +273,7 @@ impl CreateExe { ) }?; - get_module_infos(&tempdir, &atoms, object_format, &store)?; + get_module_infos(&tempdir, &atoms, object_format)?; let mut entrypoint = get_entrypoint(&tempdir)?; create_header_files_in_dir(&tempdir, &mut entrypoint, &atoms, &self.precompiled_atom)?; link_exe_from_dir( @@ -964,17 +964,14 @@ fn get_module_infos( directory: &Path, atoms: &[(String, Vec)], object_format: ObjectFormat, - store: &Store, ) -> Result, anyhow::Error> { let mut entrypoint = get_entrypoint(directory).with_context(|| anyhow::anyhow!("get module infos"))?; let mut module_infos = BTreeMap::new(); for (atom_name, atom_bytes) in atoms { - let tunables = BaseTunables::for_target(store.engine().target()); - let module_info = - Artifact::get_module_info(store.engine(), atom_bytes.as_slice(), &tunables) - .map_err(|e| anyhow::anyhow!("could not compile module {atom_name}: {e}"))?; + let module_info = Engine::get_module_info(atom_bytes.as_slice()) + .map_err(|e| anyhow::anyhow!("could not get module info for atom {atom_name}: {e}"))?; if let Some(s) = entrypoint .atoms diff --git a/lib/compiler/src/engine/artifact.rs b/lib/compiler/src/engine/artifact.rs index 4bddbe11e..2c9174752 100644 --- a/lib/compiler/src/engine/artifact.rs +++ b/lib/compiler/src/engine/artifact.rs @@ -56,19 +56,8 @@ impl Artifact { data: &[u8], tunables: &dyn Tunables, ) -> Result { - 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 { 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 = 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 { - 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. diff --git a/lib/compiler/src/engine/inner.rs b/lib/compiler/src/engine/inner.rs index 3abe6f6cd..d1c979d80 100644 --- a/lib/compiler/src/engine/inner.rs +++ b/lib/compiler/src/engine/inner.rs @@ -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 { + // 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()