aboutsummaryrefslogtreecommitdiff
path: root/flang/lib/FrontendTool
diff options
context:
space:
mode:
authorFaris Rehman <faris.rehman@arm.com>2021-01-04 16:49:33 +0000
committerAndrzej Warzynski <andrzej.warzynski@arm.com>2021-01-19 12:58:01 +0000
commit443d6957ca712aacdfd72c3408a8837580f6a286 (patch)
tree4599f076ab2c04b5e7120b7f8df7603496e87bea /flang/lib/FrontendTool
parenta6f9077b16da90204b296acd4f840769e83460ac (diff)
downloadllvm-443d6957ca712aacdfd72c3408a8837580f6a286.zip
llvm-443d6957ca712aacdfd72c3408a8837580f6a286.tar.gz
llvm-443d6957ca712aacdfd72c3408a8837580f6a286.tar.bz2
[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
Diffstat (limited to 'flang/lib/FrontendTool')
-rw-r--r--flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp b/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
index 50c9fca..6bc63b0 100644
--- a/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ b/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -84,4 +84,19 @@ bool ExecuteCompilerInvocation(CompilerInstance *flang) {
return success;
}
+bool isFixedFormSuffix(llvm::StringRef suffix) {
+ // Note: Keep this list in-sync with flang/test/lit.cfg.py
+ return suffix == "f" || suffix == "F" || suffix == "ff" || suffix == "for" ||
+ suffix == "FOR" || suffix == "fpp" || suffix == "FPP";
+}
+
+bool isFreeFormSuffix(llvm::StringRef suffix) {
+ // Note: Keep this list in-sync with flang/test/lit.cfg.py
+ // TODO: Add Cuda Fortan files (i.e. `*.cuf` and `*.CUF`).
+ return suffix == "f77" || suffix == "f90" || suffix == "F90" ||
+ suffix == "ff90" || suffix == "f95" || suffix == "F95" ||
+ suffix == "ff95" || suffix == "f03" || suffix == "F03" ||
+ suffix == "f08" || suffix == "F08" || suffix == "f18" || suffix == "F18";
+}
+
} // namespace Fortran::frontend