mirror of
https://github.com/fluencelabs/wasmer
synced 2025-07-01 01:21:32 +00:00
Added ExecFunc
This commit is contained in:
@ -191,6 +191,42 @@ pub fn execute(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
pub fn execute_fn(
|
||||||
|
module: &Module,
|
||||||
|
compilation: &Compilation,
|
||||||
|
instance: &mut Instance,
|
||||||
|
func_name: String,
|
||||||
|
) -> Result<(), String> {
|
||||||
|
println!("execute");
|
||||||
|
|
||||||
|
let start_index = match module.exports.get(&func_name) {
|
||||||
|
Some(&Export::Function(index)) => index,
|
||||||
|
_ => panic!("No func name")
|
||||||
|
};
|
||||||
|
|
||||||
|
let code_buf = &compilation.functions[module
|
||||||
|
.defined_func_index(start_index)
|
||||||
|
.expect("imported start functions not supported yet")];
|
||||||
|
|
||||||
|
// Collect all memory base addresses and Vec.
|
||||||
|
let mut mem_base_addrs = instance
|
||||||
|
.memories
|
||||||
|
.iter_mut()
|
||||||
|
.map(LinearMemory::base_addr)
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
let vmctx = make_vmctx(instance, &mut mem_base_addrs);
|
||||||
|
|
||||||
|
unsafe {
|
||||||
|
let start_func = transmute::<_, fn(*const *mut u8)>(code_buf.as_ptr());
|
||||||
|
start_func(vmctx.as_ptr())
|
||||||
|
}
|
||||||
|
println!("{:?}", module.exports);
|
||||||
|
println!("execute end");
|
||||||
|
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
// pub fn execute_fn(
|
// pub fn execute_fn(
|
||||||
// instance: &mut Instance,
|
// instance: &mut Instance,
|
||||||
// func_name: String
|
// func_name: String
|
||||||
|
@ -12,8 +12,8 @@ use cranelift_codegen::isa::TargetIsa;
|
|||||||
use cranelift_codegen::settings;
|
use cranelift_codegen::settings;
|
||||||
use cranelift_codegen::settings::Configurable;
|
use cranelift_codegen::settings::Configurable;
|
||||||
|
|
||||||
pub use self::compilation::compile_module;
|
pub use self::compilation::{compile_module, Compilation};
|
||||||
pub use self::environ::ModuleEnvironment;
|
pub use self::environ::{ModuleEnvironment};
|
||||||
pub use self::module::Module;
|
pub use self::module::Module;
|
||||||
pub use self::instance::Instance;
|
pub use self::instance::Instance;
|
||||||
pub use self::errors::{Error, ErrorKind};
|
pub use self::errors::{Error, ErrorKind};
|
||||||
@ -26,7 +26,9 @@ pub struct ResultObject {
|
|||||||
pub module: Module,
|
pub module: Module,
|
||||||
/// A WebAssembly.Instance object that contains all the Exported WebAssembly
|
/// A WebAssembly.Instance object that contains all the Exported WebAssembly
|
||||||
/// functions.
|
/// functions.
|
||||||
pub instance: Instance
|
pub instance: Instance,
|
||||||
|
|
||||||
|
pub compilation: Compilation,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ImportObject {
|
pub struct ImportObject {
|
||||||
@ -77,7 +79,8 @@ pub fn instantiate(buffer_source: Vec<u8>, import_object: Option<ImportObject>)
|
|||||||
|
|
||||||
Ok(ResultObject {
|
Ok(ResultObject {
|
||||||
module,
|
module,
|
||||||
instance
|
instance,
|
||||||
|
compilation,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user