1 //===- llvm/System/Unix/Host.inc -------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the UNIX Host support.
12 //===----------------------------------------------------------------------===//
14 //===----------------------------------------------------------------------===//
15 //=== WARNING: Implementation here must contain only generic UNIX code that
16 //=== is guaranteed to work on *all* UNIX variants.
17 //===----------------------------------------------------------------------===//
19 #include "llvm/Config/config.h"
20 #include "llvm/ADT/StringRef.h"
22 #include <sys/utsname.h>
27 static std::string getOSVersion() {
36 std::string sys::getHostTriple() {
37 // FIXME: Derive directly instead of relying on the autoconf generated
40 StringRef HostTripleString(LLVM_HOSTTRIPLE);
41 std::pair<StringRef, StringRef> ArchSplit = HostTripleString.split('-');
43 // Normalize the arch, since the host triple may not actually match the host.
44 std::string Arch = ArchSplit.first;
46 // It would be nice to do this in terms of llvm::Triple, but that is in
47 // Support which is layered above us.
48 #if defined(__x86_64__)
50 #elif defined(__i386__)
52 #elif defined(__ppc64__)
54 #elif defined(__ppc__)
56 #elif defined(__arm__)
58 // FIXME: We need to pick the right ARM triple (which involves querying the
59 // chip). However, for now this is most important for LLVM arch selection, so
60 // we only need to make sure to distinguish ARM and Thumb.
61 # if defined(__thumb__)
69 // FIXME: When enough auto-detection is in place, this should just
70 // #error. Then at least the arch selection is done, and we only need the OS
71 // etc selection to kill off the use of LLVM_HOSTTRIPLE.
75 std::string Triple(Arch);
77 Triple += ArchSplit.second;
79 // Force i<N>86 to i386.
80 if (Triple[0] == 'i' && isdigit(Triple[1]) &&
81 Triple[2] == '8' && Triple[3] == '6')
84 // On darwin, we want to update the version to match that of the
86 std::string::size_type DarwinDashIdx = Triple.find("-darwin");
87 if (DarwinDashIdx != std::string::npos) {
88 Triple.resize(DarwinDashIdx + strlen("-darwin"));
90 // Only add the major part of the os version.
91 std::string Version = getOSVersion();
92 Triple += Version.substr(0, Version.find('.'));