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