brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.4 KiB · 8ee4908 Raw
105 lines · cpp
1//===-- lib/Support/Version.cpp ---------------------------------*- C++ -*-===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8//9// This file defines several version-related utility functions for Flang.10//11//===----------------------------------------------------------------------===//12 13#include "flang/Support/Version.h"14#include "llvm/Support/raw_ostream.h"15#include <cstdlib>16#include <cstring>17 18#include "VCSVersion.inc"19 20namespace Fortran::common {21 22std::string getFlangRepositoryPath() {23#if defined(FLANG_REPOSITORY_STRING)24  return FLANG_REPOSITORY_STRING;25#else26#ifdef FLANG_REPOSITORY27  return FLANG_REPOSITORY;28#else29  return "";30#endif31#endif32}33 34std::string getLLVMRepositoryPath() {35#ifdef LLVM_REPOSITORY36  return LLVM_REPOSITORY;37#else38  return "";39#endif40}41 42std::string getFlangRevision() {43#ifdef FLANG_REVISION44  return FLANG_REVISION;45#else46  return "";47#endif48}49 50std::string getLLVMRevision() {51#ifdef LLVM_REVISION52  return LLVM_REVISION;53#else54  return "";55#endif56}57 58std::string getFlangFullRepositoryVersion() {59  std::string buf;60  llvm::raw_string_ostream OS(buf);61  std::string Path = getFlangRepositoryPath();62  std::string Revision = getFlangRevision();63  if (!Path.empty() || !Revision.empty()) {64    OS << '(';65    if (!Path.empty())66      OS << Path;67    if (!Revision.empty()) {68      if (!Path.empty())69        OS << ' ';70      OS << Revision;71    }72    OS << ')';73  }74  // Support LLVM in a separate repository.75  std::string LLVMRev = getLLVMRevision();76  if (!LLVMRev.empty() && LLVMRev != Revision) {77    OS << " (";78    std::string LLVMRepo = getLLVMRepositoryPath();79    if (!LLVMRepo.empty())80      OS << LLVMRepo << ' ';81    OS << LLVMRev << ')';82  }83  return buf;84}85 86std::string getFlangFullVersion() { return getFlangToolFullVersion("flang"); }87 88std::string getFlangToolFullVersion(llvm::StringRef ToolName) {89  std::string buf;90  llvm::raw_string_ostream OS(buf);91#ifdef FLANG_VENDOR92  OS << FLANG_VENDOR;93#endif94  OS << ToolName << " version " FLANG_VERSION_STRING;95 96  std::string repo = getFlangFullRepositoryVersion();97  if (!repo.empty()) {98    OS << " " << repo;99  }100 101  return buf;102}103 104} // end namespace Fortran::common105