mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-09 06:08:29 +00:00
Fixed code smell on Engine/CompiledModule
This commit is contained in:
@@ -208,7 +208,10 @@ impl Module {
|
|||||||
// of this steps traps, we still need to keep the instance alive
|
// of this steps traps, we still need to keep the instance alive
|
||||||
// as some of the Instance elements may have placed in other
|
// as some of the Instance elements may have placed in other
|
||||||
// instance tables.
|
// instance tables.
|
||||||
self.compiled.finish_instantiation(&instance_handle)?;
|
self.store
|
||||||
|
.engine()
|
||||||
|
.finish_instantiation(self.compiled.borrow(), &instance_handle)?;
|
||||||
|
|
||||||
Ok(instance_handle)
|
Ok(instance_handle)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -130,6 +130,16 @@ impl Engine for JITEngine {
|
|||||||
unsafe { compiled_module.instantiate(&self, resolver, Box::new(())) }
|
unsafe { compiled_module.instantiate(&self, resolver, Box::new(())) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Finish the instantiation of a WebAssembly module
|
||||||
|
unsafe fn finish_instantiation(
|
||||||
|
&self,
|
||||||
|
compiled_module: &dyn BaseCompiledModule,
|
||||||
|
handle: &InstanceHandle,
|
||||||
|
) -> Result<(), InstantiationError> {
|
||||||
|
let compiled_module = compiled_module.downcast_ref::<CompiledModule>().unwrap();
|
||||||
|
unsafe { compiled_module.finish_instantiation(&handle) }
|
||||||
|
}
|
||||||
|
|
||||||
/// Serializes a WebAssembly module
|
/// Serializes a WebAssembly module
|
||||||
fn serialize(
|
fn serialize(
|
||||||
&self,
|
&self,
|
||||||
|
|||||||
@@ -246,6 +246,21 @@ impl CompiledModule {
|
|||||||
.map_err(|trap| InstantiationError::Start(RuntimeError::from_trap(trap)))
|
.map_err(|trap| InstantiationError::Start(RuntimeError::from_trap(trap)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Finishes the instantiation of a just created `InstanceHandle`.
|
||||||
|
///
|
||||||
|
/// # Unsafety
|
||||||
|
///
|
||||||
|
/// See `InstanceHandle::finish_instantiation`
|
||||||
|
pub unsafe fn finish_instantiation(
|
||||||
|
&self,
|
||||||
|
handle: &InstanceHandle,
|
||||||
|
) -> Result<(), InstantiationError> {
|
||||||
|
let is_bulk_memory: bool = self.serializable.features.bulk_memory;
|
||||||
|
handle
|
||||||
|
.finish_instantiation(is_bulk_memory, &self.data_initializers())
|
||||||
|
.map_err(|trap| InstantiationError::Start(RuntimeError::from_trap(trap)))
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns data initializers to pass to `InstanceHandle::initialize`
|
/// Returns data initializers to pass to `InstanceHandle::initialize`
|
||||||
pub fn data_initializers(&self) -> Vec<DataInitializer<'_>> {
|
pub fn data_initializers(&self) -> Vec<DataInitializer<'_>> {
|
||||||
self.serializable
|
self.serializable
|
||||||
@@ -276,16 +291,6 @@ impl CompiledModule {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl BaseCompiledModule for CompiledModule {
|
impl BaseCompiledModule for CompiledModule {
|
||||||
unsafe fn finish_instantiation(
|
|
||||||
&self,
|
|
||||||
handle: &InstanceHandle,
|
|
||||||
) -> Result<(), InstantiationError> {
|
|
||||||
let is_bulk_memory: bool = self.serializable.features.bulk_memory;
|
|
||||||
handle
|
|
||||||
.finish_instantiation(is_bulk_memory, &self.data_initializers())
|
|
||||||
.map_err(|trap| InstantiationError::Start(RuntimeError::from_trap(trap)))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn module(&self) -> &Module {
|
fn module(&self) -> &Module {
|
||||||
&self.serializable.module
|
&self.serializable.module
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,6 +38,13 @@ pub trait Engine {
|
|||||||
resolver: &dyn Resolver,
|
resolver: &dyn Resolver,
|
||||||
) -> Result<InstanceHandle, InstantiationError>;
|
) -> Result<InstanceHandle, InstantiationError>;
|
||||||
|
|
||||||
|
/// Finish the instantiation of a WebAssembly module
|
||||||
|
unsafe fn finish_instantiation(
|
||||||
|
&self,
|
||||||
|
compiled_module: &dyn CompiledModule,
|
||||||
|
handle: &InstanceHandle,
|
||||||
|
) -> Result<(), InstantiationError>;
|
||||||
|
|
||||||
/// Serializes a WebAssembly module
|
/// Serializes a WebAssembly module
|
||||||
fn serialize(&self, compiled_module: &dyn CompiledModule) -> Result<Vec<u8>, SerializeError>;
|
fn serialize(&self, compiled_module: &dyn CompiledModule) -> Result<Vec<u8>, SerializeError>;
|
||||||
|
|
||||||
|
|||||||
@@ -8,21 +8,11 @@ use downcast_rs::{impl_downcast, Downcast};
|
|||||||
/// The `CompiledModule` trait is used by engine implementors, such
|
/// The `CompiledModule` trait is used by engine implementors, such
|
||||||
/// as a JIT or Native execution.
|
/// as a JIT or Native execution.
|
||||||
pub trait CompiledModule: Downcast {
|
pub trait CompiledModule: Downcast {
|
||||||
/// Finish instantiation of a `InstanceHandle`
|
/// Return a pointer to a module.
|
||||||
///
|
|
||||||
/// # Unsafety
|
|
||||||
///
|
|
||||||
/// See `InstanceHandle::finish_instantiation`
|
|
||||||
unsafe fn finish_instantiation(
|
|
||||||
&self,
|
|
||||||
handle: &InstanceHandle,
|
|
||||||
) -> Result<(), InstantiationError>;
|
|
||||||
|
|
||||||
/// Return a reference-counting pointer to a module.
|
|
||||||
fn module(&self) -> &Module;
|
fn module(&self) -> &Module;
|
||||||
|
|
||||||
/// Return a reference-counting pointer to a module.
|
/// Return a mutable pointer to a module.
|
||||||
fn module_mut(&mut self) -> &mut Module;
|
fn module_mut(&mut self) -> &mut Module;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl_downcast!(CompiledModule); // `sync` => also produce `Arc` downcasts.
|
impl_downcast!(CompiledModule);
|
||||||
|
|||||||
Reference in New Issue
Block a user