summaryrefslogtreecommitdiff
path: root/src/wasm.h
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2016-03-10 19:26:58 -0800
committerAlon Zakai <alonzakai@gmail.com>2016-03-10 19:26:58 -0800
commiteb1e5b6cc7f32b704bb14b147f47ee7919241503 (patch)
tree231400a35bb0d59e91646b77eebedd655175c888 /src/wasm.h
parent0467407decb3cd30ad407f553a078b9f533b479d (diff)
parenta8e570c75d3a6cc398a4b1a4c3d492d56c4d8091 (diff)
downloadbinaryen-eb1e5b6cc7f32b704bb14b147f47ee7919241503.tar.gz
binaryen-eb1e5b6cc7f32b704bb14b147f47ee7919241503.tar.bz2
binaryen-eb1e5b6cc7f32b704bb14b147f47ee7919241503.zip
Merge pull request #241 from WebAssembly/spec-updates
Spec updates
Diffstat (limited to 'src/wasm.h')
-rw-r--r--src/wasm.h32
1 files changed, 31 insertions, 1 deletions
diff --git a/src/wasm.h b/src/wasm.h
index 4bcb4bc87..b52803799 100644
--- a/src/wasm.h
+++ b/src/wasm.h
@@ -1408,7 +1408,37 @@ struct WasmWalker : public WasmWalkerBase<SubType, ReturnType> {
void walk(Expression*& curr) override {
if (!curr) return;
- ChildWalker<WasmWalker<SubType, ReturnType>>(*this).visit(curr);
+ // special-case Block, because Block nesting (in their first element) can be incredibly deep
+ if (curr->is<Block>()) {
+ auto* block = curr->dyn_cast<Block>();
+ std::vector<Block*> stack;
+ stack.push_back(block);
+ while (block->list.size() > 0 && block->list[0]->is<Block>()) {
+ block = block->list[0]->cast<Block>();
+ stack.push_back(block);
+ }
+ // walk all the children
+ for (int i = int(stack.size()) - 1; i >= 0; i--) {
+ auto* block = stack[i];
+ auto& children = block->list;
+ for (size_t j = 0; j < children.size(); j++) {
+ if (i < int(stack.size()) - 1 && j == 0) {
+ // this is one of the stacked blocks, no need to walk its children, we are doing that ourselves
+ this->visit(children[0]);
+ if (replace) {
+ children[0] = replace;
+ replace = nullptr;
+ }
+ } else {
+ this->walk(children[j]);
+ }
+ }
+ }
+ // we walked all the children, and can rejoin later below to visit this node itself
+ } else {
+ // generic child-walking
+ ChildWalker<WasmWalker<SubType, ReturnType>>(*this).visit(curr);
+ }
this->visit(curr);