summaryrefslogtreecommitdiff
path: root/src/parser/contexts.h
diff options
context:
space:
mode:
authorThomas Lively <tlively@google.com>2023-09-21 12:42:07 -0700
committerGitHub <noreply@github.com>2023-09-21 12:42:07 -0700
commitd491136eeb94b748225be50bdcc86c74cdbd154e (patch)
tree1c1633be02656af1a9c7b05a78a4e9a0928a5fad /src/parser/contexts.h
parentec0f05cb98d6a4e30375a7a6a78966d25fdb5d9c (diff)
downloadbinaryen-d491136eeb94b748225be50bdcc86c74cdbd154e.tar.gz
binaryen-d491136eeb94b748225be50bdcc86c74cdbd154e.tar.bz2
binaryen-d491136eeb94b748225be50bdcc86c74cdbd154e.zip
[Parser] Parse if-else in the new wat parser and IRBuilder (#5963)
Parse both the straight-line and folded versions of if, including the abbreviations that allow omitting the else clause. In the IRBuilder, generalize the scope stack to be able to track scopes other than blocks and add methods for visiting the beginnings of ifs and elses.
Diffstat (limited to 'src/parser/contexts.h')
-rw-r--r--src/parser/contexts.h19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/parser/contexts.h b/src/parser/contexts.h
index 210945e8d..dae938f7f 100644
--- a/src/parser/contexts.h
+++ b/src/parser/contexts.h
@@ -312,7 +312,12 @@ struct NullInstrParserCtx {
InstrT makeBlock(Index, std::optional<Name>, BlockTypeT) {
return Ok{};
}
- InstrT finishBlock(Index, InstrsT) { return Ok{}; }
+ template<typename BlockTypeT>
+ InstrT makeIf(Index, std::optional<Name>, BlockTypeT) {
+ return Ok{};
+ }
+ InstrT visitEnd(Index, InstrsT) { return Ok{}; }
+ InstrT visitElse(Index) { return Ok{}; }
InstrT makeUnreachable(Index) { return Ok{}; }
InstrT makeNop(Index) { return Ok{}; }
@@ -994,10 +999,20 @@ struct ParseDefsCtx : TypeParserCtx<ParseDefsCtx> {
type.getSignature().results));
}
- Result<> finishBlock(Index pos, InstrsT) {
+ Result<> makeIf(Index pos, std::optional<Name> label, HeapType type) {
+ // TODO: validate labels?
+ // TODO: Move error on input types to here?
+ return withLoc(
+ pos,
+ irBuilder.makeIf(label ? *label : Name{}, type.getSignature().results));
+ }
+
+ Result<> visitEnd(Index pos, InstrsT) {
return withLoc(pos, irBuilder.visitEnd());
}
+ Result<> visitElse(Index pos) { return withLoc(pos, irBuilder.visitElse()); }
+
Result<> makeUnreachable(Index pos) {
return withLoc(pos, irBuilder.makeUnreachable());
}