[flang-commits] [flang] 8720ec6 - [flang] Add -J and -module-dir to f18 driver

Tim Keith via flang-commits flang-commits at lists.llvm.org
Mon Feb 22 09:03:57 PST 2021


Author: Tim Keith
Date: 2021-02-22T09:03:31-08:00
New Revision: 8720ec6b9a288b686089c5137dda64001a7a9f38

URL: https://github.com/llvm/llvm-project/commit/8720ec6b9a288b686089c5137dda64001a7a9f38
DIFF: https://github.com/llvm/llvm-project/commit/8720ec6b9a288b686089c5137dda64001a7a9f38.diff

LOG: [flang] Add -J and -module-dir to f18 driver

Add -J to the f18 driver for compatibility with gfortran.
Add -module-dir for compatibility with the new flang driver.

They both set the output directory for .mod files and add the
directory to the search list. -module still only does the former.

Clean up the new driver test to match.

Differential Revision: https://reviews.llvm.org/D97164

Added: 
    flang/test/Driver/write-module.f90

Modified: 
    flang/test/Flang-Driver/write-module.f90
    flang/tools/f18/f18.cpp

Removed: 
    


################################################################################
diff  --git a/flang/test/Driver/write-module.f90 b/flang/test/Driver/write-module.f90
new file mode 100644
index 000000000000..47c37d6c46fd
--- /dev/null
+++ b/flang/test/Driver/write-module.f90
@@ -0,0 +1,19 @@
+! RUN: rm -rf %t && mkdir -p %t/mod-dir && cd %t && %f18 -fparse-only %s
+! RUN: ls %t/testmodule.mod && not ls %t/mod-dir/testmodule.mod
+
+! RUN: rm -rf %t && mkdir -p %t/mod-dir && cd %t && %f18 -fparse-only -module mod-dir %s
+! RUN: ls %t/mod-dir/testmodule.mod && not ls %t/testmodule.mod
+
+! RUN: rm -rf %t && mkdir -p %t/mod-dir && cd %t && %f18 -fparse-only -module-dir mod-dir %s
+! RUN: ls %t/mod-dir/testmodule.mod && not ls %t/testmodule.mod
+
+! RUN: rm -rf %t && mkdir -p %t/mod-dir && cd %t && %f18 -fparse-only -J mod-dir %s
+! RUN: ls %t/mod-dir/testmodule.mod && not ls %t/testmodule.mod
+
+! RUN: rm -rf %t && mkdir -p %t/mod-dir && cd %t && %f18 -fparse-only -Jmod-dir %s
+! RUN: ls %t/mod-dir/testmodule.mod && not ls %t/testmodule.mod
+
+module testmodule
+  type::t2
+  end type
+end

diff  --git a/flang/test/Flang-Driver/write-module.f90 b/flang/test/Flang-Driver/write-module.f90
index a0e706473640..5065be9a9bc0 100644
--- a/flang/test/Flang-Driver/write-module.f90
+++ b/flang/test/Flang-Driver/write-module.f90
@@ -1,8 +1,14 @@
-! RUN: mkdir -p %t/dir-f18 && %f18 -fparse-only -I tools/flang/include/flang -module %t/dir-f18 %s  2>&1
-! RUN: ls %t/dir-f18/testmodule.mod && not ls %t/testmodule.mod
+! RUN: rm -rf %t && mkdir -p %t/dir-flang
+! RUN: cd %t && %flang -fsyntax-only -module-dir %t/dir-flang %s
+! RUN: ls %t/dir-flang/testmodule.mod && not ls %t/testmodule.mod
 
-! RUN: mkdir -p %t/dir-flang-new && %flang-new -fsyntax-only -module-dir %t/dir-flang-new %s  2>&1
-! RUN: ls %t/dir-flang-new/testmodule.mod && not ls %t/testmodule.mod
+! RUN: rm -rf %t && mkdir -p %t/dir-flang
+! RUN: cd %t && %flang -fsyntax-only -J %t/dir-flang %s
+! RUN: ls %t/dir-flang/testmodule.mod && not ls %t/testmodule.mod
+
+! RUN: rm -rf %t && mkdir -p %t/dir-flang
+! RUN: cd %t && %flang -fsyntax-only -J%t/dir-flang %s
+! RUN: ls %t/dir-flang/testmodule.mod && not ls %t/testmodule.mod
 
 module testmodule
   type::t2

diff  --git a/flang/tools/f18/f18.cpp b/flang/tools/f18/f18.cpp
index 15d42821f1a1..5c16199c865b 100644
--- a/flang/tools/f18/f18.cpp
+++ b/flang/tools/f18/f18.cpp
@@ -583,6 +583,10 @@ int main(int argc, char *const argv[]) {
     } else if (arg == "-module") {
       driver.moduleDirectory = args.front();
       args.pop_front();
+    } else if (arg == "-module-dir") {
+      driver.moduleDirectory = args.front();
+      driver.searchDirectories.push_back(driver.moduleDirectory);
+      args.pop_front();
     } else if (arg == "-module-suffix") {
       driver.moduleFileSuffix = args.front();
       args.pop_front();
@@ -654,7 +658,8 @@ int main(int argc, char *const argv[]) {
           << "  -module dir          module output directory (default .)\n"
           << "  -flatin              interpret source as Latin-1 (ISO 8859-1) "
              "rather than UTF-8\n"
-          << "  -fsyntax-only        parsing and semantics only, no output except messages\n"
+          << "  -fsyntax-only        parsing and semantics only, no output "
+             "except messages\n"
           << "  -funparse            parse & reformat only, no code "
              "generation\n"
           << "  -funparse-with-symbols  parse, resolve symbols, and unparse\n"
@@ -691,6 +696,14 @@ int main(int argc, char *const argv[]) {
         args.pop_front();
       } else if (arg.substr(0, 2) == "-I") {
         driver.searchDirectories.push_back(arg.substr(2));
+      } else if (arg == "-J") {
+        driver.F18_FCArgs.push_back(args.front());
+        driver.moduleDirectory = args.front();
+        driver.searchDirectories.push_back(driver.moduleDirectory);
+        args.pop_front();
+      } else if (arg.substr(0, 2) == "-J") {
+        driver.moduleDirectory = arg.substr(2);
+        driver.searchDirectories.push_back(driver.moduleDirectory);
       }
     }
   }


        


More information about the flang-commits mailing list