Skip to content

Commit 17d08f5

Browse files
tlivelyradekdoulik
authored andcommitted
[Parser] Parse throw_ref (WebAssembly#6238)
1 parent 1a7c0ef commit 17d08f5

File tree

6 files changed

+131
-108
lines changed

6 files changed

+131
-108
lines changed

src/parser/contexts.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,7 @@ struct NullInstrParserCtx {
453453
Result<> makeTableCopy(Index, TableIdxT*, TableIdxT*) { return Ok{}; }
454454
Result<> makeThrow(Index, TagIdxT) { return Ok{}; }
455455
Result<> makeRethrow(Index, LabelIdxT) { return Ok{}; }
456+
Result<> makeThrowRef(Index) { return Ok{}; }
456457
Result<> makeTupleMake(Index, uint32_t) { return Ok{}; }
457458
Result<> makeTupleExtract(Index, uint32_t, uint32_t) { return Ok{}; }
458459
Result<> makeTupleDrop(Index, uint32_t) { return Ok{}; }
@@ -1721,6 +1722,10 @@ struct ParseDefsCtx : TypeParserCtx<ParseDefsCtx> {
17211722
return withLoc(pos, irBuilder.makeRethrow(label));
17221723
}
17231724

1725+
Result<> makeThrowRef(Index pos) {
1726+
return withLoc(pos, irBuilder.makeThrowRef());
1727+
}
1728+
17241729
Result<> makeTupleMake(Index pos, uint32_t arity) {
17251730
return withLoc(pos, irBuilder.makeTupleMake(arity));
17261731
}

src/parser/parsers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1646,7 +1646,7 @@ template<typename Ctx> Result<> makeRethrow(Ctx& ctx, Index pos) {
16461646
}
16471647

16481648
template<typename Ctx> Result<> makeThrowRef(Ctx& ctx, Index pos) {
1649-
return ctx.in.err("unimplemented instruction");
1649+
return ctx.makeThrowRef(pos);
16501650
}
16511651

16521652
template<typename Ctx> Result<> makeTupleMake(Ctx& ctx, Index pos) {

src/wasm-ir-builder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ class IRBuilder : public UnifiedExpressionVisitor<IRBuilder, Result<>> {
164164
const std::vector<bool>& isRefs);
165165
[[nodiscard]] Result<> makeThrow(Name tag);
166166
[[nodiscard]] Result<> makeRethrow(Index label);
167-
// [[nodiscard]] Result<> makeThrowRef();
167+
[[nodiscard]] Result<> makeThrowRef();
168168
[[nodiscard]] Result<> makeTupleMake(uint32_t arity);
169169
[[nodiscard]] Result<> makeTupleExtract(uint32_t arity, uint32_t index);
170170
[[nodiscard]] Result<> makeTupleDrop(uint32_t arity);

src/wasm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1522,6 +1522,7 @@ class Rethrow : public SpecificExpression<Expression::RethrowId> {
15221522
// 'throw_ref' from the new EH proposal
15231523
class ThrowRef : public SpecificExpression<Expression::ThrowRefId> {
15241524
public:
1525+
ThrowRef() = default;
15251526
ThrowRef(MixedArena& allocator) {}
15261527

15271528
Expression* exnref;

src/wasm/wasm-ir-builder.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1390,7 +1390,12 @@ Result<> IRBuilder::makeRethrow(Index label) {
13901390
return Ok{};
13911391
}
13921392

1393-
// Result<> IRBuilder::makeThrowRef() {}
1393+
Result<> IRBuilder::makeThrowRef() {
1394+
ThrowRef curr;
1395+
CHECK_ERR(visitThrowRef(&curr));
1396+
push(builder.makeThrowRef(curr.exnref));
1397+
return Ok{};
1398+
}
13941399

13951400
Result<> IRBuilder::makeTupleMake(uint32_t arity) {
13961401
TupleMake curr(wasm.allocator);

0 commit comments

Comments
 (0)