diff options
author | Thomas Lively <tlively@google.com> | 2024-01-02 12:36:30 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-02 12:36:30 -0800 |
commit | 5e3f81ceb1259de752bb61d80b26381ff1448828 (patch) | |
tree | 68324fc0ad0980b40196b87e82f604fe7d5a5473 /src/parser/wat-parser.cpp | |
parent | 95ed4f3f0bf0a463cee88a63c5becde4d28692ff (diff) | |
download | binaryen-5e3f81ceb1259de752bb61d80b26381ff1448828.tar.gz binaryen-5e3f81ceb1259de752bb61d80b26381ff1448828.tar.bz2 binaryen-5e3f81ceb1259de752bb61d80b26381ff1448828.zip |
[Parser] Support standalone import definitions (#6191)
We previously support the in-line import abbreviation, but now add support for
explicit, non-abbreviated imports as well.
Diffstat (limited to 'src/parser/wat-parser.cpp')
-rw-r--r-- | src/parser/wat-parser.cpp | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/src/parser/wat-parser.cpp b/src/parser/wat-parser.cpp index 95dfa1405..a9ee2a189 100644 --- a/src/parser/wat-parser.cpp +++ b/src/parser/wat-parser.cpp @@ -80,9 +80,13 @@ Result<> parseDefs(Ctx& ctx, for (auto& def : defs) { ctx.index = def.index; WithPosition with(ctx, def.pos); - auto parsed = parser(ctx); - CHECK_ERR(parsed); - assert(parsed); + if (auto parsed = parser(ctx)) { + CHECK_ERR(parsed); + } else { + auto im = import_(ctx); + assert(im); + CHECK_ERR(im); + } } return Ok{}; } @@ -174,9 +178,13 @@ Result<> parseModule(Module& wasm, std::string_view input) { ctx.index = i; CHECK_ERR(ctx.visitFunctionStart(wasm.functions[i].get())); WithPosition with(ctx, decls.funcDefs[i].pos); - auto parsed = func(ctx); - CHECK_ERR(parsed); - assert(parsed); + if (auto parsed = func(ctx)) { + CHECK_ERR(parsed); + } else { + auto im = import_(ctx); + assert(im); + CHECK_ERR(im); + } } // Parse exports. |