summaryrefslogtreecommitdiff
path: root/src/passes/Print.cpp
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2024-06-13 10:28:32 -0700
committerGitHub <noreply@github.com>2024-06-13 17:28:32 +0000
commit66610d84bc466d0826803d8e2951af48ca2f1bae (patch)
treee672c8aabf0af72b2d57b4cf7859e1be0d0ebb38 /src/passes/Print.cpp
parent34686197f5a05854c0723214f3fdffbc9b19a7d5 (diff)
downloadbinaryen-66610d84bc466d0826803d8e2951af48ca2f1bae.tar.gz
binaryen-66610d84bc466d0826803d8e2951af48ca2f1bae.tar.bz2
binaryen-66610d84bc466d0826803d8e2951af48ca2f1bae.zip
Add local.set/tee local type annotations to BINARYEN_PRINT_FULL (#6657)
With this we now print e.g. (local.set $temp (; local type: i32 ;) ... This can be nice in large functions to avoid needing to scroll up to see the local type, e.g. when debugging why unsubtyping doesn't work somewhere. Also avoid [ ] in this mode, in favor of the standard (; ;), and put those at the end rather than at the start.
Diffstat (limited to 'src/passes/Print.cpp')
-rw-r--r--src/passes/Print.cpp37
1 files changed, 25 insertions, 12 deletions
diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp
index c57ab29c3..4ca5f722b 100644
--- a/src/passes/Print.cpp
+++ b/src/passes/Print.cpp
@@ -48,13 +48,18 @@ static std::ostream& printStackIR(StackIR* ir, PrintSExpression&);
namespace {
-bool isFullForced() {
+bool checkIsFullForced() {
if (getenv("BINARYEN_PRINT_FULL")) {
return std::stoi(getenv("BINARYEN_PRINT_FULL")) != 0;
}
return false;
}
+bool isFullForced() {
+ static bool full = checkIsFullForced();
+ return full;
+}
+
std::ostream& printMemoryName(Name name, std::ostream& o, Module* wasm) {
if (!wasm || wasm->memories.size() > 1) {
o << ' ';
@@ -409,11 +414,12 @@ struct PrintExpressionContents
Function* currFunction = nullptr;
std::ostream& o;
FeatureSet features;
+ bool full;
PrintExpressionContents(PrintSExpression& parent)
: parent(parent), wasm(parent.currModule),
currFunction(parent.currFunction), o(parent.o),
- features(wasm ? wasm->features : FeatureSet::All) {}
+ features(wasm ? wasm->features : FeatureSet::All), full(isFullForced()) {}
std::ostream& printType(Type type) { return parent.printType(type); }
@@ -517,6 +523,11 @@ struct PrintExpressionContents
printMedium(o, "local.set ");
}
printLocal(curr->index, currFunction, o);
+ if (full && currFunction) {
+ o << " (; local type: ";
+ printType(currFunction->getLocalType(curr->index));
+ o << " ;)";
+ }
}
void visitGlobalGet(GlobalGet* curr) {
printMedium(o, "global.get ");
@@ -2463,12 +2474,12 @@ void PrintSExpression::printFullLine(Expression* expression) {
if (!minify) {
doIndent(o, indent);
}
+ visit(expression);
if (full) {
- o << "[";
+ o << " (; ";
printTypeOrName(expression->type, o, currModule);
- o << "] ";
+ o << " ;)";
}
- visit(expression);
o << maybeNewLine;
}
@@ -2508,13 +2519,13 @@ void PrintSExpression::visitBlock(Block* curr) {
printDebugLocation(curr);
}
stack.push_back(curr);
+ o << '(';
+ printExpressionContents(curr);
if (full) {
- o << "[";
+ o << " (; ";
printTypeOrName(curr->type, o, currModule);
- o << "]";
+ o << " ;)";
}
- o << '(';
- printExpressionContents(curr);
incIndent();
if (curr->list.size() > 0 && curr->list[0]->is<Block>()) {
// recurse into the first element
@@ -3370,11 +3381,13 @@ static std::ostream& printExpression(Expression* expression,
print.currModule = wasm;
if (full || isFullForced()) {
print.setFull(true);
- o << "[";
- printTypeOrName(expression->type, o, wasm);
- o << "] ";
}
print.visit(expression);
+ if (full || isFullForced()) {
+ o << " (; ";
+ printTypeOrName(expression->type, o, wasm);
+ o << " ;)";
+ }
return o;
}