Re-org memory allocation interfaces, add --stack-size and --heap-size option (#193)
This commit is contained in:
@ -8,7 +8,6 @@
|
||||
#include "bh_platform.h"
|
||||
#include "bh_assert.h"
|
||||
#include "bh_log.h"
|
||||
#include "bh_memory.h"
|
||||
#include "wasm_export.h"
|
||||
#include "test_wasm.h"
|
||||
|
||||
@ -63,6 +62,7 @@ void iwasm_main(void *arg1, void *arg2, void *arg3)
|
||||
uint32 wasm_file_size;
|
||||
wasm_module_t wasm_module = NULL;
|
||||
wasm_module_inst_t wasm_module_inst = NULL;
|
||||
RuntimeInitArgs init_args;
|
||||
char error_buf[128];
|
||||
#if WASM_ENABLE_LOG != 0
|
||||
int log_verbose_level = 2;
|
||||
@ -72,15 +72,17 @@ void iwasm_main(void *arg1, void *arg2, void *arg3)
|
||||
(void) arg2;
|
||||
(void) arg3;
|
||||
|
||||
if (bh_memory_init_with_pool(global_heap_buf, sizeof(global_heap_buf))
|
||||
!= 0) {
|
||||
bh_printf("Init global heap failed.\n");
|
||||
return;
|
||||
}
|
||||
memset(&init_args, 0, sizeof(RuntimeInitArgs));
|
||||
|
||||
init_args.mem_alloc_type = Alloc_With_Pool;
|
||||
init_args.mem_alloc_option.pool.heap_buf = global_heap_buf;
|
||||
init_args.mem_alloc_option.pool.heap_size = sizeof(global_heap_buf);
|
||||
|
||||
/* initialize runtime environment */
|
||||
if (!wasm_runtime_init())
|
||||
goto fail1;
|
||||
if (!wasm_runtime_full_init(&init_args)) {
|
||||
bh_printf("Init runtime environment failed.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if WASM_ENABLE_LOG != 0
|
||||
bh_log_set_verbose_level(log_verbose_level);
|
||||
@ -94,7 +96,7 @@ void iwasm_main(void *arg1, void *arg2, void *arg3)
|
||||
if (!(wasm_module = wasm_runtime_load(wasm_file_buf, wasm_file_size,
|
||||
error_buf, sizeof(error_buf)))) {
|
||||
bh_printf("%s\n", error_buf);
|
||||
goto fail2;
|
||||
goto fail1;
|
||||
}
|
||||
|
||||
/* instantiate the module */
|
||||
@ -104,7 +106,7 @@ void iwasm_main(void *arg1, void *arg2, void *arg3)
|
||||
error_buf,
|
||||
sizeof(error_buf)))) {
|
||||
bh_printf("%s\n", error_buf);
|
||||
goto fail3;
|
||||
goto fail2;
|
||||
}
|
||||
|
||||
/* invoke the main function */
|
||||
@ -113,16 +115,14 @@ void iwasm_main(void *arg1, void *arg2, void *arg3)
|
||||
/* destroy the module instance */
|
||||
wasm_runtime_deinstantiate(wasm_module_inst);
|
||||
|
||||
fail3:
|
||||
fail2:
|
||||
/* unload the module */
|
||||
wasm_runtime_unload(wasm_module);
|
||||
|
||||
fail2:
|
||||
fail1:
|
||||
/* destroy runtime environment */
|
||||
wasm_runtime_destroy();
|
||||
|
||||
fail1: bh_memory_destroy();
|
||||
|
||||
end = k_uptime_get_32();
|
||||
|
||||
printf("elpase: %d\n", (end - start));
|
||||
|
||||
Reference in New Issue
Block a user