Skip to content

Commit f32159b

Browse files
committed
[Parser] Parse throw_ref
1 parent f4081a2 commit f32159b

File tree

6 files changed

+152
-117
lines changed

6 files changed

+152
-117
lines changed

src/parser/contexts.h

Lines changed: 14 additions & 5 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{}; }
@@ -1406,7 +1407,9 @@ struct ParseDefsCtx : TypeParserCtx<ParseDefsCtx> {
14061407
irBuilder.makeTry(label ? *label : Name{}, type.getSignature().results));
14071408
}
14081409

1409-
Result<> makeTryTable(Index pos, std::optional<Name> label, HeapType type,
1410+
Result<> makeTryTable(Index pos,
1411+
std::optional<Name> label,
1412+
HeapType type,
14101413
const std::vector<CatchInfo>& info) {
14111414
std::vector<Name> tags;
14121415
std::vector<Index> labels;
@@ -1416,10 +1419,12 @@ struct ParseDefsCtx : TypeParserCtx<ParseDefsCtx> {
14161419
labels.push_back(info.label);
14171420
isRefs.push_back(info.isRef);
14181421
}
1419-
return withLoc(
1420-
pos,
1421-
irBuilder.makeTryTable(label ? *label : Name{}, type.getSignature().results,
1422-
tags, labels, isRefs));
1422+
return withLoc(pos,
1423+
irBuilder.makeTryTable(label ? *label : Name{},
1424+
type.getSignature().results,
1425+
tags,
1426+
labels,
1427+
isRefs));
14231428
}
14241429

14251430
Result<> visitCatch(Index pos, Name tag) {
@@ -1717,6 +1722,10 @@ struct ParseDefsCtx : TypeParserCtx<ParseDefsCtx> {
17171722
return withLoc(pos, irBuilder.makeRethrow(label));
17181723
}
17191724

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

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: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ class IRBuilder : public UnifiedExpressionVisitor<IRBuilder, Result<>> {
6565
[[nodiscard]] Result<> visitElse();
6666
[[nodiscard]] Result<> visitLoopStart(Loop* iff);
6767
[[nodiscard]] Result<> visitTryStart(Try* tryy, Name label = {});
68-
[[nodiscard]] Result<> visitTryTableStart(TryTable* trytable, Name label = {});
68+
[[nodiscard]] Result<> visitTryTableStart(TryTable* trytable,
69+
Name label = {});
6970
[[nodiscard]] Result<> visitCatch(Name tag);
7071
[[nodiscard]] Result<> visitCatchAll();
7172
[[nodiscard]] Result<> visitDelegate(Index label);
@@ -156,10 +157,14 @@ class IRBuilder : public UnifiedExpressionVisitor<IRBuilder, Result<>> {
156157
[[nodiscard]] Result<> makeTableFill(Name table);
157158
[[nodiscard]] Result<> makeTableCopy(Name destTable, Name srcTable);
158159
[[nodiscard]] Result<> makeTry(Name label, Type type);
159-
[[nodiscard]] Result<> makeTryTable(Name label, Type type, const std::vector<Name>& tags, const std::vector<Index>& labels, const std::vector<bool>& isRefs);
160+
[[nodiscard]] Result<> makeTryTable(Name label,
161+
Type type,
162+
const std::vector<Name>& tags,
163+
const std::vector<Index>& labels,
164+
const std::vector<bool>& isRefs);
160165
[[nodiscard]] Result<> makeThrow(Name tag);
161166
[[nodiscard]] Result<> makeRethrow(Index label);
162-
// [[nodiscard]] Result<> makeThrowRef();
167+
[[nodiscard]] Result<> makeThrowRef();
163168
[[nodiscard]] Result<> makeTupleMake(uint32_t arity);
164169
[[nodiscard]] Result<> makeTupleExtract(uint32_t arity, uint32_t index);
165170
[[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() {}
15251526
ThrowRef(MixedArena& allocator) {}
15261527

15271528
Expression* exnref;

src/wasm/wasm-ir-builder.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,8 +1356,11 @@ Result<> IRBuilder::makeTry(Name label, Type type) {
13561356
return visitTryStart(tryy, label);
13571357
}
13581358

1359-
Result<> IRBuilder::makeTryTable(Name label, Type type, const std::vector<Name>& tags,
1360-
const std::vector<Index>& labels, const std::vector<bool>& isRefs) {
1359+
Result<> IRBuilder::makeTryTable(Name label,
1360+
Type type,
1361+
const std::vector<Name>& tags,
1362+
const std::vector<Index>& labels,
1363+
const std::vector<bool>& isRefs) {
13611364
auto* trytable = wasm.allocator.alloc<TryTable>();
13621365
trytable->type = type;
13631366
trytable->catchTags.set(tags);
@@ -1387,7 +1390,12 @@ Result<> IRBuilder::makeRethrow(Index label) {
13871390
return Ok{};
13881391
}
13891392

1390-
// 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+
}
13911399

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

0 commit comments

Comments
 (0)