Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions src/passes/Print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 << ' ';
Expand Down Expand Up @@ -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); }

Expand Down Expand Up @@ -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 ");
Expand Down Expand Up @@ -2464,9 +2475,9 @@ void PrintSExpression::printFullLine(Expression* expression) {
doIndent(o, indent);
}
if (full) {
o << "[";
o << "(; ";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While we're at it, can we move the type comment to the end of the line rather than the beginning? That way the instructions will still line up nicely on the left side.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

printTypeOrName(expression->type, o, currModule);
o << "] ";
o << " ;) ";
}
visit(expression);
o << maybeNewLine;
Expand Down Expand Up @@ -2509,9 +2520,9 @@ void PrintSExpression::visitBlock(Block* curr) {
}
stack.push_back(curr);
if (full) {
o << "[";
o << " (;";
printTypeOrName(curr->type, o, currModule);
o << "]";
o << " ;)";
}
o << '(';
printExpressionContents(curr);
Expand Down Expand Up @@ -3370,9 +3381,9 @@ static std::ostream& printExpression(Expression* expression,
print.currModule = wasm;
if (full || isFullForced()) {
print.setFull(true);
o << "[";
o << "(; ";
printTypeOrName(expression->type, o, wasm);
o << "] ";
o << " ;) ";
}
print.visit(expression);
return o;
Expand Down
16 changes: 8 additions & 8 deletions test/lit/debug/full.wat
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,21 @@
;; NRML-NEXT: )
;; NRML-NEXT: )
;; FULL: (func $a
;; FULL-NEXT: [none] ;;@ src.cpp:1:2
;; FULL-NEXT: [none](block $block
;; FULL-NEXT: [none] ;;@ src.cpp:1:2
;; FULL-NEXT: (; none ;) ;;@ src.cpp:1:2
;; FULL-NEXT: (;none ;)(block $block
;; FULL-NEXT: (; none ;) ;;@ src.cpp:1:2
;; FULL-NEXT: (drop
;; FULL-NEXT: [i32] ;;@ src.cpp:1:2
;; FULL-NEXT: (; i32 ;) ;;@ src.cpp:1:2
;; FULL-NEXT: (i32.const 0)
;; FULL-NEXT: )
;; FULL-NEXT: [none] ;;@ src.cpp:3:4
;; FULL-NEXT: (; none ;) ;;@ src.cpp:3:4
;; FULL-NEXT: (drop
;; FULL-NEXT: [i32] ;;@ src.cpp:3:4
;; FULL-NEXT: (; i32 ;) ;;@ src.cpp:3:4
;; FULL-NEXT: (i32.const 1)
;; FULL-NEXT: )
;; FULL-NEXT: [none] ;;@ src.cpp:3:4
;; FULL-NEXT: (; none ;) ;;@ src.cpp:3:4
;; FULL-NEXT: (drop
;; FULL-NEXT: [i32] ;;@ src.cpp:3:4
;; FULL-NEXT: (; i32 ;) ;;@ src.cpp:3:4
;; FULL-NEXT: (i32.const 2)
;; FULL-NEXT: )
;; FULL-NEXT: ) ;; end block block
Expand Down
24 changes: 12 additions & 12 deletions test/lit/debug/replace-keep.wat
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
(module
;; CHECK: (func $test
;; CHECK-NEXT: (local $temp i32)
;; CHECK-NEXT: [none] ;;@ src.cpp:200:2
;; CHECK-NEXT: [none](block
;; CHECK-NEXT: [none] ;;@ src.cpp:200:2
;; CHECK-NEXT: (; none ;) ;;@ src.cpp:200:2
;; CHECK-NEXT: (;none ;)(block
;; CHECK-NEXT: (; none ;) ;;@ src.cpp:200:2
;; CHECK-NEXT: (call $test)
;; CHECK-NEXT: [none] ;;@ src.cpp:200:2
;; CHECK-NEXT: (local.set $temp
;; CHECK-NEXT: [i32] ;;@ src.cpp:200:2
;; CHECK-NEXT: (; none ;) ;;@ src.cpp:200:2
;; CHECK-NEXT: (local.set $temp (; local type: i32 ;)
;; CHECK-NEXT: (; i32 ;) ;;@ src.cpp:200:2
;; CHECK-NEXT: (i32.const 1)
;; CHECK-NEXT: )
;; CHECK-NEXT: ) ;; end block
Expand All @@ -40,13 +40,13 @@

;; CHECK: (func $test-no-trample
;; CHECK-NEXT: (local $temp i32)
;; CHECK-NEXT: [none] ;;@ src.cpp:300:3
;; CHECK-NEXT: [none](block
;; CHECK-NEXT: [none] ;;@ src.cpp:400:4
;; CHECK-NEXT: (; none ;) ;;@ src.cpp:300:3
;; CHECK-NEXT: (;none ;)(block
;; CHECK-NEXT: (; none ;) ;;@ src.cpp:400:4
;; CHECK-NEXT: (call $test)
;; CHECK-NEXT: [none] ;;@ src.cpp:200:2
;; CHECK-NEXT: (local.set $temp
;; CHECK-NEXT: [i32] ;;@ src.cpp:500:5
;; CHECK-NEXT: (; none ;) ;;@ src.cpp:200:2
;; CHECK-NEXT: (local.set $temp (; local type: i32 ;)
;; CHECK-NEXT: (; i32 ;) ;;@ src.cpp:500:5
;; CHECK-NEXT: (i32.const 1)
;; CHECK-NEXT: )
;; CHECK-NEXT: ) ;; end block
Expand Down