diff options
Diffstat (limited to 'src/wasm')
-rw-r--r-- | src/wasm/wasm-binary.cpp | 27 | ||||
-rw-r--r-- | src/wasm/wasm-s-parser.cpp | 2 | ||||
-rw-r--r-- | src/wasm/wasm-validator.cpp | 16 |
3 files changed, 23 insertions, 22 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index 878293caa..c6ed1dcfb 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -1920,7 +1920,7 @@ void WasmBinaryBuilder::readFunctions() { // process body assert(breakStack.empty()); assert(breakTargetNames.empty()); - assert(delegateTargetNames.empty()); + assert(exceptionTargetNames.empty()); assert(breakStack.empty()); assert(expressionStack.empty()); assert(controlFlowStack.empty()); @@ -1930,7 +1930,7 @@ void WasmBinaryBuilder::readFunctions() { assert(depth == 0); assert(breakStack.empty()); assert(breakTargetNames.empty()); - assert(delegateTargetNames.empty()); + assert(exceptionTargetNames.empty()); if (!expressionStack.empty()) { throwError("stack not empty on function exit"); } @@ -3389,7 +3389,7 @@ Expression* WasmBinaryBuilder::getBlockOrSingleton(Type type) { block->finalize(type); // maybe we don't need a block here? if (breakTargetNames.find(block->name) == breakTargetNames.end() && - delegateTargetNames.find(block->name) == delegateTargetNames.end()) { + exceptionTargetNames.find(block->name) == exceptionTargetNames.end()) { block->name = Name(); if (block->list.size() == 1) { return block->list[0]; @@ -3465,8 +3465,8 @@ WasmBinaryBuilder::getBreakTarget(int32_t offset) { return ret; } -Name WasmBinaryBuilder::getDelegateTargetName(int32_t offset) { - BYN_TRACE("getDelegateTarget " << offset << std::endl); +Name WasmBinaryBuilder::getExceptionTargetName(int32_t offset) { + BYN_TRACE("getExceptionTarget " << offset << std::endl); // We always start parsing a function by creating a block label and pushing it // in breakStack in getBlockOrSingleton, so if a 'delegate''s target is that // block, it does not mean it targets that block; it throws to the caller. @@ -3482,7 +3482,7 @@ Name WasmBinaryBuilder::getDelegateTargetName(int32_t offset) { // if the delegate is in literally unreachable code, then we will not emit it // anyhow, so do not note that the target has delegate to it if (!willBeIgnored) { - delegateTargetNames.insert(ret.name); + exceptionTargetNames.insert(ret.name); } return ret.name; } @@ -5832,7 +5832,7 @@ void WasmBinaryBuilder::visitTryOrTryInBlock(Expression*& out) { breakStack.pop_back(); if (lastSeparator == BinaryConsts::Delegate) { - curr->delegateTarget = getDelegateTargetName(getU32LEB()); + curr->delegateTarget = getExceptionTargetName(getU32LEB()); } // For simplicity, we make try's labels only can be targeted by delegates, and @@ -5843,9 +5843,10 @@ void WasmBinaryBuilder::visitTryOrTryInBlock(Expression*& out) { curr->name = getNextLabel(); if (auto* block = curr->body->dynCast<Block>()) { if (block->name.is()) { - if (delegateTargetNames.find(block->name) != delegateTargetNames.end()) { - BranchUtils::replaceDelegateTargets(block, block->name, curr->name); - delegateTargetNames.erase(block->name); + if (exceptionTargetNames.find(block->name) != + exceptionTargetNames.end()) { + BranchUtils::replaceExceptionTargets(block, block->name, curr->name); + exceptionTargetNames.erase(block->name); } // maybe we don't need a block here? if (block->list.size() == 1) { @@ -5853,11 +5854,11 @@ void WasmBinaryBuilder::visitTryOrTryInBlock(Expression*& out) { } } } - if (delegateTargetNames.find(catchLabel) != delegateTargetNames.end()) { + if (exceptionTargetNames.find(catchLabel) != exceptionTargetNames.end()) { for (auto* catchBody : curr->catchBodies) { - BranchUtils::replaceDelegateTargets(catchBody, catchLabel, curr->name); + BranchUtils::replaceExceptionTargets(catchBody, catchLabel, curr->name); } - delegateTargetNames.erase(catchLabel); + exceptionTargetNames.erase(catchLabel); } curr->finalize(curr->type); diff --git a/src/wasm/wasm-s-parser.cpp b/src/wasm/wasm-s-parser.cpp index d2b24fbed..0ff4bfb9f 100644 --- a/src/wasm/wasm-s-parser.cpp +++ b/src/wasm/wasm-s-parser.cpp @@ -2048,7 +2048,7 @@ Expression* SExpressionWasmBuilder::makeTry(Element& s) { if (inner.size() != 2) { throw ParseException("invalid delegate", inner.line, inner.col); } - ret->delegateTarget = getLabel(*inner[1], LabelType::Delegate); + ret->delegateTarget = getLabel(*inner[1], LabelType::Exception); } if (i != s.size()) { diff --git a/src/wasm/wasm-validator.cpp b/src/wasm/wasm-validator.cpp index beb994390..736d669fb 100644 --- a/src/wasm/wasm-validator.cpp +++ b/src/wasm/wasm-validator.cpp @@ -236,7 +236,7 @@ struct FunctionValidator : public WalkerPass<PostWalker<FunctionValidator>> { }; std::unordered_map<Name, BreakInfo> breakInfos; - std::unordered_set<Name> delegateTargetNames; + std::unordered_set<Name> exceptionTargetNames; std::set<Type> returnTypes; // types used in returns @@ -280,7 +280,7 @@ public: static void visitPreTry(FunctionValidator* self, Expression** currp) { auto* curr = (*currp)->cast<Try>(); if (curr->name.is()) { - self->delegateTargetNames.insert(curr->name); + self->exceptionTargetNames.insert(curr->name); } } @@ -300,7 +300,7 @@ public: static void visitPreCatch(FunctionValidator* self, Expression** currp) { auto* curr = (*currp)->cast<Try>(); if (curr->name.is()) { - self->delegateTargetNames.erase(curr->name); + self->exceptionTargetNames.erase(curr->name); } } @@ -376,7 +376,7 @@ public: void visitRefIs(RefIs* curr); void visitRefFunc(RefFunc* curr); void visitRefEq(RefEq* curr); - void noteDelegate(Name name, Expression* curr); + void noteException(Name name, Expression* curr); void visitTry(Try* curr); void visitThrow(Throw* curr); void visitRethrow(Rethrow* curr); @@ -2073,9 +2073,9 @@ void FunctionValidator::visitRefEq(RefEq* curr) { "ref.eq's right argument should be a subtype of eqref"); } -void FunctionValidator::noteDelegate(Name name, Expression* curr) { +void FunctionValidator::noteException(Name name, Expression* curr) { if (name != DELEGATE_CALLER_TARGET) { - shouldBeTrue(delegateTargetNames.find(name) != delegateTargetNames.end(), + shouldBeTrue(exceptionTargetNames.find(name) != exceptionTargetNames.end(), curr, "all delegate targets must be valid"); } @@ -2122,7 +2122,7 @@ void FunctionValidator::visitTry(Try* curr) { "try should have either catches or a delegate"); if (curr->isDelegate()) { - noteDelegate(curr->delegateTarget, curr); + noteException(curr->delegateTarget, curr); } } @@ -2533,7 +2533,7 @@ void FunctionValidator::visitFunction(Function* curr) { shouldBeTrue( breakInfos.empty(), curr->body, "all named break targets must exist"); - shouldBeTrue(delegateTargetNames.empty(), + shouldBeTrue(exceptionTargetNames.empty(), curr->body, "all named delegate targets must exist"); returnTypes.clear(); |