[PATCH] D94228: [flang][driver] Support fixed form detection

Faris via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 7 04:47:26 PST 2021


FarisRehman created this revision.
Herald added a reviewer: sscalpone.
FarisRehman requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Currently the new flang driver always runs in free form mode. Add support for fixed form mode based on the file extensions that f18 also looks for.
Additionally add support for the following missing file extensions to be compatible with f18 in this respect: .ff, .FOR, .for, .f77, .ff90, .fpp, .FPP

Summary of changes:

- Set Fortran::parser::Options#isFixedForm according to the file type
- Change FrontendOptions#GetInputKindForExtension to support the missing file extensions that f18 supports


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D94228

Files:
  flang/lib/Frontend/FrontendAction.cpp
  flang/lib/Frontend/FrontendOptions.cpp
  flang/test/Flang-Driver/Inputs/fixed-form-test.f
  flang/test/Flang-Driver/Inputs/free-form-test.f90
  flang/test/Flang-Driver/fixed-free-detection.f90


Index: flang/test/Flang-Driver/fixed-free-detection.f90
===================================================================
--- /dev/null
+++ flang/test/Flang-Driver/fixed-free-detection.f90
@@ -0,0 +1,38 @@
+! Ensure the driver behaves differently on a fixed form file, to a free form file, based on the file extension.
+
+! REQUIRES: new-flang-driver
+
+!--------------------------
+! FLANG DRIVER (flang-new)
+!--------------------------
+! RUN: %flang-new -E %S/Inputs/free-form-test.f90  2>&1 | FileCheck %s --check-prefix=FREEFORM
+! RUN: %flang-new -E %S/Inputs/fixed-form-test.f  2>&1 | FileCheck %s --check-prefix=FIXEDFORM
+! RUN: %flang-new -E %S/Inputs/free-form-test.f90 %S/Inputs/fixed-form-test.f  2>&1 | FileCheck %s --check-prefix=MULTIPLEFORMS
+
+!-----------------------------------------
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!-----------------------------------------
+! RUN: %flang-new -fc1 -E %S/Inputs/free-form-test.f90  2>&1 | FileCheck %s --check-prefix=FREEFORM
+! RUN: %flang-new -fc1 -E %S/Inputs/fixed-form-test.f  2>&1 | FileCheck %s --check-prefix=FIXEDFORM
+! RUN: %flang-new -fc1 -E %S/Inputs/free-form-test.f90 %S/Inputs/fixed-form-test.f  2>&1 | FileCheck %s --check-prefix=MULTIPLEFORMS
+
+!-------------------------------------
+! EXPECTED OUTPUT FOR A FREE FORM FILE
+!-------------------------------------
+! FREEFORM:program a
+! FREEFORM-NOT:programa
+
+!---------------------------------------
+! EXPECTED OUTPUT FOR A FIXED FORM FILE
+!---------------------------------------
+! FIXEDFORM:programa
+! FIXEDFORM-NOT:program a
+
+!------------------------------------------------
+! EXPECTED OUTPUT FOR 2 FILES OF DIFFERENT FORMS
+!------------------------------------------------
+! MULTIPLEFORMS:program a
+! MULTIPLEFORMS-NOT:programa
+! MULTIPLEFORMS-NEXT:end
+! MULTIPLEFORMS-NEXT:programa
+! MULTIPLEFORMS-NOT:program a
\ No newline at end of file
Index: flang/test/Flang-Driver/Inputs/free-form-test.f90
===================================================================
--- /dev/null
+++ flang/test/Flang-Driver/Inputs/free-form-test.f90
@@ -0,0 +1,2 @@
+program A
+end
\ No newline at end of file
Index: flang/test/Flang-Driver/Inputs/fixed-form-test.f
===================================================================
--- /dev/null
+++ flang/test/Flang-Driver/Inputs/fixed-form-test.f
@@ -0,0 +1,2 @@
+      program A
+      end
\ No newline at end of file
Index: flang/lib/Frontend/FrontendOptions.cpp
===================================================================
--- flang/lib/Frontend/FrontendOptions.cpp
+++ flang/lib/Frontend/FrontendOptions.cpp
@@ -13,9 +13,11 @@
 
 InputKind FrontendOptions::GetInputKindForExtension(llvm::StringRef extension) {
   return llvm::StringSwitch<InputKind>(extension)
-      // TODO: Should match the list in flang/test/lit.cfg.py
+      // Note: keep this list in-sync with flang/test/lit.cfg.py
+      // TODO: Add Cuda Fortan files (i.e. `*.cuf` and `*.CUF`).
       // FIXME: Currently this API allows at most 9 items per case.
       .Cases("f", "F", "f77", "f90", "F90", "f95", "F95", "ff95", "f18", "F18",
           Language::Fortran)
+      .Cases("ff", "FOR", "for", "f77", "ff90", "fpp", "FPP", Language::Fortran)
       .Default(Language::Unknown);
 }
Index: flang/lib/Frontend/FrontendAction.cpp
===================================================================
--- flang/lib/Frontend/FrontendAction.cpp
+++ flang/lib/Frontend/FrontendAction.cpp
@@ -51,6 +51,13 @@
 
   Fortran::parser::Options parserOptions =
       this->instance().invocation().fortranOpts();
+  // Set the fixed form flag based on the file extension
+  auto pathDotIndex{currentInputPath.rfind(".")};
+  if (pathDotIndex != std::string::npos) {
+    std::string pathSuffix{currentInputPath.substr(pathDotIndex + 1)};
+    parserOptions.isFixedForm =
+        pathSuffix == "f" || pathSuffix == "F" || pathSuffix == "ff";
+  }
 
   // Prescan. In case of failure, report and return.
   ci.parsing().Prescan(currentInputPath, parserOptions);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D94228.315103.patch
Type: text/x-patch
Size: 4030 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210107/ff1c2bae/attachment.bin>


More information about the llvm-commits mailing list