diff mbox series

[061/125] gccrs: session-manager: Dump name resolution pass.

Message ID 20240801145809.366388-63-arthur.cohen@embecosm.com
State New
Headers show
Series [001/125] Rust: Make 'tree'-level 'MAIN_NAME_P' work | expand

Commit Message

Arthur Cohen Aug. 1, 2024, 2:56 p.m. UTC
gcc/rust/ChangeLog:

	* rust-session-manager.cc: Add files for dumping name resolution, call
	name resolution dump function.
	(Session::dump_name_resolution): New.
	* rust-session-manager.h: New declaration.
---
 gcc/rust/rust-session-manager.cc | 30 +++++++++++++++++++++++++++---
 gcc/rust/rust-session-manager.h  |  1 +
 2 files changed, 28 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/gcc/rust/rust-session-manager.cc b/gcc/rust/rust-session-manager.cc
index 40adeb20de4..64e0190f716 100644
--- a/gcc/rust/rust-session-manager.cc
+++ b/gcc/rust/rust-session-manager.cc
@@ -69,6 +69,10 @@  const char *kASTDumpFile = "gccrs.ast.dump";
 const char *kASTPrettyDumpFile = "gccrs.ast-pretty.dump";
 const char *kASTPrettyDumpFileExpanded = "gccrs.ast-pretty-expanded.dump";
 const char *kASTExpandedDumpFile = "gccrs.ast-expanded.dump";
+const char *kASTmacroResolutionDumpFile = "gccrs.ast-macro-resolution.dump";
+const char *kASTlabelResolutionDumpFile = "gccrs.ast-label-resolution.dump";
+const char *kASTtypeResolutionDumpFile = "gccrs.ast-type-resolution.dump";
+const char *kASTvalueResolutionDumpFile = "gccrs.ast-value-resolution.dump";
 const char *kHIRDumpFile = "gccrs.hir.dump";
 const char *kHIRPrettyDumpFile = "gccrs.hir-pretty.dump";
 const char *kHIRTypeResolutionDumpFile = "gccrs.type-resolution.dump";
@@ -86,6 +90,7 @@  Session::get_instance ()
 
 static std::string
 infer_crate_name (const std::string &filename)
+
 {
   if (filename == "-")
     return kDefaultCrateName;
@@ -626,9 +631,7 @@  Session::compile_crate (const char *filename)
     Resolver::NameResolution::Resolve (parsed_crate);
 
   if (options.dump_option_enabled (CompileOptions::RESOLUTION_DUMP))
-    {
-      // TODO: what do I dump here? resolved names? AST with resolved names?
-    }
+    dump_name_resolution (name_resolution_ctx);
 
   if (saw_errors ())
     return;
@@ -982,6 +985,27 @@  Session::dump_ast_pretty (AST::Crate &crate, bool expanded) const
   out.close ();
 }
 
+void
+Session::dump_name_resolution (Resolver2_0::NameResolutionContext &ctx) const
+{
+  // YES this is ugly but NO GCC 4.8 does not allow us to make it fancier :(
+  std::string types_content = ctx.types.as_debug_string ();
+  std::ofstream types_stream{kASTtypeResolutionDumpFile};
+  types_stream << types_content;
+
+  std::string macros_content = ctx.macros.as_debug_string ();
+  std::ofstream macros_stream{kASTmacroResolutionDumpFile};
+  macros_stream << macros_content;
+
+  std::string labels_content = ctx.labels.as_debug_string ();
+  std::ofstream labels_stream{kASTlabelResolutionDumpFile};
+  labels_stream << labels_content;
+
+  std::string values_content = ctx.values.as_debug_string ();
+  std::ofstream values_stream{kASTvalueResolutionDumpFile};
+  values_stream << values_content;
+}
+
 void
 Session::dump_hir (HIR::Crate &crate) const
 {
diff --git a/gcc/rust/rust-session-manager.h b/gcc/rust/rust-session-manager.h
index 9a5691f45ee..845b53ab6db 100644
--- a/gcc/rust/rust-session-manager.h
+++ b/gcc/rust/rust-session-manager.h
@@ -396,6 +396,7 @@  private:
 
   void dump_lex (Parser<Lexer> &parser) const;
   void dump_ast_pretty (AST::Crate &crate, bool expanded = false) const;
+  void dump_name_resolution (Resolver2_0::NameResolutionContext &ctx) const;
   void dump_hir (HIR::Crate &crate) const;
   void dump_hir_pretty (HIR::Crate &crate) const;