summaryrefslogtreecommitdiff
path: root/src/passes/Print.cpp
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2019-07-03 12:45:16 -0700
committerGitHub <noreply@github.com>2019-07-03 12:45:16 -0700
commit23d8497ce605b41652e97aea06150c9d59b93796 (patch)
tree43a613319aaf47122ae37a0096f2173ce0741060 /src/passes/Print.cpp
parent7d1ff56acafae9c769bc8dd8da2c8ef3c66a2aa6 (diff)
downloadbinaryen-23d8497ce605b41652e97aea06150c9d59b93796.tar.gz
binaryen-23d8497ce605b41652e97aea06150c9d59b93796.tar.bz2
binaryen-23d8497ce605b41652e97aea06150c9d59b93796.zip
Minimal Push/Pop support (#2207)
This is the first stage of adding support for stacky/multivaluey things. It adds new push/pop instructions, and so far just shows that they can be read and written, and that the optimizer doesn't do anything immediately wrong on them. No fuzzer support, since there isn't a "correct" way to use these yet. The current test shows some "incorrect" usages of them, which is nice to see that we can parse/emit them, but we should replace them with proper usages of push/pop once we actually have those (see comments in the tests). This should be enough to unblock exceptions (which needs a pop in try-catches). It is also a step towards multivalue (I added some docs about that), but most of multivalue is left to be done.
Diffstat (limited to 'src/passes/Print.cpp')
-rw-r--r--src/passes/Print.cpp25
1 files changed, 22 insertions, 3 deletions
diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp
index 9dbf3cc1f..e1ed788c4 100644
--- a/src/passes/Print.cpp
+++ b/src/passes/Print.cpp
@@ -57,7 +57,8 @@ static Name printableLocal(Index index, Function* func) {
// Prints the internal contents of an expression: everything but
// the children.
-struct PrintExpressionContents : public Visitor<PrintExpressionContents> {
+struct PrintExpressionContents
+ : public OverriddenVisitor<PrintExpressionContents> {
Function* currFunction = nullptr;
std::ostream& o;
@@ -1150,11 +1151,17 @@ struct PrintExpressionContents : public Visitor<PrintExpressionContents> {
}
void visitNop(Nop* curr) { printMinor(o, "nop"); }
void visitUnreachable(Unreachable* curr) { printMinor(o, "unreachable"); }
+ void visitPush(Push* curr) { prepareColor(o) << "push"; }
+ void visitPop(Pop* curr) {
+ prepareColor(o) << printType(curr->type);
+ o << ".pop";
+ restoreNormalColor(o);
+ }
};
// Prints an expression in s-expr format, including both the
// internal contents and the nested children.
-struct PrintSExpression : public Visitor<PrintSExpression> {
+struct PrintSExpression : public OverriddenVisitor<PrintSExpression> {
std::ostream& o;
unsigned indent = 0;
@@ -1205,7 +1212,7 @@ struct PrintSExpression : public Visitor<PrintSExpression> {
void visit(Expression* curr) {
printDebugLocation(curr);
- Visitor<PrintSExpression>::visit(curr);
+ OverriddenVisitor<PrintSExpression>::visit(curr);
}
void setMinify(bool minify_) {
@@ -1621,6 +1628,18 @@ struct PrintSExpression : public Visitor<PrintSExpression> {
PrintExpressionContents(currFunction, o).visit(curr);
o << ')';
}
+ void visitPush(Push* curr) {
+ o << '(';
+ PrintExpressionContents(currFunction, o).visit(curr);
+ incIndent();
+ printFullLine(curr->value);
+ decIndent();
+ }
+ void visitPop(Pop* curr) {
+ o << '(';
+ PrintExpressionContents(currFunction, o).visit(curr);
+ o << ')';
+ }
// Module-level visitors
void visitFunctionType(FunctionType* curr, Name* internalName = nullptr) {
o << "(func";