diff options
-rw-r--r-- | src/asm2wasm.h | 10 | ||||
-rw-r--r-- | src/passes/Print.cpp | 9 | ||||
-rw-r--r-- | src/wasm.h | 7 |
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; |