diff options
author | Alon Zakai <azakai@google.com> | 2024-05-01 08:26:00 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-01 08:26:00 -0700 |
commit | 7d9e4a87ce4949dc552790329cfaf4dfec8b36a8 (patch) | |
tree | f0abfb1d48f3b498dfac70bfa92f704446a84c9b /src | |
parent | 049ff7a828f3e11b2877034dd452481cd7c04f96 (diff) | |
download | binaryen-7d9e4a87ce4949dc552790329cfaf4dfec8b36a8.tar.gz binaryen-7d9e4a87ce4949dc552790329cfaf4dfec8b36a8.tar.bz2 binaryen-7d9e4a87ce4949dc552790329cfaf4dfec8b36a8.zip |
[StackIR] Support source maps and DWARF with StackIR (#6564)
Helping #6509, this fixes debugging support for StackIR, which makes it more
possible to use StackIR in more places.
The fix is basically just to pass around some more state, and then to call the
parent with "please write debug info" at the correct times, mirroring the
similar calls in BinaryenIRWriter.
The relevant Emscripten tests pass, and the source map test modified
here produces identical output in StackIR and non-StackIR modes (the
test is also simplified to remove --new-wat-parser which is no longer
needed, after which the test can clearly show that StackIR has the same
output as BinaryenIR).
Diffstat (limited to 'src')
-rw-r--r-- | src/wasm-stack.h | 10 | ||||
-rw-r--r-- | src/wasm/wasm-binary.cpp | 4 | ||||
-rw-r--r-- | src/wasm/wasm-stack.cpp | 12 |
3 files changed, 21 insertions, 5 deletions
diff --git a/src/wasm-stack.h b/src/wasm-stack.h index d6c0e46ec..0b72774b6 100644 --- a/src/wasm-stack.h +++ b/src/wasm-stack.h @@ -508,17 +508,21 @@ class StackIRToBinaryWriter { public: StackIRToBinaryWriter(WasmBinaryWriter& parent, BufferWithRandomAccess& o, - Function* func) - : writer(parent, o, func, false /* sourceMap */, false /* DWARF */), - func(func) {} + Function* func, + bool sourceMap = false, + bool DWARF = false) + : parent(parent), writer(parent, o, func, sourceMap, DWARF), func(func), + sourceMap(sourceMap) {} void write(); MappedLocals& getMappedLocals() { return writer.mappedLocals; } private: + WasmBinaryWriter& parent; BinaryInstWriter writer; Function* func; + bool sourceMap; }; std::ostream& printStackIR(std::ostream& o, Module* module, bool optimize); diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index b45fe84c8..b655395bf 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -403,9 +403,9 @@ void WasmBinaryWriter::writeFunctions() { size_t start = o.size(); BYN_TRACE("writing" << func->name << std::endl); // Emit Stack IR if present, and if we can - if (func->stackIR && !sourceMap && !DWARF) { + if (func->stackIR) { BYN_TRACE("write Stack IR\n"); - StackIRToBinaryWriter writer(*this, o, func); + StackIRToBinaryWriter writer(*this, o, func, sourceMap, DWARF); writer.write(); if (debugInfo) { funcMappedLocals[func->name] = std::move(writer.getMappedLocals()); diff --git a/src/wasm/wasm-stack.cpp b/src/wasm/wasm-stack.cpp index f1413847f..99aaf517e 100644 --- a/src/wasm/wasm-stack.cpp +++ b/src/wasm/wasm-stack.cpp @@ -2779,6 +2779,9 @@ StackInst* StackIRGenerator::makeStackInst(StackInst::Op op, } void StackIRToBinaryWriter::write() { + if (func->prologLocation.size()) { + parent.writeDebugLocation(*func->prologLocation.begin()); + } writer.mapLocalsAndEmitHeader(); // Stack to track indices of catches within a try SmallVector<Index, 4> catchIndexStack; @@ -2795,7 +2798,13 @@ void StackIRToBinaryWriter::write() { case StackInst::IfBegin: case StackInst::LoopBegin: case StackInst::TryTableBegin: { + if (sourceMap) { + parent.writeDebugLocation(inst->origin, func); + } writer.visit(inst->origin); + if (sourceMap) { + parent.writeDebugLocationEnd(inst->origin, func); + } break; } case StackInst::TryEnd: @@ -2830,6 +2839,9 @@ void StackIRToBinaryWriter::write() { WASM_UNREACHABLE("unexpected op"); } } + if (func->epilogLocation.size()) { + parent.writeDebugLocation(*func->epilogLocation.begin()); + } writer.emitFunctionEnd(); } |