summaryrefslogtreecommitdiff
path: root/src/wasm/wasm-ir-builder.cpp
diff options
context:
space:
mode:
authorJérôme Vouillon <jerome.vouillon@gmail.com>2024-05-14 16:01:01 -0400
committerGitHub <noreply@github.com>2024-05-14 13:01:01 -0700
commit140386ed24ece9f30b2ad7dc55f63716f7a61f5e (patch)
treebebd167535305fbeaad79779e25ecc73b233c502 /src/wasm/wasm-ir-builder.cpp
parent55f33b55daa965672d2b8aca98ce1570e3fb52c0 (diff)
downloadbinaryen-140386ed24ece9f30b2ad7dc55f63716f7a61f5e.tar.gz
binaryen-140386ed24ece9f30b2ad7dc55f63716f7a61f5e.tar.bz2
binaryen-140386ed24ece9f30b2ad7dc55f63716f7a61f5e.zip
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.
Diffstat (limited to 'src/wasm/wasm-ir-builder.cpp')
-rw-r--r--src/wasm/wasm-ir-builder.cpp61
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);