LCOV - code coverage report
Current view: top level - lib/Support/Unix - Host.inc (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 8 17 47.1 %
Date: 2017-09-14 15:23:50 Functions: 2 3 66.7 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- llvm/Support/Unix/Host.inc -------------------------------*- C++ -*-===//
       2             : //
       3             : //                     The LLVM Compiler Infrastructure
       4             : //
       5             : // This file is distributed under the University of Illinois Open Source
       6             : // License. See LICENSE.TXT for details.
       7             : //
       8             : //===----------------------------------------------------------------------===//
       9             : //
      10             : // This file implements the UNIX Host support.
      11             : //
      12             : //===----------------------------------------------------------------------===//
      13             : 
      14             : //===----------------------------------------------------------------------===//
      15             : //=== WARNING: Implementation here must contain only generic UNIX code that
      16             : //===          is guaranteed to work on *all* UNIX variants.
      17             : //===----------------------------------------------------------------------===//
      18             : 
      19             : #include "Unix.h"
      20             : #include "llvm/ADT/StringRef.h"
      21             : #include "llvm/Config/config.h"
      22             : #include <cctype>
      23             : #include <string>
      24             : #include <sys/utsname.h>
      25             : 
      26             : using namespace llvm;
      27             : 
      28           0 : static std::string getOSVersion() {
      29             :   struct utsname info;
      30             : 
      31           0 :   if (uname(&info))
      32           0 :     return "";
      33             : 
      34           0 :   return info.release;
      35             : }
      36             : 
      37       30636 : static std::string updateTripleOSVersion(std::string TargetTripleString) {
      38             :   // On darwin, we want to update the version to match that of the target.
      39       30636 :   std::string::size_type DarwinDashIdx = TargetTripleString.find("-darwin");
      40       30636 :   if (DarwinDashIdx != std::string::npos) {
      41           0 :     TargetTripleString.resize(DarwinDashIdx + strlen("-darwin"));
      42           0 :     TargetTripleString += getOSVersion();
      43             :     return TargetTripleString;
      44             :   }
      45       30636 :   std::string::size_type MacOSDashIdx = TargetTripleString.find("-macos");
      46       30636 :   if (MacOSDashIdx != std::string::npos) {
      47           0 :     TargetTripleString.resize(MacOSDashIdx);
      48             :     // Reset the OS to darwin as the OS version from `uname` doesn't use the
      49             :     // macOS version scheme.
      50           0 :     TargetTripleString += "-darwin";
      51           0 :     TargetTripleString += getOSVersion();
      52             :   }
      53             :   return TargetTripleString;
      54             : }
      55             : 
      56       26560 : std::string sys::getDefaultTargetTriple() {
      57             :   std::string TargetTripleString =
      58      132800 :       updateTripleOSVersion(LLVM_DEFAULT_TARGET_TRIPLE);
      59             : 
      60             :   // Override the default target with an environment variable named by
      61             :   // LLVM_TARGET_TRIPLE_ENV.
      62             : #if defined(LLVM_TARGET_TRIPLE_ENV)
      63             :   if (const char *EnvTriple = std::getenv(LLVM_TARGET_TRIPLE_ENV))
      64             :     TargetTripleString = EnvTriple;
      65             : #endif
      66             : 
      67       53120 :   return Triple::normalize(TargetTripleString);
      68             : }

Generated by: LCOV version 1.13