Skip to content

Commit 3bb4f48

Browse files
authored
Add support for inline export/import of tags (#1747)
This PR adds support for inline export/import of tags in modules. e.g., ``` (tag (import "foo" "bar") (param i32)) ``` This is used in the spec tests for the exception handling proposal already: https://github.com/WebAssembly/exception-handling/blob/main/test/core/tag.wast so it would be useful to support in wabt, so that the test suite can be imported in the future.
1 parent 3101535 commit 3bb4f48

File tree

4 files changed

+29
-9
lines changed

4 files changed

+29
-9
lines changed

src/wast-parser.cc

+23-5
Original file line numberDiff line numberDiff line change
@@ -1197,13 +1197,31 @@ Result WastParser::ParseElemModuleField(Module* module) {
11971197
Result WastParser::ParseTagModuleField(Module* module) {
11981198
WABT_TRACE(ParseTagModuleField);
11991199
EXPECT(Lpar);
1200-
auto field = MakeUnique<TagModuleField>(GetLocation());
12011200
EXPECT(Tag);
1202-
ParseBindVarOpt(&field->tag.name);
1203-
CHECK_RESULT(ParseTypeUseOpt(&field->tag.decl));
1204-
CHECK_RESULT(ParseUnboundFuncSignature(&field->tag.decl.sig));
1201+
std::string name;
1202+
ParseBindVarOpt(&name);
1203+
1204+
ModuleFieldList export_fields;
1205+
CHECK_RESULT(ParseInlineExports(&export_fields, ExternalKind::Tag));
1206+
1207+
if (PeekMatchLpar(TokenType::Import)) {
1208+
CheckImportOrdering(module);
1209+
auto import = MakeUnique<TagImport>(name);
1210+
CHECK_RESULT(ParseInlineImport(import.get()));
1211+
CHECK_RESULT(ParseTypeUseOpt(&import->tag.decl));
1212+
CHECK_RESULT(ParseUnboundFuncSignature(&import->tag.decl.sig));
1213+
auto field =
1214+
MakeUnique<ImportModuleField>(std::move(import), GetLocation());
1215+
module->AppendField(std::move(field));
1216+
} else {
1217+
auto field = MakeUnique<TagModuleField>(GetLocation(), name);
1218+
CHECK_RESULT(ParseTypeUseOpt(&field->tag.decl));
1219+
CHECK_RESULT(ParseUnboundFuncSignature(&field->tag.decl.sig));
1220+
module->AppendField(std::move(field));
1221+
}
1222+
1223+
AppendInlineExportFields(module, &export_fields, module->tags.size() - 1);
12051224
EXPECT(Rpar);
1206-
module->AppendField(std::move(field));
12071225
return Result::Ok;
12081226
}
12091227

test/parse/module/export-tag.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
;;; ARGS: --enable-exceptions
33
(module
44
(tag (param i32 i32))
5-
(export "my_tag" (tag 0)))
5+
(export "my_tag" (tag 0))
6+
(tag (export "my_tag_2") (param i32)))

test/parse/module/import-tag.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
;;; TOOL: wat2wasm
22
;;; ARGS: --enable-exceptions
33
(module
4-
(import "foo" "1" (tag (param f64 f32))))
4+
(import "foo" "1" (tag (param f64 f32)))
5+
(tag $t2 (import "foo" "2") (param i32 i64)))

test/typecheck/bad-tag-results.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
;;; ERROR: 1
44
(module (tag (result i32)))
55
(;; STDERR ;;;
6-
out/test/typecheck/bad-tag-results.txt:4:10: error: Tag signature must have 0 results.
6+
out/test/typecheck/bad-tag-results.txt:4:14: error: Tag signature must have 0 results.
77
(module (tag (result i32)))
8-
^^^
8+
^
99
;;; STDERR ;;)

0 commit comments

Comments
 (0)