Add table type API support (#3515)
Add `wasm_runtime_get_export_table_inst` and `wasm_table_get_func_inst`, and related wasm_table_type_get_xxx APIs.
This commit is contained in:
@ -599,34 +599,36 @@ aot_create_comp_data(WASMModule *module, const char *target_arch,
|
||||
memset(comp_data->tables, 0, size);
|
||||
for (i = 0; i < comp_data->table_count; i++) {
|
||||
if (i < module->import_table_count) {
|
||||
comp_data->tables[i].elem_type =
|
||||
module->import_tables[i].u.table.elem_type;
|
||||
comp_data->tables[i].table_flags =
|
||||
module->import_tables[i].u.table.flags;
|
||||
comp_data->tables[i].table_init_size =
|
||||
module->import_tables[i].u.table.init_size;
|
||||
comp_data->tables[i].table_max_size =
|
||||
module->import_tables[i].u.table.max_size;
|
||||
comp_data->tables[i].table_type.elem_type =
|
||||
module->import_tables[i].u.table.table_type.elem_type;
|
||||
comp_data->tables[i].table_type.flags =
|
||||
module->import_tables[i].u.table.table_type.flags;
|
||||
comp_data->tables[i].table_type.init_size =
|
||||
module->import_tables[i].u.table.table_type.init_size;
|
||||
comp_data->tables[i].table_type.max_size =
|
||||
module->import_tables[i].u.table.table_type.max_size;
|
||||
#if WASM_ENABLE_GC != 0
|
||||
comp_data->tables[i].elem_ref_type =
|
||||
module->import_tables[i].u.table.elem_ref_type;
|
||||
comp_data->tables[i].table_type.elem_ref_type =
|
||||
module->import_tables[i].u.table.table_type.elem_ref_type;
|
||||
#endif
|
||||
comp_data->tables[i].possible_grow =
|
||||
module->import_tables[i].u.table.possible_grow;
|
||||
comp_data->tables[i].table_type.possible_grow =
|
||||
module->import_tables[i].u.table.table_type.possible_grow;
|
||||
}
|
||||
else {
|
||||
j = i - module->import_table_count;
|
||||
comp_data->tables[i].elem_type = module->tables[j].elem_type;
|
||||
comp_data->tables[i].table_flags = module->tables[j].flags;
|
||||
comp_data->tables[i].table_init_size =
|
||||
module->tables[j].init_size;
|
||||
comp_data->tables[i].table_max_size =
|
||||
module->tables[j].max_size;
|
||||
comp_data->tables[i].possible_grow =
|
||||
module->tables[j].possible_grow;
|
||||
comp_data->tables[i].table_type.elem_type =
|
||||
module->tables[j].table_type.elem_type;
|
||||
comp_data->tables[i].table_type.flags =
|
||||
module->tables[j].table_type.flags;
|
||||
comp_data->tables[i].table_type.init_size =
|
||||
module->tables[j].table_type.init_size;
|
||||
comp_data->tables[i].table_type.max_size =
|
||||
module->tables[j].table_type.max_size;
|
||||
comp_data->tables[i].table_type.possible_grow =
|
||||
module->tables[j].table_type.possible_grow;
|
||||
#if WASM_ENABLE_GC != 0
|
||||
comp_data->tables[j].elem_ref_type =
|
||||
module->tables[j].elem_ref_type;
|
||||
comp_data->tables[j].table_type.elem_ref_type =
|
||||
module->tables[j].table_type.elem_ref_type;
|
||||
/* Note: if the init_expr contains extra data for struct/array
|
||||
* initialization information (init_expr.u.data), the pointer is
|
||||
* copied.
|
||||
|
||||
@ -48,6 +48,8 @@ typedef WASMArrayType AOTArrayType;
|
||||
typedef WASMExport AOTExport;
|
||||
typedef WASMMemory AOTMemory;
|
||||
typedef WASMMemoryType AOTMemoryType;
|
||||
typedef WASMTableType AOTTableType;
|
||||
typedef WASMTable AOTTable;
|
||||
|
||||
#if WASM_ENABLE_DEBUG_AOT != 0
|
||||
typedef void *dwarf_extractor_handle_t;
|
||||
@ -110,32 +112,9 @@ typedef struct AOTMemInitData {
|
||||
typedef struct AOTImportTable {
|
||||
char *module_name;
|
||||
char *table_name;
|
||||
uint8 elem_type;
|
||||
uint8 table_flags;
|
||||
bool possible_grow;
|
||||
uint32 table_init_size;
|
||||
uint32 table_max_size;
|
||||
#if WASM_ENABLE_GC != 0
|
||||
WASMRefType *elem_ref_type;
|
||||
#endif
|
||||
AOTTableType table_type;
|
||||
} AOTImportTable;
|
||||
|
||||
/**
|
||||
* Table
|
||||
*/
|
||||
typedef struct AOTTable {
|
||||
uint8 elem_type;
|
||||
uint8 table_flags;
|
||||
bool possible_grow;
|
||||
uint32 table_init_size;
|
||||
uint32 table_max_size;
|
||||
#if WASM_ENABLE_GC != 0
|
||||
WASMRefType *elem_ref_type;
|
||||
/* init expr for the whole table */
|
||||
InitializerExpression init_expr;
|
||||
#endif
|
||||
} AOTTable;
|
||||
|
||||
/**
|
||||
* A segment of table init data
|
||||
*/
|
||||
@ -359,11 +338,12 @@ aot_get_imp_tbl_data_slots(const AOTImportTable *tbl, bool is_jit_mode)
|
||||
{
|
||||
#if WASM_ENABLE_MULTI_MODULE != 0
|
||||
if (is_jit_mode)
|
||||
return tbl->table_max_size;
|
||||
return tbl->table_type.max_size;
|
||||
#else
|
||||
(void)is_jit_mode;
|
||||
#endif
|
||||
return tbl->possible_grow ? tbl->table_max_size : tbl->table_init_size;
|
||||
return tbl->table_type.possible_grow ? tbl->table_type.max_size
|
||||
: tbl->table_type.init_size;
|
||||
}
|
||||
|
||||
static inline uint32
|
||||
@ -371,11 +351,12 @@ aot_get_tbl_data_slots(const AOTTable *tbl, bool is_jit_mode)
|
||||
{
|
||||
#if WASM_ENABLE_MULTI_MODULE != 0
|
||||
if (is_jit_mode)
|
||||
return tbl->table_max_size;
|
||||
return tbl->table_type.max_size;
|
||||
#else
|
||||
(void)is_jit_mode;
|
||||
#endif
|
||||
return tbl->possible_grow ? tbl->table_max_size : tbl->table_init_size;
|
||||
return tbl->table_type.possible_grow ? tbl->table_type.max_size
|
||||
: tbl->table_type.init_size;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@ -383,11 +383,11 @@ get_import_table_size(const AOTCompContext *comp_ctx,
|
||||
* | import_table_count
|
||||
* ------------------------------
|
||||
* | | U8 elem_type
|
||||
* | | U8 table_flags
|
||||
* | | U8 flags
|
||||
* | | U8 possible_grow
|
||||
* | AOTImportTable[N] | U8 elem_ref_type.nullable (for GC only)
|
||||
* | | U32 table_init_size
|
||||
* | | U32 table_max_size
|
||||
* | | U32 init_size
|
||||
* | | U32 max_size
|
||||
* | | U32 elem_ref_type.heap_type (for GC only)
|
||||
* ------------------------------
|
||||
*/
|
||||
@ -397,7 +397,8 @@ get_import_table_size(const AOTCompContext *comp_ctx,
|
||||
for (i = 0; i < comp_data->import_table_count; i++) {
|
||||
size += sizeof(uint32) * 3;
|
||||
#if WASM_ENABLE_GC != 0
|
||||
if (comp_ctx->enable_gc && comp_data->import_tables[i].elem_ref_type)
|
||||
if (comp_ctx->enable_gc
|
||||
&& comp_data->import_tables[i].table_type.elem_ref_type)
|
||||
size += sizeof(uint32);
|
||||
#endif
|
||||
}
|
||||
@ -412,11 +413,11 @@ get_table_size(const AOTCompContext *comp_ctx, const AOTCompData *comp_data)
|
||||
* | table_count
|
||||
* ------------------------------
|
||||
* | | U8 elem_type
|
||||
* | | U8 table_flags
|
||||
* | | U8 flags
|
||||
* | | U8 possible_grow
|
||||
* | AOTTable[N] | U8 elem_ref_type.nullable (for GC only)
|
||||
* | | U32 table_init_size
|
||||
* | | U32 table_max_size
|
||||
* | | U32 init_size
|
||||
* | | U32 max_size
|
||||
* | | U32 elem_ref_type.heap_type (for GC only)
|
||||
* | | N init_expr (for GC only)
|
||||
* ------------------------------
|
||||
@ -428,7 +429,7 @@ get_table_size(const AOTCompContext *comp_ctx, const AOTCompData *comp_data)
|
||||
size += sizeof(uint32) * 3;
|
||||
#if WASM_ENABLE_GC != 0
|
||||
if (comp_ctx->enable_gc) {
|
||||
if (comp_data->tables[i].elem_ref_type) {
|
||||
if (comp_data->tables[i].table_type.elem_ref_type) {
|
||||
size += sizeof(uint32);
|
||||
}
|
||||
size += get_init_expr_size(comp_ctx, comp_data,
|
||||
@ -1955,13 +1956,14 @@ aot_emit_table_info(uint8 *buf, uint8 *buf_end, uint32 *p_offset,
|
||||
* EMIT_STR(comp_data->import_tables[i].module_name );
|
||||
* EMIT_STR(comp_data->import_tables[i].table_name);
|
||||
*/
|
||||
EMIT_U8(comp_data->import_tables[i].elem_type);
|
||||
EMIT_U8(comp_data->import_tables[i].table_flags);
|
||||
EMIT_U8(comp_data->import_tables[i].possible_grow);
|
||||
EMIT_U8(comp_data->import_tables[i].table_type.elem_type);
|
||||
EMIT_U8(comp_data->import_tables[i].table_type.flags);
|
||||
EMIT_U8(comp_data->import_tables[i].table_type.possible_grow);
|
||||
#if WASM_ENABLE_GC != 0
|
||||
if (comp_ctx->enable_gc && comp_data->import_tables[i].elem_ref_type) {
|
||||
if (comp_ctx->enable_gc
|
||||
&& comp_data->import_tables[i].table_type.elem_ref_type) {
|
||||
EMIT_U8(comp_data->import_tables[i]
|
||||
.elem_ref_type->ref_ht_common.nullable);
|
||||
.table_type.elem_ref_type->ref_ht_common.nullable);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
@ -1969,14 +1971,15 @@ aot_emit_table_info(uint8 *buf, uint8 *buf_end, uint32 *p_offset,
|
||||
/* emit one placeholder to keep the same size */
|
||||
EMIT_U8(0);
|
||||
}
|
||||
EMIT_U32(comp_data->import_tables[i].table_init_size);
|
||||
EMIT_U32(comp_data->import_tables[i].table_max_size);
|
||||
EMIT_U32(comp_data->import_tables[i].table_type.init_size);
|
||||
EMIT_U32(comp_data->import_tables[i].table_type.max_size);
|
||||
#if WASM_ENABLE_GC != 0
|
||||
if (comp_ctx->enable_gc && comp_data->import_tables[i].elem_ref_type) {
|
||||
if (comp_ctx->enable_gc
|
||||
&& comp_data->import_tables[i].table_type.elem_ref_type) {
|
||||
bh_assert(wasm_is_type_multi_byte_type(
|
||||
comp_data->import_tables[i].elem_type));
|
||||
EMIT_U32(comp_data->import_tables[i]
|
||||
.elem_ref_type->ref_ht_common.heap_type);
|
||||
.table_type.elem_ref_type->ref_ht_common.heap_type);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@ -1985,12 +1988,14 @@ aot_emit_table_info(uint8 *buf, uint8 *buf_end, uint32 *p_offset,
|
||||
EMIT_U32(comp_data->table_count);
|
||||
/* Emit table items */
|
||||
for (i = 0; i < comp_data->table_count; i++) {
|
||||
EMIT_U8(comp_data->tables[i].elem_type);
|
||||
EMIT_U8(comp_data->tables[i].table_flags);
|
||||
EMIT_U8(comp_data->tables[i].possible_grow);
|
||||
EMIT_U8(comp_data->tables[i].table_type.elem_type);
|
||||
EMIT_U8(comp_data->tables[i].table_type.flags);
|
||||
EMIT_U8(comp_data->tables[i].table_type.possible_grow);
|
||||
#if WASM_ENABLE_GC != 0
|
||||
if (comp_ctx->enable_gc && comp_data->tables[i].elem_ref_type) {
|
||||
EMIT_U8(comp_data->tables[i].elem_ref_type->ref_ht_common.nullable);
|
||||
if (comp_ctx->enable_gc
|
||||
&& comp_data->tables[i].table_type.elem_ref_type) {
|
||||
EMIT_U8(comp_data->tables[i]
|
||||
.table_type.elem_ref_type->ref_ht_common.nullable);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
@ -1998,15 +2003,16 @@ aot_emit_table_info(uint8 *buf, uint8 *buf_end, uint32 *p_offset,
|
||||
/* emit one placeholder to keep the same size */
|
||||
EMIT_U8(0);
|
||||
}
|
||||
EMIT_U32(comp_data->tables[i].table_init_size);
|
||||
EMIT_U32(comp_data->tables[i].table_max_size);
|
||||
EMIT_U32(comp_data->tables[i].table_type.init_size);
|
||||
EMIT_U32(comp_data->tables[i].table_type.max_size);
|
||||
#if WASM_ENABLE_GC != 0
|
||||
if (comp_ctx->enable_gc) {
|
||||
if (comp_data->tables[i].elem_ref_type) {
|
||||
if (comp_data->tables[i].table_type.elem_ref_type) {
|
||||
bh_assert(wasm_is_type_multi_byte_type(
|
||||
comp_data->tables[i].elem_type));
|
||||
EMIT_U32(comp_data->tables[i]
|
||||
.elem_ref_type->ref_ht_common.heap_type);
|
||||
EMIT_U32(
|
||||
comp_data->tables[i]
|
||||
.table_type.elem_ref_type->ref_ht_common.heap_type);
|
||||
}
|
||||
if (!aot_emit_init_expr(buf, buf_end, &offset, comp_ctx,
|
||||
&comp_data->tables[i].init_expr)) {
|
||||
|
||||
Reference in New Issue
Block a user