summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/prebuilt/wasm-ast-lexer-gen.c1
-rw-r--r--src/prebuilt/wasm-ast-parser-gen.c702
-rw-r--r--src/wasm-apply-names.c2
-rw-r--r--src/wasm-ast-checker.c54
-rw-r--r--src/wasm-ast-lexer.c1
-rw-r--r--src/wasm-ast-parser-lexer-shared.c31
-rw-r--r--src/wasm-ast-parser-lexer-shared.h21
-rw-r--r--src/wasm-ast-parser.y76
-rw-r--r--src/wasm-ast-writer.c14
-rw-r--r--src/wasm-ast.c67
-rw-r--r--src/wasm-ast.h77
-rw-r--r--src/wasm-binary-reader-ast.c27
-rw-r--r--src/wasm-binary-writer-spec.c20
-rw-r--r--src/wasm-binary-writer.c125
-rw-r--r--src/wasm-interpreter.c26
15 files changed, 644 insertions, 600 deletions
diff --git a/src/prebuilt/wasm-ast-lexer-gen.c b/src/prebuilt/wasm-ast-lexer-gen.c
index d42e5ac8..bec84972 100644
--- a/src/prebuilt/wasm-ast-lexer-gen.c
+++ b/src/prebuilt/wasm-ast-lexer-gen.c
@@ -6010,7 +6010,6 @@ WasmAstLexer* wasm_new_ast_file_lexer(WasmAllocator* allocator,
lexer->source.file = fopen(filename, "rb");
if (!lexer->source.file) {
wasm_destroy_ast_lexer(lexer);
- wasm_free(allocator, lexer);
return NULL;
}
return lexer;
diff --git a/src/prebuilt/wasm-ast-parser-gen.c b/src/prebuilt/wasm-ast-parser-gen.c
index 5039616a..4cab08bf 100644
--- a/src/prebuilt/wasm-ast-parser-gen.c
+++ b/src/prebuilt/wasm-ast-parser-gen.c
@@ -138,6 +138,11 @@ static WasmResult parse_const(WasmType type, WasmLiteralType literal_type,
static void dup_text_list(WasmAllocator*, WasmTextList* text_list,
void** out_data, size_t* out_size);
+static WasmBool is_empty_signature(WasmFuncSignature* sig);
+
+static void append_implicit_func_declaration(WasmAllocator*, WasmLocation*,
+ WasmModule*, WasmFuncDeclaration*);
+
typedef struct BinaryErrorCallbackData {
WasmLocation* loc;
WasmAstLexer* lexer;
@@ -150,7 +155,7 @@ static void on_read_binary_error(uint32_t offset, const char* error,
#define wasm_ast_parser_lex wasm_ast_lexer_lex
-#line 154 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:339 */
+#line 159 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:339 */
# ifndef YY_NULLPTR
# if defined __cplusplus && 201103L <= __cplusplus
@@ -281,7 +286,7 @@ int wasm_ast_parser_parse (WasmAstLexer* lexer, WasmAstParser* parser);
/* Copy the second part of user declarations. */
-#line 285 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:358 */
+#line 290 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:358 */
#ifdef short
# undef short
@@ -586,19 +591,19 @@ static const yytype_uint8 yytranslate[] =
/* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
static const yytype_uint16 yyrline[] =
{
- 0, 187, 187, 193, 206, 207, 213, 214, 218, 222,
- 229, 233, 237, 244, 256, 263, 264, 270, 274, 290,
- 297, 298, 302, 303, 313, 314, 325, 328, 331, 336,
- 341, 347, 353, 361, 366, 372, 378, 384, 389, 393,
- 400, 407, 413, 419, 426, 430, 435, 442, 450, 462,
- 467, 473, 479, 485, 490, 493, 497, 503, 504, 507,
- 511, 519, 520, 525, 526, 532, 538, 548, 554, 560,
- 570, 573, 634, 643, 653, 661, 673, 674, 681, 685,
- 698, 706, 707, 714, 726, 737, 743, 752, 756, 763,
- 767, 774, 782, 789, 800, 807, 813, 816, 852, 870,
- 887, 895, 903, 921, 929, 940, 945, 954, 978, 984,
- 991, 997, 1005, 1012, 1022, 1023, 1031, 1043, 1044, 1047,
- 1048, 1055, 1064
+ 0, 192, 192, 198, 211, 212, 218, 219, 223, 227,
+ 234, 238, 242, 249, 261, 268, 269, 275, 279, 295,
+ 302, 303, 307, 308, 318, 319, 330, 333, 336, 341,
+ 346, 352, 358, 366, 371, 377, 383, 389, 394, 398,
+ 405, 412, 418, 424, 431, 435, 440, 447, 455, 467,
+ 472, 478, 484, 490, 495, 498, 502, 508, 509, 512,
+ 516, 524, 525, 530, 531, 537, 543, 553, 559, 565,
+ 575, 578, 633, 642, 652, 659, 670, 671, 678, 682,
+ 695, 703, 704, 711, 723, 734, 740, 749, 753, 760,
+ 764, 771, 779, 785, 795, 802, 808, 811, 850, 871,
+ 888, 896, 904, 922, 930, 941, 975, 984, 1008, 1014,
+ 1021, 1027, 1035, 1042, 1052, 1053, 1061, 1073, 1074, 1077,
+ 1078, 1085, 1094
};
#endif
@@ -1392,201 +1397,201 @@ yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocatio
switch (yytype)
{
case 59: /* text_list */
-#line 154 "src/wasm-ast-parser.y" /* yacc.c:1257 */
+#line 159 "src/wasm-ast-parser.y" /* yacc.c:1257 */
{ wasm_destroy_text_list(parser->allocator, &((*yyvaluep).text_list)); }
-#line 1398 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */
+#line 1403 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */
break;
case 60: /* value_type_list */
-#line 157 "src/wasm-ast-parser.y" /* yacc.c:1257 */
+#line 162 "src/wasm-ast-parser.y" /* yacc.c:1257 */
{ wasm_destroy_type_vector(parser->allocator, &((*yyvaluep).types)); }
-#line 1404 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */
+#line 1409 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */
break;
case 61: /* func_type */
-#line 167 "src/wasm-ast-parser.y" /* yacc.c:1257 */
+#line 172 "src/wasm-ast-parser.y" /* yacc.c:1257 */
{ wasm_destroy_func_signature(parser->allocator, &((*yyvaluep).func_sig)); }
-#line 1410 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */
+#line 1415 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */
break;
case 62: /* literal */
-#line 156 "src/wasm-ast-parser.y" /* yacc.c:1257 */
+#line 161 "src/wasm-ast-parser.y" /* yacc.c:1257 */
{ wasm_destroy_string_slice(parser->allocator, &((*yyvaluep).literal).text); }
-#line 1416 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */
+#line 1421 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */
break;
case 63: /* var */
-#line 158 "src/wasm-ast-parser.y" /* yacc.c:1257 */
+#line 163 "src/wasm-ast-parser.y" /* yacc.c:1257 */
{ wasm_destroy_var(parser->allocator, &((*yyvaluep).var)); }
-#line 1422 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */
+#line 1427 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */
break;
case 64: /* var_list */
-#line 159 "src/wasm-ast-parser.y" /* yacc.c:1257 */
+#line 164 "src/wasm-ast-parser.y" /* yacc.c:1257 */
{ wasm_destroy_var_vector_and_elements(parser->allocator, &((*yyvaluep).vars)); }
-#line 1428 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */
+#line 1433 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */
break;
case 65: /* bind_var */
-#line 155 "src/wasm-ast-parser.y" /* yacc.c:1257 */
+#line 160 "src/wasm-ast-parser.y" /* yacc.c:1257 */
{ wasm_destroy_string_slice(parser->allocator, &((*yyvaluep).text)); }
-#line 1434 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */
+#line 1439 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */
break;
case 66: /* quoted_text */
-#line 155 "src/wasm-ast-parser.y" /* yacc.c:1257 */
+#line 160 "src/wasm-ast-parser.y" /* yacc.c:1257 */
{ wasm_destroy_string_slice(parser->allocator, &((*yyvaluep).text)); }
-#line 1440 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */
+#line 1445 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */
break;
case 67: /* segment_contents */
-#line 164 "src/wasm-ast-parser.y" /* yacc.c:1257 */
+#line 169 "src/wasm-ast-parser.y" /* yacc.c:1257 */
{ wasm_destroy_segment(parser->allocator, &((*yyvaluep).segment)); }
-#line 1446 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */
+#line 1451 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */
break;
case 68: /* labeling */
-#line 155 "src/wasm-ast-parser.y" /* yacc.c:1257 */
+#line 160 "src/wasm-ast-parser.y" /* yacc.c:1257 */
{ wasm_destroy_string_slice(parser->allocator, &((*yyvaluep).text)); }
-#line 1452 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */
+#line 1457 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */
break;
case 71: /* expr */
-#line 160 "src/wasm-ast-parser.y" /* yacc.c:1257 */
+#line 165 "src/wasm-ast-parser.y" /* yacc.c:1257 */
{ wasm_destroy_expr(parser->allocator, ((*yyvaluep).expr)); }
-#line 1458 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */
+#line 1463 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */
break;
case 72: /* expr1 */
-#line 160 "src/wasm-ast-parser.y" /* yacc.c:1257 */
+#line 165 "src/wasm-ast-parser.y" /* yacc.c:1257 */
{ wasm_destroy_expr(parser->allocator, ((*yyvaluep).expr)); }
-#line 1464 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */
+#line 1469 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */
break;
case 73: /* expr_opt */
-#line 160 "src/wasm-ast-parser.y" /* yacc.c:1257 */
+#line 165 "src/wasm-ast-parser.y" /* yacc.c:1257 */
{ wasm_destroy_expr(parser->allocator, ((*yyvaluep).expr)); }
-#line 1470 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */
+#line 1475 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */
break;
case 74: /* non_empty_expr_list */
-#line 161 "src/wasm-ast-parser.y" /* yacc.c:1257 */
+#line 166 "src/wasm-ast-parser.y" /* yacc.c:1257 */
{ wasm_destroy_expr_list(parser->allocator, ((*yyvaluep).expr_list).first); }
-#line 1476 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */
+#line 1481 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */
break;
case 75: /* expr_list */
-#line 161 "src/wasm-ast-parser.y" /* yacc.c:1257 */
+#line 166 "src/wasm-ast-parser.y" /* yacc.c:1257 */
{ wasm_destroy_expr_list(parser->allocator, ((*yyvaluep).expr_list).first); }
-#line 1482 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */
+#line 1487 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */
break;
case 76: /* func_fields */
-#line 162 "src/wasm-ast-parser.y" /* yacc.c:1257 */
+#line 167 "src/wasm-ast-parser.y" /* yacc.c:1257 */
{ wasm_destroy_func_fields(parser->allocator, ((*yyvaluep).func_fields)); }
-#line 1488 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */
+#line 1493 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */
break;
case 77: /* func_body */
-#line 162 "src/wasm-ast-parser.y" /* yacc.c:1257 */
+#line 167 "src/wasm-ast-parser.y" /* yacc.c:1257 */
{ wasm_destroy_func_fields(parser->allocator, ((*yyvaluep).func_fields)); }
-#line 1494 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */
+#line 1499 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */
break;
case 79: /* func_info */
-#line 163 "src/wasm-ast-parser.y" /* yacc.c:1257 */
+#line 168 "src/wasm-ast-parser.y" /* yacc.c:1257 */
{ wasm_destroy_func(parser->allocator, ((*yyvaluep).func)); wasm_free(parser->allocator, ((*yyvaluep).func)); }
-#line 1500 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */
+#line 1505 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */
break;
case 80: /* func */
-#line 171 "src/wasm-ast-parser.y" /* yacc.c:1257 */
+#line 176 "src/wasm-ast-parser.y" /* yacc.c:1257 */
{ wasm_destroy_exported_func(parser->allocator, &((*yyvaluep).exported_func)); }
-#line 1506 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */
+#line 1511 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */
break;
case 84: /* segment */
-#line 164 "src/wasm-ast-parser.y" /* yacc.c:1257 */
+#line 169 "src/wasm-ast-parser.y" /* yacc.c:1257 */
{ wasm_destroy_segment(parser->allocator, &((*yyvaluep).segment)); }
-#line 1512 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */
+#line 1517 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */
break;
case 85: /* segment_list */
-#line 165 "src/wasm-ast-parser.y" /* yacc.c:1257 */
+#line 170 "src/wasm-ast-parser.y" /* yacc.c:1257 */
{ wasm_destroy_segment_vector_and_elements(parser->allocator, &((*yyvaluep).segments)); }
-#line 1518 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */
+#line 1523 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */
break;
case 88: /* memory */
-#line 166 "src/wasm-ast-parser.y" /* yacc.c:1257 */
+#line 171 "src/wasm-ast-parser.y" /* yacc.c:1257 */
{ wasm_destroy_memory(parser->allocator, &((*yyvaluep).memory)); }
-#line 1524 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */
+#line 1529 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */
break;
case 89: /* type_def */
-#line 168 "src/wasm-ast-parser.y" /* yacc.c:1257 */
+#line 173 "src/wasm-ast-parser.y" /* yacc.c:1257 */
{ wasm_destroy_func_type(parser->allocator, &((*yyvaluep).func_type)); }
-#line 1530 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */
+#line 1535 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */
break;
case 90: /* table */
-#line 159 "src/wasm-ast-parser.y" /* yacc.c:1257 */
+#line 164 "src/wasm-ast-parser.y" /* yacc.c:1257 */
{ wasm_destroy_var_vector_and_elements(parser->allocator, &((*yyvaluep).vars)); }
-#line 1536 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */
+#line 1541 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */
break;
case 91: /* import */
-#line 169 "src/wasm-ast-parser.y" /* yacc.c:1257 */
+#line 174 "src/wasm-ast-parser.y" /* yacc.c:1257 */
{ wasm_destroy_import(parser->allocator, ((*yyvaluep).import)); wasm_free(parser->allocator, ((*yyvaluep).import)); }
-#line 1542 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */
+#line 1547 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */
break;
case 92: /* export */
-#line 170 "src/wasm-ast-parser.y" /* yacc.c:1257 */
+#line 175 "src/wasm-ast-parser.y" /* yacc.c:1257 */
{ wasm_destroy_export(parser->allocator, &((*yyvaluep).export_)); }
-#line 1548 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */
+#line 1553 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */
break;
case 94: /* module_fields */
-#line 172 "src/wasm-ast-parser.y" /* yacc.c:1257 */
+#line 177 "src/wasm-ast-parser.y" /* yacc.c:1257 */
{ wasm_destroy_module(parser->allocator, ((*yyvaluep).module)); wasm_free(parser->allocator, ((*yyvaluep).module)); }
-#line 1554 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */
+#line 1559 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */
break;
case 95: /* raw_module */
-#line 173 "src/wasm-ast-parser.y" /* yacc.c:1257 */
+#line 178 "src/wasm-ast-parser.y" /* yacc.c:1257 */
{ wasm_destroy_raw_module(parser->allocator, &((*yyvaluep).raw_module)); }
-#line 1560 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */
+#line 1565 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */
break;
case 96: /* module */
-#line 172 "src/wasm-ast-parser.y" /* yacc.c:1257 */
+#line 177 "src/wasm-ast-parser.y" /* yacc.c:1257 */
{ wasm_destroy_module(parser->allocator, ((*yyvaluep).module)); wasm_free(parser->allocator, ((*yyvaluep).module)); }
-#line 1566 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */
+#line 1571 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */
break;
case 97: /* cmd */
-#line 175 "src/wasm-ast-parser.y" /* yacc.c:1257 */
+#line 180 "src/wasm-ast-parser.y" /* yacc.c:1257 */
{ wasm_destroy_command(parser->allocator, ((*yyvaluep).command)); wasm_free(parser->allocator, ((*yyvaluep).command)); }
-#line 1572 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */
+#line 1577 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */
break;
case 98: /* cmd_list */
-#line 176 "src/wasm-ast-parser.y" /* yacc.c:1257 */
+#line 181 "src/wasm-ast-parser.y" /* yacc.c:1257 */
{ wasm_destroy_command_vector_and_elements(parser->allocator, &((*yyvaluep).commands)); }
-#line 1578 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */
+#line 1583 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */
break;
case 101: /* const_list */
-#line 174 "src/wasm-ast-parser.y" /* yacc.c:1257 */
+#line 179 "src/wasm-ast-parser.y" /* yacc.c:1257 */
{ wasm_destroy_const_vector(parser->allocator, &((*yyvaluep).consts)); }
-#line 1584 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */
+#line 1589 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */
break;
case 102: /* script */
-#line 177 "src/wasm-ast-parser.y" /* yacc.c:1257 */
+#line 182 "src/wasm-ast-parser.y" /* yacc.c:1257 */
{ wasm_destroy_script(&((*yyvaluep).script)); }
-#line 1590 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */
+#line 1595 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */
break;
@@ -1878,18 +1883,18 @@ yyreduce:
switch (yyn)
{
case 2:
-#line 187 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 192 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
WasmTextListNode* node = new_text_list_node(parser->allocator);
DUPTEXT(node->text, (yyvsp[0].text));
node->next = NULL;
(yyval.text_list).first = (yyval.text_list).last = node;
}
-#line 1889 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 1894 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 3:
-#line 193 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 198 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.text_list) = (yyvsp[-1].text_list);
WasmTextListNode* node = new_text_list_node(parser->allocator);
@@ -1898,83 +1903,83 @@ yyreduce:
(yyval.text_list).last->next = node;
(yyval.text_list).last = node;
}
-#line 1902 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 1907 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 4:
-#line 206 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 211 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{ WASM_ZERO_MEMORY((yyval.types)); }
-#line 1908 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 1913 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 5:
-#line 207 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 212 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.types) = (yyvsp[-1].types);
wasm_append_type_value(parser->allocator, &(yyval.types), &(yyvsp[0].type));
}
-#line 1917 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 1922 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 6:
-#line 213 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 218 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{ WASM_ZERO_MEMORY((yyval.func_sig)); }
-#line 1923 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 1928 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 7:
-#line 214 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 219 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.func_sig).result_type = WASM_TYPE_VOID;
(yyval.func_sig).param_types = (yyvsp[-1].types);
}
-#line 1932 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 1937 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 8:
-#line 218 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 223 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.func_sig).result_type = (yyvsp[-1].type);
(yyval.func_sig).param_types = (yyvsp[-5].types);
}
-#line 1941 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 1946 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 9:
-#line 222 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 227 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{ WASM_ZERO_MEMORY((yyval.func_sig)); (yyval.func_sig).result_type = (yyvsp[-1].type); }
-#line 1947 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 1952 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 10:
-#line 229 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 234 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.literal).type = (yyvsp[0].literal).type;
DUPTEXT((yyval.literal).text, (yyvsp[0].literal).text);
}
-#line 1956 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 1961 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 11:
-#line 233 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 238 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.literal).type = (yyvsp[0].literal).type;
DUPTEXT((yyval.literal).text, (yyvsp[0].literal).text);
}
-#line 1965 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 1970 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 12:
-#line 237 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 242 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.literal).type = (yyvsp[0].literal).type;
DUPTEXT((yyval.literal).text, (yyvsp[0].literal).text);
}
-#line 1974 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 1979 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 13:
-#line 244 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 249 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.var).loc = (yylsp[0]);
(yyval.var).type = WASM_VAR_TYPE_INDEX;
@@ -1987,42 +1992,42 @@ yyreduce:
}
(yyval.var).index = index;
}
-#line 1991 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 1996 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 14:
-#line 256 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 261 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.var).loc = (yylsp[0]);
(yyval.var).type = WASM_VAR_TYPE_NAME;
DUPTEXT((yyval.var).name, (yyvsp[0].text));
}
-#line 2001 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2006 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 15:
-#line 263 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 268 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{ WASM_ZERO_MEMORY((yyval.vars)); }
-#line 2007 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2012 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 16:
-#line 264 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 269 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.vars) = (yyvsp[-1].vars);
wasm_append_var_value(parser->allocator, &(yyval.vars), &(yyvsp[0].var));
}
-#line 2016 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2021 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 17:
-#line 270 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 275 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{ DUPTEXT((yyval.text), (yyvsp[0].text)); }
-#line 2022 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2027 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 18:
-#line 274 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 279 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
WasmTextListNode node;
node.text = (yyvsp[0].text);
@@ -2036,38 +2041,38 @@ yyreduce:
(yyval.text).start = data;
(yyval.text).length = size;
}
-#line 2040 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2045 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 19:
-#line 290 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 295 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
dup_text_list(parser->allocator, &(yyvsp[0].text_list), &(yyval.segment).data, &(yyval.segment).size);
wasm_destroy_text_list(parser->allocator, &(yyvsp[0].text_list));
}
-#line 2049 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2054 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 20:
-#line 297 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 302 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{ WASM_ZERO_MEMORY((yyval.text)); }
-#line 2055 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2060 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 21:
-#line 298 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 303 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{ (yyval.text) = (yyvsp[0].text); }
-#line 2061 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2066 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 22:
-#line 302 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 307 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{ (yyval.u64) = 0; }
-#line 2067 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2072 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 23:
-#line 303 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 308 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
if (WASM_FAILED(wasm_parse_int64((yyvsp[0].text).start, (yyvsp[0].text).start + (yyvsp[0].text).length, &(yyval.u64),
WASM_PARSE_SIGNED_AND_UNSIGNED))) {
@@ -2076,17 +2081,17 @@ yyreduce:
WASM_PRINTF_STRING_SLICE_ARG((yyvsp[0].text)));
}
}
-#line 2080 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2085 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 24:
-#line 313 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 318 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{ (yyval.u32) = USE_NATURAL_ALIGNMENT; }
-#line 2086 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2091 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 25:
-#line 314 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 319 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
if (WASM_FAILED(wasm_parse_int32((yyvsp[0].text).start, (yyvsp[0].text).start + (yyvsp[0].text).length, &(yyval.u32),
WASM_PARSE_UNSIGNED_ONLY))) {
@@ -2095,67 +2100,67 @@ yyreduce:
WASM_PRINTF_STRING_SLICE_ARG((yyvsp[0].text)));
}
}
-#line 2099 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2104 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 26:
-#line 325 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 330 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{ (yyval.expr) = (yyvsp[-1].expr); (yyval.expr)->loc = (yylsp[-2]); }
-#line 2105 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2110 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 27:
-#line 328 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 333 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.expr) = wasm_new_empty_expr(parser->allocator, WASM_EXPR_TYPE_NOP);
}
-#line 2113 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2118 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 28:
-#line 331 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 336 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.expr) = wasm_new_block_expr(parser->allocator);
(yyval.expr)->block.label = (yyvsp[-1].text);
(yyval.expr)->block.first = (yyvsp[0].expr_list).first;
}
-#line 2123 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2128 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 29:
-#line 336 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 341 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.expr) = wasm_new_if_expr(parser->allocator);
(yyval.expr)->if_.cond = (yyvsp[-1].expr);
(yyval.expr)->if_.true_.first = (yyvsp[0].expr);
}
-#line 2133 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2138 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 30:
-#line 341 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 346 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.expr) = wasm_new_if_expr(parser->allocator);
(yyval.expr)->if_.cond = (yyvsp[-5].expr);
(yyval.expr)->if_.true_.label = (yyvsp[-2].text);
(yyval.expr)->if_.true_.first = (yyvsp[-1].expr_list).first;
}
-#line 2144 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2149 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 31:
-#line 347 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 352 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.expr) = wasm_new_if_else_expr(parser->allocator);
(yyval.expr)->if_else.cond = (yyvsp[-2].expr);
(yyval.expr)->if_else.true_.first = (yyvsp[-1].expr);
(yyval.expr)->if_else.false_.first = (yyvsp[0].expr);
}
-#line 2155 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2160 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 32:
-#line 353 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 358 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.expr) = wasm_new_if_else_expr(parser->allocator);
(yyval.expr)->if_else.cond = (yyvsp[-10].expr);
@@ -2164,73 +2169,73 @@ yyreduce:
(yyval.expr)->if_else.false_.label = (yyvsp[-2].text);
(yyval.expr)->if_else.false_.first = (yyvsp[-1].expr_list).first;
}
-#line 2168 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2173 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 33:
-#line 361 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 366 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.expr) = wasm_new_br_if_expr(parser->allocator);
(yyval.expr)->br_if.var = (yyvsp[-1].var);
(yyval.expr)->br_if.cond = (yyvsp[0].expr);
}
-#line 2178 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2183 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 34:
-#line 366 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 371 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.expr) = wasm_new_br_if_expr(parser->allocator);
(yyval.expr)->br_if.var = (yyvsp[-2].var);
(yyval.expr)->br_if.expr = (yyvsp[-1].expr);
(yyval.expr)->br_if.cond = (yyvsp[0].expr);
}
-#line 2189 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2194 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 35:
-#line 372 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 377 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.expr) = wasm_new_loop_expr(parser->allocator);
WASM_ZERO_MEMORY((yyval.expr)->loop.outer);
(yyval.expr)->loop.inner = (yyvsp[-1].text);
(yyval.expr)->loop.first = (yyvsp[0].expr_list).first;
}
-#line 2200 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2205 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 36:
-#line 378 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 383 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.expr) = wasm_new_loop_expr(parser->allocator);
(yyval.expr)->loop.outer = (yyvsp[-2].text);
(yyval.expr)->loop.inner = (yyvsp[-1].text);
(yyval.expr)->loop.first = (yyvsp[0].expr_list).first;
}
-#line 2211 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2216 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 37:
-#line 384 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 389 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.expr) = wasm_new_br_expr(parser->allocator);
(yyval.expr)->br.var = (yyvsp[-1].var);
(yyval.expr)->br.expr = (yyvsp[0].expr);
}
-#line 2221 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2226 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 38:
-#line 389 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 394 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.expr) = wasm_new_return_expr(parser->allocator);
(yyval.expr)->return_.expr = (yyvsp[0].expr);
}
-#line 2230 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2235 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 39:
-#line 393 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 398 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.expr) = wasm_new_br_table_expr(parser->allocator);
(yyval.expr)->br_table.key = (yyvsp[0].expr);
@@ -2238,11 +2243,11 @@ yyreduce:
(yyval.expr)->br_table.targets = (yyvsp[-2].vars);
(yyval.expr)->br_table.default_target = (yyvsp[-1].var);
}
-#line 2242 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2247 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 40:
-#line 400 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 405 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.expr) = wasm_new_br_table_expr(parser->allocator);
(yyval.expr)->br_table.key = (yyvsp[0].expr);
@@ -2250,33 +2255,33 @@ yyreduce:
(yyval.expr)->br_table.targets = (yyvsp[-3].vars);
(yyval.expr)->br_table.default_target = (yyvsp[-2].var);
}
-#line 2254 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2259 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 41:
-#line 407 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 412 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.expr) = wasm_new_call_expr(parser->allocator);
(yyval.expr)->call.var = (yyvsp[-1].var);
(yyval.expr)->call.first_arg = (yyvsp[0].expr_list).first;
(yyval.expr)->call.num_args = (yyvsp[0].expr_list).size;
}
-#line 2265 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2270 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 42:
-#line 413 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 418 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.expr) = wasm_new_call_import_expr(parser->allocator);
(yyval.expr)->call.var = (yyvsp[-1].var);
(yyval.expr)->call.first_arg = (yyvsp[0].expr_list).first;
(yyval.expr)->call.num_args = (yyvsp[0].expr_list).size;
}
-#line 2276 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2281 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 43:
-#line 419 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 424 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.expr) = wasm_new_call_indirect_expr(parser->allocator);
(yyval.expr)->call_indirect.var = (yyvsp[-2].var);
@@ -2284,30 +2289,30 @@ yyreduce:
(yyval.expr)->call_indirect.first_arg = (yyvsp[0].expr_list).first;
(yyval.expr)->call_indirect.num_args = (yyvsp[0].expr_list).size;
}
-#line 2288 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2293 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 44:
-#line 426 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 431 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.expr) = wasm_new_get_local_expr(parser->allocator);
(yyval.expr)->get_local.var = (yyvsp[0].var);
}
-#line 2297 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2302 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 45:
-#line 430 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 435 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.expr) = wasm_new_set_local_expr(parser->allocator);
(yyval.expr)->set_local.var = (yyvsp[-1].var);
(yyval.expr)->set_local.expr = (yyvsp[0].expr);
}
-#line 2307 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2312 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 46:
-#line 435 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 440 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.expr) = wasm_new_load_expr(parser->allocator);
(yyval.expr)->load.opcode = (yyvsp[-3].opcode);
@@ -2315,11 +2320,11 @@ yyreduce:
(yyval.expr)->load.align = (yyvsp[-1].u32);
(yyval.expr)->load.addr = (yyvsp[0].expr);
}
-#line 2319 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2324 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 47:
-#line 442 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 447 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.expr) = wasm_new_store_expr(parser->allocator);
(yyval.expr)->store.opcode = (yyvsp[-4].opcode);
@@ -2328,11 +2333,11 @@ yyreduce:
(yyval.expr)->store.addr = (yyvsp[-1].expr);
(yyval.expr)->store.value = (yyvsp[0].expr);
}
-#line 2332 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2337 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 48:
-#line 450 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 455 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.expr) = wasm_new_const_expr(parser->allocator);
(yyval.expr)->const_.loc = (yylsp[-1]);
@@ -2345,144 +2350,144 @@ yyreduce:
}
wasm_free(parser->allocator, (char*)(yyvsp[0].literal).text.start);
}
-#line 2349 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2354 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 49:
-#line 462 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 467 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.expr) = wasm_new_unary_expr(parser->allocator);
(yyval.expr)->unary.opcode = (yyvsp[-1].opcode);
(yyval.expr)->unary.expr = (yyvsp[0].expr);
}
-#line 2359 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2364 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 50:
-#line 467 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 472 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.expr) = wasm_new_binary_expr(parser->allocator);
(yyval.expr)->binary.opcode = (yyvsp[-2].opcode);
(yyval.expr)->binary.left = (yyvsp[-1].expr);
(yyval.expr)->binary.right = (yyvsp[0].expr);
}
-#line 2370 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2375 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 51:
-#line 473 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 478 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.expr) = wasm_new_select_expr(parser->allocator);
(yyval.expr)->select.true_ = (yyvsp[-2].expr);
(yyval.expr)->select.false_ = (yyvsp[-1].expr);
(yyval.expr)->select.cond = (yyvsp[0].expr);
}
-#line 2381 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2386 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 52:
-#line 479 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 484 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.expr) = wasm_new_compare_expr(parser->allocator);
(yyval.expr)->compare.opcode = (yyvsp[-2].opcode);
(yyval.expr)->compare.left = (yyvsp[-1].expr);
(yyval.expr)->compare.right = (yyvsp[0].expr);
}
-#line 2392 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2397 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 53:
-#line 485 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 490 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.expr) = wasm_new_convert_expr(parser->allocator);
(yyval.expr)->convert.opcode = (yyvsp[-1].opcode);
(yyval.expr)->convert.expr = (yyvsp[0].expr);
}
-#line 2402 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2407 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 54:
-#line 490 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 495 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.expr) = wasm_new_empty_expr(parser->allocator, WASM_EXPR_TYPE_UNREACHABLE);
}
-#line 2410 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2415 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 55:
-#line 493 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 498 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.expr) = wasm_new_empty_expr(parser->allocator,
WASM_EXPR_TYPE_CURRENT_MEMORY);
}
-#line 2419 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2424 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 56:
-#line 497 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 502 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.expr) = wasm_new_grow_memory_expr(parser->allocator);
(yyval.expr)->grow_memory.expr = (yyvsp[0].expr);
}
-#line 2428 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2433 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 57:
-#line 503 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 508 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{ (yyval.expr) = NULL; }
-#line 2434 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2439 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 59:
-#line 507 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 512 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.expr_list).first = (yyval.expr_list).last = (yyvsp[0].expr);
(yyval.expr_list).size = 1;
}
-#line 2443 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2448 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 60:
-#line 511 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 516 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.expr_list) = (yyvsp[-1].expr_list);
(yyval.expr_list).last->next = (yyvsp[0].expr);
(yyval.expr_list).last = (yyvsp[0].expr);
(yyval.expr_list).size++;
}
-#line 2454 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2459 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 61:
-#line 519 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 524 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{ WASM_ZERO_MEMORY((yyval.expr_list)); }
-#line 2460 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2465 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 64:
-#line 526 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 531 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.func_fields) = new_func_field(parser->allocator);
(yyval.func_fields)->type = WASM_FUNC_FIELD_TYPE_RESULT_TYPE;
(yyval.func_fields)->result_type = (yyvsp[-2].type);
(yyval.func_fields)->next = (yyvsp[0].func_fields);
}
-#line 2471 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2476 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 65:
-#line 532 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 537 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.func_fields) = new_func_field(parser->allocator);
(yyval.func_fields)->type = WASM_FUNC_FIELD_TYPE_PARAM_TYPES;
(yyval.func_fields)->types = (yyvsp[-2].types);
(yyval.func_fields)->next = (yyvsp[0].func_fields);
}
-#line 2482 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2487 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 66:
-#line 538 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 543 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.func_fields) = new_func_field(parser->allocator);
(yyval.func_fields)->type = WASM_FUNC_FIELD_TYPE_BOUND_PARAM;
@@ -2491,33 +2496,33 @@ yyreduce:
(yyval.func_fields)->bound_type.type = (yyvsp[-2].type);
(yyval.func_fields)->next = (yyvsp[0].func_fields);
}
-#line 2495 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2500 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 67:
-#line 548 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 553 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.func_fields) = new_func_field(parser->allocator);
(yyval.func_fields)->type = WASM_FUNC_FIELD_TYPE_EXPRS;
(yyval.func_fields)->first_expr = (yyvsp[0].expr_list).first;
(yyval.func_fields)->next = NULL;
}
-#line 2506 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2511 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 68:
-#line 554 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 559 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.func_fields) = new_func_field(parser->allocator);
(yyval.func_fields)->type = WASM_FUNC_FIELD_TYPE_LOCAL_TYPES;
(yyval.func_fields)->types = (yyvsp[-2].types);
(yyval.func_fields)->next = (yyvsp[0].func_fields);
}
-#line 2517 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2522 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 69:
-#line 560 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 565 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.func_fields) = new_func_field(parser->allocator);
(yyval.func_fields)->type = WASM_FUNC_FIELD_TYPE_BOUND_LOCAL;
@@ -2526,29 +2531,23 @@ yyreduce:
(yyval.func_fields)->bound_type.type = (yyvsp[-2].type);
(yyval.func_fields)->next = (yyvsp[0].func_fields);
}
-#line 2530 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2535 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 70:
-#line 570 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 575 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{ (yyval.var) = (yyvsp[-1].var); }
-#line 2536 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2541 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 71:
-#line 573 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 578 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.func) = new_func(parser->allocator);
WasmFuncField* field = (yyvsp[0].func_fields);
+
while (field) {
WasmFuncField* next = field->next;
-
- if (field->type == WASM_FUNC_FIELD_TYPE_PARAM_TYPES ||
- field->type == WASM_FUNC_FIELD_TYPE_BOUND_PARAM ||
- field->type == WASM_FUNC_FIELD_TYPE_RESULT_TYPE) {
- (yyval.func)->decl.flags = WASM_FUNC_DECLARATION_FLAG_HAS_SIGNATURE;
- }
-
switch (field->type) {
case WASM_FUNC_FIELD_TYPE_EXPRS:
(yyval.func)->first_expr = field->first_expr;
@@ -2596,11 +2595,11 @@ yyreduce:
field = next;
}
}
-#line 2600 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2599 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 72:
-#line 634 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 633 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.exported_func).func = (yyvsp[-1].func);
(yyval.exported_func).func->loc = (yylsp[-4]);
@@ -2610,11 +2609,11 @@ yyreduce:
(yyval.exported_func).export_.var.type = WASM_VAR_TYPE_INDEX;
(yyval.exported_func).export_.var.index = -1;
}
-#line 2614 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2613 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 73:
-#line 643 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 642 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.exported_func).func = (yyvsp[-1].func);
(yyval.exported_func).func->loc = (yylsp[-5]);
@@ -2625,50 +2624,48 @@ yyreduce:
(yyval.exported_func).export_.var.type = WASM_VAR_TYPE_INDEX;
(yyval.exported_func).export_.var.index = -1;
}
-#line 2629 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2628 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 74:
-#line 653 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 652 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.exported_func).func = (yyvsp[-1].func);
(yyval.exported_func).func->loc = (yylsp[-3]);
- (yyval.exported_func).func->decl.flags = WASM_FUNC_DECLARATION_FLAG_HAS_SIGNATURE;
(yyval.exported_func).export_.name = (yyvsp[-2].text);
(yyval.exported_func).export_.var.type = WASM_VAR_TYPE_INDEX;
(yyval.exported_func).export_.var.index = -1;
}
-#line 2642 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2640 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 75:
-#line 661 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 659 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.exported_func).func = (yyvsp[-1].func);
(yyval.exported_func).func->loc = (yylsp[-4]);
- (yyval.exported_func).func->decl.flags = WASM_FUNC_DECLARATION_FLAG_HAS_SIGNATURE;
(yyval.exported_func).func->name = (yyvsp[-2].text);
(yyval.exported_func).export_.name = (yyvsp[-3].text);
(yyval.exported_func).export_.var.type = WASM_VAR_TYPE_INDEX;
(yyval.exported_func).export_.var.index = -1;
}
-#line 2656 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2653 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 76:
-#line 673 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 670 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{ WASM_ZERO_MEMORY((yyval.text)); }
-#line 2662 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2659 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 78:
-#line 681 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 678 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{ (yyval.var) = (yyvsp[-1].var); }
-#line 2668 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2665 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 79:
-#line 685 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 682 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
if (WASM_FAILED(wasm_parse_int32((yyvsp[0].literal).text.start,
(yyvsp[0].literal).text.start + (yyvsp[0].literal).text.length, &(yyval.u32),
@@ -2679,37 +2676,37 @@ yyreduce:
WASM_PRINTF_STRING_SLICE_ARG((yyvsp[0].literal).text));
}
}
-#line 2683 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2680 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 80:
-#line 698 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 695 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.segment).loc = (yylsp[-3]);
(yyval.segment).data = (yyvsp[-1].segment).data;
(yyval.segment).size = (yyvsp[-1].segment).size;
(yyval.segment).addr = (yyvsp[-2].u32);
}
-#line 2694 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2691 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 81:
-#line 706 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 703 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{ WASM_ZERO_MEMORY((yyval.segments)); }
-#line 2700 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2697 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 82:
-#line 707 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 704 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.segments) = (yyvsp[-1].segments);
wasm_append_segment_value(parser->allocator, &(yyval.segments), &(yyvsp[0].segment));
}
-#line 2709 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2706 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 83:
-#line 714 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 711 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
if (WASM_FAILED(wasm_parse_uint64((yyvsp[0].literal).text.start,
(yyvsp[0].literal).text.start + (yyvsp[0].literal).text.length, &(yyval.u64)))) {
@@ -2719,11 +2716,11 @@ yyreduce:
WASM_PRINTF_STRING_SLICE_ARG((yyvsp[0].literal).text));
}
}
-#line 2723 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2720 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 84:
-#line 726 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 723 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
if (WASM_FAILED(wasm_parse_uint64((yyvsp[0].literal).text.start,
(yyvsp[0].literal).text.start + (yyvsp[0].literal).text.length, &(yyval.u64)))) {
@@ -2732,57 +2729,57 @@ yyreduce:
WASM_PRINTF_STRING_SLICE_ARG((yyvsp[0].literal).text));
}
}
-#line 2736 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2733 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 85:
-#line 737 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 734 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.memory).loc = (yylsp[-4]);
(yyval.memory).initial_pages = (yyvsp[-3].u64);
(yyval.memory).max_pages = (yyvsp[-2].u64);
(yyval.memory).segments = (yyvsp[-1].segments);
}
-#line 2747 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2744 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 86:
-#line 743 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 740 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.memory).loc = (yylsp[-3]);
(yyval.memory).initial_pages = (yyvsp[-2].u64);
(yyval.memory).max_pages = (yyval.memory).initial_pages;
(yyval.memory).segments = (yyvsp[-1].segments);
}
-#line 2758 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2755 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 87:
-#line 752 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 749 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
WASM_ZERO_MEMORY((yyval.func_type));
(yyval.func_type).sig = (yyvsp[-2].func_sig);
}
-#line 2767 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2764 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 88:
-#line 756 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 753 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.func_type).name = (yyvsp[-5].text);
(yyval.func_type).sig = (yyvsp[-2].func_sig);
}
-#line 2776 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2773 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 89:
-#line 763 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 760 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{ (yyval.vars) = (yyvsp[-1].vars); }
-#line 2782 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2779 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 90:
-#line 767 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 764 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.import) = new_import(parser->allocator);
(yyval.import)->module_name = (yyvsp[-3].text);
@@ -2790,11 +2787,11 @@ yyreduce:
(yyval.import)->decl.flags = WASM_FUNC_DECLARATION_FLAG_HAS_FUNC_TYPE;
(yyval.import)->decl.type_var = (yyvsp[-1].var);
}
-#line 2794 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2791 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 91:
-#line 774 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 771 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.import) = new_import(parser->allocator);
(yyval.import)->name = (yyvsp[-4].text);
@@ -2803,61 +2800,59 @@ yyreduce:
(yyval.import)->decl.flags = WASM_FUNC_DECLARATION_FLAG_HAS_FUNC_TYPE;
(yyval.import)->decl.type_var = (yyvsp[-1].var);
}
-#line 2807 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2804 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 92:
-#line 782 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 779 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.import) = new_import(parser->allocator);
(yyval.import)->module_name = (yyvsp[-3].text);
(yyval.import)->func_name = (yyvsp[-2].text);
- (yyval.import)->decl.flags = WASM_FUNC_DECLARATION_FLAG_HAS_SIGNATURE;
(yyval.import)->decl.sig = (yyvsp[-1].func_sig);
}
-#line 2819 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2815 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 93:
-#line 789 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 785 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.import) = new_import(parser->allocator);
(yyval.import)->name = (yyvsp[-4].text);
(yyval.import)->module_name = (yyvsp[-3].text);
(yyval.import)->func_name = (yyvsp[-2].text);
- (yyval.import)->decl.flags = WASM_FUNC_DECLARATION_FLAG_HAS_SIGNATURE;
(yyval.import)->decl.sig = (yyvsp[-1].func_sig);
}
-#line 2832 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2827 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 94:
-#line 800 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 795 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.export_).name = (yyvsp[-2].text);
(yyval.export_).var = (yyvsp[-1].var);
}
-#line 2841 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2836 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 95:
-#line 807 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 802 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.export_memory).name = (yyvsp[-2].text);
}
-#line 2849 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2844 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 96:
-#line 813 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 808 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.module) = new_module(parser->allocator);
}
-#line 2857 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2852 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 97:
-#line 816 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 811 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.module) = (yyvsp[-1].module);
WasmModuleField* field = wasm_append_module_field(parser->allocator, (yyval.module));
@@ -2866,6 +2861,9 @@ yyreduce:
field->func = *(yyvsp[0].exported_func).func;
wasm_free(parser->allocator, (yyvsp[0].exported_func).func);
+ append_implicit_func_declaration(parser->allocator, &(yylsp[0]), (yyval.module),
+ &field->func.decl);
+
WasmFunc* func_ptr = &field->func;
wasm_append_func_ptr_value(parser->allocator, &(yyval.module)->funcs, &func_ptr);
if (field->func.name.start) {
@@ -2894,11 +2892,11 @@ yyreduce:
binding->index = (yyval.module)->exports.size - 1;
}
}
-#line 2898 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2896 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 98:
-#line 852 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 850 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.module) = (yyvsp[-1].module);
WasmModuleField* field = wasm_append_module_field(parser->allocator, (yyval.module));
@@ -2907,6 +2905,9 @@ yyreduce:
field->import = *(yyvsp[0].import);
wasm_free(parser->allocator, (yyvsp[0].import));
+ append_implicit_func_declaration(parser->allocator, &(yylsp[0]), (yyval.module),
+ &field->import.decl);
+
WasmImport* import_ptr = &field->import;
wasm_append_import_ptr_value(parser->allocator, &(yyval.module)->imports,
&import_ptr);
@@ -2917,11 +2918,11 @@ yyreduce:
binding->index = (yyval.module)->imports.size - 1;
}
}
-#line 2921 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2922 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 99:
-#line 870 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 871 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.module) = (yyvsp[-1].module);
WasmModuleField* field = wasm_append_module_field(parser->allocator, (yyval.module));
@@ -2939,11 +2940,11 @@ yyreduce:
binding->index = (yyval.module)->exports.size - 1;
}
}
-#line 2943 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2944 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 100:
-#line 887 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 888 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.module) = (yyvsp[-1].module);
WasmModuleField* field = wasm_append_module_field(parser->allocator, (yyval.module));
@@ -2952,11 +2953,11 @@ yyreduce:
field->export_memory = (yyvsp[0].export_memory);
(yyval.module)->export_memory = &field->export_memory;
}
-#line 2956 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2957 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 101:
-#line 895 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 896 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.module) = (yyvsp[-1].module);
WasmModuleField* field = wasm_append_module_field(parser->allocator, (yyval.module));
@@ -2965,11 +2966,11 @@ yyreduce:
field->table = (yyvsp[0].vars);
(yyval.module)->table = &field->table;
}
-#line 2969 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2970 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 102:
-#line 903 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 904 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.module) = (yyvsp[-1].module);
WasmModuleField* field = wasm_append_module_field(parser->allocator, (yyval.module));
@@ -2988,11 +2989,11 @@ yyreduce:
binding->index = (yyval.module)->func_types.size - 1;
}
}
-#line 2992 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 2993 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 103:
-#line 921 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 922 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.module) = (yyvsp[-1].module);
WasmModuleField* field = wasm_append_module_field(parser->allocator, (yyval.module));
@@ -3001,11 +3002,11 @@ yyreduce:
field->memory = (yyvsp[0].memory);
(yyval.module)->memory = &field->memory;
}
-#line 3005 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 3006 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 104:
-#line 929 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 930 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.module) = (yyvsp[-1].module);
WasmModuleField* field = wasm_append_module_field(parser->allocator, (yyval.module));
@@ -3014,32 +3015,61 @@ yyreduce:
field->start = (yyvsp[0].var);
(yyval.module)->start = &field->start;
}
-#line 3018 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 3019 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 105:
-#line 940 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 941 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.raw_module).type = WASM_RAW_MODULE_TYPE_TEXT;
(yyval.raw_module).text = (yyvsp[-1].module);
(yyval.raw_module).loc = (yylsp[-2]);
+
+ /* resolve func type variables where the signature was not specified
+ * explicitly */
+ size_t i;
+ for (i = 0; i < (yyvsp[-1].module)->funcs.size; ++i) {
+ WasmFunc* func = (yyvsp[-1].module)->funcs.data[i];
+ if (wasm_decl_has_func_type(&func->decl) &&
+ is_empty_signature(&func->decl.sig)) {
+ WasmFuncType* func_type =
+ wasm_get_func_type_by_var((yyvsp[-1].module), &func->decl.type_var);
+ if (func_type) {
+ func->decl.sig = func_type->sig;
+ func->decl.flags |= WASM_FUNC_DECLARATION_FLAG_SHARED_SIGNATURE;
+ }
+ }
+ }
+
+ for (i = 0; i < (yyvsp[-1].module)->imports.size; ++i) {
+ WasmImport* import = (yyvsp[-1].module)->imports.data[i];
+ if (wasm_decl_has_func_type(&import->decl) &&
+ is_empty_signature(&import->decl.sig)) {
+ WasmFuncType* func_type =
+ wasm_get_func_type_by_var((yyvsp[-1].module), &import->decl.type_var);
+ if (func_type) {
+ import->decl.sig = func_type->sig;
+ import->decl.flags |= WASM_FUNC_DECLARATION_FLAG_SHARED_SIGNATURE;
+ }
+ }
+ }
}
-#line 3028 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 3058 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 106:
-#line 945 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 975 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.raw_module).type = WASM_RAW_MODULE_TYPE_BINARY;
(yyval.raw_module).loc = (yylsp[-2]);
dup_text_list(parser->allocator, &(yyvsp[-1].text_list), &(yyval.raw_module).binary.data, &(yyval.raw_module).binary.size);
wasm_destroy_text_list(parser->allocator, &(yyvsp[-1].text_list));
}
-#line 3039 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 3069 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 107:
-#line 954 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 984 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
if ((yyvsp[0].raw_module).type == WASM_RAW_MODULE_TYPE_TEXT) {
(yyval.module) = (yyvsp[0].raw_module).text;
@@ -3059,22 +3089,22 @@ yyreduce:
wasm_free(parser->allocator, (yyvsp[0].raw_module).binary.data);
}
}
-#line 3063 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 3093 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 108:
-#line 978 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 1008 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.command) = new_command(parser->allocator);
(yyval.command)->type = WASM_COMMAND_TYPE_MODULE;
(yyval.command)->module = *(yyvsp[0].module);
wasm_free(parser->allocator, (yyvsp[0].module));
}
-#line 3074 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 3104 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 109:
-#line 984 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 1014 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.command) = new_command(parser->allocator);
(yyval.command)->type = WASM_COMMAND_TYPE_INVOKE;
@@ -3082,22 +3112,22 @@ yyreduce:
(yyval.command)->invoke.name = (yyvsp[-2].text);
(yyval.command)->invoke.args = (yyvsp[-1].consts);
}
-#line 3086 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 3116 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 110:
-#line 991 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 1021 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.command) = new_command(parser->allocator);
(yyval.command)->type = WASM_COMMAND_TYPE_ASSERT_INVALID;
(yyval.command)->assert_invalid.module = (yyvsp[-2].raw_module);
(yyval.command)->assert_invalid.text = (yyvsp[-1].text);
}
-#line 3097 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 3127 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 111:
-#line 997 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 1027 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.command) = new_command(parser->allocator);
(yyval.command)->type = WASM_COMMAND_TYPE_ASSERT_RETURN;
@@ -3106,11 +3136,11 @@ yyreduce:
(yyval.command)->assert_return.invoke.args = (yyvsp[-3].consts);
(yyval.command)->assert_return.expected = (yyvsp[-1].const_);
}
-#line 3110 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 3140 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 112:
-#line 1005 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 1035 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.command) = new_command(parser->allocator);
(yyval.command)->type = WASM_COMMAND_TYPE_ASSERT_RETURN_NAN;
@@ -3118,11 +3148,11 @@ yyreduce:
(yyval.command)->assert_return_nan.invoke.name = (yyvsp[-3].text);
(yyval.command)->assert_return_nan.invoke.args = (yyvsp[-2].consts);
}
-#line 3122 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 3152 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 113:
-#line 1012 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 1042 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.command) = new_command(parser->allocator);
(yyval.command)->type = WASM_COMMAND_TYPE_ASSERT_TRAP;
@@ -3131,27 +3161,27 @@ yyreduce:
(yyval.command)->assert_trap.invoke.args = (yyvsp[-3].consts);
(yyval.command)->assert_trap.text = (yyvsp[-1].text);
}
-#line 3135 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 3165 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 114:
-#line 1022 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 1052 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{ WASM_ZERO_MEMORY((yyval.commands)); }
-#line 3141 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 3171 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 115:
-#line 1023 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 1053 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.commands) = (yyvsp[-1].commands);
wasm_append_command_value(parser->allocator, &(yyval.commands), (yyvsp[0].command));
wasm_free(parser->allocator, (yyvsp[0].command));
}
-#line 3151 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 3181 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 116:
-#line 1031 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 1061 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.const_).loc = (yylsp[-2]);
if (WASM_FAILED(parse_const((yyvsp[-2].type), (yyvsp[-1].literal).type, (yyvsp[-1].literal).text.start,
@@ -3162,41 +3192,41 @@ yyreduce:
}
wasm_free(parser->allocator, (char*)(yyvsp[-1].literal).text.start);
}
-#line 3166 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 3196 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 117:
-#line 1043 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 1073 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{ (yyval.const_).type = WASM_TYPE_VOID; }
-#line 3172 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 3202 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 119:
-#line 1047 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 1077 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{ WASM_ZERO_MEMORY((yyval.consts)); }
-#line 3178 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 3208 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 120:
-#line 1048 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 1078 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.consts) = (yyvsp[-1].consts);
wasm_append_const_value(parser->allocator, &(yyval.consts), &(yyvsp[0].const_));
}
-#line 3187 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 3217 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
case 121:
-#line 1055 "src/wasm-ast-parser.y" /* yacc.c:1646 */
+#line 1085 "src/wasm-ast-parser.y" /* yacc.c:1646 */
{
(yyval.script).commands = (yyvsp[0].commands);
parser->script = (yyval.script);
}
-#line 3196 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 3226 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
break;
-#line 3200 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
+#line 3230 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */
default: break;
}
/* User semantic actions sometimes alter yychar, and that requires
@@ -3431,7 +3461,7 @@ yyreturn:
#endif
return yyresult;
}
-#line 1067 "src/wasm-ast-parser.y" /* yacc.c:1906 */
+#line 1097 "src/wasm-ast-parser.y" /* yacc.c:1906 */
static WasmResult parse_const(WasmType type,
@@ -3533,6 +3563,30 @@ static void dup_text_list(WasmAllocator* allocator,
*out_size = dest - result;
}
+static WasmBool is_empty_signature(WasmFuncSignature* sig) {
+ return sig->result_type == WASM_TYPE_VOID && sig->param_types.size == 0;
+}
+
+static void append_implicit_func_declaration(WasmAllocator* allocator,
+ WasmLocation* loc,
+ WasmModule* module,
+ WasmFuncDeclaration* decl) {
+ if (wasm_decl_has_func_type(decl))
+ return;
+
+ int sig_index = wasm_get_func_type_index_by_decl(module, decl);
+ if (sig_index == -1) {
+ wasm_append_implicit_func_type(allocator, loc, module, &decl->sig);
+ } else {
+ /* signature already exists, share that one and destroy this one */
+ wasm_destroy_func_signature(allocator, &decl->sig);
+ WasmFuncSignature* sig = &module->func_types.data[sig_index]->sig;
+ decl->sig = *sig;
+ }
+
+ decl->flags |= WASM_FUNC_DECLARATION_FLAG_SHARED_SIGNATURE;
+}
+
WasmResult wasm_parse_ast(WasmAstLexer* lexer,
struct WasmScript* out_script,
WasmSourceErrorHandler* error_handler) {
diff --git a/src/wasm-apply-names.c b/src/wasm-apply-names.c
index 1489e134..f21abd63 100644
--- a/src/wasm-apply-names.c
+++ b/src/wasm-apply-names.c
@@ -274,8 +274,6 @@ static WasmResult visit_func(Context* ctx,
&func->decl.type_var));
}
- assert(wasm_decl_has_signature(&func->decl));
-
wasm_make_type_binding_reverse_mapping(
ctx->allocator, &func->decl.sig.param_types, &func->param_bindings,
&ctx->param_index_to_name);
diff --git a/src/wasm-ast-checker.c b/src/wasm-ast-checker.c
index dbd63712..b940d621 100644
--- a/src/wasm-ast-checker.c
+++ b/src/wasm-ast-checker.c
@@ -508,17 +508,9 @@ static void check_expr(Context* ctx,
case WASM_EXPR_TYPE_CALL: {
const WasmFunc* callee;
if (WASM_SUCCEEDED(check_func_var(ctx, &expr->call.var, &callee))) {
- const WasmFuncSignature* sig =
- wasm_decl_get_signature(ctx->current_module, &callee->decl);
- if (sig) {
- check_call(ctx, &expr->loc, &callee->name, sig, expr->call.first_arg,
- expr->call.num_args, expected_type, "call");
- } else {
- assert(wasm_decl_has_func_type(&callee->decl));
- /* We already know this will fail. Call anyway to print and log the
- * error. */
- check_func_type_var(ctx, &callee->decl.type_var, NULL);
- }
+ check_call(ctx, &expr->loc, &callee->name, &callee->decl.sig,
+ expr->call.first_arg, expr->call.num_args, expected_type,
+ "call");
}
break;
}
@@ -526,17 +518,9 @@ static void check_expr(Context* ctx,
case WASM_EXPR_TYPE_CALL_IMPORT: {
const WasmImport* import;
if (WASM_SUCCEEDED(check_import_var(ctx, &expr->call.var, &import))) {
- const WasmFuncSignature* sig =
- wasm_decl_get_signature(ctx->current_module, &import->decl);
- if (sig) {
- check_call(ctx, &expr->loc, &import->name, sig, expr->call.first_arg,
- expr->call.num_args, expected_type, "call_import");
- } else {
- assert(wasm_decl_has_func_type(&import->decl));
- /* We already know this will fail. Call anyway to print and log the
- * error. */
- check_func_type_var(ctx, &import->decl.type_var, NULL);
- }
+ check_call(ctx, &expr->loc, &import->name, &import->decl.sig,
+ expr->call.first_arg, expr->call.num_args, expected_type,
+ "call_import");
}
break;
}
@@ -746,26 +730,22 @@ static void check_func(Context* ctx,
const WasmFuncType* func_type;
if (WASM_SUCCEEDED(
check_func_type_var(ctx, &func->decl.type_var, &func_type))) {
- if (wasm_decl_has_signature(&func->decl))
- check_func_signature_matches_func_type(ctx, &func->loc, &func->decl.sig,
- func_type);
+ check_func_signature_matches_func_type(ctx, &func->loc, &func->decl.sig,
+ func_type);
}
}
check_duplicate_bindings(ctx, &func->param_bindings, "parameter");
check_duplicate_bindings(ctx, &func->local_bindings, "local");
- const WasmFuncSignature* sig =
- wasm_decl_get_signature(ctx->current_module, &func->decl);
- if (sig) {
- /* The function has an implicit label; branching to it is equivalent to the
- * returning from the function. */
- LabelNode node;
- WasmLabel label = wasm_empty_string_slice();
- push_label(ctx, &func->loc, &node, &label, sig->result_type, "func");
- check_expr_list(ctx, &func->loc, func->first_expr, sig->result_type,
- " of function result");
- pop_label(ctx);
- }
+ /* The function has an implicit label; branching to it is equivalent to the
+ * returning from the function. */
+ LabelNode node;
+ WasmLabel label = wasm_empty_string_slice();
+ push_label(ctx, &func->loc, &node, &label, func->decl.sig.result_type,
+ "func");
+ check_expr_list(ctx, &func->loc, func->first_expr, func->decl.sig.result_type,
+ " of function result");
+ pop_label(ctx);
ctx->current_func = NULL;
}
diff --git a/src/wasm-ast-lexer.c b/src/wasm-ast-lexer.c
index 508a05fc..a5824bfd 100644
--- a/src/wasm-ast-lexer.c
+++ b/src/wasm-ast-lexer.c
@@ -471,7 +471,6 @@ WasmAstLexer* wasm_new_ast_file_lexer(WasmAllocator* allocator,
lexer->source.file = fopen(filename, "rb");
if (!lexer->source.file) {
wasm_destroy_ast_lexer(lexer);
- wasm_free(allocator, lexer);
return NULL;
}
return lexer;
diff --git a/src/wasm-ast-parser-lexer-shared.c b/src/wasm-ast-parser-lexer-shared.c
index 63eb44e7..cd29172a 100644
--- a/src/wasm-ast-parser-lexer-shared.c
+++ b/src/wasm-ast-parser-lexer-shared.c
@@ -86,3 +86,34 @@ void wasm_destroy_text_list(WasmAllocator* allocator, WasmTextList* text_list) {
node = next;
}
}
+
+void wasm_destroy_func_fields(struct WasmAllocator* allocator,
+ WasmFuncField* func_field) {
+ /* destroy the entire linked-list */
+ while (func_field) {
+ WasmFuncField* next_func_field = func_field->next;
+
+ switch (func_field->type) {
+ case WASM_FUNC_FIELD_TYPE_EXPRS:
+ wasm_destroy_expr_list(allocator, func_field->first_expr);
+ break;
+
+ case WASM_FUNC_FIELD_TYPE_PARAM_TYPES:
+ case WASM_FUNC_FIELD_TYPE_LOCAL_TYPES:
+ wasm_destroy_type_vector(allocator, &func_field->types);
+ break;
+
+ case WASM_FUNC_FIELD_TYPE_BOUND_PARAM:
+ case WASM_FUNC_FIELD_TYPE_BOUND_LOCAL:
+ wasm_destroy_string_slice(allocator, &func_field->bound_type.name);
+ break;
+
+ case WASM_FUNC_FIELD_TYPE_RESULT_TYPE:
+ /* nothing to free */
+ break;
+ }
+
+ wasm_free(allocator, func_field);
+ func_field = next_func_field;
+ }
+}
diff --git a/src/wasm-ast-parser-lexer-shared.h b/src/wasm-ast-parser-lexer-shared.h
index 1617a3e1..116fa3a5 100644
--- a/src/wasm-ast-parser-lexer-shared.h
+++ b/src/wasm-ast-parser-lexer-shared.h
@@ -53,6 +53,26 @@ typedef struct WasmExportedFunc {
WasmExport export_;
} WasmExportedFunc;
+typedef enum WasmFuncFieldType {
+ WASM_FUNC_FIELD_TYPE_EXPRS,
+ WASM_FUNC_FIELD_TYPE_PARAM_TYPES,
+ WASM_FUNC_FIELD_TYPE_BOUND_PARAM,
+ WASM_FUNC_FIELD_TYPE_RESULT_TYPE,
+ WASM_FUNC_FIELD_TYPE_LOCAL_TYPES,
+ WASM_FUNC_FIELD_TYPE_BOUND_LOCAL,
+} WasmFuncFieldType;
+
+typedef struct WasmFuncField {
+ WasmFuncFieldType type;
+ union {
+ WasmExpr* first_expr;
+ WasmTypeVector types; /* WASM_FUNC_FIELD_TYPE_{PARAM,LOCAL}_TYPES */
+ WasmBoundType bound_type; /* WASM_FUNC_FIELD_TYPE_BOUND_{LOCAL, PARAM} */
+ WasmType result_type;
+ };
+ struct WasmFuncField* next;
+} WasmFuncField;
+
typedef union WasmToken {
/* terminals */
WasmStringSlice text;
@@ -122,6 +142,7 @@ void wasm_ast_format_error(WasmSourceErrorHandler*,
va_list);
void wasm_destroy_exported_func(WasmAllocator*, WasmExportedFunc*);
void wasm_destroy_text_list(WasmAllocator*, WasmTextList*);
+void wasm_destroy_func_fields(WasmAllocator*, WasmFuncField*);
WASM_EXTERN_C_END
#endif /* WASM_AST_PARSER_LEXER_SHARED_H_ */
diff --git a/src/wasm-ast-parser.y b/src/wasm-ast-parser.y
index c6e193a8..d2c21395 100644
--- a/src/wasm-ast-parser.y
+++ b/src/wasm-ast-parser.y
@@ -81,6 +81,11 @@ static WasmResult parse_const(WasmType type, WasmLiteralType literal_type,
static void dup_text_list(WasmAllocator*, WasmTextList* text_list,
void** out_data, size_t* out_size);
+static WasmBool is_empty_signature(WasmFuncSignature* sig);
+
+static void append_implicit_func_declaration(WasmAllocator*, WasmLocation*,
+ WasmModule*, WasmFuncDeclaration*);
+
typedef struct BinaryErrorCallbackData {
WasmLocation* loc;
WasmAstLexer* lexer;
@@ -573,15 +578,9 @@ func_info :
func_fields {
$$ = new_func(parser->allocator);
WasmFuncField* field = $1;
+
while (field) {
WasmFuncField* next = field->next;
-
- if (field->type == WASM_FUNC_FIELD_TYPE_PARAM_TYPES ||
- field->type == WASM_FUNC_FIELD_TYPE_BOUND_PARAM ||
- field->type == WASM_FUNC_FIELD_TYPE_RESULT_TYPE) {
- $$->decl.flags = WASM_FUNC_DECLARATION_FLAG_HAS_SIGNATURE;
- }
-
switch (field->type) {
case WASM_FUNC_FIELD_TYPE_EXPRS:
$$->first_expr = field->first_expr;
@@ -653,7 +652,6 @@ func :
| LPAR FUNC export_opt func_info RPAR {
$$.func = $4;
$$.func->loc = @2;
- $$.func->decl.flags = WASM_FUNC_DECLARATION_FLAG_HAS_SIGNATURE;
$$.export_.name = $3;
$$.export_.var.type = WASM_VAR_TYPE_INDEX;
$$.export_.var.index = -1;
@@ -661,7 +659,6 @@ func :
| LPAR FUNC export_opt bind_var func_info RPAR {
$$.func = $5;
$$.func->loc = @2;
- $$.func->decl.flags = WASM_FUNC_DECLARATION_FLAG_HAS_SIGNATURE;
$$.func->name = $4;
$$.export_.name = $3;
$$.export_.var.type = WASM_VAR_TYPE_INDEX;
@@ -783,7 +780,6 @@ import :
$$ = new_import(parser->allocator);
$$->module_name = $3;
$$->func_name = $4;
- $$->decl.flags = WASM_FUNC_DECLARATION_FLAG_HAS_SIGNATURE;
$$->decl.sig = $5;
}
| LPAR IMPORT bind_var quoted_text quoted_text func_type RPAR /* Sugar */ {
@@ -791,7 +787,6 @@ import :
$$->name = $3;
$$->module_name = $4;
$$->func_name = $5;
- $$->decl.flags = WASM_FUNC_DECLARATION_FLAG_HAS_SIGNATURE;
$$->decl.sig = $6;
}
;
@@ -821,6 +816,9 @@ module_fields :
field->func = *$2.func;
wasm_free(parser->allocator, $2.func);
+ append_implicit_func_declaration(parser->allocator, &@2, $$,
+ &field->func.decl);
+
WasmFunc* func_ptr = &field->func;
wasm_append_func_ptr_value(parser->allocator, &$$->funcs, &func_ptr);
if (field->func.name.start) {
@@ -857,6 +855,9 @@ module_fields :
field->import = *$2;
wasm_free(parser->allocator, $2);
+ append_implicit_func_declaration(parser->allocator, &@2, $$,
+ &field->import.decl);
+
WasmImport* import_ptr = &field->import;
wasm_append_import_ptr_value(parser->allocator, &$$->imports,
&import_ptr);
@@ -941,6 +942,35 @@ raw_module :
$$.type = WASM_RAW_MODULE_TYPE_TEXT;
$$.text = $3;
$$.loc = @2;
+
+ /* resolve func type variables where the signature was not specified
+ * explicitly */
+ size_t i;
+ for (i = 0; i < $3->funcs.size; ++i) {
+ WasmFunc* func = $3->funcs.data[i];
+ if (wasm_decl_has_func_type(&func->decl) &&
+ is_empty_signature(&func->decl.sig)) {
+ WasmFuncType* func_type =
+ wasm_get_func_type_by_var($3, &func->decl.type_var);
+ if (func_type) {
+ func->decl.sig = func_type->sig;
+ func->decl.flags |= WASM_FUNC_DECLARATION_FLAG_SHARED_SIGNATURE;
+ }
+ }
+ }
+
+ for (i = 0; i < $3->imports.size; ++i) {
+ WasmImport* import = $3->imports.data[i];
+ if (wasm_decl_has_func_type(&import->decl) &&
+ is_empty_signature(&import->decl.sig)) {
+ WasmFuncType* func_type =
+ wasm_get_func_type_by_var($3, &import->decl.type_var);
+ if (func_type) {
+ import->decl.sig = func_type->sig;
+ import->decl.flags |= WASM_FUNC_DECLARATION_FLAG_SHARED_SIGNATURE;
+ }
+ }
+ }
}
| LPAR MODULE text_list RPAR {
$$.type = WASM_RAW_MODULE_TYPE_BINARY;
@@ -1165,6 +1195,30 @@ static void dup_text_list(WasmAllocator* allocator,
*out_size = dest - result;
}
+static WasmBool is_empty_signature(WasmFuncSignature* sig) {
+ return sig->result_type == WASM_TYPE_VOID && sig->param_types.size == 0;
+}
+
+static void append_implicit_func_declaration(WasmAllocator* allocator,
+ WasmLocation* loc,
+ WasmModule* module,
+ WasmFuncDeclaration* decl) {
+ if (wasm_decl_has_func_type(decl))
+ return;
+
+ int sig_index = wasm_get_func_type_index_by_decl(module, decl);
+ if (sig_index == -1) {
+ wasm_append_implicit_func_type(allocator, loc, module, &decl->sig);
+ } else {
+ /* signature already exists, share that one and destroy this one */
+ wasm_destroy_func_signature(allocator, &decl->sig);
+ WasmFuncSignature* sig = &module->func_types.data[sig_index]->sig;
+ decl->sig = *sig;
+ }
+
+ decl->flags |= WASM_FUNC_DECLARATION_FLAG_SHARED_SIGNATURE;
+}
+
WasmResult wasm_parse_ast(WasmAstLexer* lexer,
struct WasmScript* out_script,
WasmSourceErrorHandler* error_handler) {
diff --git a/src/wasm-ast-writer.c b/src/wasm-ast-writer.c
index 794fe4d1..e5c45685 100644
--- a/src/wasm-ast-writer.c
+++ b/src/wasm-ast-writer.c
@@ -584,14 +584,12 @@ static void write_func(Context* ctx,
write_var(ctx, &func->decl.type_var, NEXT_CHAR_NONE);
write_close_space(ctx);
}
- if (wasm_decl_has_signature(&func->decl)) {
- write_type_bindings(ctx, "param", func, &func->decl.sig.param_types,
- &func->param_bindings);
- if (wasm_get_result_type(module, func) != WASM_TYPE_VOID) {
- write_open_space(ctx, "result");
- write_type(ctx, wasm_get_result_type(module, func), NEXT_CHAR_NONE);
- write_close_space(ctx);
- }
+ write_type_bindings(ctx, "param", func, &func->decl.sig.param_types,
+ &func->param_bindings);
+ if (wasm_get_result_type(module, func) != WASM_TYPE_VOID) {
+ write_open_space(ctx, "result");
+ write_type(ctx, wasm_get_result_type(module, func), NEXT_CHAR_NONE);
+ write_close_space(ctx);
}
write_newline(ctx, NO_FORCE_NEWLINE);
if (func->local_types.size) {
diff --git a/src/wasm-ast.c b/src/wasm-ast.c
index 54282f2d..4510ddb8 100644
--- a/src/wasm-ast.c
+++ b/src/wasm-ast.c
@@ -222,6 +222,24 @@ WasmFuncTypePtr wasm_get_func_type_by_var(const WasmModule* module,
return module->func_types.data[index];
}
+int wasm_get_func_type_index_by_sig(const WasmModule* module,
+ const WasmFuncSignature* sig) {
+ size_t i;
+ for (i = 0; i < module->func_types.size; ++i)
+ if (wasm_signatures_are_equal(&module->func_types.data[i]->sig, sig))
+ return i;
+ return -1;
+}
+
+int wasm_get_func_type_index_by_decl(const WasmModule* module,
+ const WasmFuncDeclaration* decl) {
+ if (wasm_decl_has_func_type(decl)) {
+ return wasm_get_func_type_index_by_var(module, &decl->type_var);
+ } else {
+ return wasm_get_func_type_index_by_sig(module, &decl->sig);
+ }
+}
+
WasmImportPtr wasm_get_import_by_var(const WasmModule* module,
const WasmVar* var) {
int index = wasm_get_index_from_var(&module->import_bindings, var);
@@ -265,6 +283,21 @@ WasmModuleField* wasm_append_module_field(struct WasmAllocator* allocator,
return result;
}
+WasmFuncType* wasm_append_implicit_func_type(struct WasmAllocator* allocator,
+ WasmLocation* loc,
+ WasmModule* module,
+ WasmFuncSignature* sig) {
+ WasmModuleField* field = wasm_append_module_field(allocator, module);
+ field->loc = *loc;
+ field->type = WASM_MODULE_FIELD_TYPE_FUNC_TYPE;
+ field->func_type.sig = *sig;
+
+ WasmFuncType* func_type_ptr = &field->func_type;
+ wasm_append_func_type_ptr_value(allocator, &module->func_types,
+ &func_type_ptr);
+ return func_type_ptr;
+}
+
#define ALLOC_EXPR_TYPE_ZERO(allocator, member) \
wasm_alloc_zero(allocator, \
offsetof(WasmExpr, member) + sizeof(((WasmExpr*)0)->member), \
@@ -454,7 +487,8 @@ void wasm_destroy_expr(WasmAllocator* allocator, WasmExpr* expr) {
void wasm_destroy_func_declaration(WasmAllocator* allocator,
WasmFuncDeclaration* decl) {
wasm_destroy_var(allocator, &decl->type_var);
- wasm_destroy_func_signature(allocator, &decl->sig);
+ if (!(decl->flags & WASM_FUNC_DECLARATION_FLAG_SHARED_SIGNATURE))
+ wasm_destroy_func_signature(allocator, &decl->sig);
}
void wasm_destroy_func(WasmAllocator* allocator, WasmFunc* func) {
@@ -483,37 +517,6 @@ void wasm_destroy_func_type(WasmAllocator* allocator, WasmFuncType* func_type) {
wasm_destroy_func_signature(allocator, &func_type->sig);
}
-void wasm_destroy_func_fields(struct WasmAllocator* allocator,
- WasmFuncField* func_field) {
- /* destroy the entire linked-list */
- while (func_field) {
- WasmFuncField* next_func_field = func_field->next;
-
- switch (func_field->type) {
- case WASM_FUNC_FIELD_TYPE_EXPRS:
- wasm_destroy_expr_list(allocator, func_field->first_expr);
- break;
-
- case WASM_FUNC_FIELD_TYPE_PARAM_TYPES:
- case WASM_FUNC_FIELD_TYPE_LOCAL_TYPES:
- wasm_destroy_type_vector(allocator, &func_field->types);
- break;
-
- case WASM_FUNC_FIELD_TYPE_BOUND_PARAM:
- case WASM_FUNC_FIELD_TYPE_BOUND_LOCAL:
- wasm_destroy_string_slice(allocator, &func_field->bound_type.name);
- break;
-
- case WASM_FUNC_FIELD_TYPE_RESULT_TYPE:
- /* nothing to free */
- break;
- }
-
- wasm_free(allocator, func_field);
- func_field = next_func_field;
- }
-}
-
void wasm_destroy_segment(WasmAllocator* allocator, WasmSegment* segment) {
wasm_free(allocator, segment->data);
}
diff --git a/src/wasm-ast.h b/src/wasm-ast.h
index 4988bcd2..3c8f270c 100644
--- a/src/wasm-ast.h
+++ b/src/wasm-ast.h
@@ -165,27 +165,6 @@ typedef struct WasmBoundType {
WasmType type;
} WasmBoundType;
-/* only used for parsing */
-typedef enum WasmFuncFieldType {
- WASM_FUNC_FIELD_TYPE_EXPRS,
- WASM_FUNC_FIELD_TYPE_PARAM_TYPES,
- WASM_FUNC_FIELD_TYPE_BOUND_PARAM,
- WASM_FUNC_FIELD_TYPE_RESULT_TYPE,
- WASM_FUNC_FIELD_TYPE_LOCAL_TYPES,
- WASM_FUNC_FIELD_TYPE_BOUND_LOCAL,
-} WasmFuncFieldType;
-
-typedef struct WasmFuncField {
- WasmFuncFieldType type;
- union {
- WasmExpr* first_expr;
- WasmTypeVector types; /* WASM_FUNC_FIELD_TYPE_{PARAM,LOCAL}_TYPES */
- WasmBoundType bound_type; /* WASM_FUNC_FIELD_TYPE_BOUND_{LOCAL, PARAM} */
- WasmType result_type;
- };
- struct WasmFuncField* next;
-} WasmFuncField;
-
typedef struct WasmFuncSignature {
WasmType result_type;
WasmTypeVector param_types;
@@ -200,7 +179,8 @@ WASM_DEFINE_VECTOR(func_type_ptr, WasmFuncTypePtr);
enum {
WASM_FUNC_DECLARATION_FLAG_HAS_FUNC_TYPE = 1,
- WASM_FUNC_DECLARATION_FLAG_HAS_SIGNATURE = 2,
+ /* set if the signature is owned by module */
+ WASM_FUNC_DECLARATION_FLAG_SHARED_SIGNATURE = 2,
};
typedef uint32_t WasmFuncDeclarationFlags;
@@ -420,6 +400,11 @@ WasmBinding* wasm_insert_binding(struct WasmAllocator*,
WasmBool wasm_hash_entry_is_free(const WasmBindingHashEntry*);
WasmModuleField* wasm_append_module_field(struct WasmAllocator*, WasmModule*);
+/* ownership of the function signature is passed to the module */
+WasmFuncType* wasm_append_implicit_func_type(struct WasmAllocator*,
+ WasmLocation*,
+ WasmModule*,
+ WasmFuncSignature*);
/* WasmExpr creation functions */
WasmExpr* wasm_new_binary_expr(struct WasmAllocator*);
@@ -458,7 +443,6 @@ void wasm_destroy_export(struct WasmAllocator*, WasmExport*);
void wasm_destroy_expr(struct WasmAllocator*, WasmExpr*);
void wasm_destroy_expr_list(struct WasmAllocator*, WasmExpr*);
void wasm_destroy_func_declaration(struct WasmAllocator*, WasmFuncDeclaration*);
-void wasm_destroy_func_fields(struct WasmAllocator*, WasmFuncField*);
void wasm_destroy_func_signature(struct WasmAllocator*, WasmFuncSignature*);
void wasm_destroy_func_type(struct WasmAllocator*, WasmFuncType*);
void wasm_destroy_func(struct WasmAllocator*, WasmFunc*);
@@ -482,6 +466,11 @@ int wasm_get_index_from_var(const WasmBindingHash* bindings,
int wasm_get_func_index_by_var(const WasmModule* module, const WasmVar* var);
int wasm_get_func_type_index_by_var(const WasmModule* module,
const WasmVar* var);
+int wasm_get_func_type_index_by_sig(const WasmModule* module,
+ const WasmFuncSignature* sig);
+int wasm_get_func_type_index_by_decl(const WasmModule* module,
+ const WasmFuncDeclaration* decl);
+
int wasm_get_import_index_by_var(const WasmModule* module, const WasmVar* var);
int wasm_get_local_index_by_var(const WasmFunc* func, const WasmVar* var);
@@ -505,31 +494,23 @@ wasm_decl_has_func_type(const WasmFuncDeclaration* decl) {
}
static WASM_INLINE WasmBool
-wasm_decl_has_signature(const WasmFuncDeclaration* decl) {
- return decl->flags & WASM_FUNC_DECLARATION_FLAG_HAS_SIGNATURE;
-}
-
-static WASM_INLINE const WasmFuncSignature* wasm_decl_get_signature(
- const WasmModule* module,
- const WasmFuncDeclaration* decl) {
- if (wasm_decl_has_func_type(decl)) {
- const WasmFuncType* func_type =
- wasm_get_func_type_by_var(module, &decl->type_var);
- if (!func_type)
- return NULL;
- return &func_type->sig;
- } else if (wasm_decl_has_signature(decl)) {
- return &decl->sig;
- } else {
- return NULL;
+wasm_signatures_are_equal(const WasmFuncSignature* sig1,
+ const WasmFuncSignature* sig2) {
+ if (sig1->result_type != sig2->result_type)
+ return WASM_FALSE;
+ if (sig1->param_types.size != sig2->param_types.size)
+ return WASM_FALSE;
+ size_t i;
+ for (i = 0; i < sig1->param_types.size; ++i) {
+ if (sig1->param_types.data[i] != sig2->param_types.data[i])
+ return WASM_FALSE;
}
+ return WASM_TRUE;
}
static WASM_INLINE size_t wasm_get_num_params(const WasmModule* module,
const WasmFunc* func) {
- const WasmFuncSignature* sig = wasm_decl_get_signature(module, &func->decl);
- assert(sig);
- return sig->param_types.size;
+ return func->decl.sig.param_types.size;
}
static WASM_INLINE size_t wasm_get_num_locals(const WasmFunc* func) {
@@ -544,10 +525,8 @@ wasm_get_num_params_and_locals(const WasmModule* module, const WasmFunc* func) {
static WASM_INLINE WasmType wasm_get_param_type(const WasmModule* module,
const WasmFunc* func,
int index) {
- const WasmFuncSignature* sig = wasm_decl_get_signature(module, &func->decl);
- assert(sig);
- assert((size_t)index < sig->param_types.size);
- return sig->param_types.data[index];
+ assert((size_t)index < func->decl.sig.param_types.size);
+ return func->decl.sig.param_types.data[index];
}
static WASM_INLINE WasmType wasm_get_local_type(const WasmFunc* func,
@@ -558,9 +537,7 @@ static WASM_INLINE WasmType wasm_get_local_type(const WasmFunc* func,
static WASM_INLINE WasmType wasm_get_result_type(const WasmModule* module,
const WasmFunc* func) {
- const WasmFuncSignature* sig = wasm_decl_get_signature(module, &func->decl);
- assert(sig);
- return sig->result_type;
+ return func->decl.sig.result_type;
}
static WASM_INLINE WasmType
diff --git a/src/wasm-binary-reader-ast.c b/src/wasm-binary-reader-ast.c
index a3dc6d37..91a79dcd 100644
--- a/src/wasm-binary-reader-ast.c
+++ b/src/wasm-binary-reader-ast.c
@@ -51,7 +51,6 @@
#define CHECK_LOCAL(local_index) \
do { \
- assert(wasm_decl_has_func_type(&ctx->current_func->decl)); \
uint32_t max_local_index = \
wasm_get_num_params_and_locals(ctx->module, ctx->current_func); \
if ((local_index) >= max_local_index) { \
@@ -351,20 +350,23 @@ static WasmResult on_import(uint32_t index,
WasmStringSlice function_name,
void* user_data) {
Context* ctx = user_data;
+ assert(index < ctx->module->imports.capacity);
+ assert(sig_index < ctx->module->func_types.size);
+
WasmModuleField* field =
wasm_append_module_field(ctx->allocator, ctx->module);
field->type = WASM_MODULE_FIELD_TYPE_IMPORT;
WasmImport* import = &field->import;
WASM_ZERO_MEMORY(*import);
- import->decl.flags = WASM_FUNC_DECLARATION_FLAG_HAS_FUNC_TYPE;
import->module_name = wasm_dup_string_slice(ctx->allocator, module_name);
import->func_name = wasm_dup_string_slice(ctx->allocator, function_name);
+ import->decl.flags = WASM_FUNC_DECLARATION_FLAG_HAS_FUNC_TYPE |
+ WASM_FUNC_DECLARATION_FLAG_SHARED_SIGNATURE;
import->decl.type_var.type = WASM_VAR_TYPE_INDEX;
- assert(sig_index < ctx->module->func_types.size);
import->decl.type_var.index = sig_index;
+ import->decl.sig = ctx->module->func_types.data[sig_index]->sig;
- assert(index < ctx->module->imports.capacity);
WasmImportPtr* import_ptr =
wasm_append_import_ptr(ctx->allocator, &ctx->module->imports);
*import_ptr = import;
@@ -382,6 +384,9 @@ static WasmResult on_function_signature(uint32_t index,
uint32_t sig_index,
void* user_data) {
Context* ctx = user_data;
+ assert(index < ctx->module->funcs.capacity);
+ assert(sig_index < ctx->module->func_types.size);
+
WasmModuleField* field =
wasm_append_module_field(ctx->allocator, ctx->module);
field->type = WASM_MODULE_FIELD_TYPE_FUNC;
@@ -389,21 +394,11 @@ static WasmResult on_function_signature(uint32_t index,
WasmFunc* func = &field->func;
WASM_ZERO_MEMORY(*func);
func->decl.flags = WASM_FUNC_DECLARATION_FLAG_HAS_FUNC_TYPE |
- WASM_FUNC_DECLARATION_FLAG_HAS_SIGNATURE;
+ WASM_FUNC_DECLARATION_FLAG_SHARED_SIGNATURE;
func->decl.type_var.type = WASM_VAR_TYPE_INDEX;
- assert(sig_index < ctx->module->func_types.size);
func->decl.type_var.index = sig_index;
+ func->decl.sig = ctx->module->func_types.data[sig_index]->sig;
- /* copy the signature from the function type */
- WasmFuncSignature* sig = &ctx->module->func_types.data[sig_index]->sig;
- size_t i;
- for (i = 0; i < sig->param_types.size; ++i) {
- wasm_append_type_value(ctx->allocator, &func->decl.sig.param_types,
- &sig->param_types.data[i]);
- }
- func->decl.sig.result_type = sig->result_type;
-
- assert(index < ctx->module->funcs.capacity);
WasmFuncPtr* func_ptr =
wasm_append_func_ptr(ctx->allocator, &ctx->module->funcs);
*func_ptr = func;
diff --git a/src/wasm-binary-writer-spec.c b/src/wasm-binary-writer-spec.c
index b76529e6..1185c0d3 100644
--- a/src/wasm-binary-writer-spec.c
+++ b/src/wasm-binary-writer-spec.c
@@ -223,11 +223,27 @@ static WasmFunc* append_nullary_func(WasmAllocator* allocator,
WasmModule* module,
WasmType result_type,
WasmStringSlice export_name) {
+ WasmFuncType* func_type;
+ WasmFuncSignature sig;
+ WASM_ZERO_MEMORY(sig);
+ sig.result_type = result_type;
+ int sig_index = wasm_get_func_type_index_by_sig(module, &sig);
+ if (sig_index == -1) {
+ WasmLocation loc;
+ WASM_ZERO_MEMORY(loc);
+ func_type = wasm_append_implicit_func_type(allocator, &loc, module, &sig);
+ sig_index = module->func_types.size - 1;
+ } else {
+ func_type = module->func_types.data[sig_index];
+ }
+
WasmModuleField* func_field =
append_module_field(allocator, module, WASM_MODULE_FIELD_TYPE_FUNC);
WasmFunc* func = &func_field->func;
- func->decl.flags = WASM_FUNC_DECLARATION_FLAG_HAS_SIGNATURE;
- func->decl.sig.result_type = result_type;
+ func->decl.flags = WASM_FUNC_DECLARATION_FLAG_HAS_FUNC_TYPE;
+ func->decl.type_var.type = WASM_VAR_TYPE_INDEX;
+ func->decl.type_var.index = sig_index;
+ func->decl.sig = func_type->sig;
int func_index = module->funcs.size - 1;
WasmModuleField* export_field =
diff --git a/src/wasm-binary-writer.c b/src/wasm-binary-writer.c
index 5019d6f5..8b699089 100644
--- a/src/wasm-binary-writer.c
+++ b/src/wasm-binary-writer.c
@@ -70,20 +70,10 @@ typedef struct Context {
size_t last_section_offset;
size_t last_section_leb_size_guess;
- int* import_sig_indexes;
- int* func_sig_indexes;
uint32_t* remapped_locals; /* from unpacked -> packed index */
uint32_t* reverse_remapped_locals; /* from packed -> unpacked index */
} Context;
-WASM_DEFINE_VECTOR(func_signature, WasmFuncSignature);
-
-static void destroy_func_signature_vector_and_elements(
- WasmAllocator* allocator,
- WasmFuncSignatureVector* sigs) {
- WASM_DESTROY_VECTOR_AND_ELEMENTS(allocator, *sigs, func_signature);
-}
-
static void write_header(Context* ctx, const char* name, int index) {
if (ctx->log_stream) {
if (index == PRINT_HEADER_NO_INDEX) {
@@ -305,93 +295,6 @@ static void pop_label(Context* ctx, const WasmLabel* label) {
pop_unused_label(ctx, label);
}
-static int find_func_signature(const WasmFuncSignatureVector* sigs,
- const WasmType result_type,
- const WasmTypeVector* param_types) {
- size_t i;
- for (i = 0; i < sigs->size; ++i) {
- const WasmFuncSignature* sig2 = &sigs->data[i];
- if (sig2->result_type != result_type)
- continue;
- if (sig2->param_types.size != param_types->size)
- continue;
- size_t j;
- for (j = 0; j < param_types->size; ++j) {
- if (sig2->param_types.data[j] != param_types->data[j])
- break;
- }
- if (j == param_types->size)
- return i;
- }
- return -1;
-}
-
-static void get_or_create_func_signature(Context* ctx,
- WasmFuncSignatureVector* sigs,
- WasmType result_type,
- const WasmTypeVector* param_types,
- int* out_index) {
- int index = find_func_signature(sigs, result_type, param_types);
- if (index == -1) {
- index = sigs->size;
- WasmFuncSignature* sig = wasm_append_func_signature(ctx->allocator, sigs);
- sig->result_type = result_type;
- WASM_ZERO_MEMORY(sig->param_types);
- wasm_extend_types(ctx->allocator, &sig->param_types, param_types);
- }
- *out_index = index;
-}
-
-static int get_signature_index(Context* ctx,
- const WasmModule* module,
- WasmFuncSignatureVector* sigs,
- const WasmFuncDeclaration* decl) {
- int index = -1;
- if (wasm_decl_has_signature(decl)) {
- get_or_create_func_signature(ctx, sigs, decl->sig.result_type,
- &decl->sig.param_types, &index);
- } else {
- assert(wasm_decl_has_func_type(decl));
- index = wasm_get_func_type_index_by_var(module, &decl->type_var);
- assert(index != -1);
- }
- return index;
-}
-
-static void get_func_signatures(Context* ctx,
- const WasmModule* module,
- WasmFuncSignatureVector* sigs) {
- /* function types are not deduped; we don't want the signature index to match
- if they were specified separately in the source */
- size_t i;
- for (i = 0; i < module->func_types.size; ++i) {
- const WasmFuncType* func_type = module->func_types.data[i];
- WasmFuncSignature* sig = wasm_append_func_signature(ctx->allocator, sigs);
- sig->result_type = func_type->sig.result_type;
- WASM_ZERO_MEMORY(sig->param_types);
- wasm_extend_types(ctx->allocator, &sig->param_types,
- &func_type->sig.param_types);
- }
-
- ctx->import_sig_indexes =
- wasm_realloc(ctx->allocator, ctx->import_sig_indexes,
- module->imports.size * sizeof(int), WASM_DEFAULT_ALIGN);
- for (i = 0; i < module->imports.size; ++i) {
- const WasmImport* import = module->imports.data[i];
- ctx->import_sig_indexes[i] =
- get_signature_index(ctx, module, sigs, &import->decl);
- }
-
- ctx->func_sig_indexes =
- wasm_realloc(ctx->allocator, ctx->func_sig_indexes,
- module->funcs.size * sizeof(int), WASM_DEFAULT_ALIGN);
- for (i = 0; i < module->funcs.size; ++i) {
- const WasmFunc* func = module->funcs.data[i];
- ctx->func_sig_indexes[i] =
- get_signature_index(ctx, module, sigs, &func->decl);
- }
-}
-
static void remap_locals(Context* ctx,
const WasmModule* module,
const WasmFunc* func) {
@@ -779,14 +682,12 @@ static void write_module(Context* ctx, const WasmModule* module) {
wasm_write_u32(&ctx->stream, WASM_BINARY_MAGIC, "WASM_BINARY_MAGIC");
wasm_write_u32(&ctx->stream, WASM_BINARY_VERSION, "WASM_BINARY_VERSION");
- WasmFuncSignatureVector sigs;
- WASM_ZERO_MEMORY(sigs);
- get_func_signatures(ctx, module, &sigs);
- if (sigs.size) {
+ if (module->func_types.size) {
begin_section(ctx, WASM_SECTION_NAME_TYPE, leb_size_guess);
- write_u32_leb128(&ctx->stream, sigs.size, "num types");
- for (i = 0; i < sigs.size; ++i) {
- const WasmFuncSignature* sig = &sigs.data[i];
+ write_u32_leb128(&ctx->stream, module->func_types.size, "num types");
+ for (i = 0; i < module->func_types.size; ++i) {
+ const WasmFuncType* func_type = module->func_types.data[i];
+ const WasmFuncSignature* sig = &func_type->sig;
write_header(ctx, "type", i);
wasm_write_u8(&ctx->stream, WASM_BINARY_TYPE_FORM_FUNCTION,
"function form");
@@ -812,7 +713,8 @@ static void write_module(Context* ctx, const WasmModule* module) {
for (i = 0; i < module->imports.size; ++i) {
const WasmImport* import = module->imports.data[i];
write_header(ctx, "import header", i);
- write_u32_leb128(&ctx->stream, ctx->import_sig_indexes[i],
+ write_u32_leb128(&ctx->stream,
+ wasm_get_func_type_index_by_decl(module, &import->decl),
"import signature index");
write_str(&ctx->stream, import->module_name.start,
import->module_name.length, WASM_PRINT_CHARS,
@@ -828,10 +730,13 @@ static void write_module(Context* ctx, const WasmModule* module) {
write_u32_leb128(&ctx->stream, module->funcs.size, "num functions");
for (i = 0; i < module->funcs.size; ++i) {
+ const WasmFunc* func = module->funcs.data[i];
char desc[100];
wasm_snprintf(desc, sizeof(desc), "function %" PRIzd " signature index",
i);
- write_u32_leb128(&ctx->stream, ctx->func_sig_indexes[i], desc);
+ write_u32_leb128(&ctx->stream,
+ wasm_get_func_type_index_by_decl(module, &func->decl),
+ desc);
}
end_section(ctx);
}
@@ -938,12 +843,9 @@ static void write_module(Context* ctx, const WasmModule* module) {
write_u32_leb128(&ctx->stream, num_params_and_locals, "num locals");
if (num_params_and_locals) {
- const WasmFuncSignature* sig =
- wasm_decl_get_signature(module, &func->decl);
remap_locals(ctx, module, func);
-
wasm_make_type_binding_reverse_mapping(
- ctx->allocator, &sig->param_types, &func->param_bindings,
+ ctx->allocator, &func->decl.sig.param_types, &func->param_bindings,
&index_to_name);
size_t j;
for (j = 0; j < num_params; ++j) {
@@ -971,7 +873,6 @@ static void write_module(Context* ctx, const WasmModule* module) {
wasm_destroy_string_slice_vector(ctx->allocator, &index_to_name);
}
- destroy_func_signature_vector_and_elements(ctx->allocator, &sigs);
}
static void write_commands(Context* ctx, const WasmScript* script) {
@@ -995,8 +896,6 @@ static void write_commands(Context* ctx, const WasmScript* script) {
}
static void cleanup_context(Context* ctx) {
- wasm_free(ctx->allocator, ctx->import_sig_indexes);
- wasm_free(ctx->allocator, ctx->func_sig_indexes);
wasm_free(ctx->allocator, ctx->remapped_locals);
wasm_free(ctx->allocator, ctx->reverse_remapped_locals);
}
diff --git a/src/wasm-interpreter.c b/src/wasm-interpreter.c
index 29d7ea82..2279cebc 100644
--- a/src/wasm-interpreter.c
+++ b/src/wasm-interpreter.c
@@ -133,7 +133,9 @@ void wasm_destroy_interpreter_thread(WasmAllocator* allocator,
* 1 11111111 111...11 => 0xffffffff => -nan(0x7fffff)
*/
+#define F32_MAX 0x7f7fffffU
#define F32_INF 0x7f800000U
+#define F32_NEG_MAX 0xff7fffffU
#define F32_NEG_INF 0xff800000U
#define F32_NEG_ONE 0xbf800000U
#define F32_NEG_ZERO 0x80000000U
@@ -242,6 +244,20 @@ static WASM_INLINE WasmBool is_in_range_f64_demote_f32(uint64_t f64_bits) {
(f64_bits >= F64_NEG_ZERO && f64_bits <= 0xc7efffffe0000000ULL);
}
+/* The WebAssembly rounding mode means that these values (which are > F32_MAX)
+ * should be rounded to F32_MAX and not set to infinity. Unfortunately, UBSAN
+ * complains that the value is not representable as a float, so we'll special
+ * case them. */
+static WASM_INLINE WasmBool
+is_in_range_f64_demote_f32_round_to_f32_max(uint64_t f64_bits) {
+ return f64_bits > 0x47efffffe0000000ULL && f64_bits < 0x47effffff0000000ULL;
+}
+
+static WASM_INLINE WasmBool
+is_in_range_f64_demote_f32_round_to_neg_f32_max(uint64_t f64_bits) {
+ return f64_bits > 0xc7efffffe0000000ULL && f64_bits < 0xc7effffff0000000ULL;
+}
+
#define IS_NAN_F32 is_nan_f32
#define IS_NAN_F64 is_nan_f64
#define IS_ZERO_F32 is_zero_f32
@@ -1342,7 +1358,13 @@ WasmInterpreterResult wasm_run_interpreter(WasmInterpreterModule* module,
case WASM_OPCODE_F32_DEMOTE_F64: {
VALUE_TYPE_F64 value = POP_F64();
- if (WASM_UNLIKELY(!is_in_range_f64_demote_f32(value))) {
+ if (WASM_LIKELY(is_in_range_f64_demote_f32(value))) {
+ PUSH_F32(BITCAST_FROM_F32((float)BITCAST_TO_F64(value)));
+ } else if (is_in_range_f64_demote_f32_round_to_f32_max(value)) {
+ PUSH_F32(F32_MAX);
+ } else if (is_in_range_f64_demote_f32_round_to_neg_f32_max(value)) {
+ PUSH_F32(F32_NEG_MAX);
+ } else {
uint32_t sign = (value >> 32) & F32_SIGN_MASK;
uint32_t tag = 0;
if (IS_NAN_F64(value)) {
@@ -1350,8 +1372,6 @@ WasmInterpreterResult wasm_run_interpreter(WasmInterpreterModule* module,
((value >> (F64_SIG_BITS - F32_SIG_BITS)) & F32_SIG_MASK);
}
PUSH_F32(sign | F32_INF | tag);
- } else {
- PUSH_F32(BITCAST_FROM_F32((float)BITCAST_TO_F64(value)));
}
break;
}