From 140386ed24ece9f30b2ad7dc55f63716f7a61f5e Mon Sep 17 00:00:00 2001 From: Jérôme Vouillon Date: Tue, 14 May 2024 16:01:01 -0400 Subject: Source maps: Allow specifying that an expression has no debug info in text (#6520) ;;@ with nothing else (no source:line) can be used to specify that the following expression does not have any debug info associated to it. This can be used to stop the automatic propagation of debug info in the text parsers. The text printer has also been updated to output this comment when needed. --- src/wasm/wasm-ir-builder.cpp | 61 +++++++++++++++++++++++++++++--------------- 1 file changed, 40 insertions(+), 21 deletions(-) (limited to 'src/wasm/wasm-ir-builder.cpp') 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 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& 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(&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(&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(&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(&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 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(&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(&debugLoc)) { + func->epilogLocation.insert(*loc); + } } + debugLoc = CanReceiveDebug(); auto expr = finishScope(scope.getBlock()); CHECK_ERR(expr); -- cgit v1.2.3