diff options
Diffstat (limited to 'src/wasm/wasm-ir-builder.cpp')
-rw-r--r-- | src/wasm/wasm-ir-builder.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/wasm/wasm-ir-builder.cpp b/src/wasm/wasm-ir-builder.cpp index 54cd0149e..fcb1fc48d 100644 --- a/src/wasm/wasm-ir-builder.cpp +++ b/src/wasm/wasm-ir-builder.cpp @@ -150,6 +150,12 @@ void IRBuilder::push(Expression* expr) { scope.exprStack.push_back(expr); applyDebugLoc(expr); + if (binaryPos && func && lastBinaryPos != *binaryPos) { + func->expressionLocations[expr] = + BinaryLocations::Span{BinaryLocation(lastBinaryPos - codeSectionOffset), + BinaryLocation(*binaryPos - codeSectionOffset)}; + lastBinaryPos = *binaryPos; + } DBG(std::cerr << "After pushing " << ShallowExpression{expr} << ":\n"); DBG(dump()); @@ -708,6 +714,11 @@ Result<> IRBuilder::visitFunctionStart(Function* func) { debugLoc = CanReceiveDebug(); scopeStack.push_back(ScopeCtx::makeFunc(func)); this->func = func; + + if (binaryPos) { + lastBinaryPos = *binaryPos; + } + return Ok{}; } @@ -841,6 +852,12 @@ Result<> IRBuilder::visitElse() { auto expr = finishScope(); CHECK_ERR(expr); iff->ifTrue = *expr; + + if (binaryPos && func) { + func->delimiterLocations[iff][BinaryLocations::Else] = + lastBinaryPos - codeSectionOffset; + } + pushScope(ScopeCtx::makeElse(iff, originalLabel, label, labelUsed)); return Ok{}; } @@ -868,6 +885,12 @@ Result<> IRBuilder::visitCatch(Name tag) { tryy->catchBodies.push_back(*expr); } tryy->catchTags.push_back(tag); + + if (binaryPos && func) { + auto& delimiterLocs = func->delimiterLocations[tryy]; + delimiterLocs[delimiterLocs.size()] = lastBinaryPos - codeSectionOffset; + } + pushScope( ScopeCtx::makeCatch(tryy, originalLabel, label, labelUsed, branchLabel)); // Push a pop for the exception payload if necessary. @@ -878,6 +901,7 @@ Result<> IRBuilder::visitCatch(Name tag) { scopeStack[0].notePop(); push(builder.makePop(params)); } + return Ok{}; } @@ -903,6 +927,12 @@ Result<> IRBuilder::visitCatchAll() { } else { tryy->catchBodies.push_back(*expr); } + + if (binaryPos && func) { + auto& delimiterLocs = func->delimiterLocations[tryy]; + delimiterLocs[delimiterLocs.size()] = lastBinaryPos - codeSectionOffset; + } + pushScope( ScopeCtx::makeCatchAll(tryy, originalLabel, label, labelUsed, branchLabel)); return Ok{}; @@ -980,6 +1010,10 @@ Result<> IRBuilder::visitEnd() { return block; }; + // The binary position we record for the block instruction should start at the + // beginning of the block, not at the beginning of the `end`. + lastBinaryPos = scope.startPos; + if (auto* func = scope.getFunction()) { func->body = maybeWrapForLabel(*expr); labelDepths.clear(); |