diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-07-21 16:07:30 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-07-21 16:07:30 -0700 |
commit | fdbba5eb702a945c0a72ae5c4ab00c5579730f4a (patch) | |
tree | 5d402051ae1781328fb8fe0725cf9c4286c0ff5c /src/passes/Print.cpp | |
parent | 12abb63203788cba23f5c65a971a2af922e05bfc (diff) | |
download | binaryen-fdbba5eb702a945c0a72ae5c4ab00c5579730f4a.tar.gz binaryen-fdbba5eb702a945c0a72ae5c4ab00c5579730f4a.tar.bz2 binaryen-fdbba5eb702a945c0a72ae5c4ab00c5579730f4a.zip |
support wasm globals (#650)
Diffstat (limited to 'src/passes/Print.cpp')
-rw-r--r-- | src/passes/Print.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp index 5fe7f93ac..e967d1850 100644 --- a/src/passes/Print.cpp +++ b/src/passes/Print.cpp @@ -35,6 +35,7 @@ struct PrintSExpression : public Visitor<PrintSExpression> { bool fullAST = false; // whether to not elide nodes in output when possible // (like implicit blocks) + Module* currModule = nullptr; Function* currFunction = nullptr; PrintSExpression(std::ostream& o) : o(o) { @@ -78,6 +79,10 @@ struct PrintSExpression : public Visitor<PrintSExpression> { return name; } + Name printableGlobal(Index index) { + return currModule->getGlobal(index)->name; + } + std::ostream& printName(Name name) { // we need to quote names if they have tricky chars if (strpbrk(name.str, "()")) { @@ -239,6 +244,15 @@ struct PrintSExpression : public Visitor<PrintSExpression> { printFullLine(curr->value); decIndent(); } + void visitGetGlobal(GetGlobal *curr) { + printOpening(o, "get_global ") << printableGlobal(curr->index) << ')'; + } + void visitSetGlobal(SetGlobal *curr) { + printOpening(o, "set_global ") << printableGlobal(curr->index); + incIndent(); + printFullLine(curr->value); + decIndent(); + } void visitLoad(Load *curr) { o << '('; prepareColor(o) << printWasmType(curr->type) << ".load"; @@ -519,6 +533,12 @@ struct PrintSExpression : public Visitor<PrintSExpression> { printText(o, curr->name.str) << ' '; printName(curr->value) << ')'; } + void visitGlobal(Global *curr) { + printOpening(o, "global "); + printName(curr->name) << ' ' << printWasmType(curr->type); + printFullLine(curr->init); + o << ')'; + } void visitFunction(Function *curr) { currFunction = curr; printOpening(o, "func ", true); @@ -563,6 +583,7 @@ struct PrintSExpression : public Visitor<PrintSExpression> { o << ')'; } void visitModule(Module *curr) { + currModule = curr; printOpening(o, "module", true); incIndent(); doIndent(o, indent); @@ -621,6 +642,11 @@ struct PrintSExpression : public Visitor<PrintSExpression> { visitExport(child.get()); o << maybeNewLine; } + for (auto& child : curr->globals) { + doIndent(o, indent); + visitGlobal(child.get()); + o << maybeNewLine; + } if (curr->table.names.size() > 0) { doIndent(o, indent); visitTable(&curr->table); @@ -633,6 +659,7 @@ struct PrintSExpression : public Visitor<PrintSExpression> { } decIndent(); o << maybeNewLine; + currModule = nullptr; } }; |