summaryrefslogtreecommitdiff
path: root/src/passes/Print.cpp
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2016-03-08 12:20:53 -0800
committerAlon Zakai <alonzakai@gmail.com>2016-03-10 16:30:01 -0800
commit7734ce6ef5f95697c5bdebc18b96d3902c766b8e (patch)
tree61e24549dec76a6f989a7fd74a68a59d783d90c8 /src/passes/Print.cpp
parent0467407decb3cd30ad407f553a078b9f533b479d (diff)
downloadbinaryen-7734ce6ef5f95697c5bdebc18b96d3902c766b8e.tar.gz
binaryen-7734ce6ef5f95697c5bdebc18b96d3902c766b8e.tar.bz2
binaryen-7734ce6ef5f95697c5bdebc18b96d3902c766b8e.zip
de-recurse operations on nested blocks
Diffstat (limited to 'src/passes/Print.cpp')
-rw-r--r--src/passes/Print.cpp37
1 files changed, 31 insertions, 6 deletions
diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp
index b69f7a977..2a940359f 100644
--- a/src/passes/Print.cpp
+++ b/src/passes/Print.cpp
@@ -54,13 +54,38 @@ struct PrintSExpression : public WasmVisitor<PrintSExpression, void> {
o << maybeNewLine;
}
void visitBlock(Block *curr) {
- printOpening(o, "block");
- if (curr->name.is()) {
- o << ' ' << curr->name;
+ // special-case Block, because Block nesting (in their first element) can be incredibly deep
+ std::vector<Block*> stack;
+ while (1) {
+ if (stack.size() > 0) doIndent(o, indent);
+ stack.push_back(curr);
+ printOpening(o, "block");
+ if (curr->name.is()) {
+ o << ' ' << curr->name;
+ }
+ incIndent();
+ if (curr->list.size() > 0 && curr->list[0]->is<Block>()) {
+ // recurse into the first element
+ curr = curr->list[0]->cast<Block>();
+ continue;
+ } else {
+ break; // that's all we can recurse, start to unwind
+ }
}
- incIndent();
- for (auto expression : curr->list) {
- printFullLine(expression);
+ auto* top = stack.back();
+ while (stack.size() > 0) {
+ curr = stack.back();
+ stack.pop_back();
+ auto& list = curr->list;
+ for (size_t i = 0; i < list.size(); i++) {
+ if (curr != top && i == 0) {
+ // one of the block recursions we already handled
+ decIndent();
+ o << '\n';
+ continue;
+ }
+ printFullLine(list[i]);
+ }
}
decIndent();
}