OLD | NEW |
1 //===- llvm/Support/Unix/Host.inc -------------------------------*- C++ -*-===// | 1 //===- llvm/Support/Unix/Host.inc -------------------------------*- C++ -*-===// |
2 // | 2 // |
3 // The LLVM Compiler Infrastructure | 3 // The LLVM Compiler Infrastructure |
4 // | 4 // |
5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
7 // | 7 // |
8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
9 // | 9 // |
10 // This file implements the UNIX Host support. | 10 // This file implements the UNIX Host support. |
11 // | 11 // |
12 //===----------------------------------------------------------------------===// | 12 //===----------------------------------------------------------------------===// |
13 | 13 |
14 //===----------------------------------------------------------------------===// | 14 //===----------------------------------------------------------------------===// |
15 //=== WARNING: Implementation here must contain only generic UNIX code that | 15 //=== WARNING: Implementation here must contain only generic UNIX code that |
16 //=== is guaranteed to work on *all* UNIX variants. | 16 //=== is guaranteed to work on *all* UNIX variants. |
17 //===----------------------------------------------------------------------===// | 17 //===----------------------------------------------------------------------===// |
18 | 18 |
19 #include "llvm/Config/config.h" | 19 #include "llvm/Config/config.h" |
20 #include "llvm/ADT/StringRef.h" | 20 #include "llvm/ADT/StringRef.h" |
21 #include "Unix.h" | 21 #include "Unix.h" |
| 22 #if !defined(__native_client__) |
22 #include <sys/utsname.h> | 23 #include <sys/utsname.h> |
| 24 #endif // (__native_client__) |
23 #include <cctype> | 25 #include <cctype> |
24 #include <string> | 26 #include <string> |
25 | 27 |
26 using namespace llvm; | 28 using namespace llvm; |
27 | 29 |
28 static std::string getOSVersion() { | 30 static std::string getOSVersion() { |
| 31 #if !defined(__native_client__) |
29 struct utsname info; | 32 struct utsname info; |
30 | 33 |
31 if (uname(&info)) | 34 if (uname(&info)) |
32 return ""; | 35 return ""; |
33 | 36 |
34 return info.release; | 37 return info.release; |
| 38 #else // (__native_client__) |
| 39 return ""; |
| 40 #endif // (__native_client__) |
35 } | 41 } |
36 | 42 |
37 std::string sys::getDefaultTargetTriple() { | 43 std::string sys::getDefaultTargetTriple() { |
38 StringRef TargetTripleString(LLVM_DEFAULT_TARGET_TRIPLE); | 44 StringRef TargetTripleString(LLVM_DEFAULT_TARGET_TRIPLE); |
39 std::pair<StringRef, StringRef> ArchSplit = TargetTripleString.split('-'); | 45 std::pair<StringRef, StringRef> ArchSplit = TargetTripleString.split('-'); |
40 | 46 |
41 // Normalize the arch, since the target triple may not actually match the | 47 // Normalize the arch, since the target triple may not actually match the |
42 // target. | 48 // target. |
43 std::string Arch = ArchSplit.first; | 49 std::string Arch = ArchSplit.first; |
44 | 50 |
45 std::string Triple(Arch); | 51 std::string Triple(Arch); |
46 Triple += '-'; | 52 Triple += '-'; |
47 Triple += ArchSplit.second; | 53 Triple += ArchSplit.second; |
48 | 54 |
49 // Force i<N>86 to i386. | 55 // Force i<N>86 to i386. |
50 if (Triple[0] == 'i' && isdigit(Triple[1]) && | 56 if (Triple[0] == 'i' && isdigit(Triple[1]) && |
51 Triple[2] == '8' && Triple[3] == '6') | 57 Triple[2] == '8' && Triple[3] == '6') |
52 Triple[1] = '3'; | 58 Triple[1] = '3'; |
53 | 59 |
54 // On darwin, we want to update the version to match that of the | 60 // On darwin, we want to update the version to match that of the |
55 // target. | 61 // target. |
56 std::string::size_type DarwinDashIdx = Triple.find("-darwin"); | 62 std::string::size_type DarwinDashIdx = Triple.find("-darwin"); |
57 if (DarwinDashIdx != std::string::npos) { | 63 if (DarwinDashIdx != std::string::npos) { |
58 Triple.resize(DarwinDashIdx + strlen("-darwin")); | 64 Triple.resize(DarwinDashIdx + strlen("-darwin")); |
59 Triple += getOSVersion(); | 65 Triple += getOSVersion(); |
60 } | 66 } |
61 | 67 |
62 return Triple::normalize(Triple); | 68 return Triple::normalize(Triple); |
63 } | 69 } |
OLD | NEW |