Skip to content

Commit 0f475a5

Browse files
committed
use union to replace single WASMValue
1 parent 2233ff4 commit 0f475a5

11 files changed

Lines changed: 283 additions & 230 deletions

File tree

core/iwasm/aot/aot_loader.c

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,7 +1160,7 @@ destroy_init_expr(InitializerExpression *expr)
11601160
if (expr->init_expr_type == INIT_EXPR_TYPE_STRUCT_NEW
11611161
|| expr->init_expr_type == INIT_EXPR_TYPE_ARRAY_NEW
11621162
|| expr->init_expr_type == INIT_EXPR_TYPE_ARRAY_NEW_FIXED) {
1163-
wasm_runtime_free(expr->u.data);
1163+
wasm_runtime_free(expr->u.unary.v.data);
11641164
}
11651165
}
11661166
#endif /* end of WASM_ENABLE_GC != 0 */
@@ -1218,34 +1218,34 @@ load_init_expr(const uint8 **p_buf, const uint8 *buf_end, AOTModule *module,
12181218
break;
12191219
case INIT_EXPR_TYPE_I32_CONST:
12201220
case INIT_EXPR_TYPE_F32_CONST:
1221-
read_uint32(buf, buf_end, expr->u.i32);
1221+
read_uint32(buf, buf_end, expr->u.unary.v.i32);
12221222
break;
12231223
case INIT_EXPR_TYPE_I64_CONST:
12241224
case INIT_EXPR_TYPE_F64_CONST:
1225-
read_uint64(buf, buf_end, expr->u.i64);
1225+
read_uint64(buf, buf_end, expr->u.unary.v.i64);
12261226
break;
12271227
case INIT_EXPR_TYPE_V128_CONST:
1228-
i64x2 = (uint64 *)expr->u.v128.i64x2;
1228+
i64x2 = (uint64 *)expr->u.unary.v.v128.i64x2;
12291229
CHECK_BUF(buf, buf_end, sizeof(uint64) * 2);
12301230
wasm_runtime_read_v128(buf, &i64x2[0], &i64x2[1]);
12311231
buf += sizeof(uint64) * 2;
12321232
break;
12331233
case INIT_EXPR_TYPE_GET_GLOBAL:
1234-
read_uint32(buf, buf_end, expr->u.global_index);
1234+
read_uint32(buf, buf_end, expr->u.unary.v.global_index);
12351235
break;
12361236
/* INIT_EXPR_TYPE_FUNCREF_CONST can be used when
12371237
both reference types and GC are disabled */
12381238
case INIT_EXPR_TYPE_FUNCREF_CONST:
1239-
read_uint32(buf, buf_end, expr->u.ref_index);
1239+
read_uint32(buf, buf_end, expr->u.unary.v.ref_index);
12401240
break;
12411241
#if WASM_ENABLE_GC != 0 || WASM_ENABLE_REF_TYPES != 0
12421242
case INIT_EXPR_TYPE_REFNULL_CONST:
1243-
read_uint32(buf, buf_end, expr->u.ref_index);
1243+
read_uint32(buf, buf_end, expr->u.unary.v.ref_index);
12441244
break;
12451245
#endif /* end of WASM_ENABLE_GC != 0 || WASM_ENABLE_REF_TYPES != 0 */
12461246
#if WASM_ENABLE_GC != 0
12471247
case INIT_EXPR_TYPE_I31_NEW:
1248-
read_uint32(buf, buf_end, expr->u.i32);
1248+
read_uint32(buf, buf_end, expr->u.unary.v.i32);
12491249
break;
12501250
case INIT_EXPR_TYPE_STRUCT_NEW:
12511251
{
@@ -1266,7 +1266,7 @@ load_init_expr(const uint8 **p_buf, const uint8 *buf_end, AOTModule *module,
12661266
free_if_fail = true;
12671267
init_values->count = field_count;
12681268
init_values->type_idx = type_idx;
1269-
expr->u.data = init_values;
1269+
expr->u.unary.v.data = init_values;
12701270

12711271
if (type_idx >= module->type_count) {
12721272
set_error_buf(error_buf, error_buf_size,
@@ -1304,7 +1304,7 @@ load_init_expr(const uint8 **p_buf, const uint8 *buf_end, AOTModule *module,
13041304
break;
13051305
}
13061306
case INIT_EXPR_TYPE_STRUCT_NEW_DEFAULT:
1307-
read_uint32(buf, buf_end, expr->u.type_index);
1307+
read_uint32(buf, buf_end, expr->u.unary.v.type_index);
13081308
break;
13091309
case INIT_EXPR_TYPE_ARRAY_NEW:
13101310
case INIT_EXPR_TYPE_ARRAY_NEW_DEFAULT:
@@ -1320,8 +1320,8 @@ load_init_expr(const uint8 **p_buf, const uint8 *buf_end, AOTModule *module,
13201320
read_uint32(buf, buf_end, length);
13211321

13221322
if (init_expr_type == INIT_EXPR_TYPE_ARRAY_NEW_DEFAULT) {
1323-
expr->u.array_new_default.type_index = type_idx;
1324-
expr->u.array_new_default.length = length;
1323+
expr->u.unary.v.array_new_default.type_index = type_idx;
1324+
expr->u.unary.v.array_new_default.length = length;
13251325
}
13261326
else {
13271327
uint32 i, elem_size, elem_data_count;
@@ -1332,7 +1332,7 @@ load_init_expr(const uint8 **p_buf, const uint8 *buf_end, AOTModule *module,
13321332
return false;
13331333
}
13341334
free_if_fail = true;
1335-
expr->u.data = init_values;
1335+
expr->u.unary.v.data = init_values;
13361336

13371337
init_values->type_idx = type_idx;
13381338
init_values->length = length;
@@ -1368,20 +1368,22 @@ load_init_expr(const uint8 **p_buf, const uint8 *buf_end, AOTModule *module,
13681368
case INIT_EXPR_TYPE_I64_SUB:
13691369
case INIT_EXPR_TYPE_I64_MUL:
13701370
{
1371-
expr->l_expr = expr->r_expr = NULL;
1372-
if (!(expr->l_expr = loader_malloc(sizeof(InitializerExpression),
1373-
error_buf, error_buf_size))) {
1371+
expr->u.binary.l_expr = expr->u.binary.r_expr = NULL;
1372+
if (!(expr->u.binary.l_expr =
1373+
loader_malloc(sizeof(InitializerExpression), error_buf,
1374+
error_buf_size))) {
13741375
goto fail;
13751376
}
1376-
if (!load_init_expr(&buf, buf_end, module, expr->l_expr, error_buf,
1377-
error_buf_size))
1377+
if (!load_init_expr(&buf, buf_end, module, expr->u.binary.l_expr,
1378+
error_buf, error_buf_size))
13781379
goto fail;
1379-
if (!(expr->r_expr = loader_malloc(sizeof(InitializerExpression),
1380-
error_buf, error_buf_size))) {
1380+
if (!(expr->u.binary.r_expr =
1381+
loader_malloc(sizeof(InitializerExpression), error_buf,
1382+
error_buf_size))) {
13811383
goto fail;
13821384
}
1383-
if (!load_init_expr(&buf, buf_end, module, expr->r_expr, error_buf,
1384-
error_buf_size))
1385+
if (!load_init_expr(&buf, buf_end, module, expr->u.binary.r_expr,
1386+
error_buf, error_buf_size))
13851387
goto fail;
13861388
break;
13871389
}
@@ -1398,7 +1400,7 @@ load_init_expr(const uint8 **p_buf, const uint8 *buf_end, AOTModule *module,
13981400
fail:
13991401
#if WASM_ENABLE_GC != 0
14001402
if (free_if_fail) {
1401-
wasm_runtime_free(expr->u.data);
1403+
wasm_runtime_free(expr->u.unary.v.data);
14021404
}
14031405
#else
14041406
(void)free_if_fail;

0 commit comments

Comments
 (0)