summaryrefslogtreecommitdiff
path: root/src/passes/Print.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/passes/Print.cpp')
-rw-r--r--src/passes/Print.cpp27
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;
}
};