Skip to content

Commit d902dd0

Browse files
committed
[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
1 parent ca3cd34 commit d902dd0

File tree

5 files changed

+4
-34
lines changed

5 files changed

+4
-34
lines changed

flang/include/flang/Frontend/FrontendOptions.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
namespace Fortran::frontend {
2121

2222
enum ActionKind {
23-
InvalidAction = 0,
24-
2523
/// -test-io mode
2624
InputOutputTest,
2725

@@ -244,7 +242,7 @@ struct FrontendOptions {
244242
std::string outputFile;
245243

246244
/// The frontend action to perform.
247-
frontend::ActionKind programAction;
245+
frontend::ActionKind programAction = ParseSyntaxOnly;
248246

249247
// The form to process files in, if specified.
250248
FortranForm fortranForm = FortranForm::Unknown;

flang/include/flang/FrontendTool/Utils.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,6 @@
1717
namespace Fortran::frontend {
1818

1919
class CompilerInstance;
20-
class FrontendAction;
21-
22-
/// Construct the FrontendAction of a compiler invocation based on the
23-
/// options specified for the compiler invocation.
24-
///
25-
/// \return - The created FrontendAction object
26-
std::unique_ptr<FrontendAction> CreateFrontendAction(CompilerInstance &ci);
2720

2821
/// ExecuteCompilerInvocation - Execute the given actions described by the
2922
/// compiler invocation object in the given compiler instance.

flang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,6 @@ static void ParseTargetArgs(TargetOptions &opts, llvm::opt::ArgList &args) {
9898

9999
// Tweak the frontend configuration based on the frontend action
100100
static void setUpFrontendBasedOnAction(FrontendOptions &opts) {
101-
assert(opts.programAction != Fortran::frontend::InvalidAction &&
102-
"Fortran frontend action not set!");
103-
104101
if (opts.programAction == DebugDumpParsingLog)
105102
opts.instrumentedParse = true;
106103

flang/lib/Frontend/FrontendAction.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include "flang/Frontend/FrontendActions.h"
1212
#include "flang/Frontend/FrontendOptions.h"
1313
#include "flang/Frontend/FrontendPluginRegistry.h"
14-
#include "flang/FrontendTool/Utils.h"
1514
#include "clang/Basic/DiagnosticFrontend.h"
1615
#include "llvm/Support/Errc.h"
1716
#include "llvm/Support/VirtualFileSystem.h"

flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,10 @@
2424

2525
namespace Fortran::frontend {
2626

27-
static std::unique_ptr<FrontendAction> CreateFrontendBaseAction(
27+
static std::unique_ptr<FrontendAction> CreateFrontendAction(
2828
CompilerInstance &ci) {
2929

30-
ActionKind ak = ci.frontendOpts().programAction;
31-
switch (ak) {
30+
switch (ci.frontendOpts().programAction) {
3231
case InputOutputTest:
3332
return std::make_unique<InputOutputTestAction>();
3433
case PrintPreprocessedInput:
@@ -90,25 +89,9 @@ static std::unique_ptr<FrontendAction> CreateFrontendBaseAction(
9089
ci.diagnostics().Report(diagID) << ci.frontendOpts().ActionName;
9190
return nullptr;
9291
}
93-
default:
94-
break;
95-
// TODO:
96-
// case ParserSyntaxOnly:
97-
// case EmitLLVM:
98-
// case EmitLLVMOnly:
99-
// case EmitCodeGenOnly:
100-
// (...)
10192
}
102-
return 0;
103-
}
104-
105-
std::unique_ptr<FrontendAction> CreateFrontendAction(CompilerInstance &ci) {
106-
// Create the underlying action.
107-
std::unique_ptr<FrontendAction> act = CreateFrontendBaseAction(ci);
108-
if (!act)
109-
return nullptr;
11093

111-
return act;
94+
llvm_unreachable("Invalid program action!");
11295
}
11396

11497
bool ExecuteCompilerInvocation(CompilerInstance *flang) {

0 commit comments

Comments
 (0)