diff options
author | Arthur Cohen <arthur.cohen@embecosm.com> | 2022-07-04 13:57:22 +0200 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2022-07-04 13:57:22 +0200 |
commit | 6eee318c244bf1e32bee8979083286b09e3f4dd4 (patch) | |
tree | 83557945c49ddef6a9507a20d568c8a310820e83 /gcc/rust/rust-session-manager.cc | |
parent | 408b7f87b99c1b9d074787ac279c86319ab00667 (diff) | |
download | gcc-6eee318c244bf1e32bee8979083286b09e3f4dd4.zip gcc-6eee318c244bf1e32bee8979083286b09e3f4dd4.tar.gz gcc-6eee318c244bf1e32bee8979083286b09e3f4dd4.tar.bz2 |
session-manager: Add -frust-dump-ast-pretty
Diffstat (limited to 'gcc/rust/rust-session-manager.cc')
-rw-r--r-- | gcc/rust/rust-session-manager.cc | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/gcc/rust/rust-session-manager.cc b/gcc/rust/rust-session-manager.cc index 9fd112c..8d18f95 100644 --- a/gcc/rust/rust-session-manager.cc +++ b/gcc/rust/rust-session-manager.cc @@ -32,6 +32,7 @@ #include "rust-lint-scan-deadcode.h" #include "rust-lint-unused-var.h" #include "rust-hir-dump.h" +#include "rust-ast-dump.h" #include "diagnostic.h" #include "input.h" @@ -51,6 +52,7 @@ namespace Rust { const char *kLexDumpFile = "gccrs.lex.dump"; const char *kASTDumpFile = "gccrs.ast.dump"; +const char *kASTPrettyDumpFile = "gccrs.ast-pretty.dump"; const char *kASTExpandedDumpFile = "gccrs.ast-expanded.dump"; const char *kHIRDumpFile = "gccrs.hir.dump"; const char *kHIRPrettyDumpFile = "gccrs.hir-pretty.dump"; @@ -506,6 +508,10 @@ Session::enable_dump (std::string arg) { options.enable_dump_option (CompileOptions::PARSER_AST_DUMP); } + else if (arg == "ast-pretty") + { + options.enable_dump_option (CompileOptions::AST_DUMP_PRETTY); + } else if (arg == "register_plugins") { options.enable_dump_option (CompileOptions::REGISTER_PLUGINS_DUMP); @@ -667,6 +673,10 @@ Session::parse_file (const char *filename) { dump_ast (parser, parsed_crate); } + if (options.dump_option_enabled (CompileOptions::AST_DUMP_PRETTY)) + { + dump_ast_pretty (parsed_crate); + } if (options.dump_option_enabled (CompileOptions::TARGET_OPTION_DUMP)) { options.target_data.dump_target_options (); @@ -1040,6 +1050,23 @@ Session::dump_ast (Parser<Lexer> &parser, AST::Crate &crate) const } void +Session::dump_ast_pretty (AST::Crate &crate) const +{ + std::ofstream out; + out.open (kASTPrettyDumpFile); + if (out.fail ()) + { + rust_error_at (Linemap::unknown_location (), "cannot open %s:%m; ignored", + kASTDumpFile); + return; + } + + AST::Dump (out).go (crate); + + out.close (); +} + +void Session::dump_ast_expanded (Parser<Lexer> &parser, AST::Crate &crate) const { std::ofstream out; |