From d6ce516017f6ea809babb6d81e5bb791ea94659c Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 21 Jan 2020 19:03:22 -0800 Subject: DWARF: Track the positions of 'end', 'else', 'catch' binary locations (#2603) Control flow structures have those in addition to the normal span of (start, end), and we need to track them too. Tracking them during reading requires us to track control flow structures while parsing, so that we can know to which structure an end/else/catch refers to. We track these locations using a map on the side of instruction to its "extra" locations. That avoids increasing the size of the tracking info for the much more common non-control flow instructions. Note that there is one more 'end' location, that of the function (not referring to any instruction). I left that to a later PR to not increase this one too much. --- src/wasm/wasm-stack.cpp | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'src/wasm/wasm-stack.cpp') diff --git a/src/wasm/wasm-stack.cpp b/src/wasm/wasm-stack.cpp index a96dbb153..dee0caa82 100644 --- a/src/wasm/wasm-stack.cpp +++ b/src/wasm/wasm-stack.cpp @@ -33,10 +33,13 @@ void BinaryInstWriter::visitIf(If* curr) { o << binaryType(curr->type != Type::unreachable ? curr->type : Type::none); } -void BinaryInstWriter::emitIfElse() { +void BinaryInstWriter::emitIfElse(If* curr) { assert(!breakStack.empty()); breakStack.pop_back(); - breakStack.emplace_back(IMPOSSIBLE_CONTINUE); // TODO dito + breakStack.emplace_back(IMPOSSIBLE_CONTINUE); // TODO same as If + if (func && !sourceMap) { + parent.writeExtraDebugLocation(curr, func, BinaryLocations::Else); + } o << int8_t(BinaryConsts::Else); } @@ -1595,10 +1598,13 @@ void BinaryInstWriter::visitTry(Try* curr) { o << binaryType(curr->type != Type::unreachable ? curr->type : Type::none); } -void BinaryInstWriter::emitCatch() { +void BinaryInstWriter::emitCatch(Try* curr) { assert(!breakStack.empty()); breakStack.pop_back(); breakStack.emplace_back(IMPOSSIBLE_CONTINUE); + if (func && !sourceMap) { + parent.writeExtraDebugLocation(curr, func, BinaryLocations::Catch); + } o << int8_t(BinaryConsts::Catch); } @@ -1633,9 +1639,12 @@ void BinaryInstWriter::visitPop(Pop* curr) { // Turns into nothing in the binary format } -void BinaryInstWriter::emitScopeEnd() { +void BinaryInstWriter::emitScopeEnd(Expression* curr) { assert(!breakStack.empty()); breakStack.pop_back(); + if (func && !sourceMap) { + parent.writeExtraDebugLocation(curr, func, BinaryLocations::End); + } o << int8_t(BinaryConsts::End); } @@ -1838,15 +1847,15 @@ void StackIRToBinaryWriter::write() { case StackInst::IfEnd: case StackInst::LoopEnd: case StackInst::TryEnd: { - writer.emitScopeEnd(); + writer.emitScopeEnd(inst->origin); break; } case StackInst::IfElse: { - writer.emitIfElse(); + writer.emitIfElse(inst->origin->cast()); break; } case StackInst::Catch: { - writer.emitCatch(); + writer.emitCatch(inst->origin->cast()); break; } default: -- cgit v1.2.3