aboutsummaryrefslogtreecommitdiff
path: root/flang/lib/Frontend/CompilerInvocation.cpp
diff options
context:
space:
mode:
authorArnamoy Bhattacharyya <arnamoy10@gmail.com>2021-02-04 16:13:04 +0000
committerAndrzej Warzynski <andrzej.warzynski@arm.com>2021-02-04 16:31:40 +0000
commit985a42fdf8ae3117442ea129b684569fa6942a71 (patch)
tree65a79bba9a61d03c8b120e9f1f572eca95e3b0fb /flang/lib/Frontend/CompilerInvocation.cpp
parenta83475d34b4550ff5bd40430d6537e630eb761f1 (diff)
downloadllvm-985a42fdf8ae3117442ea129b684569fa6942a71.zip
llvm-985a42fdf8ae3117442ea129b684569fa6942a71.tar.gz
llvm-985a42fdf8ae3117442ea129b684569fa6942a71.tar.bz2
[flang][driver] Add support for `-J/-module-dir`
Add support for option -J/-module-dir in the new Flang driver. This will allow for including module files in other directories, as the default search path is currently the working folder. This also provides an option of storing the output module in the specified folder. Differential Revision: https://reviews.llvm.org/D95448
Diffstat (limited to 'flang/lib/Frontend/CompilerInvocation.cpp')
-rw-r--r--flang/lib/Frontend/CompilerInvocation.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp
index 563953f7..445feaa 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -221,6 +221,25 @@ static void parsePreprocessorArgs(
opts.searchDirectoriesFromDashI.emplace_back(currentArg->getValue());
}
+/// Parses all semantic related arguments and populates the variables
+/// options accordingly.
+static void parseSemaArgs(std::string &moduleDir, llvm::opt::ArgList &args,
+ clang::DiagnosticsEngine &diags) {
+
+ auto moduleDirList =
+ args.getAllArgValues(clang::driver::options::OPT_module_dir);
+ // User can only specify -J/-module-dir once
+ // https://gcc.gnu.org/onlinedocs/gfortran/Directory-Options.html
+ if (moduleDirList.size() > 1) {
+ const unsigned diagID =
+ diags.getCustomDiagID(clang::DiagnosticsEngine::Error,
+ "Only one '-module-dir/-J' option allowed");
+ diags.Report(diagID);
+ }
+ if (moduleDirList.size() == 1)
+ moduleDir = moduleDirList[0];
+}
+
bool CompilerInvocation::CreateFromArgs(CompilerInvocation &res,
llvm::ArrayRef<const char *> commandLineArgs,
clang::DiagnosticsEngine &diags) {
@@ -250,6 +269,8 @@ bool CompilerInvocation::CreateFromArgs(CompilerInvocation &res,
ParseFrontendArgs(res.frontendOpts(), args, diags);
// Parse the preprocessor args
parsePreprocessorArgs(res.preprocessorOpts(), args);
+ // Parse semantic args
+ parseSemaArgs(res.moduleDir(), args, diags);
return success;
}
@@ -314,6 +335,7 @@ void CompilerInvocation::setFortranOpts() {
auto &fortranOptions = fortranOpts();
const auto &frontendOptions = frontendOpts();
const auto &preprocessorOptions = preprocessorOpts();
+ auto &moduleDirJ = moduleDir();
if (frontendOptions.fortranForm_ != FortranForm::Unknown) {
fortranOptions.isFixedForm =
@@ -327,4 +349,18 @@ void CompilerInvocation::setFortranOpts() {
fortranOptions.searchDirectories.end(),
preprocessorOptions.searchDirectoriesFromDashI.begin(),
preprocessorOptions.searchDirectoriesFromDashI.end());
+
+ // Add the directory supplied through -J/-module-dir to the list of search
+ // directories
+ if (moduleDirJ.compare(".") != 0)
+ fortranOptions.searchDirectories.emplace_back(moduleDirJ);
+}
+
+void CompilerInvocation::setSemanticsOpts(
+ Fortran::semantics::SemanticsContext &semaCtxt) {
+ auto &fortranOptions = fortranOpts();
+ auto &moduleDirJ = moduleDir();
+ semaCtxt.set_moduleDirectory(moduleDirJ)
+ .set_searchDirectories(fortranOptions.searchDirectories);
+ return;
}