diff options
author | Alon Zakai <azakai@google.com> | 2024-08-16 12:53:52 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-16 12:53:52 -0700 |
commit | 958ff4115e542ef1d0ae712f4961e342386efe54 (patch) | |
tree | 7805d641d9a73b32650a053931c4bd8c3814d804 /src/parser | |
parent | 7209629bec3961fcc12b150ba6df546d3997b6c2 (diff) | |
download | binaryen-958ff4115e542ef1d0ae712f4961e342386efe54.tar.gz binaryen-958ff4115e542ef1d0ae712f4961e342386efe54.tar.bz2 binaryen-958ff4115e542ef1d0ae712f4961e342386efe54.zip |
Implement table.init (#6827)
Also use TableInit in the interpreter to initialize module's table
state, which will now handle traps properly, fixing #6431
Diffstat (limited to 'src/parser')
-rw-r--r-- | src/parser/contexts.h | 13 | ||||
-rw-r--r-- | src/parser/parsers.h | 12 |
2 files changed, 25 insertions, 0 deletions
diff --git a/src/parser/contexts.h b/src/parser/contexts.h index 5acb842d6..7e70b6776 100644 --- a/src/parser/contexts.h +++ b/src/parser/contexts.h @@ -674,6 +674,10 @@ struct NullInstrParserCtx { makeTableCopy(Index, const std::vector<Annotation>&, TableIdxT*, TableIdxT*) { return Ok{}; } + Result<> + makeTableInit(Index, const std::vector<Annotation>&, TableIdxT*, ElemIdxT) { + return Ok{}; + } Result<> makeThrow(Index, const std::vector<Annotation>&, TagIdxT) { return Ok{}; } @@ -2325,6 +2329,15 @@ struct ParseDefsCtx : TypeParserCtx<ParseDefsCtx> { return withLoc(pos, irBuilder.makeTableCopy(*dest, *src)); } + Result<> makeTableInit(Index pos, + const std::vector<Annotation>& annotations, + Name* table, + Name elem) { + auto t = getTable(pos, table); + CHECK_ERR(t); + return withLoc(pos, irBuilder.makeTableInit(elem, *t)); + } + Result<> makeThrow(Index pos, const std::vector<Annotation>& annotations, Name tag) { return withLoc(pos, irBuilder.makeThrow(tag)); diff --git a/src/parser/parsers.h b/src/parser/parsers.h index 23286bb28..85a1febb5 100644 --- a/src/parser/parsers.h +++ b/src/parser/parsers.h @@ -206,6 +206,8 @@ Result<> makeTableFill(Ctx&, Index, const std::vector<Annotation>&); template<typename Ctx> Result<> makeTableCopy(Ctx&, Index, const std::vector<Annotation>&); template<typename Ctx> +Result<> makeTableInit(Ctx&, Index, const std::vector<Annotation>&); +template<typename Ctx> Result<> makeThrow(Ctx&, Index, const std::vector<Annotation>&); template<typename Ctx> Result<> makeRethrow(Ctx&, Index, const std::vector<Annotation>&); @@ -2069,6 +2071,16 @@ makeTableCopy(Ctx& ctx, Index pos, const std::vector<Annotation>& annotations) { template<typename Ctx> Result<> +makeTableInit(Ctx& ctx, Index pos, const std::vector<Annotation>& annotations) { + auto table = maybeTableidx(ctx); + CHECK_ERR(table); + auto elem = elemidx(ctx); + CHECK_ERR(elem); + return ctx.makeTableInit(pos, annotations, table.getPtr(), *elem); +} + +template<typename Ctx> +Result<> makeThrow(Ctx& ctx, Index pos, const std::vector<Annotation>& annotations) { auto tag = tagidx(ctx); CHECK_ERR(tag); |