From 139d0203d520ca589070ad5d5c2d8c08e7d96afe Mon Sep 17 00:00:00 2001 From: Thomas Lively <7121787+tlively@users.noreply.github.com> Date: Mon, 15 Jun 2020 17:21:58 -0700 Subject: Add Expression::dump for use while debugging (#2912) 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. --- src/wasm.h | 3 +++ src/wasm/wasm.cpp | 8 ++++++++ 2 files changed, 11 insertions(+) (limited to 'src') diff --git a/src/wasm.h b/src/wasm.h index a1c386289..b52e7539b 100644 --- a/src/wasm.h +++ b/src/wasm.h @@ -588,6 +588,9 @@ public: 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); diff --git a/src/wasm/wasm.cpp b/src/wasm/wasm.cpp index 6f86a13ac..f1d51bbca 100644 --- a/src/wasm/wasm.cpp +++ b/src/wasm/wasm.cpp @@ -16,6 +16,7 @@ #include "wasm.h" #include "ir/branch-utils.h" +#include "wasm-printing.h" #include "wasm-traversal.h" namespace wasm { @@ -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: -- cgit v1.2.3