Skip to content

Commit

Permalink
gccrs: Add debug helper to dump HIR
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
dkm authored and philberty committed Sep 18, 2023
1 parent f9455fb commit 612a48a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
19 changes: 19 additions & 0 deletions gcc/rust/hir/rust-hir-dump.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
}
6 changes: 6 additions & 0 deletions gcc/rust/hir/rust-hir-dump.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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

0 comments on commit 612a48a

Please sign in to comment.