mirror of
https://github.com/fluencelabs/wasmer
synced 2025-03-31 15:01:03 +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 <stdio.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
int main( int argc, char * argv [] ) {
|
int main() {
|
||||||
int x;
|
int x;
|
||||||
printf("ab%gc%nd\n", 1.23f, &x);
|
printf("ab%gc%nd\n", 1.23f, &x);
|
||||||
printf("n=%d\n", x);
|
printf("n=%d\n", x);
|
||||||
|
Binary file not shown.
@ -1,3 +1,4 @@
|
|||||||
ignore = [
|
ignore = [
|
||||||
"src/spectests",
|
"src/spectests",
|
||||||
|
"src/emtests",
|
||||||
]
|
]
|
||||||
|
@ -11,6 +11,7 @@ use cranelift_codegen::{
|
|||||||
isa,
|
isa,
|
||||||
settings::{self, Configurable},
|
settings::{self, Configurable},
|
||||||
};
|
};
|
||||||
|
use cranelift_wasm::ModuleEnvironment;
|
||||||
use std::panic;
|
use std::panic;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use target_lexicon;
|
use target_lexicon;
|
||||||
@ -226,11 +227,26 @@ pub fn start_instance(
|
|||||||
_ => panic!("_main emscripten function not found"),
|
_ => panic!("_main emscripten function not found"),
|
||||||
};
|
};
|
||||||
|
|
||||||
let main: extern "C" fn(u32, u32, &Instance) = get_instance_function!(instance, func_index);
|
let sig_index = module.get_func_type(func_index);
|
||||||
|
let signature = module.get_signature(sig_index);
|
||||||
let (argc, argv) = store_module_arguments(path, args, instance);
|
let num_params = signature.params.len();
|
||||||
|
match num_params {
|
||||||
call_protected!(main(argc, argv, &instance)).map_err(|err| format!("{}", err))
|
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__
|
// TODO: We should implement emscripten __ATEXIT__
|
||||||
} else {
|
} else {
|
||||||
let func_index =
|
let func_index =
|
||||||
|
Loading…
x
Reference in New Issue
Block a user