aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrzej Warzynski <andrzej.warzynski@arm.com>2021-04-14 11:42:11 +0000
committerAndrzej Warzynski <andrzej.warzynski@arm.com>2021-04-20 14:00:45 +0000
commit6d0fef48609cbec9579716b77998059501969352 (patch)
tree5fa856daaa6b0ece721f9afb5669f53c213a41be
parent[SLP] Add detection of shuffled/perfect matching of tree entries. (diff)
downloadllvm-project-6d0fef48609cbec9579716b77998059501969352.tar.gz
llvm-project-6d0fef48609cbec9579716b77998059501969352.tar.bz2
llvm-project-6d0fef48609cbec9579716b77998059501969352.zip
[flang][driver] Refactor methods for parsing options (nfc)
This is just a small update that makes sure that errors arising from parsing command-line options are captured more visibly. Also, all parsing methods will now consistently return either a bool ("may fail") or void ("never fails"). An instance of `InputKind` coming from `-x` is added to `FrontendOptions` rather then being returned from `ParseFrontendArgs`. It's currently not used, but we will require it shortly. In particular, once code-generation is available we will use it to differentiate between LLVM IR and Fortran input. `FrontendOptions` is a very suitable place to keep it. This changes don't affect the error reporting in the driver. In this respect these are non-functional-changes. However, it will simplify things in the forthcoming patches in which we may need a better error tracking/recovery mechanism. Differential Revision: https://reviews.llvm.org/D100556
-rw-r--r--flang/include/flang/Frontend/FrontendOptions.h4
-rw-r--r--flang/lib/Frontend/CompilerInvocation.cpp39
2 files changed, 25 insertions, 18 deletions
diff --git a/flang/include/flang/Frontend/FrontendOptions.h b/flang/include/flang/Frontend/FrontendOptions.h
index 43b38f6db2a5..24fbdd3aff2a 100644
--- a/flang/include/flang/Frontend/FrontendOptions.h
+++ b/flang/include/flang/Frontend/FrontendOptions.h
@@ -222,6 +222,10 @@ public:
// source file.
int fixedFormColumns_ = 72;
+ /// The input kind, either specified via -x argument or deduced from the input
+ /// file name.
+ InputKind dashX_;
+
// Language features
common::LanguageFeatureControl features_;
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp
index d1203c7912d0..a8879294eebf 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -99,8 +99,8 @@ static void setUpFrontendBasedOnAction(FrontendOptions &opts) {
opts.needProvenanceRangeToCharBlockMappings_ = true;
}
-static InputKind ParseFrontendArgs(FrontendOptions &opts,
- llvm::opt::ArgList &args, clang::DiagnosticsEngine &diags) {
+static void ParseFrontendArgs(FrontendOptions &opts, llvm::opt::ArgList &args,
+ clang::DiagnosticsEngine &diags) {
// By default the frontend driver creates a ParseSyntaxOnly action.
opts.programAction_ = ParseSyntaxOnly;
@@ -292,8 +292,7 @@ static InputKind ParseFrontendArgs(FrontendOptions &opts,
}
setUpFrontendBasedOnAction(opts);
-
- return dashX;
+ opts.dashX_ = dashX;
}
// Generate the path to look for intrinsic modules
@@ -343,9 +342,10 @@ static void parsePreprocessorArgs(
}
/// Parses all semantic related arguments and populates the variables
-/// options accordingly.
-static void parseSemaArgs(CompilerInvocation &res, llvm::opt::ArgList &args,
+/// options accordingly. Returns false if new errors are generated.
+static bool parseSemaArgs(CompilerInvocation &res, llvm::opt::ArgList &args,
clang::DiagnosticsEngine &diags) {
+ unsigned numErrorsBefore = diags.getNumErrors();
// -J/module-dir option
auto moduleDirList =
@@ -365,12 +365,16 @@ static void parseSemaArgs(CompilerInvocation &res, llvm::opt::ArgList &args,
if (args.hasArg(clang::driver::options::OPT_fdebug_module_writer)) {
res.SetDebugModuleDir(true);
}
+
+ return diags.getNumErrors() == numErrorsBefore;
}
/// Parses all diagnostics related arguments and populates the variables
-/// options accordingly.
-static void parseDiagArgs(CompilerInvocation &res, llvm::opt::ArgList &args,
+/// options accordingly. Returns false if new errors are generated.
+static bool parseDiagArgs(CompilerInvocation &res, llvm::opt::ArgList &args,
clang::DiagnosticsEngine &diags) {
+ unsigned numErrorsBefore = diags.getNumErrors();
+
// -Werror option
// TODO: Currently throws a Diagnostic for anything other than -W<error>,
// this has to change when other -W<opt>'s are supported.
@@ -385,12 +389,15 @@ static void parseDiagArgs(CompilerInvocation &res, llvm::opt::ArgList &args,
diags.Report(diagID);
}
}
+
+ return diags.getNumErrors() == numErrorsBefore;
}
/// Parses all Dialect related arguments and populates the variables
-/// options accordingly.
-static void parseDialectArgs(CompilerInvocation &res, llvm::opt::ArgList &args,
+/// options accordingly. Returns false if new errors are generated.
+static bool parseDialectArgs(CompilerInvocation &res, llvm::opt::ArgList &args,
clang::DiagnosticsEngine &diags) {
+ unsigned numErrorsBefore = diags.getNumErrors();
// -fdefault* family
if (args.hasArg(clang::driver::options::OPT_fdefault_real_8)) {
@@ -446,7 +453,7 @@ static void parseDialectArgs(CompilerInvocation &res, llvm::opt::ArgList &args,
diags.Report(diagID);
}
}
- return;
+ return diags.getNumErrors() == numErrorsBefore;
}
bool CompilerInvocation::CreateFromArgs(CompilerInvocation &res,
@@ -476,14 +483,10 @@ bool CompilerInvocation::CreateFromArgs(CompilerInvocation &res,
// Parse the frontend args
ParseFrontendArgs(res.frontendOpts(), args, diags);
- // Parse the preprocessor args
parsePreprocessorArgs(res.preprocessorOpts(), args);
- // Parse semantic args
- parseSemaArgs(res, args, diags);
- // Parse dialect arguments
- parseDialectArgs(res, args, diags);
- // Parse diagnostic arguments
- parseDiagArgs(res, args, diags);
+ success &= parseSemaArgs(res, args, diags);
+ success &= parseDialectArgs(res, args, diags);
+ success &= parseDiagArgs(res, args, diags);
return success;
}