[flang-commits] [flang] 20bd214 - [flang][driver] Add support for `-module-suffix`
Andrzej Warzynski via flang-commits
flang-commits at lists.llvm.org
Fri Jun 4 05:58:37 PDT 2021
Author: Andrzej Warzynski
Date: 2021-06-04T13:58:04+01:00
New Revision: 20bd2142d46536f4ffd61f28a029d6bda68f1a7f
URL: https://github.com/llvm/llvm-project/commit/20bd2142d46536f4ffd61f28a029d6bda68f1a7f
DIFF: https://github.com/llvm/llvm-project/commit/20bd2142d46536f4ffd61f28a029d6bda68f1a7f.diff
LOG: [flang][driver] Add support for `-module-suffix`
This option is supported in `f18`, but not yet available in `flang-new`.
It is required in order to call `flang-new` from the `flang` bash
script.
Differential Revision: https://reviews.llvm.org/D103613
Added:
flang/test/Driver/module-suffix.f90
Modified:
clang/include/clang/Driver/Options.td
flang/include/flang/Frontend/CompilerInvocation.h
flang/lib/Frontend/CompilerInvocation.cpp
flang/test/Driver/driver-help.f90
Removed:
################################################################################
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 4945538ec0f01..c2945fb0bf184 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4522,6 +4522,9 @@ def fdebug_module_writer : Flag<["-"],"fdebug-module-writer">,
def fget_symbols_sources : Flag<["-"], "fget-symbols-sources">, Group<Action_Group>,
HelpText<"Dump symbols and their source code locations">;
+def module_suffix : Separate<["-"], "module-suffix">, Group<f_Group>, MetaVarName<"<suffix>">,
+ HelpText<"Use <suffix> as the suffix for module files (the default value is `.mod`)">;
+
}
//===----------------------------------------------------------------------===//
diff --git a/flang/include/flang/Frontend/CompilerInvocation.h b/flang/include/flang/Frontend/CompilerInvocation.h
index edd32917b175c..f449a69dfa8a0 100644
--- a/flang/include/flang/Frontend/CompilerInvocation.h
+++ b/flang/include/flang/Frontend/CompilerInvocation.h
@@ -69,6 +69,8 @@ class CompilerInvocation : public CompilerInvocationBase {
// of options.
std::string moduleDir_ = ".";
+ std::string moduleFileSuffix_ = ".mod";
+
bool debugModuleDir_ = false;
bool warnAsErr_ = false;
@@ -97,6 +99,9 @@ class CompilerInvocation : public CompilerInvocationBase {
std::string &moduleDir() { return moduleDir_; }
const std::string &moduleDir() const { return moduleDir_; }
+ std::string &moduleFileSuffix() { return moduleFileSuffix_; }
+ const std::string &moduleFileSuffix() const { return moduleFileSuffix_; }
+
bool &debugModuleDir() { return debugModuleDir_; }
const bool &debugModuleDir() const { return debugModuleDir_; }
@@ -129,6 +134,10 @@ class CompilerInvocation : public CompilerInvocationBase {
/// Useful setters
void SetModuleDir(std::string &moduleDir) { moduleDir_ = moduleDir; }
+ void SetModuleFileSuffix(const char *moduleFileSuffix) {
+ moduleFileSuffix_ = std::string(moduleFileSuffix);
+ }
+
void SetDebugModuleDir(bool flag) { debugModuleDir_ = flag; }
void SetWarnAsErr(bool flag) { warnAsErr_ = flag; }
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp
index 1f61e0e9ff305..1d18dda5e7eea 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -392,6 +392,12 @@ static bool parseSemaArgs(CompilerInvocation &res, llvm::opt::ArgList &args,
res.SetDebugModuleDir(true);
}
+ // -module-suffix
+ if (const auto *moduleSuffix =
+ args.getLastArg(clang::driver::options::OPT_module_suffix)) {
+ res.SetModuleFileSuffix(moduleSuffix->getValue());
+ }
+
return diags.getNumErrors() == numErrorsBefore;
}
@@ -639,5 +645,6 @@ void CompilerInvocation::setSemanticsOpts(
semanticsContext_->set_moduleDirectory(moduleDir())
.set_searchDirectories(fortranOptions.searchDirectories)
.set_warnOnNonstandardUsage(enableConformanceChecks())
- .set_warningsAreErrors(warnAsErr());
+ .set_warningsAreErrors(warnAsErr())
+ .set_moduleFileSuffix(moduleFileSuffix());
}
diff --git a/flang/test/Driver/driver-help.f90 b/flang/test/Driver/driver-help.f90
index 9783751a2c9e7..696c437a574b8 100644
--- a/flang/test/Driver/driver-help.f90
+++ b/flang/test/Driver/driver-help.f90
@@ -106,6 +106,7 @@
! HELP-FC1-NEXT: -help Display available options
! HELP-FC1-NEXT: -I <dir> Add directory to the end of the list of include search paths
! HELP-FC1-NEXT: -module-dir <dir> Put MODULE files in <dir>
+! HELP-FC1-NEXT: -module-suffix <suffix> Use <suffix> as the suffix for module files (the default value is `.mod`)
! HELP-FC1-NEXT: -nocpp Disable predefined and command line preprocessor macros
! HELP-FC1-NEXT: -o <file> Write output to <file>
! HELP-FC1-NEXT: -pedantic Warn on language extensions
diff --git a/flang/test/Driver/module-suffix.f90 b/flang/test/Driver/module-suffix.f90
new file mode 100644
index 0000000000000..151688492c932
--- /dev/null
+++ b/flang/test/Driver/module-suffix.f90
@@ -0,0 +1,16 @@
+! Tests `-module-suffix` frontend option
+
+!--------------------------
+! RUN lines
+!--------------------------
+! RUN: rm -rf %t && mkdir -p %t/dir-flang/
+! RUN: cd %t && %flang_fc1 -fsyntax-only -module-suffix .f18.mod -module-dir %t/dir-flang %s
+! RUN: ls %t/dir-flang/testmodule.f18.mod && not ls %t/dir-flang/testmodule.mod
+
+!--------------------------
+! INPUT
+!--------------------------
+module testmodule
+ type::t2
+ end type
+end
More information about the flang-commits
mailing list