Enable multi-module support for wasm-c-api (#426)
it is allowed that all imported functions and globals can be linked by multi-module feature automatically or by wasm-c-api manually
This commit is contained in:
@ -1696,7 +1696,14 @@ interp_global_set(const WASMModuleInstance *inst_interp,
|
||||
const WASMGlobalInstance *global_interp =
|
||||
inst_interp->globals + global_idx_rt;
|
||||
uint8 val_type_rt = global_interp->type;
|
||||
#if WASM_ENABLE_MULTI_MODULE != 0
|
||||
uint8 *data = global_interp->import_global_inst
|
||||
? global_interp->import_module_inst->global_data
|
||||
+ global_interp->import_global_inst->data_offset
|
||||
: inst_interp->global_data + global_interp->data_offset;
|
||||
#else
|
||||
uint8 *data = inst_interp->global_data + global_interp->data_offset;
|
||||
#endif
|
||||
bool ret = true;
|
||||
|
||||
switch (val_type_rt) {
|
||||
@ -1732,7 +1739,14 @@ interp_global_get(const WASMModuleInstance *inst_interp,
|
||||
{
|
||||
WASMGlobalInstance *global_interp = inst_interp->globals + global_idx_rt;
|
||||
uint8 val_type_rt = global_interp->type;
|
||||
#if WASM_ENABLE_MULTI_MODULE != 0
|
||||
uint8 *data = global_interp->import_global_inst
|
||||
? global_interp->import_module_inst->global_data
|
||||
+ global_interp->import_global_inst->data_offset
|
||||
: inst_interp->global_data + global_interp->data_offset;
|
||||
#else
|
||||
uint8 *data = inst_interp->global_data + global_interp->data_offset;
|
||||
#endif
|
||||
bool ret = true;
|
||||
|
||||
switch (val_type_rt) {
|
||||
@ -2080,6 +2094,7 @@ interp_link_global(const WASMModule *module_interp,
|
||||
}
|
||||
|
||||
import->global_idx_rt = global_idx_rt;
|
||||
imported_global_interp->u.global.is_linked = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -2432,35 +2447,44 @@ wasm_instance_new(wasm_store_t *store,
|
||||
}
|
||||
|
||||
/* link module and imports */
|
||||
if (INTERP_MODE == current_runtime_mode()) {
|
||||
if (imports) {
|
||||
if (INTERP_MODE == current_runtime_mode()) {
|
||||
#if WASM_ENABLE_INTERP != 0
|
||||
import_count = ((WASMModule *)*module)->import_count;
|
||||
INIT_VEC(instance->imports, wasm_extern_vec, import_count);
|
||||
if (!instance->imports) {
|
||||
goto failed;
|
||||
}
|
||||
import_count = ((WASMModule *)*module)->import_count;
|
||||
INIT_VEC(instance->imports, wasm_extern_vec, import_count);
|
||||
if (!instance->imports) {
|
||||
goto failed;
|
||||
}
|
||||
|
||||
import_count = interp_link(instance, (WASMModule *)*module,
|
||||
(wasm_extern_t **)imports);
|
||||
if (import_count) {
|
||||
import_count = interp_link(instance, (WASMModule *)*module,
|
||||
(wasm_extern_t **)imports);
|
||||
if ((int32)import_count < 0) {
|
||||
goto failed;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
}
|
||||
else {
|
||||
#if WASM_ENABLE_AOT != 0
|
||||
import_count = ((AOTModule *)*module)->import_func_count
|
||||
+ ((AOTModule *)*module)->import_global_count
|
||||
+ ((AOTModule *)*module)->import_memory_count
|
||||
+ ((AOTModule *)*module)->import_table_count;
|
||||
INIT_VEC(instance->imports, wasm_extern_vec, import_count);
|
||||
if (!instance->imports) {
|
||||
goto failed;
|
||||
}
|
||||
import_count = ((AOTModule *)*module)->import_func_count
|
||||
+ ((AOTModule *)*module)->import_global_count
|
||||
+ ((AOTModule *)*module)->import_memory_count
|
||||
+ ((AOTModule *)*module)->import_table_count;
|
||||
INIT_VEC(instance->imports, wasm_extern_vec, import_count);
|
||||
if (!instance->imports) {
|
||||
goto failed;
|
||||
}
|
||||
|
||||
import_count =
|
||||
aot_link(instance, (AOTModule *)*module, (wasm_extern_t **)imports);
|
||||
if (import_count) {
|
||||
import_count = aot_link(instance, (AOTModule *)*module,
|
||||
(wasm_extern_t **)imports);
|
||||
if ((int32)import_count < 0) {
|
||||
goto failed;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
if ((int32)import_count < 0) {
|
||||
goto failed;
|
||||
}
|
||||
}
|
||||
|
||||
instance->inst_comm_rt = wasm_runtime_instantiate(
|
||||
|
||||
@ -539,6 +539,12 @@ wasm_runtime_destroy_loading_module_list()
|
||||
}
|
||||
#endif /* WASM_ENABLE_MULTI_MODULE */
|
||||
|
||||
bool
|
||||
wasm_runtime_is_host_module(const char *module_name)
|
||||
{
|
||||
return strlen(module_name) == 0;
|
||||
}
|
||||
|
||||
bool
|
||||
wasm_runtime_is_built_in_module(const char *module_name)
|
||||
{
|
||||
@ -2342,7 +2348,8 @@ wasm_application_execute_func(WASMModuleInstanceCommon *module_inst,
|
||||
wasm_runtime_set_exception(module_inst, buf);
|
||||
goto fail;
|
||||
}
|
||||
type = wasm_func->u.func->func_type;
|
||||
type = wasm_func->is_import_func ? wasm_func->u.func_import->func_type
|
||||
: wasm_func->u.func->func_type;
|
||||
argc1 = wasm_func->param_cell_num;
|
||||
cell_num = argc1 > wasm_func->ret_cell_num ?
|
||||
argc1 : wasm_func->ret_cell_num;
|
||||
|
||||
@ -373,6 +373,9 @@ void
|
||||
wasm_runtime_destroy_loading_module_list();
|
||||
#endif /* WASM_ENALBE_MULTI_MODULE */
|
||||
|
||||
bool
|
||||
wasm_runtime_is_host_module(const char *module_name);
|
||||
|
||||
bool
|
||||
wasm_runtime_is_built_in_module(const char *module_name);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user