summaryrefslogtreecommitdiff
path: root/src/wasm
diff options
context:
space:
mode:
Diffstat (limited to 'src/wasm')
-rw-r--r--src/wasm/wasm-binary.cpp4
-rw-r--r--src/wasm/wasm-ir-builder.cpp61
-rw-r--r--src/wasm/wasm-s-parser.cpp4
3 files changed, 46 insertions, 23 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp
index c1e506c8e..d72626b90 100644
--- a/src/wasm/wasm-binary.cpp
+++ b/src/wasm/wasm-binary.cpp
@@ -1411,9 +1411,9 @@ void WasmBinaryWriter::writeDebugLocation(Expression* curr, Function* func) {
if (sourceMap) {
auto& debugLocations = func->debugLocations;
auto iter = debugLocations.find(curr);
- if (iter != debugLocations.end()) {
+ if (iter != debugLocations.end() && iter->second) {
// There is debug information here, write it out.
- writeDebugLocation(iter->second);
+ writeDebugLocation(*(iter->second));
} else {
// This expression has no debug location.
writeNoDebugLocation();
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);
diff --git a/src/wasm/wasm-s-parser.cpp b/src/wasm/wasm-s-parser.cpp
index bca94a768..be6fc5100 100644
--- a/src/wasm/wasm-s-parser.cpp
+++ b/src/wasm/wasm-s-parser.cpp
@@ -219,6 +219,10 @@ void SExpressionParser::parseDebugLocation() {
while (debugLocEnd[0] && debugLocEnd[0] != '\n') {
debugLocEnd++;
}
+ if (debugLocEnd == debugLoc) {
+ loc = nullptr;
+ return;
+ }
char const* pos = debugLoc;
while (pos < debugLocEnd && pos[0] != ':') {
pos++;