[flang-commits] [PATCH] D84334: Version information in flang/f18

Camille Coti via Phabricator via flang-commits flang-commits at lists.llvm.org
Thu Jul 23 17:25:45 PDT 2020


coti updated this revision to Diff 280303.
coti edited the summary of this revision.
coti added a comment.
Herald added a subscriber: mgorny.

Let cmake grab the version numbers.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D84334/new/

https://reviews.llvm.org/D84334

Files:
  flang/tools/f18/CMakeLists.txt
  flang/tools/f18/f18.cpp
  flang/tools/f18/f18_version.h.in


Index: flang/tools/f18/f18_version.h.in
===================================================================
--- flang/tools/f18/f18_version.h.in
+++ flang/tools/f18/f18_version.h.in
@@ -0,0 +1,13 @@
+#ifndef _F18_H_
+#define _F18_H_
+
+#define __F18                "@LLVM_VERSION_MAJOR at .@LLVM_VERSION_MINOR at .@LLVM_VERSION_PATCH@"
+#define __F18_MAJOR__        "@LLVM_VERSION_MAJOR@"
+#define __F18_MINOR__        "@LLVM_VERSION_MINOR@"
+#define __F18_PATCHLEVEL__   "@LLVM_VERSION_PATCH@"
+#define __FLANG              "@LLVM_VERSION_MAJOR at .@LLVM_VERSION_MINOR at .@LLVM_VERSION_PATCH@"
+#define __FLANG_MAJOR__      "@LLVM_VERSION_MAJOR@"
+#define __FLANG_MINOR__      "@LLVM_VERSION_MINOR@"
+#define __FLANG_PATCHLEVEL__ "@LLVM_VERSION_PATCH@"
+
+#endif // _F18_H_
Index: flang/tools/f18/f18.cpp
===================================================================
--- flang/tools/f18/f18.cpp
+++ 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) {
@@ -386,6 +388,11 @@
   }
 }
 
+int printVersion(){
+  llvm::errs() << "\nf18 compiler (under development)\n";
+  return exitStatus;
+}
+
 int main(int argc, char *const argv[]) {
 
   atexit(CleanUpAtExit);
@@ -402,10 +409,14 @@
   driver.prefix = prefix.data();
 
   Fortran::parser::Options options;
-  options.predefinitions.emplace_back("__F18", "1");
-  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("__F18", __F18 );
+  options.predefinitions.emplace_back("__F18_MAJOR__", __F18_MAJOR__);
+  options.predefinitions.emplace_back("__F18_MINOR__", __F18_MINOR__);
+  options.predefinitions.emplace_back("__F18_PATCHLEVEL__", __F18_PATCHLEVEL__);
+  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
@@ -622,13 +633,16 @@
           << "  -help                print this again\n"
           << "Other options are passed through to the compiler.\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());
Index: flang/tools/f18/CMakeLists.txt
===================================================================
--- flang/tools/f18/CMakeLists.txt
+++ flang/tools/f18/CMakeLists.txt
@@ -61,6 +61,7 @@
 set(FLANG_INTRINSIC_MODULES_DIR ${FLANG_BINARY_DIR}/include/flang)
 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/flang.sh.in ${CMAKE_BINARY_DIR}/tools/flang/bin/flang @ONLY)
 file(COPY ${CMAKE_BINARY_DIR}/tools/flang/bin/flang DESTINATION ${CMAKE_BINARY_DIR}/bin FILE_PERMISSIONS OWNER_EXECUTE OWNER_READ OWNER_WRITE)
+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/f18_version.h.in ${CMAKE_CURRENT_SOURCE_DIR}/f18_version.h @ONLY)
 # 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)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D84334.280303.patch
Type: text/x-patch
Size: 3997 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20200724/b5d29cd4/attachment.bin>


More information about the flang-commits mailing list