fix master; add some emscripten calls

This commit is contained in:
Mark McCaskey
2019-04-05 10:04:39 -07:00
parent d9114e40bc
commit 91d7416680
4 changed files with 61 additions and 29 deletions

View File

@ -23,3 +23,8 @@ pub fn ___cxa_begin_catch(_ctx: &mut Ctx, _exception_object_ptr: u32) -> i32 {
pub fn ___cxa_end_catch(_ctx: &mut Ctx) { pub fn ___cxa_end_catch(_ctx: &mut Ctx) {
debug!("emscripten::___cxa_end_catch"); debug!("emscripten::___cxa_end_catch");
} }
pub fn ___cxa_uncaught_exception(_ctx: &mut Ctx) -> i32 {
debug!("emscripten::___cxa_uncaught_exception");
-1
}

View File

@ -607,6 +607,7 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject
"___cxa_throw" => func!(crate::exception::___cxa_throw), "___cxa_throw" => func!(crate::exception::___cxa_throw),
"___cxa_begin_catch" => func!(crate::exception::___cxa_begin_catch), "___cxa_begin_catch" => func!(crate::exception::___cxa_begin_catch),
"___cxa_end_catch" => func!(crate::exception::___cxa_end_catch), "___cxa_end_catch" => func!(crate::exception::___cxa_end_catch),
"___cxa_uncaught_exception" => func!(crate::exception::___cxa_uncaught_exception),
// Time // Time
"_gettimeofday" => func!(crate::time::_gettimeofday), "_gettimeofday" => func!(crate::time::_gettimeofday),
@ -619,6 +620,7 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject
"_localtime" => func!(crate::time::_localtime), "_localtime" => func!(crate::time::_localtime),
"_time" => func!(crate::time::_time), "_time" => func!(crate::time::_time),
"_strftime" => func!(crate::time::_strftime), "_strftime" => func!(crate::time::_strftime),
"_strftime_l" => func!(crate::time::_strftime_l),
"_localtime_r" => func!(crate::time::_localtime_r), "_localtime_r" => func!(crate::time::_localtime_r),
"_gmtime_r" => func!(crate::time::_gmtime_r), "_gmtime_r" => func!(crate::time::_gmtime_r),
"_mktime" => func!(crate::time::_mktime), "_mktime" => func!(crate::time::_mktime),

View File

@ -310,3 +310,20 @@ pub fn _strftime(
); );
0 0
} }
/// emscripten: _strftime_l
pub fn _strftime_l(
ctx: &mut Ctx,
s_ptr: c_int,
maxsize: u32,
format_ptr: c_int,
tm_ptr: c_int,
_last: c_int,
) -> i32 {
debug!(
"emscripten::_strftime_l {} {} {} {}",
s_ptr, maxsize, format_ptr, tm_ptr
);
_strftime(ctx, s_ptr, maxsize, format_ptr, tm_ptr)
}

View File

@ -17,6 +17,20 @@ use wasmer_runtime_core::{self, backend::CompilerConfig};
#[cfg(feature = "wasi")] #[cfg(feature = "wasi")]
use wasmer_wasi; use wasmer_wasi;
// stub module to make conditional compilation happy
#[cfg(not(feature = "wasi"))]
mod wasmer_wasi {
use wasmer_runtime_core::{import::ImportObject, module::Module};
pub fn is_wasi_module(_module: &Module) -> bool {
false
}
pub fn generate_import_object(_args: Vec<Vec<u8>>, _envs: Vec<Vec<u8>>) -> ImportObject {
unimplemented!()
}
}
#[derive(Debug, StructOpt)] #[derive(Debug, StructOpt)]
#[structopt(name = "wasmer", about = "Wasm execution runtime.")] #[structopt(name = "wasmer", about = "Wasm execution runtime.")]
/// The options for the wasmer Command Line Interface /// The options for the wasmer Command Line Interface
@ -213,7 +227,6 @@ fn execute_wasm(options: &Run) -> Result<(), String> {
}; };
// TODO: refactor this // TODO: refactor this
#[cfg(not(feature = "wasi"))]
let (abi, import_object, _em_globals) = if wasmer_emscripten::is_emscripten_module(&module) { let (abi, import_object, _em_globals) = if wasmer_emscripten::is_emscripten_module(&module) {
let mut emscripten_globals = wasmer_emscripten::EmscriptenGlobals::new(&module); let mut emscripten_globals = wasmer_emscripten::EmscriptenGlobals::new(&module);
( (
@ -222,34 +235,29 @@ fn execute_wasm(options: &Run) -> Result<(), String> {
Some(emscripten_globals), // TODO Em Globals is here to extend, lifetime, find better solution Some(emscripten_globals), // TODO Em Globals is here to extend, lifetime, find better solution
) )
} else { } else {
( if cfg!(feature = "wasi") && wasmer_wasi::is_wasi_module(&module) {
InstanceABI::None, (
wasmer_runtime_core::import::ImportObject::new(), InstanceABI::WASI,
None, wasmer_wasi::generate_import_object(
) [options.path.to_str().unwrap().to_owned()]
}; .iter()
.chain(options.args.iter())
#[cfg(feature = "wasi")] .cloned()
let (abi, import_object) = if wasmer_wasi::is_wasi_module(&module) { .map(|arg| arg.into_bytes())
( .collect(),
InstanceABI::WASI, env::vars()
wasmer_wasi::generate_import_object( .map(|(k, v)| format!("{}={}", k, v).into_bytes())
[options.path.to_str().unwrap().to_owned()] .collect(),
.iter() ),
.chain(options.args.iter()) None,
.cloned() )
.map(|arg| arg.into_bytes()) } else {
.collect(), (
env::vars() InstanceABI::None,
.map(|(k, v)| format!("{}={}", k, v).into_bytes()) wasmer_runtime_core::import::ImportObject::new(),
.collect(), None,
), )
) }
} else {
(
InstanceABI::None,
wasmer_runtime_core::import::ImportObject::new(),
)
}; };
let mut instance = module let mut instance = module