Skip to content

Commit

Permalink
refactor: wasm_table_inst
Browse files Browse the repository at this point in the history
Use WASMTableInstance.
  • Loading branch information
lum1n0us committed Nov 11, 2024
1 parent bf78863 commit 28b39b5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 24 deletions.
26 changes: 13 additions & 13 deletions core/iwasm/common/wasm_runtime_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -2097,26 +2097,24 @@ wasm_runtime_get_export_global_inst(WASMModuleInstanceCommon *const module_inst,

bool
wasm_runtime_get_export_table_inst(WASMModuleInstanceCommon *const module_inst,
char const *name,
wasm_table_inst_t *table_inst)
char const *name, wasm_table_inst_t out)
{
#if WASM_ENABLE_INTERP != 0
if (module_inst->module_type == Wasm_Module_Bytecode) {
const WASMModuleInstance *wasm_module_inst =
(const WASMModuleInstance *)module_inst;
const WASMModule *wasm_module = wasm_module_inst->module;

uint32 i;
for (i = 0; i < wasm_module->export_count; i++) {
const WASMExport *wasm_export = &wasm_module->exports[i];
if ((wasm_export->kind == WASM_IMPORT_EXPORT_KIND_TABLE)
&& !strcmp(wasm_export->name, name)) {
const WASMTableInstance *wasm_table_inst =
wasm_module_inst->tables[wasm_export->index];
table_inst->elem_kind =
val_type_to_val_kind(wasm_table_inst->elem_type);
table_inst->cur_size = wasm_table_inst->cur_size;
table_inst->max_size = wasm_table_inst->max_size;
table_inst->elems = (void *)wasm_table_inst->elems;

bh_memcpy_s(out, sizeof(WASMTableInstance), wasm_table_inst,
sizeof(WASMTableInstance));
return true;
}
}
Expand All @@ -2127,18 +2125,20 @@ wasm_runtime_get_export_table_inst(WASMModuleInstanceCommon *const module_inst,
const AOTModuleInstance *aot_module_inst =
(AOTModuleInstance *)module_inst;
const AOTModule *aot_module = (AOTModule *)aot_module_inst->module;

uint32 i;
for (i = 0; i < aot_module->export_count; i++) {
const AOTExport *aot_export = &aot_module->exports[i];
if ((aot_export->kind == WASM_IMPORT_EXPORT_KIND_TABLE)
&& !strcmp(aot_export->name, name)) {
const AOTTableInstance *aot_table_inst =
aot_module_inst->tables[aot_export->index];
table_inst->elem_kind =
val_type_to_val_kind(aot_table_inst->elem_type);
table_inst->cur_size = aot_table_inst->cur_size;
table_inst->max_size = aot_table_inst->max_size;
table_inst->elems = (void *)aot_table_inst->elems;

bh_static_assert(sizeof(AOTTableInstance)
== sizeof(WASMTableInstance));

bh_memcpy_s(out, sizeof(WASMTableInstance), aot_table_inst,
sizeof(AOTTableInstance));
return true;
}
}
Expand All @@ -2150,7 +2150,7 @@ wasm_runtime_get_export_table_inst(WASMModuleInstanceCommon *const module_inst,

WASMFunctionInstanceCommon *
wasm_table_get_func_inst(struct WASMModuleInstanceCommon *const module_inst,
const wasm_table_inst_t *table_inst, uint32_t idx)
const wasm_table_inst_t table_inst, uint32_t idx)
{
if (!table_inst) {
bh_assert(0);
Expand Down
17 changes: 6 additions & 11 deletions core/iwasm/include/wasm_export.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ typedef WASMFunctionInstanceCommon *wasm_function_inst_t;
struct WASMMemoryInstance;
typedef struct WASMMemoryInstance *wasm_memory_inst_t;

/* Table instance */
struct WASMTableInstance;
typedef struct WASMTableInstance *wasm_table_inst_t;

/* WASM section */
typedef struct wasm_section_t {
struct wasm_section_t *next;
Expand Down Expand Up @@ -315,15 +319,6 @@ typedef struct wasm_global_inst_t {
void *global_data;
} wasm_global_inst_t;

/* Table instance*/
typedef struct wasm_table_inst_t {
wasm_valkind_t elem_kind;
uint32_t cur_size;
uint32_t max_size;
/* represents the elements of the table, for internal use only */
void *elems;
} wasm_table_inst_t;

typedef enum {
WASM_LOG_LEVEL_FATAL = 0,
WASM_LOG_LEVEL_ERROR = 1,
Expand Down Expand Up @@ -1711,7 +1706,7 @@ wasm_runtime_get_export_global_inst(const wasm_module_inst_t module_inst,
WASM_RUNTIME_API_EXTERN bool
wasm_runtime_get_export_table_inst(const wasm_module_inst_t module_inst,
const char *name,
wasm_table_inst_t *table_inst);
wasm_table_inst_t table_inst);

/**
* Get a function instance from a table.
Expand All @@ -1724,7 +1719,7 @@ wasm_runtime_get_export_table_inst(const wasm_module_inst_t module_inst,
*/
WASM_RUNTIME_API_EXTERN wasm_function_inst_t
wasm_table_get_func_inst(const wasm_module_inst_t module_inst,
const wasm_table_inst_t *table_inst, uint32_t idx);
const wasm_table_inst_t table_inst, uint32_t idx);

/**
* Get attachment of native function from execution environment
Expand Down

0 comments on commit 28b39b5

Please sign in to comment.