diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/parser/contexts.h | 11 | ||||
-rw-r--r-- | src/parser/parsers.h | 10 | ||||
-rw-r--r-- | src/wasm-ir-builder.h | 3 | ||||
-rw-r--r-- | src/wasm.h | 1 | ||||
-rw-r--r-- | src/wasm/wasm-ir-builder.cpp | 18 |
5 files changed, 33 insertions, 10 deletions
diff --git a/src/parser/contexts.h b/src/parser/contexts.h index bf6c291e7..4147f7bda 100644 --- a/src/parser/contexts.h +++ b/src/parser/contexts.h @@ -398,6 +398,12 @@ struct NullInstrParserCtx { template<typename TypeT> Result<> makeRefTest(Index, TypeT) { return Ok{}; } template<typename TypeT> Result<> makeRefCast(Index, TypeT) { return Ok{}; } + Result<> makeBrOn(Index, LabelIdxT, BrOnOp) { return Ok{}; } + + template<typename TypeT> Result<> makeBrOn(Index, LabelIdxT, BrOnOp, TypeT) { + return Ok{}; + } + template<typename HeapTypeT> Result<> makeStructNew(Index, HeapTypeT) { return Ok{}; } @@ -1290,6 +1296,11 @@ struct ParseDefsCtx : TypeParserCtx<ParseDefsCtx> { return withLoc(pos, irBuilder.makeRefCast(type)); } + Result<> + makeBrOn(Index pos, Index label, BrOnOp op, Type castType = Type::none) { + return withLoc(pos, irBuilder.makeBrOn(label, op, castType)); + } + Result<> makeStructNew(Index pos, HeapType type) { return withLoc(pos, irBuilder.makeStructNew(type)); } diff --git a/src/parser/parsers.h b/src/parser/parsers.h index 6b6bb0aa5..e2fb3732a 100644 --- a/src/parser/parsers.h +++ b/src/parser/parsers.h @@ -1315,11 +1315,17 @@ template<typename Ctx> Result<> makeRefCast(Ctx& ctx, Index pos) { } template<typename Ctx> Result<> makeBrOnNull(Ctx& ctx, Index pos, bool onFail) { - return ctx.in.err("unimplemented instruction"); + auto label = labelidx(ctx); + CHECK_ERR(label); + return ctx.makeBrOn(pos, *label, onFail ? BrOnNonNull : BrOnNull); } template<typename Ctx> Result<> makeBrOnCast(Ctx& ctx, Index pos, bool onFail) { - return ctx.in.err("unimplemented instruction"); + auto label = labelidx(ctx); + CHECK_ERR(label); + auto type = reftype(ctx); + CHECK_ERR(type); + return ctx.makeBrOn(pos, *label, onFail ? BrOnCastFail : BrOnCast, *type); } template<typename Ctx> diff --git a/src/wasm-ir-builder.h b/src/wasm-ir-builder.h index c0cd7b4a1..64ee0d62e 100644 --- a/src/wasm-ir-builder.h +++ b/src/wasm-ir-builder.h @@ -151,7 +151,8 @@ public: // [[nodiscard]] Result<> makeCallRef(); [[nodiscard]] Result<> makeRefTest(Type type); [[nodiscard]] Result<> makeRefCast(Type type); - // [[nodiscard]] Result<> makeBrOn(); + [[nodiscard]] Result<> + makeBrOn(Index label, BrOnOp op, Type castType = Type::none); [[nodiscard]] Result<> makeStructNew(HeapType type); [[nodiscard]] Result<> makeStructNewDefault(HeapType type); [[nodiscard]] Result<> diff --git a/src/wasm.h b/src/wasm.h index 96c9271fe..dbedc05f4 100644 --- a/src/wasm.h +++ b/src/wasm.h @@ -1566,6 +1566,7 @@ public: class BrOn : public SpecificExpression<Expression::BrOnId> { public: + BrOn() = default; BrOn(MixedArena& allocator) {} BrOnOp op; diff --git a/src/wasm/wasm-ir-builder.cpp b/src/wasm/wasm-ir-builder.cpp index c973238e9..cc2bfb433 100644 --- a/src/wasm/wasm-ir-builder.cpp +++ b/src/wasm/wasm-ir-builder.cpp @@ -220,18 +220,15 @@ Result<> IRBuilder::visitExpression(Expression* curr) { #define DELEGATE_FIELD_CHILD_VECTOR(id, field) \ WASM_UNREACHABLE("should have called visit" #id " because " #id \ " has child vector " #field); -#define DELEGATE_FIELD_SCOPE_NAME_USE(id, field) \ - WASM_UNREACHABLE("should have called visit" #id " because " #id \ - " has scope name use " #field); -#define DELEGATE_FIELD_SCOPE_NAME_USE_VECTOR(id, field) \ - WASM_UNREACHABLE("should have called visit" #id " because " #id \ - " has scope name use vector " #field); #define DELEGATE_FIELD_INT(id, field) #define DELEGATE_FIELD_INT_ARRAY(id, field) #define DELEGATE_FIELD_LITERAL(id, field) #define DELEGATE_FIELD_NAME(id, field) #define DELEGATE_FIELD_NAME_VECTOR(id, field) +#define DELEGATE_FIELD_SCOPE_NAME_USE(id, field) +#define DELEGATE_FIELD_SCOPE_NAME_USE_VECTOR(id, field) + #define DELEGATE_FIELD_TYPE(id, field) #define DELEGATE_FIELD_HEAPTYPE(id, field) #define DELEGATE_FIELD_ADDRESS(id, field) @@ -933,7 +930,14 @@ Result<> IRBuilder::makeRefCast(Type type) { return Ok{}; } -// Result<> IRBuilder::makeBrOn() {} +Result<> IRBuilder::makeBrOn(Index label, BrOnOp op, Type castType) { + BrOn curr; + CHECK_ERR(visitBrOn(&curr)); + auto name = getLabelName(label); + CHECK_ERR(name); + push(builder.makeBrOn(op, *name, curr.ref, castType)); + return Ok{}; +} Result<> IRBuilder::makeStructNew(HeapType type) { StructNew curr(wasm.allocator); |