mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-16 17:18:57 +00:00
Simplify instantiation
This commit is contained in:
@@ -223,19 +223,16 @@ impl Module {
|
|||||||
resolver: &dyn Resolver,
|
resolver: &dyn Resolver,
|
||||||
) -> Result<InstanceHandle, InstantiationError> {
|
) -> Result<InstanceHandle, InstantiationError> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let instance_handle = self
|
let instance_handle =
|
||||||
.store
|
self.artifact
|
||||||
.engine()
|
.instantiate(self.store.engine().as_ref(), resolver, Box::new(()))?;
|
||||||
.instantiate(self.artifact.borrow(), resolver)?;
|
|
||||||
|
|
||||||
// After the instance handle is created, we need to initialize
|
// After the instance handle is created, we need to initialize
|
||||||
// the data, call the start function and so. However, if any
|
// the data, call the start function and so. However, if any
|
||||||
// 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.store
|
self.artifact.finish_instantiation(&instance_handle)?;
|
||||||
.engine()
|
|
||||||
.finish_instantiation(self.artifact.borrow(), &instance_handle)?;
|
|
||||||
|
|
||||||
Ok(instance_handle)
|
Ok(instance_handle)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,12 +10,9 @@ use wasmer_compiler::{
|
|||||||
};
|
};
|
||||||
#[cfg(feature = "compiler")]
|
#[cfg(feature = "compiler")]
|
||||||
use wasmer_compiler::{Compiler, CompilerConfig};
|
use wasmer_compiler::{Compiler, CompilerConfig};
|
||||||
use wasmer_engine::{
|
use wasmer_engine::{Artifact, DeserializeError, Engine, SerializeError, Tunables};
|
||||||
Artifact, DeserializeError, Engine, InstantiationError, Resolver, SerializeError, Tunables,
|
|
||||||
};
|
|
||||||
use wasmer_runtime::{
|
use wasmer_runtime::{
|
||||||
InstanceHandle, ModuleInfo, SignatureRegistry, VMFunctionBody, VMSharedSignatureIndex,
|
ModuleInfo, SignatureRegistry, VMFunctionBody, VMSharedSignatureIndex, VMTrampoline,
|
||||||
VMTrampoline,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// A WebAssembly `JIT` Engine.
|
/// A WebAssembly `JIT` Engine.
|
||||||
@@ -120,30 +117,6 @@ impl Engine for JITEngine {
|
|||||||
Ok(Arc::new(JITArtifact::new(&self, binary)?))
|
Ok(Arc::new(JITArtifact::new(&self, binary)?))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Instantiates a WebAssembly module
|
|
||||||
unsafe fn instantiate(
|
|
||||||
&self,
|
|
||||||
compiled_module: &dyn Artifact,
|
|
||||||
resolver: &dyn Resolver,
|
|
||||||
) -> Result<InstanceHandle, InstantiationError> {
|
|
||||||
let compiled_module = compiled_module
|
|
||||||
.downcast_ref::<JITArtifact>()
|
|
||||||
.expect("The provided module is not a JIT compiled module");
|
|
||||||
compiled_module.instantiate(self, resolver, Box::new(()))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Finish the instantiation of a WebAssembly module
|
|
||||||
unsafe fn finish_instantiation(
|
|
||||||
&self,
|
|
||||||
compiled_module: &dyn Artifact,
|
|
||||||
handle: &InstanceHandle,
|
|
||||||
) -> Result<(), InstantiationError> {
|
|
||||||
let compiled_module = compiled_module
|
|
||||||
.downcast_ref::<JITArtifact>()
|
|
||||||
.expect("The provided module is not a JIT compiled module");
|
|
||||||
compiled_module.finish_instantiation(&handle)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Serializes a WebAssembly module
|
/// Serializes a WebAssembly module
|
||||||
fn serialize(&self, compiled_module: &dyn Artifact) -> Result<Vec<u8>, SerializeError> {
|
fn serialize(&self, compiled_module: &dyn Artifact) -> Result<Vec<u8>, SerializeError> {
|
||||||
let compiled_module = compiled_module
|
let compiled_module = compiled_module
|
||||||
|
|||||||
@@ -12,10 +12,8 @@ use wasm_common::FunctionType;
|
|||||||
use wasmer_compiler::CompileError;
|
use wasmer_compiler::CompileError;
|
||||||
#[cfg(feature = "compiler")]
|
#[cfg(feature = "compiler")]
|
||||||
use wasmer_compiler::{Compiler, CompilerConfig};
|
use wasmer_compiler::{Compiler, CompilerConfig};
|
||||||
use wasmer_engine::{
|
use wasmer_engine::{Artifact, DeserializeError, Engine, SerializeError, Tunables};
|
||||||
Artifact, DeserializeError, Engine, InstantiationError, Resolver, SerializeError, Tunables,
|
use wasmer_runtime::{SignatureRegistry, VMSharedSignatureIndex, VMTrampoline};
|
||||||
};
|
|
||||||
use wasmer_runtime::{InstanceHandle, SignatureRegistry, VMSharedSignatureIndex, VMTrampoline};
|
|
||||||
|
|
||||||
/// A WebAssembly `Native` Engine.
|
/// A WebAssembly `Native` Engine.
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
@@ -161,30 +159,6 @@ impl Engine for NativeEngine {
|
|||||||
Ok(Arc::new(NativeArtifact::new(&self, binary)?))
|
Ok(Arc::new(NativeArtifact::new(&self, binary)?))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Instantiates a WebAssembly module
|
|
||||||
unsafe fn instantiate(
|
|
||||||
&self,
|
|
||||||
compiled_module: &dyn Artifact,
|
|
||||||
resolver: &dyn Resolver,
|
|
||||||
) -> Result<InstanceHandle, InstantiationError> {
|
|
||||||
let compiled_module = compiled_module
|
|
||||||
.downcast_ref::<NativeArtifact>()
|
|
||||||
.expect("The provided module is not a Native compiled module");
|
|
||||||
compiled_module.instantiate(self, resolver, Box::new(()))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Finish the instantiation of a WebAssembly module
|
|
||||||
unsafe fn finish_instantiation(
|
|
||||||
&self,
|
|
||||||
compiled_module: &dyn Artifact,
|
|
||||||
handle: &InstanceHandle,
|
|
||||||
) -> Result<(), InstantiationError> {
|
|
||||||
let compiled_module = compiled_module
|
|
||||||
.downcast_ref::<NativeArtifact>()
|
|
||||||
.expect("The provided module is not a Native compiled module");
|
|
||||||
compiled_module.finish_instantiation(&handle)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Serializes a WebAssembly module
|
/// Serializes a WebAssembly module
|
||||||
fn serialize(&self, compiled_module: &dyn Artifact) -> Result<Vec<u8>, SerializeError> {
|
fn serialize(&self, compiled_module: &dyn Artifact) -> Result<Vec<u8>, SerializeError> {
|
||||||
let compiled_module = compiled_module
|
let compiled_module = compiled_module
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use crate::{resolve_imports, Engine, InstantiationError, Resolver, RuntimeError, Tunables};
|
use crate::{resolve_imports, Engine, InstantiationError, Resolver, RuntimeError};
|
||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use wasm_common::entity::{BoxedSlice, PrimaryMap};
|
use wasm_common::entity::{BoxedSlice, PrimaryMap};
|
||||||
@@ -8,8 +8,7 @@ use wasm_common::{
|
|||||||
};
|
};
|
||||||
use wasmer_compiler::Features;
|
use wasmer_compiler::Features;
|
||||||
use wasmer_runtime::{
|
use wasmer_runtime::{
|
||||||
InstanceHandle, MemoryPlan, ModuleInfo, SignatureRegistry, TablePlan, VMFunctionBody,
|
InstanceHandle, MemoryPlan, ModuleInfo, TablePlan, VMFunctionBody, VMSharedSignatureIndex,
|
||||||
VMSharedSignatureIndex,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use downcast_rs::{impl_downcast, Downcast};
|
use downcast_rs::{impl_downcast, Downcast};
|
||||||
|
|||||||
@@ -1,14 +1,12 @@
|
|||||||
//! JIT compilation.
|
//! JIT compilation.
|
||||||
|
|
||||||
use crate::error::InstantiationError;
|
|
||||||
use crate::resolver::Resolver;
|
|
||||||
use crate::tunables::Tunables;
|
use crate::tunables::Tunables;
|
||||||
use crate::{Artifact, DeserializeError, SerializeError};
|
use crate::{Artifact, DeserializeError, SerializeError};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use wasm_common::FunctionType;
|
use wasm_common::FunctionType;
|
||||||
use wasmer_compiler::CompileError;
|
use wasmer_compiler::CompileError;
|
||||||
use wasmer_runtime::{InstanceHandle, VMSharedSignatureIndex, VMTrampoline};
|
use wasmer_runtime::{VMSharedSignatureIndex, VMTrampoline};
|
||||||
|
|
||||||
/// A unimplemented Wasmer `Engine`.
|
/// A unimplemented Wasmer `Engine`.
|
||||||
///
|
///
|
||||||
@@ -34,20 +32,6 @@ pub trait Engine {
|
|||||||
/// Compile a WebAssembly binary
|
/// Compile a WebAssembly binary
|
||||||
fn compile(&self, binary: &[u8]) -> Result<Arc<dyn Artifact>, CompileError>;
|
fn compile(&self, binary: &[u8]) -> Result<Arc<dyn Artifact>, CompileError>;
|
||||||
|
|
||||||
/// Instantiates a WebAssembly module
|
|
||||||
unsafe fn instantiate(
|
|
||||||
&self,
|
|
||||||
compiled_module: &dyn Artifact,
|
|
||||||
resolver: &dyn Resolver,
|
|
||||||
) -> Result<InstanceHandle, InstantiationError>;
|
|
||||||
|
|
||||||
/// Finish the instantiation of a WebAssembly module
|
|
||||||
unsafe fn finish_instantiation(
|
|
||||||
&self,
|
|
||||||
compiled_module: &dyn Artifact,
|
|
||||||
handle: &InstanceHandle,
|
|
||||||
) -> Result<(), InstantiationError>;
|
|
||||||
|
|
||||||
/// Serializes a WebAssembly module
|
/// Serializes a WebAssembly module
|
||||||
fn serialize(&self, compiled_module: &dyn Artifact) -> Result<Vec<u8>, SerializeError>;
|
fn serialize(&self, compiled_module: &dyn Artifact) -> Result<Vec<u8>, SerializeError>;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user