summaryrefslogtreecommitdiff
path: root/src/wasm
diff options
context:
space:
mode:
Diffstat (limited to 'src/wasm')
-rw-r--r--src/wasm/wasm-binary.cpp44
-rw-r--r--src/wasm/wasm-debug.cpp5
-rw-r--r--src/wasm/wasm-stack.cpp7
3 files changed, 31 insertions, 25 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp
index cc289e7ec..bf71d3a4d 100644
--- a/src/wasm/wasm-binary.cpp
+++ b/src/wasm/wasm-binary.cpp
@@ -915,8 +915,9 @@ void WasmBinaryWriter::writeDebugLocationEnd(Expression* curr, Function* func) {
}
}
-void WasmBinaryWriter::writeExtraDebugLocation(
- Expression* curr, Function* func, BinaryLocations::DelimiterId id) {
+void WasmBinaryWriter::writeExtraDebugLocation(Expression* curr,
+ Function* func,
+ size_t id) {
if (func && !func->expressionLocations.empty()) {
binaryLocations.delimiters[curr][id] = o.size();
}
@@ -2836,13 +2837,30 @@ BinaryConsts::ASTNodes WasmBinaryBuilder::readExpression(Expression*& curr) {
}
break;
case BinaryConsts::Else:
+ case BinaryConsts::Catch: {
curr = nullptr;
- continueControlFlow(BinaryLocations::Else, startPos);
- break;
- case BinaryConsts::Catch:
- curr = nullptr;
- continueControlFlow(BinaryLocations::Catch, startPos);
+ if (DWARF && currFunction) {
+ assert(!controlFlowStack.empty());
+ auto currControlFlow = controlFlowStack.back();
+ BinaryLocation delimiterId;
+ // Else and CatchAll have the same binary ID, so differentiate them
+ // using the control flow stack.
+ static_assert(BinaryConsts::CatchAll == BinaryConsts::Else,
+ "Else and CatchAll should have identical codes");
+ if (currControlFlow->is<If>()) {
+ delimiterId = BinaryLocations::Else;
+ } else {
+ // Both Catch and CatchAll can simply append to the list as we go, as
+ // we visit them in the right order in the binary, and like the binary
+ // we store the CatchAll at the end.
+ delimiterId =
+ currFunction->delimiterLocations[currControlFlow].size();
+ }
+ currFunction->delimiterLocations[currControlFlow][delimiterId] =
+ startPos - codeSectionLocation;
+ }
break;
+ }
case BinaryConsts::RefNull:
visitRefNull((curr = allocator.alloc<RefNull>())->cast<RefNull>());
break;
@@ -3102,18 +3120,6 @@ void WasmBinaryBuilder::startControlFlow(Expression* curr) {
}
}
-void WasmBinaryBuilder::continueControlFlow(BinaryLocations::DelimiterId id,
- BinaryLocation pos) {
- if (DWARF && currFunction) {
- assert(!controlFlowStack.empty());
- auto currControlFlow = controlFlowStack.back();
- // We are called after parsing the byte, so we need to subtract one to
- // get its position.
- currFunction->delimiterLocations[currControlFlow][id] =
- pos - codeSectionLocation;
- }
-}
-
void WasmBinaryBuilder::pushBlockElements(Block* curr,
Type type,
size_t start) {
diff --git a/src/wasm/wasm-debug.cpp b/src/wasm/wasm-debug.cpp
index 52baaf24d..2c5ed9515 100644
--- a/src/wasm/wasm-debug.cpp
+++ b/src/wasm/wasm-debug.cpp
@@ -361,7 +361,7 @@ struct AddrExprMap {
// bloat the common case which is represented in the earlier maps.
struct DelimiterInfo {
Expression* expr;
- BinaryLocations::DelimiterId id;
+ size_t id;
};
std::unordered_map<BinaryLocation, DelimiterInfo> delimiterMap;
@@ -414,8 +414,7 @@ private:
for (Index i = 0; i < delimiter.size(); i++) {
if (delimiter[i] != 0) {
assert(delimiterMap.count(delimiter[i]) == 0);
- delimiterMap[delimiter[i]] =
- DelimiterInfo{expr, BinaryLocations::DelimiterId(i)};
+ delimiterMap[delimiter[i]] = DelimiterInfo{expr, i};
}
}
}
diff --git a/src/wasm/wasm-stack.cpp b/src/wasm/wasm-stack.cpp
index 8a5726f1f..fae9da140 100644
--- a/src/wasm/wasm-stack.cpp
+++ b/src/wasm/wasm-stack.cpp
@@ -1887,9 +1887,8 @@ void BinaryInstWriter::emitCatch(Try* curr, Index i) {
assert(!breakStack.empty());
breakStack.pop_back();
breakStack.emplace_back(IMPOSSIBLE_CONTINUE);
- // TODO Fix handling of BinaryLocations for the new EH spec
if (func && !sourceMap) {
- parent.writeExtraDebugLocation(curr, func, BinaryLocations::Catch);
+ parent.writeExtraDebugLocation(curr, func, i);
}
o << int8_t(BinaryConsts::Catch)
<< U32LEB(parent.getEventIndex(curr->catchEvents[i]));
@@ -1899,7 +1898,9 @@ void BinaryInstWriter::emitCatchAll(Try* curr) {
assert(!breakStack.empty());
breakStack.pop_back();
breakStack.emplace_back(IMPOSSIBLE_CONTINUE);
- // TODO Fix handling of BinaryLocations for the new EH spec
+ if (func && !sourceMap) {
+ parent.writeExtraDebugLocation(curr, func, curr->catchBodies.size());
+ }
o << int8_t(BinaryConsts::CatchAll);
}