summaryrefslogtreecommitdiff
path: root/src/wasm/wasm-binary.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/wasm/wasm-binary.cpp')
-rw-r--r--src/wasm/wasm-binary.cpp32
1 files changed, 16 insertions, 16 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp
index 47bcc8ba5..018e463e0 100644
--- a/src/wasm/wasm-binary.cpp
+++ b/src/wasm/wasm-binary.cpp
@@ -2073,6 +2073,20 @@ BinaryConsts::ASTNodes WasmBinaryBuilder::readExpression(Expression*& curr) {
return BinaryConsts::ASTNodes(code);
}
+void WasmBinaryBuilder::pushBlockElements(Block* curr, size_t start, size_t end) {
+ for (size_t i = start; i < end; i++) {
+ auto* item = expressionStack[i];
+ curr->list.push_back(item);
+ if (i < end - 1) {
+ // stacky&unreachable code may introduce elements that need to be dropped in non-final positions
+ if (isConcreteWasmType(item->type)) {
+ curr->list.back() = Builder(wasm).makeDrop(curr->list.back());
+ }
+ }
+ }
+ expressionStack.resize(start);
+}
+
void WasmBinaryBuilder::visitBlock(Block *curr) {
if (debug) std::cerr << "zz node: Block" << std::endl;
// special-case Block and de-recurse nested blocks in their first position, as that is
@@ -2108,18 +2122,7 @@ void WasmBinaryBuilder::visitBlock(Block *curr) {
if (end < start) {
throw ParseException("block cannot pop from outside");
}
- for (size_t i = start; i < end; i++) {
- if (debug) std::cerr << " " << size_t(expressionStack[i]) << "\n zz Block element " << curr->list.size() << std::endl;
- auto* item = expressionStack[i];
- curr->list.push_back(item);
- if (i < end - 1) {
- // stacky&unreachable code may introduce elements that need to be dropped in non-final positions
- if (isConcreteWasmType(item->type)) {
- curr->list.back() = Builder(wasm).makeDrop(curr->list.back());
- }
- }
- }
- expressionStack.resize(start);
+ pushBlockElements(curr, start, end);
curr->finalize(curr->type);
breakStack.pop_back();
}
@@ -2136,11 +2139,8 @@ Expression* WasmBinaryBuilder::getMaybeBlock(WasmType type) {
throw ParseException("block cannot pop from outside");
}
auto* block = allocator.alloc<Block>();
- for (size_t i = start; i < end; i++) {
- block->list.push_back(expressionStack[i]);
- }
+ pushBlockElements(block, start, end);
block->finalize(type);
- expressionStack.resize(start);
return block;
}