summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2016-04-09 12:34:29 -0700
committerAlon Zakai <alonzakai@gmail.com>2016-04-09 12:34:29 -0700
commit4c98c3f9c6d0c98fbcbaa44a4fc5eb3b7e21b201 (patch)
treeab085cebcfeb1e79d0cc6985747e1e38838d4acb /src
parentd70661f8372ebd72a15e39675eddda463d8cdb31 (diff)
downloadbinaryen-4c98c3f9c6d0c98fbcbaa44a4fc5eb3b7e21b201.tar.gz
binaryen-4c98c3f9c6d0c98fbcbaa44a4fc5eb3b7e21b201.tar.bz2
binaryen-4c98c3f9c6d0c98fbcbaa44a4fc5eb3b7e21b201.zip
add option to print full ast, no elisions
Diffstat (limited to 'src')
-rw-r--r--src/passes/Print.cpp34
1 files changed, 28 insertions, 6 deletions
diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp
index 030fc64cd..8e3d503b8 100644
--- a/src/passes/Print.cpp
+++ b/src/passes/Print.cpp
@@ -26,12 +26,16 @@ namespace wasm {
struct PrintSExpression : public WasmVisitor<PrintSExpression, void> {
std::ostream& o;
- unsigned indent;
+ unsigned indent = 0;
+
bool minify;
const char *maybeSpace;
const char *maybeNewLine;
- PrintSExpression(std::ostream& o) : o(o), indent(0) {
+ bool fullAST = false; // whether to not elide nodes in output when possible
+ // (like implicit blocks)
+
+ PrintSExpression(std::ostream& o) : o(o) {
setMinify(false);
}
@@ -41,6 +45,8 @@ struct PrintSExpression : public WasmVisitor<PrintSExpression, void> {
maybeNewLine = minify ? "" : "\n";
}
+ void setFullAST(bool fullAST_) { fullAST = fullAST_; }
+
void incIndent() {
if (minify) return;
o << '\n';
@@ -99,13 +105,13 @@ struct PrintSExpression : public WasmVisitor<PrintSExpression, void> {
incIndent();
printFullLine(curr->condition);
// ifTrue and False have implict blocks, avoid printing them if possible
- if (curr->ifTrue->is<Block>() && curr->ifTrue->dyn_cast<Block>()->name.isNull() && curr->ifTrue->dyn_cast<Block>()->list.size() == 1) {
+ if (!fullAST && curr->ifTrue->is<Block>() && curr->ifTrue->dyn_cast<Block>()->name.isNull() && curr->ifTrue->dyn_cast<Block>()->list.size() == 1) {
printFullLine(curr->ifTrue->dyn_cast<Block>()->list.back());
} else {
printFullLine(curr->ifTrue);
}
if (curr->ifFalse) {
- if (curr->ifFalse->is<Block>() && curr->ifFalse->dyn_cast<Block>()->name.isNull() && curr->ifFalse->dyn_cast<Block>()->list.size() == 1) {
+ if (!fullAST && curr->ifFalse->is<Block>() && curr->ifFalse->dyn_cast<Block>()->name.isNull() && curr->ifFalse->dyn_cast<Block>()->list.size() == 1) {
printFullLine(curr->ifFalse->dyn_cast<Block>()->list.back());
} else {
printFullLine(curr->ifFalse);
@@ -124,7 +130,7 @@ struct PrintSExpression : public WasmVisitor<PrintSExpression, void> {
}
incIndent();
auto block = curr->body->dyn_cast<Block>();
- if (block && block->name.isNull()) {
+ if (!fullAST && block && block->name.isNull()) {
// wasm spec has loops containing children directly, while our ast
// has a single child for simplicity. print out the optimal form.
for (auto expression : block->list) {
@@ -439,7 +445,7 @@ struct PrintSExpression : public WasmVisitor<PrintSExpression, void> {
}
// It is ok to emit a block here, as a function can directly contain a list, even if our
// ast avoids that for simplicity. We can just do that optimization here..
- if (curr->body->is<Block>() && curr->body->cast<Block>()->name.isNull()) {
+ if (!fullAST && curr->body->is<Block>() && curr->body->cast<Block>()->name.isNull()) {
Block* block = curr->body->cast<Block>();
for (auto item : block->list) {
printFullLine(item);
@@ -553,6 +559,22 @@ class MinifiedPrinter : public Printer {
static RegisterPass<MinifiedPrinter> registerMinifyPass("print-minified", "print in minified s-expression format");
+// Prints out a module withough elision, i.e., the full ast
+
+class FullPrinter : public Printer {
+ public:
+ FullPrinter() : Printer() {}
+ FullPrinter(std::ostream& o) : Printer(o) {}
+
+ void run(PassRunner* runner, Module* module) override {
+ PrintSExpression print(o);
+ print.setFullAST(true);
+ print.visitModule(module);
+ }
+};
+
+static RegisterPass<FullPrinter> registerFullASTPass("print-full", "print in full s-expression format");
+
// Print individual expressions
std::ostream& WasmPrinter::printExpression(Expression* expression, std::ostream& o, bool minify) {