summaryrefslogtreecommitdiff
path: root/src/passes
diff options
context:
space:
mode:
authorYury Delendik <ydelendik@mozilla.com>2018-09-17 10:05:43 -0500
committerGitHub <noreply@github.com>2018-09-17 10:05:43 -0500
commitcefbbfadae87135ff37fb4fc1058c6baf8de0140 (patch)
tree4be93c23ad7cb95623f699a2fff9ef829abc426c /src/passes
parent403be53fb84645b9338454681792538af876cf87 (diff)
downloadbinaryen-cefbbfadae87135ff37fb4fc1058c6baf8de0140.tar.gz
binaryen-cefbbfadae87135ff37fb4fc1058c6baf8de0140.tar.bz2
binaryen-cefbbfadae87135ff37fb4fc1058c6baf8de0140.zip
Add debug information locations to the function prolog/epilog (#1674)
The current patch: * Preserves the debug locations from function prolog and epilog * Preserves the debug locations of the nested blocks
Diffstat (limited to 'src/passes')
-rw-r--r--src/passes/Print.cpp43
1 files changed, 34 insertions, 9 deletions
diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp
index 87fa62b95..77562af4b 100644
--- a/src/passes/Print.cpp
+++ b/src/passes/Print.cpp
@@ -437,20 +437,29 @@ struct PrintSExpression : public Visitor<PrintSExpression> {
if (!full) full = isFullForced();
}
- void visit(Expression* curr) {
+ void printDebugLocation(const Function::DebugLocation &location) {
+ if (lastPrintedLocation == location) {
+ return;
+ }
+ lastPrintedLocation = location;
+ auto fileName = currModule->debugInfoFileNames[location.fileIndex];
+ o << ";;@ " << fileName << ":" << location.lineNumber << ":" << location.columnNumber << '\n';
+ doIndent(o, indent);
+ }
+
+ void printDebugLocation(Expression* curr) {
if (currFunction) {
// show an annotation, if there is one
auto& debugLocations = currFunction->debugLocations;
auto iter = debugLocations.find(curr);
if (iter != debugLocations.end()) {
- auto fileName = currModule->debugInfoFileNames[iter->second.fileIndex];
- if (lastPrintedLocation != iter->second) {
- lastPrintedLocation = iter->second;
- o << ";;@ " << fileName << ":" << iter->second.lineNumber << ":" << iter->second.columnNumber << '\n';
- doIndent(o, indent);
- }
+ printDebugLocation(iter->second);
}
}
+ }
+
+ void visit(Expression* curr) {
+ printDebugLocation(curr);
Visitor<PrintSExpression>::visit(curr);
}
@@ -487,7 +496,10 @@ struct PrintSExpression : public Visitor<PrintSExpression> {
// special-case Block, because Block nesting (in their first element) can be incredibly deep
std::vector<Block*> stack;
while (1) {
- if (stack.size() > 0) doIndent(o, indent);
+ if (stack.size() > 0) {
+ doIndent(o, indent);
+ printDebugLocation(curr);
+ }
stack.push_back(curr);
if (full) {
o << "[" << printType(curr->type) << "] ";
@@ -849,6 +861,9 @@ struct PrintSExpression : public Visitor<PrintSExpression> {
void visitFunction(Function* curr) {
currFunction = curr;
lastPrintedLocation = { 0, 0, 0 };
+ if (currFunction->prologLocation.size()) {
+ printDebugLocation(*currFunction->prologLocation.begin());
+ }
o << '(';
printMajor(o, "func ");
printName(curr->name, o);
@@ -901,7 +916,17 @@ struct PrintSExpression : public Visitor<PrintSExpression> {
// Print the stack IR.
WasmPrinter::printStackIR(curr->stackIR.get(), o, curr);
}
- decIndent();
+ if (currFunction->epilogLocation.size() && lastPrintedLocation != *currFunction->epilogLocation.begin()) {
+ // Print last debug location: mix of decIndent and printDebugLocation logic.
+ doIndent(o, indent);
+ if (!minify) {
+ indent--;
+ }
+ printDebugLocation(*currFunction->epilogLocation.begin());
+ o << ')';
+ } else {
+ decIndent();
+ }
}
void printTableHeader(Table* curr) {
o << '(';