awarzynski created this revision. Herald added a reviewer: sscalpone. Herald added a subscriber: dang. awarzynski requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
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. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D104305 Files: 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
Index: flang/test/Driver/driver-help.f90 =================================================================== --- flang/test/Driver/driver-help.f90 +++ 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 Index: flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp =================================================================== --- flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp +++ flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp @@ -55,6 +55,9 @@ case DebugDumpParseTreeNoSema: return std::make_unique<DebugDumpParseTreeNoSemaAction>(); break; + case DebugDumpAll: + return std::make_unique<DebugDumpAllAction>(); + break; case DebugDumpProvenance: return std::make_unique<DebugDumpProvenanceAction>(); break; Index: flang/lib/Frontend/FrontendActions.cpp =================================================================== --- flang/lib/Frontend/FrontendActions.cpp +++ flang/lib/Frontend/FrontendActions.cpp @@ -305,6 +305,42 @@ 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 = Index: flang/lib/Frontend/CompilerInvocation.cpp =================================================================== --- flang/lib/Frontend/CompilerInvocation.cpp +++ flang/lib/Frontend/CompilerInvocation.cpp @@ -141,6 +141,9 @@ 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; Index: flang/include/flang/Frontend/FrontendOptions.h =================================================================== --- flang/include/flang/Frontend/FrontendOptions.h +++ flang/include/flang/Frontend/FrontendOptions.h @@ -51,6 +51,9 @@ /// Parse, run semantics and then output the parse tree DebugDumpParseTree, + /// Parse, run semantics and then output the parse tree symbols + DebugDumpAll, + /// Parse and then output the parse tree, skip the semantic checks DebugDumpParseTreeNoSema, Index: flang/include/flang/Frontend/FrontendActions.h =================================================================== --- flang/include/flang/Frontend/FrontendActions.h +++ flang/include/flang/Frontend/FrontendActions.h @@ -116,6 +116,10 @@ void ExecuteAction() override; }; +class DebugDumpAllAction : public PrescanAndSemaAction { + void ExecuteAction() override; +}; + class DebugPreFIRTreeAction : public PrescanAndSemaAction { void ExecuteAction() override; }; Index: clang/include/clang/Driver/Options.td =================================================================== --- clang/include/clang/Driver/Options.td +++ clang/include/clang/Driver/Options.td @@ -4527,6 +4527,8 @@ 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>,
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits