diff options
author | Thomas Lively <tlively@google.com> | 2024-11-14 16:29:37 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-14 13:29:37 -0800 |
commit | 6efd41779272d2ac7eb75705c21c9f437a1409c9 (patch) | |
tree | 9890e82b1e35f483ea76394b5dcc3cfb1bb59e79 /src | |
parent | d4e7fee97c9fa7ae2c6f069d4428964cc1ea1795 (diff) | |
download | binaryen-6efd41779272d2ac7eb75705c21c9f437a1409c9.tar.gz binaryen-6efd41779272d2ac7eb75705c21c9f437a1409c9.tar.bz2 binaryen-6efd41779272d2ac7eb75705c21c9f437a1409c9.zip |
Record binary locations for nested blocks (#7078)
The binary reader has special handling for blocks immediately nested
inside other blocks to eliminate recursion while parsing very deep
stacks of blocks. This special handling did not record binary locations
for the nested blocks, though.
Add logic to record binary locations for nested blocks. This binary
reading code is about to be replaced with completely different code that
uses IRBuilder instead, but this change will eliminate some test
differences that we would otherwise see when we make that change.
Diffstat (limited to 'src')
-rw-r--r-- | src/wasm/wasm-binary.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index f5bf11206..73718e636 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -4453,13 +4453,21 @@ void WasmBinaryReader::visitBlock(Block* curr) { // special-case Block and de-recurse nested blocks in their first position, as // that is a common pattern that can be very highly nested. std::vector<Block*> stack; + // Track start positions for all blocks except for the outermost block, which + // is already handled in the caller. + std::vector<size_t> startPosStack; + size_t startPos = -1; while (1) { curr->type = getType(); curr->name = getNextLabel(); breakStack.push_back({curr->name, curr->type}); stack.push_back(curr); + if (startPos != size_t(-1)) { + startPosStack.push_back(startPos); + } if (more() && input[pos] == BinaryConsts::Block) { // a recursion + startPos = pos; readNextDebugLocation(); curr = allocator.alloc<Block>(); startControlFlow(curr); @@ -4478,6 +4486,12 @@ void WasmBinaryReader::visitBlock(Block* curr) { while (stack.size() > 0) { curr = stack.back(); stack.pop_back(); + if (startPosStack.empty()) { + startPos = -1; + } else { + startPos = startPosStack.back(); + startPosStack.pop_back(); + } // everything after this, that is left when we see the marker, is ours size_t start = expressionStack.size(); if (last) { @@ -4497,6 +4511,12 @@ void WasmBinaryReader::visitBlock(Block* curr) { : Block::NoBreak); breakStack.pop_back(); breakTargetNames.erase(curr->name); + + if (DWARF && currFunction && startPos != size_t(-1)) { + currFunction->expressionLocations[curr] = + BinaryLocations::Span{BinaryLocation(startPos - codeSectionLocation), + BinaryLocation(pos - codeSectionLocation)}; + } } } |