[clang] 523d7bc - [flang][driver] Add `-fdebug-dump-parsing-log`
Andrzej Warzynski via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 10 04:09:59 PST 2021
Author: Andrzej Warzynski
Date: 2021-03-10T12:09:16Z
New Revision: 523d7bc6f427f9ae32e54dbf1764826cfb269d21
URL: https://github.com/llvm/llvm-project/commit/523d7bc6f427f9ae32e54dbf1764826cfb269d21
DIFF: https://github.com/llvm/llvm-project/commit/523d7bc6f427f9ae32e54dbf1764826cfb269d21.diff
LOG: [flang][driver] Add `-fdebug-dump-parsing-log`
This patch adds `-fdebug-dump-parsing-log` in the new driver. This option is
semantically identical to `-fdebug-instrumented-parse` in `f18` (the
former is added as an alias in `f18`).
As dumping the parsing log makes only sense for instrumented parses, we
set Fortran::parser::Options::instrumentedParse to `True` when
`-fdebug-dump-parsing-log` is used. This is consistent with `f18`.
To facilitate tweaking the configuration of the frontend based on the
action being requested, `setUpFrontendBasedOnAction` is introduced in
CompilerInvocation.cpp.
Differential Revision: https://reviews.llvm.org/D97457
Added:
flang/test/Driver/debug-parsing-log.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
flang/tools/f18/f18.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 8e71aff2e96d..376a3baf0a4b 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4361,6 +4361,8 @@ def fdebug_dump_parse_tree : Flag<["-"], "fdebug-dump-parse-tree">, Group<Action
HelpText<"Dump the parse tree">;
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>,
+ HelpText<"Run instrumented parse and dump the parsing log">;
def fdebug_measure_parse_tree : Flag<["-"], "fdebug-measure-parse-tree">, Group<Action_Group>,
HelpText<"Measure the parse tree">;
def fdebug_pre_fir_tree : Flag<["-"], "fdebug-pre-fir-tree">, Group<Action_Group>,
diff --git a/flang/include/flang/Frontend/FrontendActions.h b/flang/include/flang/Frontend/FrontendActions.h
index f6dfdd2dc09b..35d1e6f29b0f 100644
--- a/flang/include/flang/Frontend/FrontendActions.h
+++ b/flang/include/flang/Frontend/FrontendActions.h
@@ -54,6 +54,10 @@ class DebugDumpProvenanceAction : public PrescanAction {
void ExecuteAction() override;
};
+class DebugDumpParsingLogAction : public PrescanAction {
+ void ExecuteAction() override;
+};
+
class DebugMeasureParseTreeAction : public PrescanAction {
void ExecuteAction() override;
};
diff --git a/flang/include/flang/Frontend/FrontendOptions.h b/flang/include/flang/Frontend/FrontendOptions.h
index 98a717dfa6ec..48182f488466 100644
--- a/flang/include/flang/Frontend/FrontendOptions.h
+++ b/flang/include/flang/Frontend/FrontendOptions.h
@@ -50,6 +50,9 @@ enum ActionKind {
/// Dump provenance
DebugDumpProvenance,
+ /// Parse then output the parsing log
+ DebugDumpParsingLog,
+
/// Parse then output the number of objects in the parse tree and the overall
/// size
DebugMeasureParseTree,
@@ -172,6 +175,9 @@ class FrontendOptions {
/// Show the -version text.
unsigned showVersion_ : 1;
+ /// Instrument the parse to get a more verbose log
+ unsigned instrumentedParse_ : 1;
+
/// The input files and their types.
std::vector<FrontendInputFile> inputs_;
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp
index 0dc7e7c3d395..17649700e0d2 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -85,6 +85,15 @@ bool Fortran::frontend::ParseDiagnosticArgs(clang::DiagnosticOptions &opts,
return true;
}
+// Tweak the frontend configuration based on the frontend action
+static void setUpFrontendBasedOnAction(FrontendOptions &opts) {
+ assert(opts.programAction_ != Fortran::frontend::InvalidAction &&
+ "Fortran frontend action not set!");
+
+ if (opts.programAction_ == DebugDumpParsingLog)
+ opts.instrumentedParse_ = true;
+}
+
static InputKind ParseFrontendArgs(FrontendOptions &opts,
llvm::opt::ArgList &args, clang::DiagnosticsEngine &diags) {
@@ -125,6 +134,9 @@ static InputKind ParseFrontendArgs(FrontendOptions &opts,
case clang::driver::options::OPT_fdebug_dump_provenance:
opts.programAction_ = DebugDumpProvenance;
break;
+ case clang::driver::options::OPT_fdebug_dump_parsing_log:
+ opts.programAction_ = DebugDumpParsingLog;
+ break;
case clang::driver::options::OPT_fdebug_measure_parse_tree:
opts.programAction_ = DebugMeasureParseTree;
break;
@@ -264,6 +276,9 @@ static InputKind ParseFrontendArgs(FrontendOptions &opts,
<< arg->getAsString(args) << argValue;
}
}
+
+ setUpFrontendBasedOnAction(opts);
+
return dashX;
}
@@ -484,6 +499,9 @@ void CompilerInvocation::setFortranOpts() {
// directories
if (moduleDirJ.compare(".") != 0)
fortranOptions.searchDirectories.emplace_back(moduleDirJ);
+
+ if (frontendOptions.instrumentedParse_)
+ fortranOptions.instrumentedParse = true;
}
void CompilerInvocation::setSemanticsOpts(
diff --git a/flang/lib/Frontend/FrontendActions.cpp b/flang/lib/Frontend/FrontendActions.cpp
index b7e4f912171f..f956015a3f2f 100644
--- a/flang/lib/Frontend/FrontendActions.cpp
+++ b/flang/lib/Frontend/FrontendActions.cpp
@@ -307,6 +307,13 @@ void DebugPreFIRTreeAction::ExecuteAction() {
}
}
+void DebugDumpParsingLogAction::ExecuteAction() {
+ CompilerInstance &ci = this->instance();
+
+ ci.parsing().Parse(llvm::errs());
+ ci.parsing().DumpParsingLog(llvm::outs());
+}
+
void EmitObjAction::ExecuteAction() {
CompilerInstance &ci = this->instance();
unsigned DiagID = ci.diagnostics().getCustomDiagID(
diff --git a/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp b/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
index c5f7bb27e8b8..041e79b946f5 100644
--- a/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ b/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -52,6 +52,9 @@ static std::unique_ptr<FrontendAction> CreateFrontendBaseAction(
case DebugDumpProvenance:
return std::make_unique<DebugDumpProvenanceAction>();
break;
+ case DebugDumpParsingLog:
+ return std::make_unique<DebugDumpParsingLogAction>();
+ break;
case DebugMeasureParseTree:
return std::make_unique<DebugMeasureParseTreeAction>();
break;
diff --git a/flang/test/Driver/debug-parsing-log.f90 b/flang/test/Driver/debug-parsing-log.f90
new file mode 100644
index 000000000000..f658fa673e86
--- /dev/null
+++ b/flang/test/Driver/debug-parsing-log.f90
@@ -0,0 +1,31 @@
+! RUN: %flang_fc1 -fdebug-dump-parsing-log %s 2>&1 | FileCheck %s
+
+!-----------------
+! EXPECTED OUTPUT
+!-----------------
+! Below are just few lines extracted from the dump. The actual output is much _much_ bigger.
+
+! CHECK: {{.*}}/debug-parsing-log.f90:31:1: IMPLICIT statement
+! CHECK-NEXT: END PROGRAM
+! CHECK-NEXT: ^
+! CHECK-NEXT: fail 3
+! CHECK-NEXT: {{.*}}/debug-parsing-log.f90:31:1: error: expected 'IMPLICIT NONE'
+! CHECK-NEXT: END PROGRAM
+! CHECK-NEXT: ^
+! CHECK-NEXT: {{.*}}/debug-parsing-log.f90:31:1: in the context: IMPLICIT statement
+! CHECK-NEXT: END PROGRAM
+! CHECK-NEXT: ^
+! CHECK-NEXT: {{.*}}/debug-parsing-log.f90:31:1: in the context: implicit part
+! CHECK-NEXT: END PROGRAM
+! CHECK-NEXT: ^
+! CHECK-NEXT: {{.*}}/debug-parsing-log.f90:31:1: in the context: specification part
+! CHECK-NEXT: END PROGRAM
+! CHECK-NEXT: ^
+! CHECK-NEXT: {{.*}}/debug-parsing-log.f90:31:1: in the context: main program
+! CHECK-NEXT: END PROGRAM
+! CHECK-NEXT: ^
+
+!-----------------
+! TEST INPUT
+!-----------------
+END PROGRAM
diff --git a/flang/test/Driver/driver-help.f90 b/flang/test/Driver/driver-help.f90
index d1d507868bb3..37daeea1c7fd 100644
--- a/flang/test/Driver/driver-help.f90
+++ b/flang/test/Driver/driver-help.f90
@@ -62,6 +62,8 @@
! 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-parse-tree Dump the parse tree
+! HELP-FC1-NEXT: -fdebug-dump-parsing-log
+! HELP-FC1-NEXT: Run instrumented parse and dump the parsing log
! HELP-FC1-NEXT: -fdebug-dump-provenance Dump provenance
! HELP-FC1-NEXT: -fdebug-dump-symbols Dump symbols after the semantic analysis
! HELP-FC1-NEXT: -fdebug-measure-parse-tree
diff --git a/flang/tools/f18/f18.cpp b/flang/tools/f18/f18.cpp
index f43813e56f4b..5bc069cb5859 100644
--- a/flang/tools/f18/f18.cpp
+++ b/flang/tools/f18/f18.cpp
@@ -537,7 +537,8 @@ int main(int argc, char *const argv[]) {
driver.debugModuleWriter = true;
} else if (arg == "-fdebug-measure-parse-tree") {
driver.measureTree = true;
- } else if (arg == "-fdebug-instrumented-parse") {
+ } else if (arg == "-fdebug-instrumented-parse" ||
+ arg == "-fdebug-dump-parsing-log") {
options.instrumentedParse = true;
} else if (arg == "-fdebug-no-semantics") {
driver.debugNoSemantics = true;
More information about the cfe-commits
mailing list