summaryrefslogtreecommitdiff
path: root/src/passes/Print.cpp
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/passes/Print.cpp
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/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();
}