diff options
Diffstat (limited to 'src/wasm/wasm-ir-builder.cpp')
-rw-r--r-- | src/wasm/wasm-ir-builder.cpp | 61 |
1 files changed, 40 insertions, 21 deletions
diff --git a/src/wasm/wasm-ir-builder.cpp b/src/wasm/wasm-ir-builder.cpp index 91e990180..f816d4d1e 100644 --- a/src/wasm/wasm-ir-builder.cpp +++ b/src/wasm/wasm-ir-builder.cpp @@ -168,21 +168,37 @@ Result<Expression*> IRBuilder::build() { return expr; } -void IRBuilder::setDebugLocation(const Function::DebugLocation& loc) { - DBG(std::cerr << "setting debugloc " << loc.fileIndex << ":" << loc.lineNumber - << ":" << loc.columnNumber << "\n";); - debugLoc = loc; +void IRBuilder::setDebugLocation( + const std::optional<Function::DebugLocation>& loc) { + if (loc) { + DBG(std::cerr << "setting debugloc " << loc->fileIndex << ":" + << loc->lineNumber << ":" << loc->columnNumber << "\n";); + } else { + DBG(std::cerr << "setting debugloc to none\n";); + } + if (loc) { + debugLoc = *loc; + } else { + debugLoc = NoDebug(); + } } void IRBuilder::applyDebugLoc(Expression* expr) { - if (debugLoc) { + if (!std::get_if<CanReceiveDebug>(&debugLoc)) { if (func) { - DBG(std::cerr << "applying debugloc " << debugLoc->fileIndex << ":" - << debugLoc->lineNumber << ":" << debugLoc->columnNumber - << " to expression " << ShallowExpression{expr} << "\n"); - func->debugLocations[expr] = *debugLoc; + if (auto* loc = std::get_if<Function::DebugLocation>(&debugLoc)) { + DBG(std::cerr << "applying debugloc " << loc->fileIndex << ":" + << loc->lineNumber << ":" << loc->columnNumber + << " to expression " << ShallowExpression{expr} << "\n"); + func->debugLocations[expr] = *loc; + } else { + assert(std::get_if<NoDebug>(&debugLoc)); + DBG(std::cerr << "applying debugloc to expression " + << ShallowExpression{expr} << "\n"); + func->debugLocations[expr] = std::nullopt; + } } - debugLoc.reset(); + debugLoc = CanReceiveDebug(); } } @@ -677,10 +693,10 @@ Result<> IRBuilder::visitFunctionStart(Function* func) { if (!scopeStack.empty()) { return Err{"unexpected start of function"}; } - if (debugLoc) { - func->prologLocation.insert(*debugLoc); - debugLoc.reset(); + if (auto* loc = std::get_if<Function::DebugLocation>(&debugLoc)) { + func->prologLocation.insert(*loc); } + debugLoc = CanReceiveDebug(); scopeStack.push_back(ScopeCtx::makeFunc(func)); this->func = func; return Ok{}; @@ -718,12 +734,13 @@ Result<> IRBuilder::visitTryTableStart(TryTable* trytable, Name label) { } Result<Expression*> IRBuilder::finishScope(Block* block) { - if (debugLoc) { - DBG(std::cerr << "discarding debugloc " << debugLoc->fileIndex << ":" - << debugLoc->lineNumber << ":" << debugLoc->columnNumber - << "\n"); +#if IR_BUILDER_DEBUG + if (auto* loc = std::get_if<Function::DebugLocation>(&debugLoc)) { + std::cerr << "discarding debugloc " << loc->fileIndex << ":" + << loc->lineNumber << ":" << loc->columnNumber << "\n"; } - debugLoc.reset(); +#endif + debugLoc = CanReceiveDebug(); if (scopeStack.empty() || scopeStack.back().isNone()) { return Err{"unexpected end of scope"}; @@ -913,10 +930,12 @@ Result<> IRBuilder::visitEnd() { if (scope.isNone()) { return Err{"unexpected end"}; } - if (auto* func = scope.getFunction(); func && debugLoc) { - func->epilogLocation.insert(*debugLoc); - debugLoc.reset(); + if (auto* func = scope.getFunction(); func) { + if (auto* loc = std::get_if<Function::DebugLocation>(&debugLoc)) { + func->epilogLocation.insert(*loc); + } } + debugLoc = CanReceiveDebug(); auto expr = finishScope(scope.getBlock()); CHECK_ERR(expr); |