diff options
author | Thomas Lively <tlively@google.com> | 2023-09-21 15:35:12 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-21 15:35:12 -0700 |
commit | c290aadaf6c08a35311fc6fcaee557bbd66968e4 (patch) | |
tree | 9a98e4bac4374296ea9dbc622630c0281b198e51 /src/parser/contexts.h | |
parent | 38197b57aa5bd94a879c0203b75a35cb826db929 (diff) | |
download | binaryen-c290aadaf6c08a35311fc6fcaee557bbd66968e4.tar.gz binaryen-c290aadaf6c08a35311fc6fcaee557bbd66968e4.tar.bz2 binaryen-c290aadaf6c08a35311fc6fcaee557bbd66968e4.zip |
[Parser] Support loops (#5966)
Parse loops in the new wat parser and add support for them to the IRBuilder.
Diffstat (limited to 'src/parser/contexts.h')
-rw-r--r-- | src/parser/contexts.h | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/src/parser/contexts.h b/src/parser/contexts.h index 2ecaac70e..f2aeb2489 100644 --- a/src/parser/contexts.h +++ b/src/parser/contexts.h @@ -309,8 +309,12 @@ struct NullInstrParserCtx { Result<> makeIf(Index, std::optional<Name>, BlockTypeT) { return Ok{}; } - Result<> visitEnd(Index) { return Ok{}; } - Result<> visitElse(Index) { return Ok{}; } + Result<> visitElse() { return Ok{}; } + template<typename BlockTypeT> + Result<> makeLoop(Index, std::optional<Name>, BlockTypeT) { + return Ok{}; + } + Result<> visitEnd() { return Ok{}; } Result<> makeUnreachable(Index) { return Ok{}; } Result<> makeNop(Index) { return Ok{}; } @@ -989,9 +993,17 @@ struct ParseDefsCtx : TypeParserCtx<ParseDefsCtx> { irBuilder.makeIf(label ? *label : Name{}, type.getSignature().results)); } - Result<> visitEnd(Index pos) { return withLoc(pos, irBuilder.visitEnd()); } + Result<> visitElse() { return withLoc(irBuilder.visitElse()); } + + Result<> makeLoop(Index pos, std::optional<Name> label, HeapType type) { + // TODO: validate labels? + // TODO: Move error on input types to here? + return withLoc( + pos, + irBuilder.makeLoop(label ? *label : Name{}, type.getSignature().results)); + } - Result<> visitElse(Index pos) { return withLoc(pos, irBuilder.visitElse()); } + Result<> visitEnd() { return withLoc(irBuilder.visitEnd()); } Result<> makeUnreachable(Index pos) { return withLoc(pos, irBuilder.makeUnreachable()); |