From 612a48a8891fe80d71a0ae1c7d7f450f2e5d78fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= Date: Mon, 18 Sep 2023 22:16:06 +0200 Subject: [PATCH] gccrs: Add debug helper to dump HIR MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add simple debug wrapper to dump HIR nodes on stderr. Similar to what we already have for AST. gcc/rust/ChangeLog: * hir/rust-hir-dump.cc (Dump::debug): New. (debug): New. * hir/rust-hir-dump.h (debug): New. Signed-off-by: Marc Poulhiès --- gcc/rust/hir/rust-hir-dump.cc | 19 +++++++++++++++++++ gcc/rust/hir/rust-hir-dump.h | 6 ++++++ 2 files changed, 25 insertions(+) diff --git a/gcc/rust/hir/rust-hir-dump.cc b/gcc/rust/hir/rust-hir-dump.cc index 9e9157667c09..342c62e58a1b 100644 --- a/gcc/rust/hir/rust-hir-dump.cc +++ b/gcc/rust/hir/rust-hir-dump.cc @@ -68,6 +68,18 @@ BoundPolarityString (BoundPolarity polarity) return "unknown"; } +/** + * Static member used to dump HIR from the debugger to stderr. + * + * @param v The HIR node to dump + */ +void +Dump::debug (FullVisitable &v) +{ + Dump dump (std::cerr); + v.accept_vis (dump); +} + void Dump::go (HIR::Crate &e) { @@ -2390,3 +2402,10 @@ Dump::visit (BareFunctionType &e) } // namespace HIR } // namespace Rust + +// In the global namespace to make it easier to call from debugger +void +debug (Rust::HIR::FullVisitable &v) +{ + Rust::HIR::Dump::debug (v); +} diff --git a/gcc/rust/hir/rust-hir-dump.h b/gcc/rust/hir/rust-hir-dump.h index a2bc4cbab55e..947feaeae8ba 100644 --- a/gcc/rust/hir/rust-hir-dump.h +++ b/gcc/rust/hir/rust-hir-dump.h @@ -32,6 +32,8 @@ namespace HIR { class Dump : public HIRFullVisitor { public: + static void debug (FullVisitable &v); + Dump (std::ostream &stream); void go (HIR::Crate &crate); @@ -248,4 +250,8 @@ class Dump : public HIRFullVisitor } // namespace HIR } // namespace Rust +// In the global namespace to make it easier to call from debugger +void +debug (Rust::HIR::FullVisitable &v); + #endif // !RUST_HIR_DUMP_H