diff options
author | Arnamoy Bhattacharyya <arnamoy.bhattacharyya@huawei.com> | 2021-03-23 12:24:57 -0400 |
---|---|---|
committer | Arnamoy Bhattacharyya <arnamoy10@gmail.com> | 2021-03-23 12:28:19 -0400 |
commit | cd4abc5242c03804b3d88277b03b52215a899f75 (patch) | |
tree | 43348cf25b0488fccf5dcdd8494810a459d98820 /flang/lib/Frontend/CompilerInvocation.cpp | |
parent | 7a804c09798a7051bd9189a0e59d84ea30b1e337 (diff) | |
download | llvm-cd4abc5242c03804b3d88277b03b52215a899f75.zip llvm-cd4abc5242c03804b3d88277b03b52215a899f75.tar.gz llvm-cd4abc5242c03804b3d88277b03b52215a899f75.tar.bz2 |
[flang][driver] Add -fintrinsic-modules-path option
Reviewed By: awarzynski
Differential Revision: https://reviews.llvm.org/D97080
Diffstat (limited to 'flang/lib/Frontend/CompilerInvocation.cpp')
-rw-r--r-- | flang/lib/Frontend/CompilerInvocation.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp index d2318d3..69c78bd 100644 --- a/flang/lib/Frontend/CompilerInvocation.cpp +++ b/flang/lib/Frontend/CompilerInvocation.cpp @@ -21,6 +21,8 @@ #include "llvm/Option/Arg.h" #include "llvm/Option/ArgList.h" #include "llvm/Option/OptTable.h" +#include "llvm/Support/FileSystem.h" +#include "llvm/Support/FileUtilities.h" #include "llvm/Support/Process.h" #include "llvm/Support/raw_ostream.h" #include <memory> @@ -285,6 +287,16 @@ static InputKind ParseFrontendArgs(FrontendOptions &opts, return dashX; } +// Generate the path to look for intrinsic modules +static std::string getIntrinsicDir() { + // TODO: Find a system independent API + llvm::SmallString<128> driverPath; + driverPath.assign(llvm::sys::fs::getMainExecutable(nullptr, nullptr)); + llvm::sys::path::remove_filename(driverPath); + driverPath.append("/../include/flang/"); + return std::string(driverPath); +} + /// Parses all preprocessor input arguments and populates the preprocessor /// options accordingly. /// @@ -305,6 +317,12 @@ static void parsePreprocessorArgs( // Add the ordered list of -I's. for (const auto *currentArg : args.filtered(clang::driver::options::OPT_I)) opts.searchDirectoriesFromDashI.emplace_back(currentArg->getValue()); + + // Prepend the ordered list of -intrinsic-modules-path + // to the default location to search. + for (const auto *currentArg : + args.filtered(clang::driver::options::OPT_fintrinsic_modules_path)) + opts.searchDirectoriesFromIntrModPath.emplace_back(currentArg->getValue()); } /// Parses all semantic related arguments and populates the variables @@ -499,11 +517,21 @@ void CompilerInvocation::setFortranOpts() { collectMacroDefinitions(preprocessorOptions, fortranOptions); + // Adding search directories specified by -I fortranOptions.searchDirectories.insert( fortranOptions.searchDirectories.end(), preprocessorOptions.searchDirectoriesFromDashI.begin(), preprocessorOptions.searchDirectoriesFromDashI.end()); + // Add the ordered list of -intrinsic-modules-path + fortranOptions.searchDirectories.insert( + fortranOptions.searchDirectories.end(), + preprocessorOptions.searchDirectoriesFromIntrModPath.begin(), + preprocessorOptions.searchDirectoriesFromIntrModPath.end()); + + // Add the default intrinsic module directory at the end + fortranOptions.searchDirectories.emplace_back(getIntrinsicDir()); + // Add the directory supplied through -J/-module-dir to the list of search // directories if (moduleDirJ.compare(".") != 0) |