diff options
author | Thomas Lively <tlively@google.com> | 2023-09-22 10:37:33 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-22 10:37:33 -0700 |
commit | 7d4d502500bfd22a0a4e9c1762b1bddccbe14c1c (patch) | |
tree | cc7da749e2c8e816b6da548267430320a3771171 /src/parser | |
parent | c290aadaf6c08a35311fc6fcaee557bbd66968e4 (diff) | |
download | binaryen-7d4d502500bfd22a0a4e9c1762b1bddccbe14c1c.tar.gz binaryen-7d4d502500bfd22a0a4e9c1762b1bddccbe14c1c.tar.bz2 binaryen-7d4d502500bfd22a0a4e9c1762b1bddccbe14c1c.zip |
Support function contexts in IRBuilder (#5967)
Add a `visitFunctionStart` function to IRBuilder and make it responsible for
setting the function's body when the context is closed. This will simplify
outlining, will be necessary to support branches to function scope properly, and
removes an extra block around function bodies in the new wat parser.
Diffstat (limited to 'src/parser')
-rw-r--r-- | src/parser/context-defs.cpp | 3 | ||||
-rw-r--r-- | src/parser/contexts.h | 5 | ||||
-rw-r--r-- | src/parser/wat-parser.cpp | 3 |
3 files changed, 4 insertions, 7 deletions
diff --git a/src/parser/context-defs.cpp b/src/parser/context-defs.cpp index b43b7049f..76e61d4fb 100644 --- a/src/parser/context-defs.cpp +++ b/src/parser/context-defs.cpp @@ -57,9 +57,6 @@ Result<> ParseDefsCtx::addFunc(Name, std::optional<LocalsT>, Index pos) { CHECK_ERR(withLoc(pos, irBuilder.visitEnd())); - auto body = irBuilder.build(); - CHECK_ERR(withLoc(pos, body)); - wasm.functions[index]->body = *body; return Ok{}; } diff --git a/src/parser/contexts.h b/src/parser/contexts.h index f2aeb2489..7eedcccc2 100644 --- a/src/parser/contexts.h +++ b/src/parser/contexts.h @@ -816,9 +816,10 @@ struct ParseDefsCtx : TypeParserCtx<ParseDefsCtx> { IRBuilder irBuilder; - void setFunction(Function* func) { + Result<> visitFunctionStart(Function* func) { this->func = func; - irBuilder.setFunction(func); + CHECK_ERR(irBuilder.visitFunctionStart(func)); + return Ok{}; } ParseDefsCtx(std::string_view in, diff --git a/src/parser/wat-parser.cpp b/src/parser/wat-parser.cpp index 7b58be4d5..7e106d3b9 100644 --- a/src/parser/wat-parser.cpp +++ b/src/parser/wat-parser.cpp @@ -157,8 +157,7 @@ Result<> parseModule(Module& wasm, std::string_view input) { for (Index i = 0; i < decls.funcDefs.size(); ++i) { ctx.index = i; - ctx.setFunction(wasm.functions[i].get()); - CHECK_ERR(ctx.irBuilder.makeBlock(Name{}, ctx.func->getResults())); + CHECK_ERR(ctx.visitFunctionStart(wasm.functions[i].get())); WithPosition with(ctx, decls.funcDefs[i].pos); auto parsed = func(ctx); CHECK_ERR(parsed); |