Skip to content

Commit

Permalink
Add Expression::dump for use while debugging (#2912)
Browse files Browse the repository at this point in the history
I have found that similar dump functions have been extremely helpful
while debugging LLVM. Rather than re-implement this locally whenever I
need it, it would be better have this utility upstream.
  • Loading branch information
tlively committed Jun 16, 2020
1 parent d26f90b commit 139d020
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/wasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,9 @@ class Expression {
assert(int(_id) == int(T::SpecificId));
return (const T*)this;
}

// Print the expression to stderr. Meant for use while debugging.
void dump();
};

const char* getExpressionName(Expression* curr);
Expand Down
8 changes: 8 additions & 0 deletions src/wasm/wasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include "wasm.h"
#include "ir/branch-utils.h"
#include "wasm-printing.h"
#include "wasm-traversal.h"

namespace wasm {
Expand Down Expand Up @@ -93,6 +94,13 @@ Name ATTR("attr");

// Expressions

void Expression::dump() {
WasmPrinter::printExpression(this,
std::cerr,
/*minify=*/false,
/*full=*/true);
}

const char* getExpressionName(Expression* curr) {
switch (curr->_id) {
case Expression::Id::InvalidId:
Expand Down

0 comments on commit 139d020

Please sign in to comment.