Add wasm module global type information APIs (#3406)
Support getting global type from `wasm_runtime_get_import_type` and `wasm_runtime_get_export_type`, and add two APIs: ```C wasm_valkind_t wasm_global_type_get_valkind(const wasm_global_type_t global_type); bool wasm_global_type_get_mutable(const wasm_global_type_t global_type); ```
This commit is contained in:
@ -221,16 +221,16 @@ aot_create_import_globals(const WASMModule *module, bool gc_enabled,
|
||||
WASMGlobalImport *import_global = &module->import_globals[i].u.global;
|
||||
import_globals[i].module_name = import_global->module_name;
|
||||
import_globals[i].global_name = import_global->field_name;
|
||||
import_globals[i].type = import_global->type;
|
||||
import_globals[i].is_mutable = import_global->is_mutable;
|
||||
import_globals[i].type.val_type = import_global->type.val_type;
|
||||
import_globals[i].type.is_mutable = import_global->type.is_mutable;
|
||||
import_globals[i].global_data_linked =
|
||||
import_global->global_data_linked;
|
||||
|
||||
import_globals[i].data_offset_64bit = data_offset_64bit;
|
||||
import_globals[i].data_offset_32bit = data_offset_32bit;
|
||||
|
||||
get_value_type_size(import_global->type, gc_enabled, &value_size_64bit,
|
||||
&value_size_32bit);
|
||||
get_value_type_size(import_global->type.val_type, gc_enabled,
|
||||
&value_size_64bit, &value_size_32bit);
|
||||
|
||||
import_globals[i].size_64bit = value_size_64bit;
|
||||
import_globals[i].size_32bit = value_size_32bit;
|
||||
@ -269,16 +269,16 @@ aot_create_globals(const WASMModule *module, bool gc_enabled,
|
||||
/* Create each global */
|
||||
for (i = 0; i < module->global_count; i++) {
|
||||
WASMGlobal *global = &module->globals[i];
|
||||
globals[i].type = global->type;
|
||||
globals[i].is_mutable = global->is_mutable;
|
||||
globals[i].type.val_type = global->type.val_type;
|
||||
globals[i].type.is_mutable = global->type.is_mutable;
|
||||
memcpy(&globals[i].init_expr, &global->init_expr,
|
||||
sizeof(global->init_expr));
|
||||
|
||||
globals[i].data_offset_64bit = data_offset_64bit;
|
||||
globals[i].data_offset_32bit = data_offset_32bit;
|
||||
|
||||
get_value_type_size(global->type, gc_enabled, &value_size_64bit,
|
||||
&value_size_32bit);
|
||||
get_value_type_size(global->type.val_type, gc_enabled,
|
||||
&value_size_64bit, &value_size_32bit);
|
||||
|
||||
globals[i].size_64bit = value_size_64bit;
|
||||
globals[i].size_32bit = value_size_32bit;
|
||||
|
||||
@ -175,9 +175,7 @@ typedef struct AOTTableInitData {
|
||||
typedef struct AOTImportGlobal {
|
||||
char *module_name;
|
||||
char *global_name;
|
||||
/* VALUE_TYPE_I32/I64/F32/F64 */
|
||||
uint8 type;
|
||||
bool is_mutable;
|
||||
WASMGlobalType type;
|
||||
uint32 size;
|
||||
/* The data offset of current global in global data */
|
||||
uint32 data_offset;
|
||||
@ -203,9 +201,7 @@ typedef struct AOTImportGlobal {
|
||||
* Global variable
|
||||
*/
|
||||
typedef struct AOTGlobal {
|
||||
/* VALUE_TYPE_I32/I64/F32/F64 */
|
||||
uint8 type;
|
||||
bool is_mutable;
|
||||
WASMGlobalType type;
|
||||
uint32 size;
|
||||
/* The data offset of current global in global data */
|
||||
uint32 data_offset;
|
||||
|
||||
@ -2241,8 +2241,8 @@ aot_emit_import_global_info(uint8 *buf, uint8 *buf_end, uint32 *p_offset,
|
||||
|
||||
for (i = 0; i < comp_data->import_global_count; i++, import_global++) {
|
||||
offset = align_uint(offset, 2);
|
||||
EMIT_U8(import_global->type);
|
||||
EMIT_U8(import_global->is_mutable);
|
||||
EMIT_U8(import_global->type.val_type);
|
||||
EMIT_U8(import_global->type.is_mutable);
|
||||
EMIT_STR(import_global->module_name);
|
||||
offset = align_uint(offset, 2);
|
||||
EMIT_STR(import_global->global_name);
|
||||
@ -2273,8 +2273,8 @@ aot_emit_global_info(uint8 *buf, uint8 *buf_end, uint32 *p_offset,
|
||||
|
||||
for (i = 0; i < comp_data->global_count; i++, global++) {
|
||||
offset = align_uint(offset, 4);
|
||||
EMIT_U8(global->type);
|
||||
EMIT_U8(global->is_mutable);
|
||||
EMIT_U8(global->type.val_type);
|
||||
EMIT_U8(global->type.is_mutable);
|
||||
|
||||
offset = align_uint(offset, 4);
|
||||
if (!aot_emit_init_expr(buf, buf_end, &offset, comp_ctx,
|
||||
|
||||
@ -174,7 +174,7 @@ compile_global(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||
+ (comp_ctx->pointer_size == sizeof(uint64)
|
||||
? comp_data->import_globals[global_idx].data_offset_64bit
|
||||
: comp_data->import_globals[global_idx].data_offset_32bit);
|
||||
global_type = comp_data->import_globals[global_idx].type;
|
||||
global_type = comp_data->import_globals[global_idx].type.val_type;
|
||||
}
|
||||
else {
|
||||
global_offset =
|
||||
@ -185,7 +185,8 @@ compile_global(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||
.data_offset_64bit
|
||||
: comp_data->globals[global_idx - import_global_count]
|
||||
.data_offset_32bit);
|
||||
global_type = comp_data->globals[global_idx - import_global_count].type;
|
||||
global_type =
|
||||
comp_data->globals[global_idx - import_global_count].type.val_type;
|
||||
}
|
||||
|
||||
if (comp_ctx->enable_gc && aot_is_type_gc_reftype(global_type))
|
||||
|
||||
Reference in New Issue
Block a user