mirror of
https://github.com/fluencelabs/wasmer
synced 2024-12-13 06:15:33 +00:00
Merge pull request #60 from wasmerio/fix/emscripten-main-zero-params
Added support for 0 or 2 params in main emscripten function
This commit is contained in:
commit
1f3aec4029
@ -8,7 +8,7 @@
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
int main( int argc, char * argv [] ) {
|
||||
int main() {
|
||||
int x;
|
||||
printf("ab%gc%nd\n", 1.23f, &x);
|
||||
printf("n=%d\n", x);
|
||||
|
Binary file not shown.
@ -1,3 +1,4 @@
|
||||
ignore = [
|
||||
"src/spectests",
|
||||
"src/emtests",
|
||||
]
|
||||
|
@ -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 =
|
||||
|
Loading…
Reference in New Issue
Block a user