Skip to content

Commit

Permalink
Handle a new scenario where an item is both exported and imported. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
lum1n0us authored Dec 29, 2024
1 parent 24ecee8 commit 7f3e0df
Showing 1 changed file with 118 additions and 36 deletions.
154 changes: 118 additions & 36 deletions core/iwasm/common/wasm_runtime_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -4266,31 +4266,68 @@ wasm_runtime_get_export_type(WASMModuleCommon *const module, int32 export_index,
export_type->kind = aot_export->kind;
switch (export_type->kind) {
case WASM_IMPORT_EXPORT_KIND_FUNC:
export_type->u.func_type =
(AOTFuncType *)aot_module
->types[aot_module->func_type_indexes
[aot_export->index
- aot_module->import_func_count]];
{
if (aot_export->index < aot_module->import_func_count) {
export_type->u.func_type =
(AOTFuncType *)aot_module
->import_funcs[aot_export->index]
.func_type;
}
else {
export_type->u.func_type =
(AOTFuncType *)aot_module
->types[aot_module->func_type_indexes
[aot_export->index
- aot_module->import_func_count]];
}
break;
}
case WASM_IMPORT_EXPORT_KIND_GLOBAL:
export_type->u.global_type =
&aot_module
->globals[aot_export->index
- aot_module->import_global_count]
.type;
{
if (aot_export->index < aot_module->import_global_count) {
export_type->u.global_type =
&aot_module->import_globals[aot_export->index].type;
}
else {
export_type->u.global_type =
&aot_module
->globals[aot_export->index
- aot_module->import_global_count]
.type;
}
break;
}
case WASM_IMPORT_EXPORT_KIND_TABLE:
export_type->u.table_type =
&aot_module
->tables[aot_export->index
- aot_module->import_table_count]
.table_type;
{
if (aot_export->index < aot_module->import_table_count) {
export_type->u.table_type =
&aot_module->import_tables[aot_export->index]
.table_type;
}
else {
export_type->u.table_type =
&aot_module
->tables[aot_export->index
- aot_module->import_table_count]
.table_type;
}
break;
}
case WASM_IMPORT_EXPORT_KIND_MEMORY:
export_type->u.memory_type =
&aot_module->memories[aot_export->index
- aot_module->import_memory_count];
{
if (aot_export->index < aot_module->import_memory_count) {
export_type->u.memory_type =
&aot_module->import_memories[aot_export->index]
.mem_type;
}
else {
export_type->u.memory_type =
&aot_module
->memories[aot_export->index
- aot_module->import_memory_count];
}
break;
}
default:
bh_assert(0);
break;
Expand All @@ -4312,31 +4349,76 @@ wasm_runtime_get_export_type(WASMModuleCommon *const module, int32 export_index,
export_type->kind = wasm_export->kind;
switch (export_type->kind) {
case WASM_IMPORT_EXPORT_KIND_FUNC:
export_type->u.func_type =
wasm_module
->functions[wasm_export->index
- wasm_module->import_function_count]
->func_type;
{
if (wasm_export->index < wasm_module->import_function_count) {
export_type->u.func_type =
(WASMFuncType *)wasm_module
->import_functions[wasm_export->index]
.u.function.func_type;
}
else {
export_type->u.func_type =
wasm_module
->functions[wasm_export->index
- wasm_module->import_function_count]
->func_type;
}

break;
}
case WASM_IMPORT_EXPORT_KIND_GLOBAL:
export_type->u.global_type =
&wasm_module
->globals[wasm_export->index
- wasm_module->import_global_count]
.type;
{
if (wasm_export->index < wasm_module->import_global_count) {
export_type->u.global_type =
(WASMGlobalType *)&wasm_module
->import_globals[wasm_export->index]
.u.global.type;
}
else {
export_type->u.global_type =
&wasm_module
->globals[wasm_export->index
- wasm_module->import_global_count]
.type;
}

break;
}
case WASM_IMPORT_EXPORT_KIND_TABLE:
export_type->u.table_type =
&wasm_module
->tables[wasm_export->index
- wasm_module->import_table_count]
.table_type;
{
if (wasm_export->index < wasm_module->import_table_count) {
export_type->u.table_type =
(WASMTableType *)&wasm_module
->import_tables[wasm_export->index]
.u.table.table_type;
}
else {
export_type->u.table_type =
&wasm_module
->tables[wasm_export->index
- wasm_module->import_table_count]
.table_type;
}

break;
}
case WASM_IMPORT_EXPORT_KIND_MEMORY:
export_type->u.memory_type =
&wasm_module->memories[wasm_export->index
- wasm_module->import_memory_count];
{
if (wasm_export->index < wasm_module->import_memory_count) {
export_type->u.memory_type =
(WASMMemoryType *)&wasm_module
->import_memories[wasm_export->index]
.u.memory.mem_type;
}
else {
export_type->u.memory_type =
&wasm_module
->memories[wasm_export->index
- wasm_module->import_memory_count];
}

break;
}
default:
bh_assert(0);
break;
Expand Down

0 comments on commit 7f3e0df

Please sign in to comment.