OSDN Git Service

[flang][driver] Add support for fixed form detection
authorFaris Rehman <faris.rehman@arm.com>
Mon, 4 Jan 2021 16:49:33 +0000 (16:49 +0000)
committerAndrzej Warzynski <andrzej.warzynski@arm.com>
Tue, 19 Jan 2021 12:58:01 +0000 (12:58 +0000)
commit443d6957ca712aacdfd72c3408a8837580f6a286
tree4599f076ab2c04b5e7120b7f8df7603496e87bea
parenta6f9077b16da90204b296acd4f840769e83460ac
[flang][driver] Add support for fixed form detection

Currently the new flang driver always runs in free form mode. This patch
adds support for fixed form mode detection based on the file extensions.

Like `f18`, `flang-new` will treat files ending with ".f", ".F" and
".ff" as fixed form. Additionally, ".for", ".FOR", ".fpp" and ".FPP"
file extensions are recognised as fixed form files. This is consistent
with gfortran [1]. In summary, files with the following extensions are
treated as fixed-form:
  * ".f", ".F", ".ff", ".for", ".FOR", ".fpp", ".FPP"

For consistency with flang/test/lit.cfg.py and f18, this patch also adds
support for the following file extensions:
  * ".ff", ".FOR", ".for", ".ff90", ".fpp", ".FPP"
This is added in flang/lib/Frontend/FrontendOptions.cpp. Additionally,
the following extensions are included:
  * ".f03", ".F03", ".f08", ".F08"
This is for compatibility with gfortran [1] and other popular Fortran
compilers [2].

NOTE: internally Flang will only differentiate between fixed and free
form files. Currently Flang does not support switching between language
standards, so in this regard file extensions are irrelevant. More
specifically, both `file.f03` and `file.f18` are represented with
`Language::Fortran` (as opposed to e.g. `Language::Fortran03`).

Summary of changes:
- Set Fortran::parser::Options::sFixedForm according to the file type
- Add isFixedFormSuffix and isFreeFormSuffix helper functions to
  FrontendTool/Utils.h
- Change FrontendOptions::GetInputKindForExtension to support the missing
  file extensions that f18 supports and some additional ones
- FrontendActionTest.cpp is updated to make sure that the test input is
  treated as free-form

[1] https://gcc.gnu.org/onlinedocs/gfortran/GNU-Fortran-and-GCC.html
[2] https://github.com/llvm/llvm-project/blob/master/flang/docs/OptionComparison.md#notes

Differential Revision: https://reviews.llvm.org/D94228
flang/include/flang/FrontendTool/Utils.h
flang/lib/Frontend/FrontendAction.cpp
flang/lib/Frontend/FrontendOptions.cpp
flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
flang/test/Flang-Driver/Inputs/fixed-form-test.f [new file with mode: 0644]
flang/test/Flang-Driver/Inputs/free-form-test.f90 [new file with mode: 0644]
flang/test/Flang-Driver/fixed-free-detection.f90 [new file with mode: 0644]
flang/test/lit.cfg.py
flang/unittests/Frontend/FrontendActionTest.cpp