Author: Andrzej Warzynski Date: 2021-06-16T07:54:27Z New Revision: a6be6e31f1810012922e50dab0d4c15cdf990d2e
URL: https://github.com/llvm/llvm-project/commit/a6be6e31f1810012922e50dab0d4c15cdf990d2e DIFF: https://github.com/llvm/llvm-project/commit/a6be6e31f1810012922e50dab0d4c15cdf990d2e.diff LOG: [flang][driver] Add `-fdebug-dump-all` The new option will run the semantic checks and then dump the parse tree and all the symbols. This is equivalent to running the driver twice, once with `-fdebug-dump-parse-tree` and then with the `-fdebug-dump-symbols` action flag. Currently we wouldn't be able to achieve the same by simply running: ``` flang-new -fc1 -fdebug-dump-parse-tree -fdebug-dump-symbols <input-file> ``` That's because the new driver will only run one frontend action per invocation (both of the flags used here are action flags). Diverging from this design would lead to costly compromises and it's best avoided. We may want to consider re-designing our debugging actions (and action options) in the future so that there's more code re-use. For now, I'm focusing on making sure that we support all the major cases requested by our users. Differential Revision: https://reviews.llvm.org/D104305 Added: flang/test/Driver/dump-all.f90 Modified: clang/include/clang/Driver/Options.td flang/include/flang/Frontend/FrontendActions.h flang/include/flang/Frontend/FrontendOptions.h flang/lib/Frontend/CompilerInvocation.cpp flang/lib/Frontend/FrontendActions.cpp flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp flang/test/Driver/driver-help.f90 Removed: ################################################################################ diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 7c6b22c029693..151968de1789e 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -4523,6 +4523,8 @@ def fdebug_dump_parse_tree_no_sema : Flag<["-"], "fdebug-dump-parse-tree-no-sema HelpText<"Dump the parse tree (skips the semantic checks)">, DocBrief<[{Run the Parser and then output the parse tree. Semantic checks are disabled.}]>; +def fdebug_dump_all : Flag<["-"], "fdebug-dump-all">, Group<Action_Group>, + HelpText<"Dump symbols and the parse tree after the semantic checks">; def fdebug_dump_provenance : Flag<["-"], "fdebug-dump-provenance">, Group<Action_Group>, HelpText<"Dump provenance">; def fdebug_dump_parsing_log : Flag<["-"], "fdebug-dump-parsing-log">, Group<Action_Group>, diff --git a/flang/include/flang/Frontend/FrontendActions.h b/flang/include/flang/Frontend/FrontendActions.h index 7a88382075741..72eb44223fe49 100644 --- a/flang/include/flang/Frontend/FrontendActions.h +++ b/flang/include/flang/Frontend/FrontendActions.h @@ -116,6 +116,10 @@ class DebugDumpParseTreeAction : public PrescanAndSemaAction { void ExecuteAction() override; }; +class DebugDumpAllAction : public PrescanAndSemaAction { + void ExecuteAction() override; +}; + class DebugPreFIRTreeAction : public PrescanAndSemaAction { void ExecuteAction() override; }; diff --git a/flang/include/flang/Frontend/FrontendOptions.h b/flang/include/flang/Frontend/FrontendOptions.h index 9c34abb68f2d6..42ce499566e9f 100644 --- a/flang/include/flang/Frontend/FrontendOptions.h +++ b/flang/include/flang/Frontend/FrontendOptions.h @@ -51,6 +51,9 @@ enum ActionKind { /// Parse, run semantics and then output the parse tree DebugDumpParseTree, + /// Parse, run semantics and then output the parse tree and symbols + DebugDumpAll, + /// Parse and then output the parse tree, skip the semantic checks DebugDumpParseTreeNoSema, diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp index 5098da42dfc0f..dc771ecbc9a8f 100644 --- a/flang/lib/Frontend/CompilerInvocation.cpp +++ b/flang/lib/Frontend/CompilerInvocation.cpp @@ -141,6 +141,9 @@ static bool ParseFrontendArgs(FrontendOptions &opts, llvm::opt::ArgList &args, case clang::driver::options::OPT_fdebug_dump_parse_tree: opts.programAction_ = DebugDumpParseTree; break; + case clang::driver::options::OPT_fdebug_dump_all: + opts.programAction_ = DebugDumpAll; + break; case clang::driver::options::OPT_fdebug_dump_parse_tree_no_sema: opts.programAction_ = DebugDumpParseTreeNoSema; break; diff --git a/flang/lib/Frontend/FrontendActions.cpp b/flang/lib/Frontend/FrontendActions.cpp index f4ba515440d9b..d3cce62681cc0 100644 --- a/flang/lib/Frontend/FrontendActions.cpp +++ b/flang/lib/Frontend/FrontendActions.cpp @@ -305,6 +305,42 @@ void DebugDumpSymbolsAction::ExecuteAction() { semantics.DumpSymbols(llvm::outs()); } +void DebugDumpAllAction::ExecuteAction() { + CompilerInstance &ci = this->instance(); + + // Dump parse tree + auto &parseTree{instance().parsing().parseTree()}; + Fortran::parser::AnalyzedObjectsAsFortran asFortran = + Fortran::frontend::getBasicAsFortran(); + llvm::outs() << "========================"; + llvm::outs() << " Flang: parse tree dump "; + llvm::outs() << "========================\n"; + Fortran::parser::DumpTree(llvm::outs(), parseTree, &asFortran); + + auto &semantics = this->semantics(); + auto tables{Fortran::semantics::BuildRuntimeDerivedTypeTables( + instance().invocation().semanticsContext())}; + // The runtime derived type information table builder may find and report + // semantic errors. So it is important that we report them _after_ + // BuildRuntimeDerivedTypeTables is run. + reportFatalSemanticErrors( + semantics, this->instance().diagnostics(), GetCurrentFileOrBufferName()); + + if (!tables.schemata) { + unsigned DiagID = + ci.diagnostics().getCustomDiagID(clang::DiagnosticsEngine::Error, + "could not find module file for __fortran_type_info"); + ci.diagnostics().Report(DiagID); + llvm::errs() << "\n"; + } + + // Dump symbols + llvm::outs() << "====================="; + llvm::outs() << " Flang: symbols dump "; + llvm::outs() << "=====================\n"; + semantics.DumpSymbols(llvm::outs()); +} + void DebugDumpParseTreeNoSemaAction::ExecuteAction() { auto &parseTree{instance().parsing().parseTree()}; Fortran::parser::AnalyzedObjectsAsFortran asFortran = diff --git a/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp b/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp index ffc0d75edb008..e53f652d3b2c4 100644 --- a/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp +++ b/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp @@ -55,6 +55,9 @@ static std::unique_ptr<FrontendAction> CreateFrontendBaseAction( case DebugDumpParseTreeNoSema: return std::make_unique<DebugDumpParseTreeNoSemaAction>(); break; + case DebugDumpAll: + return std::make_unique<DebugDumpAllAction>(); + break; case DebugDumpProvenance: return std::make_unique<DebugDumpProvenanceAction>(); break; diff --git a/flang/test/Driver/driver-help.f90 b/flang/test/Driver/driver-help.f90 index 1a11ba1dc78c5..9fa35d28af3d7 100644 --- a/flang/test/Driver/driver-help.f90 +++ b/flang/test/Driver/driver-help.f90 @@ -69,6 +69,7 @@ ! HELP-FC1-NEXT: -falternative-parameter-statement ! HELP-FC1-NEXT: Enable the old style PARAMETER statement ! HELP-FC1-NEXT: -fbackslash Specify that backslash in string introduces an escape character +! HELP-FC1-NEXT: -fdebug-dump-all Dump symbols and the parse tree after the semantic checks ! HELP-FC1-NEXT: -fdebug-dump-parse-tree-no-sema ! HELP-FC1-NEXT: Dump the parse tree (skips the semantic checks) ! HELP-FC1-NEXT: -fdebug-dump-parse-tree Dump the parse tree diff --git a/flang/test/Driver/dump-all.f90 b/flang/test/Driver/dump-all.f90 new file mode 100644 index 0000000000000..92c62be0222b3 --- /dev/null +++ b/flang/test/Driver/dump-all.f90 @@ -0,0 +1,17 @@ +!---------- +! RUN lines +!---------- +! RUN: %flang_fc1 -fdebug-dump-all %s 2>&1 | FileCheck %s + +!---------------- +! EXPECTED OUTPUT +!---------------- +! CHECK: Flang: parse tree dump +! CHECK: Flang: symbols dump + +!------- +! INPUT +!------- +parameter(i=1) +integer :: j +end program _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits