[flang-commits] [flang] d902dd0 - [flang][driver] NFC: Make code more in line with LLVM style
Andrzej Warzynski via flang-commits
flang-commits at lists.llvm.org
Wed Apr 27 02:20:48 PDT 2022
Author: Andrzej Warzynski
Date: 2022-04-27T09:20:07Z
New Revision: d902dd011c9403ff746613a73c5d83e13db93fe5
URL: https://github.com/llvm/llvm-project/commit/d902dd011c9403ff746613a73c5d83e13db93fe5
DIFF: https://github.com/llvm/llvm-project/commit/d902dd011c9403ff746613a73c5d83e13db93fe5.diff
LOG: [flang][driver] NFC: Make code more in line with LLVM style
This patch basically implements [1] in ExecuteCompilerInvocation.cpp. It
also:
* replaces `CreateFrontendBaseAction` with `CreateFrontendAction`
(only one method is needed ATM, this change removes the extra
indirection)
* removes `InvalidAction` from the `ActionKind` enum (I don't think it
adds much and keeping it would mean adding a new void case in
`CreateFrontendAction`)
* sets the default frontend action in FrontendOptions.h to
`ParseSyntaxOnly` (note that this is still overridden independently
in `ParseFrontendArg` in CompilerInvocation.cpp)
No new functionality is added, hence no tests.
[1] https://llvm.org/docs/CodingStandards.html#don-t-use-default-labels-in-fully-covered-switches-over-enumerations
Differential Revision: https://reviews.llvm.org/D124245
Added:
Modified:
flang/include/flang/Frontend/FrontendOptions.h
flang/include/flang/FrontendTool/Utils.h
flang/lib/Frontend/CompilerInvocation.cpp
flang/lib/Frontend/FrontendAction.cpp
flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
Removed:
################################################################################
diff --git a/flang/include/flang/Frontend/FrontendOptions.h b/flang/include/flang/Frontend/FrontendOptions.h
index ab085172e6d9f..be5a9ee4b9c2e 100644
--- a/flang/include/flang/Frontend/FrontendOptions.h
+++ b/flang/include/flang/Frontend/FrontendOptions.h
@@ -20,8 +20,6 @@
namespace Fortran::frontend {
enum ActionKind {
- InvalidAction = 0,
-
/// -test-io mode
InputOutputTest,
@@ -244,7 +242,7 @@ struct FrontendOptions {
std::string outputFile;
/// The frontend action to perform.
- frontend::ActionKind programAction;
+ frontend::ActionKind programAction = ParseSyntaxOnly;
// The form to process files in, if specified.
FortranForm fortranForm = FortranForm::Unknown;
diff --git a/flang/include/flang/FrontendTool/Utils.h b/flang/include/flang/FrontendTool/Utils.h
index d62c03d8dc0b3..f49c4e6dae62d 100644
--- a/flang/include/flang/FrontendTool/Utils.h
+++ b/flang/include/flang/FrontendTool/Utils.h
@@ -17,13 +17,6 @@
namespace Fortran::frontend {
class CompilerInstance;
-class FrontendAction;
-
-/// Construct the FrontendAction of a compiler invocation based on the
-/// options specified for the compiler invocation.
-///
-/// \return - The created FrontendAction object
-std::unique_ptr<FrontendAction> CreateFrontendAction(CompilerInstance &ci);
/// ExecuteCompilerInvocation - Execute the given actions described by the
/// compiler invocation object in the given compiler instance.
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp
index 0f0db576a4fed..d56566df9660d 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -98,9 +98,6 @@ static void ParseTargetArgs(TargetOptions &opts, llvm::opt::ArgList &args) {
// 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;
diff --git a/flang/lib/Frontend/FrontendAction.cpp b/flang/lib/Frontend/FrontendAction.cpp
index ce838c45dc1a1..020aa15670dae 100644
--- a/flang/lib/Frontend/FrontendAction.cpp
+++ b/flang/lib/Frontend/FrontendAction.cpp
@@ -11,7 +11,6 @@
#include "flang/Frontend/FrontendActions.h"
#include "flang/Frontend/FrontendOptions.h"
#include "flang/Frontend/FrontendPluginRegistry.h"
-#include "flang/FrontendTool/Utils.h"
#include "clang/Basic/DiagnosticFrontend.h"
#include "llvm/Support/Errc.h"
#include "llvm/Support/VirtualFileSystem.h"
diff --git a/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp b/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
index bc2bf1dcfd4cb..8f5b3132f654d 100644
--- a/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ b/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -24,11 +24,10 @@
namespace Fortran::frontend {
-static std::unique_ptr<FrontendAction> CreateFrontendBaseAction(
+static std::unique_ptr<FrontendAction> CreateFrontendAction(
CompilerInstance &ci) {
- ActionKind ak = ci.frontendOpts().programAction;
- switch (ak) {
+ switch (ci.frontendOpts().programAction) {
case InputOutputTest:
return std::make_unique<InputOutputTestAction>();
case PrintPreprocessedInput:
@@ -90,25 +89,9 @@ static std::unique_ptr<FrontendAction> CreateFrontendBaseAction(
ci.diagnostics().Report(diagID) << ci.frontendOpts().ActionName;
return nullptr;
}
- default:
- break;
- // TODO:
- // case ParserSyntaxOnly:
- // case EmitLLVM:
- // case EmitLLVMOnly:
- // case EmitCodeGenOnly:
- // (...)
}
- return 0;
-}
-
-std::unique_ptr<FrontendAction> CreateFrontendAction(CompilerInstance &ci) {
- // Create the underlying action.
- std::unique_ptr<FrontendAction> act = CreateFrontendBaseAction(ci);
- if (!act)
- return nullptr;
- return act;
+ llvm_unreachable("Invalid program action!");
}
bool ExecuteCompilerInvocation(CompilerInstance *flang) {
More information about the flang-commits
mailing list