Remove unused argument in wasm_runtime_lookup_function and refactor WASMModuleInstance (#3218)

Remove the unused parameter `signature` from `wasm_runtime_lookup_function`.

Refactor the layout of WASMModuleInstance structure:
- move common data members `c_api_func_imports` and `cur_exec_env` from
  `WASMModuleInstanceExtraCommon` to `WASMModuleInstance`
- In `WASMModuleInstance`, enlarge `reserved[3]` to `reserved[5]` in case that
  we need to add more fields in the future

ps.
https://github.com/bytecodealliance/wasm-micro-runtime/issues/2530
https://github.com/bytecodealliance/wasm-micro-runtime/issues/3202
This commit is contained in:
TianlongLiang
2024-03-13 12:28:45 +08:00
committed by GitHub
parent ce44e0ec0c
commit c3e33a96ea
28 changed files with 100 additions and 136 deletions

View File

@ -147,10 +147,10 @@ execute_main(WASMModuleInstanceCommon *module_inst, int32 argc, char *argv[])
}
#endif /* end of WASM_ENABLE_LIBC_WASI */
if (!(func = wasm_runtime_lookup_function(module_inst, "main", NULL))
&& !(func = wasm_runtime_lookup_function(module_inst,
"__main_argc_argv", NULL))
&& !(func = wasm_runtime_lookup_function(module_inst, "_main", NULL))) {
if (!(func = wasm_runtime_lookup_function(module_inst, "main"))
&& !(func =
wasm_runtime_lookup_function(module_inst, "__main_argc_argv"))
&& !(func = wasm_runtime_lookup_function(module_inst, "_main"))) {
#if WASM_ENABLE_LIBC_WASI != 0
wasm_runtime_set_exception(
module_inst, "lookup the entry point symbol (like _start, main, "
@ -337,8 +337,7 @@ execute_func(WASMModuleInstanceCommon *module_inst, const char *name,
bh_assert(argc >= 0);
LOG_DEBUG("call a function \"%s\" with %d arguments", name, argc);
if (!(target_func =
wasm_runtime_lookup_function(module_inst, name, NULL))) {
if (!(target_func = wasm_runtime_lookup_function(module_inst, name))) {
snprintf(buf, sizeof(buf), "lookup function %s failed", name);
wasm_runtime_set_exception(module_inst, buf);
goto fail;

View File

@ -4939,19 +4939,17 @@ wasm_instance_new_with_args_ex(wasm_store_t *store, const wasm_module_t *module,
/* create the c-api func import list */
#if WASM_ENABLE_INTERP != 0
if (instance->inst_comm_rt->module_type == Wasm_Module_Bytecode) {
WASMModuleInstanceExtra *e =
((WASMModuleInstance *)instance->inst_comm_rt)->e;
p_func_imports = &(e->common.c_api_func_imports);
WASMModuleInstance *wasm_module_inst =
(WASMModuleInstance *)instance->inst_comm_rt;
p_func_imports = &(wasm_module_inst->c_api_func_imports);
import_func_count = MODULE_INTERP(module)->import_function_count;
}
#endif
#if WASM_ENABLE_AOT != 0
if (instance->inst_comm_rt->module_type == Wasm_Module_AoT) {
AOTModuleInstanceExtra *e =
(AOTModuleInstanceExtra *)((AOTModuleInstance *)
instance->inst_comm_rt)
->e;
p_func_imports = &(e->common.c_api_func_imports);
AOTModuleInstance *aot_module_inst =
(AOTModuleInstance *)instance->inst_comm_rt;
p_func_imports = &(aot_module_inst->c_api_func_imports);
import_func_count = MODULE_AOT(module)->import_func_count;
}
#endif
@ -4965,7 +4963,7 @@ wasm_instance_new_with_args_ex(wasm_store_t *store, const wasm_module_t *module,
goto failed;
}
/* fill in module_inst->e->c_api_func_imports */
/* fill in module_inst->c_api_func_imports */
for (i = 0; imports && i < imports->num_elems; i++) {
wasm_func_t *func_host = NULL;
wasm_extern_t *in = imports->data[i];

View File

@ -823,13 +823,11 @@ return_func:
#if WASM_ENABLE_INTERP != 0
if (module->module_type == Wasm_Module_Bytecode)
exec_env =
((WASMModuleInstanceExtra *)module->e)->common.cur_exec_env;
exec_env = ((WASMModuleInstance *)module)->cur_exec_env;
#endif
#if WASM_ENABLE_AOT != 0
if (module->module_type == Wasm_Module_AoT)
exec_env =
((AOTModuleInstanceExtra *)module->e)->common.cur_exec_env;
exec_env = ((AOTModuleInstance *)module)->cur_exec_env;
#endif
enlarge_memory_error_cb(inc_page_count, total_size_old, 0,

View File

@ -1853,17 +1853,17 @@ wasm_runtime_get_function_type(const WASMFunctionInstanceCommon *function,
WASMFunctionInstanceCommon *
wasm_runtime_lookup_function(WASMModuleInstanceCommon *const module_inst,
const char *name, const char *signature)
const char *name)
{
#if WASM_ENABLE_INTERP != 0
if (module_inst->module_type == Wasm_Module_Bytecode)
return (WASMFunctionInstanceCommon *)wasm_lookup_function(
(const WASMModuleInstance *)module_inst, name, signature);
(const WASMModuleInstance *)module_inst, name);
#endif
#if WASM_ENABLE_AOT != 0
if (module_inst->module_type == Wasm_Module_AoT)
return (WASMFunctionInstanceCommon *)aot_lookup_function(
(const AOTModuleInstance *)module_inst, name, signature);
(const AOTModuleInstance *)module_inst, name);
#endif
return NULL;
}

View File

@ -611,7 +611,7 @@ wasm_runtime_get_module(WASMModuleInstanceCommon *module_inst);
/* See wasm_export.h for description */
WASM_RUNTIME_API_EXTERN WASMFunctionInstanceCommon *
wasm_runtime_lookup_function(WASMModuleInstanceCommon *const module_inst,
const char *name, const char *signature);
const char *name);
/* Internal API */
WASMFuncType *