aboutsummaryrefslogtreecommitdiff
path: root/flang/lib/Frontend/CompilerInvocation.cpp
diff options
context:
space:
mode:
authorAndrzej Warzynski <andrzej.warzynski@arm.com>2021-04-14 10:43:14 +0000
committerAndrzej Warzynski <andrzej.warzynski@arm.com>2021-04-21 09:31:36 +0000
commitdc256a443a456a8e0e4d72736fee1c9442bcf4bd (patch)
treeb7b681db5ad7291ecf8b8fab9299c5fb5a4497e2 /flang/lib/Frontend/CompilerInvocation.cpp
parentcd64273f5ed39ec697ff1e20a1fe25ebd3502629 (diff)
downloadllvm-dc256a443a456a8e0e4d72736fee1c9442bcf4bd.zip
llvm-dc256a443a456a8e0e4d72736fee1c9442bcf4bd.tar.gz
llvm-dc256a443a456a8e0e4d72736fee1c9442bcf4bd.tar.bz2
[flang][driver] Add support for `-fget-definition`
This patch adds `-fget-definition` to `flang-new`. The semantics of this option are identical in both drivers. The error message in the "throwaway" driver is updated so that it matches the one from `flang-new` (which is auto-generated and cannot be changed easily). Tests are updated accordingly. A dedicated test for error handling was added: get-definition.f90 (for the sake of simplicity, getdefinition01.f90 no longer tests for errors). The `ParseFrontendArgs` function is updated so that it can return errors. This change is required in order to report invalid values following `-fget-definition`. The actual implementation of `GetDefinitionAction::ExecuteAction()` was extracted from f18.cpp (i.e. the bit that deals with `-fget-definition`). Depends on: https://reviews.llvm.org/D100556 Differential Revision: https://reviews.llvm.org/D100558
Diffstat (limited to 'flang/lib/Frontend/CompilerInvocation.cpp')
-rw-r--r--flang/lib/Frontend/CompilerInvocation.cpp35
1 files changed, 31 insertions, 4 deletions
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp
index a887929..c79c2f2 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -95,12 +95,14 @@ static void setUpFrontendBasedOnAction(FrontendOptions &opts) {
if (opts.programAction_ == DebugDumpParsingLog)
opts.instrumentedParse_ = true;
- if (opts.programAction_ == DebugDumpProvenance)
+ if (opts.programAction_ == DebugDumpProvenance ||
+ opts.programAction_ == Fortran::frontend::GetDefinition)
opts.needProvenanceRangeToCharBlockMappings_ = true;
}
-static void ParseFrontendArgs(FrontendOptions &opts, llvm::opt::ArgList &args,
+static bool ParseFrontendArgs(FrontendOptions &opts, llvm::opt::ArgList &args,
clang::DiagnosticsEngine &diags) {
+ unsigned numErrorsBefore = diags.getNumErrors();
// By default the frontend driver creates a ParseSyntaxOnly action.
opts.programAction_ = ParseSyntaxOnly;
@@ -157,6 +159,9 @@ static void ParseFrontendArgs(FrontendOptions &opts, llvm::opt::ArgList &args,
case clang::driver::options::OPT_fget_symbols_sources:
opts.programAction_ = GetSymbolsSources;
break;
+ case clang::driver::options::OPT_fget_definition:
+ opts.programAction_ = GetDefinition;
+ break;
// TODO:
// case calng::driver::options::OPT_emit_llvm:
@@ -165,6 +170,27 @@ static void ParseFrontendArgs(FrontendOptions &opts, llvm::opt::ArgList &args,
// case clang::driver::options::OPT_emit_module:
// (...)
}
+
+ // Parse the values provided with `-fget-definition` (there should be 3
+ // integers)
+ if (llvm::opt::OptSpecifier(a->getOption().getID()) ==
+ clang::driver::options::OPT_fget_definition) {
+ unsigned optVals[3] = {0, 0, 0};
+
+ for (unsigned i = 0; i < 3; i++) {
+ llvm::StringRef val = a->getValue(i);
+
+ if (val.getAsInteger(10, optVals[i])) {
+ // A non-integer was encountered - that's an error.
+ diags.Report(clang::diag::err_drv_invalid_value)
+ << a->getOption().getName() << val;
+ break;
+ }
+ }
+ opts.getDefVals_.line = optVals[0];
+ opts.getDefVals_.startColumn = optVals[1];
+ opts.getDefVals_.endColumn = optVals[2];
+ }
}
opts.outputFile_ = args.getLastArgValue(clang::driver::options::OPT_o);
@@ -293,6 +319,8 @@ static void ParseFrontendArgs(FrontendOptions &opts, llvm::opt::ArgList &args,
setUpFrontendBasedOnAction(opts);
opts.dashX_ = dashX;
+
+ return diags.getNumErrors() == numErrorsBefore;
}
// Generate the path to look for intrinsic modules
@@ -481,8 +509,7 @@ bool CompilerInvocation::CreateFromArgs(CompilerInvocation &res,
success = false;
}
- // Parse the frontend args
- ParseFrontendArgs(res.frontendOpts(), args, diags);
+ success &= ParseFrontendArgs(res.frontendOpts(), args, diags);
parsePreprocessorArgs(res.preprocessorOpts(), args);
success &= parseSemaArgs(res, args, diags);
success &= parseDialectArgs(res, args, diags);