diff --git a/emtests/printf.c b/emtests/printf.c index 3f2ad8b71..55abc0ad5 100644 --- a/emtests/printf.c +++ b/emtests/printf.c @@ -8,7 +8,7 @@ #include #include -int main( int argc, char * argv [] ) { +int main() { int x; printf("ab%gc%nd\n", 1.23f, &x); printf("n=%d\n", x); diff --git a/emtests/printf.wasm b/emtests/printf.wasm index 0d4197a24..bd5c1ebf4 100644 Binary files a/emtests/printf.wasm and b/emtests/printf.wasm differ diff --git a/rustfmt.toml b/rustfmt.toml index dc26521c0..4a3e0232a 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1,3 +1,4 @@ ignore = [ "src/spectests", + "src/emtests", ] diff --git a/src/webassembly/mod.rs b/src/webassembly/mod.rs index 5c679ba48..d91ac003f 100644 --- a/src/webassembly/mod.rs +++ b/src/webassembly/mod.rs @@ -11,6 +11,7 @@ use cranelift_codegen::{ isa, settings::{self, Configurable}, }; +use cranelift_wasm::ModuleEnvironment; use std::panic; use std::str::FromStr; use target_lexicon; @@ -226,11 +227,26 @@ pub fn start_instance( _ => panic!("_main emscripten function not found"), }; - let main: extern "C" fn(u32, u32, &Instance) = get_instance_function!(instance, func_index); - - let (argc, argv) = store_module_arguments(path, args, instance); - - call_protected!(main(argc, argv, &instance)).map_err(|err| format!("{}", err)) + let sig_index = module.get_func_type(func_index); + let signature = module.get_signature(sig_index); + let num_params = signature.params.len(); + match num_params { + 2 => { + let main: extern "C" fn(u32, u32, &Instance) = + get_instance_function!(instance, func_index); + let (argc, argv) = store_module_arguments(path, args, instance); + call_protected!(main(argc, argv, &instance)) + } + 0 => { + let main: extern "C" fn(&Instance) = get_instance_function!(instance, func_index); + call_protected!(main(&instance)) + } + _ => panic!( + "The emscripten main function has received an incorrect number of params {}", + num_params + ), + } + .map_err(|err| format!("{}", err)) // TODO: We should implement emscripten __ATEXIT__ } else { let func_index =