summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDerek Schuff <dschuff@chromium.org>2017-04-13 15:12:48 -0700
committerGitHub <noreply@github.com>2017-04-13 15:12:48 -0700
commitec66e273e350c3d48df0ccaaf73c53b14485848f (patch)
treefeb2c5369686faf7a4a170df550e0ce18229b39c
parent57a2bb96c7b8a98433446828aca845a9e9be8c3d (diff)
downloadbinaryen-ec66e273e350c3d48df0ccaaf73c53b14485848f.tar.gz
binaryen-ec66e273e350c3d48df0ccaaf73c53b14485848f.tar.bz2
binaryen-ec66e273e350c3d48df0ccaaf73c53b14485848f.zip
Replace text annotations with explicit file/line for debug info (#967)
Rather than storing debug info as text annotations, store explicit file and line information. This will make it easier to experiment with outputting other serializations or representations (e.g. source maps), and will allow outputting debug info for binaries as well.
-rw-r--r--src/asm2wasm.h10
-rw-r--r--src/passes/Print.cpp9
-rw-r--r--src/wasm.h7
3 files changed, 16 insertions, 10 deletions
diff --git a/src/asm2wasm.h b/src/asm2wasm.h
index 5adf82762..ada026176 100644
--- a/src/asm2wasm.h
+++ b/src/asm2wasm.h
@@ -1171,6 +1171,7 @@ void Asm2WasmBuilder::processAsm(Ref ast) {
if (runOptimizationPasses) {
optimizingBuilder->finish();
}
+ wasm.debugInfoFileNames = std::move(preprocessor.debugInfoFileNames);
// second pass. first, function imports
@@ -1306,11 +1307,12 @@ void Asm2WasmBuilder::processAsm(Ref ast) {
// this is a debuginfo node. turn it into an annotation on the last stack
auto* last = lastExpression;
lastExpression = nullptr;
- auto& annotations = getFunction()->annotations;
+ auto& debugLocations = getFunction()->debugLocations;
if (last) {
- auto fileIndex = call->operands[0]->cast<Const>()->value.geti32();
- auto lineNumber = call->operands[1]->cast<Const>()->value.geti32();
- annotations[last] = parent->preprocessor.debugInfoFileNames[fileIndex] + ":" + std::to_string(lineNumber);
+ uint32_t fileIndex = call->operands[0]->cast<Const>()->value.geti32();
+ assert(getModule()->debugInfoFileNames.size() > fileIndex);
+ uint32_t lineNumber = call->operands[1]->cast<Const>()->value.geti32();
+ debugLocations[last] = {fileIndex, lineNumber};
}
// eliminate the debug info call
ExpressionManipulator::nop(curr);
diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp
index 04bf74529..9a2edcb6b 100644
--- a/src/passes/Print.cpp
+++ b/src/passes/Print.cpp
@@ -49,10 +49,11 @@ struct PrintSExpression : public Visitor<PrintSExpression> {
void visit(Expression* curr) {
if (currFunction) {
// show an annotation, if there is one
- auto& annotations = currFunction->annotations;
- auto iter = annotations.find(curr);
- if (iter != annotations.end()) {
- o << ";; " << iter->second << '\n';
+ auto& debugLocations = currFunction->debugLocations;
+ auto iter = debugLocations.find(curr);
+ if (iter != debugLocations.end()) {
+ auto fileName = currModule->debugInfoFileNames[iter->second.fileIndex];
+ o << ";; " << fileName << ":" << iter->second.lineNumber << '\n';
doIndent(o, indent);
}
}
diff --git a/src/wasm.h b/src/wasm.h
index 9cfcb4ca8..b27fe6acb 100644
--- a/src/wasm.h
+++ b/src/wasm.h
@@ -510,8 +510,10 @@ public:
std::vector<Name> localNames;
std::map<Name, Index> localIndices;
- // node annotations, printed alongside the node in the text format
- std::unordered_map<Expression*, std::string> annotations;
+ struct DebugLocation {
+ uint32_t fileIndex, lineNumber;
+ };
+ std::unordered_map<Expression*, DebugLocation> debugLocations;
Function() : result(none) {}
@@ -647,6 +649,7 @@ public:
Name start;
std::vector<UserSection> userSections;
+ std::vector<std::string> debugInfoFileNames;
MixedArena allocator;