mirror of
https://github.com/fluencelabs/wasmer
synced 2025-03-16 08:10:49 +00:00
Update emscripten to latest changes
This commit is contained in:
parent
16a67c996a
commit
0bf6ce49f6
@ -32,7 +32,7 @@ impl FuncResolver for PlaceholderFuncResolver {
|
||||
|
||||
/// This contains all of the items in a `ModuleInner` except the `func_resolver`.
|
||||
pub struct Module {
|
||||
module: ModuleInner,
|
||||
pub module: ModuleInner,
|
||||
}
|
||||
|
||||
impl Module {
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -6,14 +6,16 @@ use std::ffi::CStr;
|
||||
use std::mem::size_of;
|
||||
use std::os::raw::c_char;
|
||||
use std::slice;
|
||||
use std::sync::Arc;
|
||||
/// We check if a provided module is an Emscripten generated one
|
||||
pub fn is_emscripten_module(module: &Module) -> bool {
|
||||
for (_, import_name) in &module.imported_functions {
|
||||
if import_name.name == "_emscripten_memcpy_big" && import_name.namespace == "env" {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
false
|
||||
pub fn is_emscripten_module(module: &Arc<Module>) -> bool {
|
||||
// for (_, import_name) in &module.imported_functions {
|
||||
// if import_name.name == "_emscripten_memcpy_big" && import_name.namespace == "env" {
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
// false
|
||||
true
|
||||
}
|
||||
|
||||
pub unsafe fn write_to_buf(string: *const c_char, buf: u32, max: u32, instance: &Instance) -> u32 {
|
||||
|
@ -24,7 +24,7 @@ pub(crate) struct InstanceInner {
|
||||
}
|
||||
|
||||
pub struct Instance {
|
||||
pub(crate) module: Rc<ModuleInner>,
|
||||
pub module: Rc<ModuleInner>,
|
||||
inner: Box<InstanceInner>,
|
||||
#[allow(dead_code)]
|
||||
imports: Box<Imports>,
|
||||
|
@ -3,7 +3,7 @@
|
||||
extern crate field_offset;
|
||||
|
||||
#[macro_use]
|
||||
mod macros;
|
||||
pub mod macros;
|
||||
#[doc(hidden)]
|
||||
pub mod backend;
|
||||
mod backing;
|
||||
|
@ -1,3 +1,4 @@
|
||||
#[macro_export]
|
||||
macro_rules! debug {
|
||||
($fmt:expr) => (if cfg!(any(debug_assertions, feature="debug")) { println!(concat!("wasmer-runtime(:{})::", $fmt), line!()) });
|
||||
($fmt:expr, $($arg:tt)*) => (if cfg!(any(debug_assertions, feature="debug")) { println!(concat!("wasmer-runtime(:{})::", $fmt, "\n"), line!(), $($arg)*) });
|
||||
|
@ -39,7 +39,7 @@ pub struct ModuleInner {
|
||||
pub sig_registry: SigRegistry,
|
||||
}
|
||||
|
||||
pub struct Module(Rc<ModuleInner>);
|
||||
pub struct Module(pub Rc<ModuleInner>);
|
||||
|
||||
impl Module {
|
||||
pub(crate) fn new(inner: Rc<ModuleInner>) -> Self {
|
||||
|
@ -83,26 +83,23 @@ fn execute_wasm(options: &Run) -> Result<(), String> {
|
||||
|
||||
let emscripten_globals = wasmer_emscripten::EmscriptenGlobals::new();
|
||||
|
||||
let import_object = if abi == webassembly::InstanceABI::Emscripten {
|
||||
let mut import_object = if abi == webassembly::InstanceABI::Emscripten {
|
||||
wasmer_emscripten::generate_emscripten_env(&emscripten_globals)
|
||||
} else {
|
||||
wasmer_runtime::import::Imports::new()
|
||||
};
|
||||
|
||||
let import_object = Rc::new(import_object);
|
||||
|
||||
let instance_options = webassembly::InstanceOptions {
|
||||
mock_missing_imports: true,
|
||||
mock_missing_globals: true,
|
||||
mock_missing_tables: true,
|
||||
abi: abi,
|
||||
show_progressbar: true,
|
||||
// isa: isa,
|
||||
};
|
||||
|
||||
debug!("webassembly - creating instance");
|
||||
|
||||
let mut instance = module.instantiate(import_object)
|
||||
let mut instance = module.instantiate(&mut import_object)
|
||||
.map_err(|err| format!("Can't instantiate the WebAssembly module: {}", err))?;
|
||||
|
||||
webassembly::start_instance(
|
||||
|
@ -6,7 +6,7 @@ pub mod utils;
|
||||
use wasmer_clif_backend::CraneliftCompiler;
|
||||
use wasmer_runtime::{
|
||||
backend::Compiler,
|
||||
module::Module,
|
||||
module::{Module, ModuleInner},
|
||||
import::Imports,
|
||||
instance::Instance,
|
||||
};
|
||||
@ -17,6 +17,7 @@ use cranelift_codegen::{
|
||||
use std::panic;
|
||||
use std::str::FromStr;
|
||||
use std::sync::Arc;
|
||||
use std::rc::Rc;
|
||||
use target_lexicon;
|
||||
use wasmparser;
|
||||
use wasmparser::WasmDecoder;
|
||||
@ -122,11 +123,11 @@ pub fn instantiate_streaming(
|
||||
/// webassembly::CompileError.
|
||||
pub fn compile(buffer_source: &[u8]) -> Result<Arc<Module>, ErrorKind> {
|
||||
let compiler = &CraneliftCompiler {};
|
||||
let module = compiler
|
||||
let module_inner = compiler
|
||||
.compile(buffer_source)
|
||||
.map_err(|e| ErrorKind::CompileError(e))?;
|
||||
|
||||
Ok(Arc::new(module))
|
||||
Ok(Arc::new(Module(Rc::new(module_inner))))
|
||||
}
|
||||
|
||||
/// The webassembly::validate() function validates a given typed
|
||||
@ -230,7 +231,7 @@ pub fn start_instance(
|
||||
path: &str,
|
||||
args: Vec<&str>,
|
||||
) -> Result<(), String> {
|
||||
let main_name = if is_emscripten_module(&instance.module) {
|
||||
let main_name = if is_emscripten_module(&module) {
|
||||
"_main"
|
||||
} else {
|
||||
"main"
|
||||
|
Loading…
x
Reference in New Issue
Block a user