summaryrefslogtreecommitdiff
path: root/src/wasm/wasm-stack.cpp
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2020-01-21 19:03:22 -0800
committerGitHub <noreply@github.com>2020-01-21 19:03:22 -0800
commitd6ce516017f6ea809babb6d81e5bb791ea94659c (patch)
treed8eb77d3b7791010d73b12bccc803a429de66709 /src/wasm/wasm-stack.cpp
parent51fff211d7aae002ff28e1c6245e3f9349493f11 (diff)
downloadbinaryen-d6ce516017f6ea809babb6d81e5bb791ea94659c.tar.gz
binaryen-d6ce516017f6ea809babb6d81e5bb791ea94659c.tar.bz2
binaryen-d6ce516017f6ea809babb6d81e5bb791ea94659c.zip
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.
Diffstat (limited to 'src/wasm/wasm-stack.cpp')
-rw-r--r--src/wasm/wasm-stack.cpp23
1 files changed, 16 insertions, 7 deletions
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<If>());
break;
}
case StackInst::Catch: {
- writer.emitCatch();
+ writer.emitCatch(inst->origin->cast<Try>());
break;
}
default: