OSDN Git Service

use getHostTriple instead of getDefaultTargetTriple in getClosestTargetForJIT
[android-x86/external-llvm.git] / lib / Support / Unix / Host.inc
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 "llvm/Config/config.h"
20 #include "llvm/ADT/StringRef.h"
21 #include "Unix.h"
22 #include <sys/utsname.h>
23 #include <cctype>
24 #include <string>
25 #include <cstdlib> // ::getenv
26
27 using namespace llvm;
28
29 static std::string getOSVersion() {
30   struct utsname info;
31
32   if (uname(&info))
33     return "";
34
35   return info.release;
36 }
37
38 std::string getTriple(StringRef &TripleString) {
39   std::pair<StringRef, StringRef> ArchSplit = TripleString.split('-');
40   std::string Arch = ArchSplit.first;
41   std::string Triple(Arch);
42   Triple += '-';
43   Triple += ArchSplit.second;
44
45   // Force i<N>86 to i386.
46   if (Triple[0] == 'i' && isdigit(Triple[1]) &&
47       Triple[2] == '8' && Triple[3] == '6')
48     Triple[1] = '3';
49
50   // On darwin, we want to update the version to match that of the
51   // target.
52   std::string::size_type DarwinDashIdx = Triple.find("-darwin");
53   if (DarwinDashIdx != std::string::npos) {
54     Triple.resize(DarwinDashIdx + strlen("-darwin"));
55     Triple += getOSVersion();
56   }
57
58   return Triple;
59 }
60
61 std::string sys::getDefaultTargetTriple() {
62   StringRef TargetTripleString(LLVM_DEFAULT_TARGET_TRIPLE);
63   return getTriple(TargetTripleString);
64 }
65
66 std::string sys::getHostTriple() {
67   StringRef HostTripleString(LLVM_HOST_TRIPLE);
68   return getTriple(HostTripleString);
69 }