public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] cli: add "hir-pretty" as a "dump" option
@ 2022-06-25  9:32 Thomas Schwinge
  0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2022-06-25  9:32 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:557b8d93be1a827886eb006f767d9c03221e587e

commit 557b8d93be1a827886eb006f767d9c03221e587e
Author: andrewnaguib <24280372+ndrwnaguib@users.noreply.github.com>
Date:   Fri Jun 24 04:17:12 2022 -0700

    cli: add "hir-pretty" as a "dump" option
    
    Instead of mixing the ongoing project of pretty dumping the HIR with the current
    implementation, this commit adds a new option "-frust-dump-hir-pretty" which
    calls the hir pretty dump visitor class. Closes https://github.com/Rust-GCC/gccrs/issues/1333
    
    Co-authored-by: CohenArthur <arthur.cohen@embecosm.com>

Diff:
---
 gcc/rust/rust-session-manager.cc | 26 ++++++++++++++++++++++++++
 gcc/rust/rust-session-manager.h  |  3 +++
 2 files changed, 29 insertions(+)

diff --git a/gcc/rust/rust-session-manager.cc b/gcc/rust/rust-session-manager.cc
index bbc4d6ee46f..9fd112cd5b1 100644
--- a/gcc/rust/rust-session-manager.cc
+++ b/gcc/rust/rust-session-manager.cc
@@ -53,6 +53,7 @@ const char *kLexDumpFile = "gccrs.lex.dump";
 const char *kASTDumpFile = "gccrs.ast.dump";
 const char *kASTExpandedDumpFile = "gccrs.ast-expanded.dump";
 const char *kHIRDumpFile = "gccrs.hir.dump";
+const char *kHIRPrettyDumpFile = "gccrs.hir-pretty.dump";
 const char *kHIRTypeResolutionDumpFile = "gccrs.type-resolution.dump";
 const char *kTargetOptionsDumpFile = "gccrs.target-options.dump";
 
@@ -529,6 +530,10 @@ Session::enable_dump (std::string arg)
     {
       options.enable_dump_option (CompileOptions::HIR_DUMP);
     }
+  else if (arg == "hir-pretty")
+    {
+      options.enable_dump_option (CompileOptions::HIR_DUMP_PRETTY);
+    }
   else
     {
       rust_error_at (
@@ -735,6 +740,11 @@ Session::parse_file (const char *filename)
       dump_hir (hir);
     }
 
+  if (options.dump_option_enabled (CompileOptions::HIR_DUMP_PRETTY))
+    {
+      dump_hir_pretty (hir);
+    }
+
   if (saw_errors ())
     return;
 
@@ -1057,6 +1067,22 @@ Session::dump_hir (HIR::Crate &crate) const
       return;
     }
 
+  out << crate.as_string ();
+  out.close ();
+}
+
+void
+Session::dump_hir_pretty (HIR::Crate &crate) const
+{
+  std::ofstream out;
+  out.open (kHIRPrettyDumpFile);
+  if (out.fail ())
+    {
+      rust_error_at (Linemap::unknown_location (), "cannot open %s:%m; ignored",
+		     kHIRPrettyDumpFile);
+      return;
+    }
+
   HIR::Dump (out).go (crate);
   out.close ();
 }
diff --git a/gcc/rust/rust-session-manager.h b/gcc/rust/rust-session-manager.h
index 97b546922cf..f616a07dfad 100644
--- a/gcc/rust/rust-session-manager.h
+++ b/gcc/rust/rust-session-manager.h
@@ -172,6 +172,7 @@ struct CompileOptions
     RESOLUTION_DUMP,
     TARGET_OPTION_DUMP,
     HIR_DUMP,
+    HIR_DUMP_PRETTY,
     TYPE_RESOLUTION_DUMP,
   };
 
@@ -211,6 +212,7 @@ struct CompileOptions
     enable_dump_option (DumpOption::RESOLUTION_DUMP);
     enable_dump_option (DumpOption::TARGET_OPTION_DUMP);
     enable_dump_option (DumpOption::HIR_DUMP);
+    enable_dump_option (DumpOption::HIR_DUMP_PRETTY);
     enable_dump_option (DumpOption::TYPE_RESOLUTION_DUMP);
   }
 
@@ -291,6 +293,7 @@ private:
   void dump_ast (Parser<Lexer> &parser, AST::Crate &crate) const;
   void dump_ast_expanded (Parser<Lexer> &parser, AST::Crate &crate) const;
   void dump_hir (HIR::Crate &crate) const;
+  void dump_hir_pretty (HIR::Crate &crate) const;
   void dump_type_resolution (HIR::Crate &crate) const;
 
   void debug_dump_load_crates (Parser<Lexer> &parser);


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-06-25  9:32 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-25  9:32 [gcc/devel/rust/master] cli: add "hir-pretty" as a "dump" option Thomas Schwinge

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).