diff options
author | Camille Coti <camille.coti@gmail.com> | 2020-08-10 16:16:35 +0100 |
---|---|---|
committer | Hans Wennborg <hans@chromium.org> | 2020-08-18 11:58:55 +0200 |
commit | 844f018114b52325b36e1042c8a8fc0ea82d9c17 (patch) | |
tree | 752aaa78620aa6f02135b3fce0859e453f518c08 /flang | |
parent | 633865571bfdd104d84eadfd7ed9dedbdf6027ee (diff) | |
download | llvm-844f018114b52325b36e1042c8a8fc0ea82d9c17.tar.gz |
[flang] Version information in flang/f18
Fixed some version information in flang/f18:
- fixed the behavior of the -v switch: this flag enables verbosity with used with arguments, but just displays the version when used alone (related to this bug: https://bugs.llvm.org/show_bug.cgi?id=46017)
- added __FLANG, __FLANG_MAJOR__, __FLANG_MINOR__ and __FLANG_PATCHLEVEL__ (similar to their __F18* counterparts) for compatibility purpose
Reviewed By: sscalpone, AlexisPerry, richard.barton.arm, tskeith
Differential Revision: https://reviews.llvm.org/D84334
(cherry picked from commit 89a9db438f85c6d4c0f11ecd0448bb71e1deac24)
Diffstat (limited to 'flang')
-rw-r--r-- | flang/test/Driver/version_test.f90 | 7 | ||||
-rw-r--r-- | flang/test/Preprocessing/compiler_defined_macros.F90 | 12 | ||||
-rw-r--r-- | flang/tools/f18/CMakeLists.txt | 1 | ||||
-rw-r--r-- | flang/tools/f18/f18.cpp | 25 | ||||
-rw-r--r-- | flang/tools/f18/f18_version.h.in | 9 |
5 files changed, 48 insertions, 6 deletions
diff --git a/flang/test/Driver/version_test.f90 b/flang/test/Driver/version_test.f90 index 08ea35ba49ea..7fe229e2be17 100644 --- a/flang/test/Driver/version_test.f90 +++ b/flang/test/Driver/version_test.f90 @@ -1,7 +1,10 @@ ! Check that lit configuration works by checking the compiler version -! RUN: %f18 -V 2>&1 | FileCheck -check-prefix=VERSION %s ! VERSION-NOT:{{![[:space:]]}} ! VERSION:{{[[:space:]]}} -! VERSION-SAME:f18 compiler (under development) +! VERSION-SAME:f18 compiler (under development), version {{[1-9][0-9]*.[0-9]*.[0-9]*}} ! VERSION-EMPTY: + +! RUN: %f18 -V 2>&1 | FileCheck -check-prefix=VERSION %s +! RUN: %f18 -v 2>&1 | FileCheck -check-prefix=VERSION %s +! RUN: %f18 --version 2>&1 | FileCheck -check-prefix=VERSION %s diff --git a/flang/test/Preprocessing/compiler_defined_macros.F90 b/flang/test/Preprocessing/compiler_defined_macros.F90 new file mode 100644 index 000000000000..80852cfb4472 --- /dev/null +++ b/flang/test/Preprocessing/compiler_defined_macros.F90 @@ -0,0 +1,12 @@ +! Check that the macros that give the verion number are set properly + +!CHECK: flang_major = {{[1-9][0-9]*$}} +!CHECK: flang_minor = {{[0-9]+$}} +!CHECK: flang_patchlevel = {{[0-9]+$}} +!RUN: %f18 -E %s | FileCheck --ignore-case %s + + +integer, parameter :: flang_major = __flang_major__ +integer, parameter :: flang_minor = __flang_minor__ +integer, parameter :: flang_patchlevel = __flang_patchlevel__ + diff --git a/flang/tools/f18/CMakeLists.txt b/flang/tools/f18/CMakeLists.txt index 46c38fa43a2e..3dfce3437948 100644 --- a/flang/tools/f18/CMakeLists.txt +++ b/flang/tools/f18/CMakeLists.txt @@ -64,5 +64,6 @@ file(COPY ${CMAKE_BINARY_DIR}/tools/flang/bin/flang DESTINATION ${CMAKE_BINARY_D # The flang script to be installed needs a different path to the headers. set(FLANG_INTRINSIC_MODULES_DIR ${CMAKE_INSTALL_PREFIX}/include/flang) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/flang.sh.in ${FLANG_BINARY_DIR}/bin/flang-install.sh @ONLY) +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/f18_version.h.in ${CMAKE_CURRENT_BINARY_DIR}/f18_version.h @ONLY) install(PROGRAMS ${FLANG_BINARY_DIR}/bin/flang-install.sh DESTINATION bin RENAME flang PERMISSIONS OWNER_EXECUTE OWNER_READ OWNER_WRITE) diff --git a/flang/tools/f18/f18.cpp b/flang/tools/f18/f18.cpp index 03c0f7afe810..23b104ee520c 100644 --- a/flang/tools/f18/f18.cpp +++ b/flang/tools/f18/f18.cpp @@ -38,6 +38,8 @@ #include <unistd.h> #include <vector> +#include "f18_version.h" + static std::list<std::string> argList(int argc, char *const argv[]) { std::list<std::string> result; for (int j = 0; j < argc; ++j) { @@ -390,6 +392,13 @@ void Link(std::vector<std::string> &liblist, std::vector<std::string> &objects, } } +int printVersion() { + llvm::errs() << "\nf18 compiler (under development), version " + << __FLANG_MAJOR__ << "." << __FLANG_MINOR__ << "." + << __FLANG_PATCHLEVEL__ << "\n"; + return exitStatus; +} + int main(int argc, char *const argv[]) { atexit(CleanUpAtExit); @@ -411,6 +420,11 @@ int main(int argc, char *const argv[]) { options.predefinitions.emplace_back("__F18_MAJOR__", "1"); options.predefinitions.emplace_back("__F18_MINOR__", "1"); options.predefinitions.emplace_back("__F18_PATCHLEVEL__", "1"); + options.predefinitions.emplace_back("__flang__", __FLANG__); + options.predefinitions.emplace_back("__flang_major__", __FLANG_MAJOR__); + options.predefinitions.emplace_back("__flang_minor__", __FLANG_MINOR__); + options.predefinitions.emplace_back( + "__flang_patchlevel__", __FLANG_PATCHLEVEL__); #if __x86_64__ options.predefinitions.emplace_back("__x86_64__", "1"); #endif @@ -651,13 +665,16 @@ int main(int argc, char *const argv[]) { << "Unrecognised options are passed through to the external compiler\n" << "set by F18_FC (see defaults).\n"; return exitStatus; - } else if (arg == "-V") { - llvm::errs() << "\nf18 compiler (under development)\n"; - return exitStatus; + } else if (arg == "-V" || arg == "--version") { + return printVersion(); } else { driver.F18_FCArgs.push_back(arg); if (arg == "-v") { - driver.verbose = true; + if (args.size() > 1) { + driver.verbose = true; + } else { + return printVersion(); + } } else if (arg == "-I") { driver.F18_FCArgs.push_back(args.front()); driver.searchDirectories.push_back(args.front()); diff --git a/flang/tools/f18/f18_version.h.in b/flang/tools/f18/f18_version.h.in new file mode 100644 index 000000000000..0c8d5227cd00 --- /dev/null +++ b/flang/tools/f18/f18_version.h.in @@ -0,0 +1,9 @@ +#ifndef _F18_H_ +#define _F18_H_ + +#define __FLANG__ "1" +#define __FLANG_MAJOR__ "@LLVM_VERSION_MAJOR@" +#define __FLANG_MINOR__ "@LLVM_VERSION_MINOR@" +#define __FLANG_PATCHLEVEL__ "@LLVM_VERSION_PATCH@" + +#endif // _F18_H_ |