2014-09-24 12:44:37 +08:00
|
|
|
//===- llvm/Support/Unix/Host.inc -------------------------------*- C++ -*-===//
|
2009-02-09 05:10:57 +08:00
|
|
|
//
|
2008-10-02 09:17:28 +08:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2009-02-09 05:10:57 +08:00
|
|
|
//
|
2008-10-02 09:17:28 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the UNIX Host support.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//=== WARNING: Implementation here must contain only generic UNIX code that
|
|
|
|
//=== is guaranteed to work on *all* UNIX variants.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-09-03 09:10:13 +08:00
|
|
|
#include "llvm/Config/config.h"
|
|
|
|
#include "llvm/ADT/StringRef.h"
|
2008-10-02 09:17:28 +08:00
|
|
|
#include "Unix.h"
|
|
|
|
#include <sys/utsname.h>
|
2010-12-20 04:43:38 +08:00
|
|
|
#include <cctype>
|
2008-10-02 09:17:28 +08:00
|
|
|
#include <string>
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2009-04-01 01:30:15 +08:00
|
|
|
static std::string getOSVersion() {
|
2008-10-02 09:17:28 +08:00
|
|
|
struct utsname info;
|
|
|
|
|
|
|
|
if (uname(&info))
|
|
|
|
return "";
|
|
|
|
|
2009-04-01 01:30:15 +08:00
|
|
|
return info.release;
|
2008-10-02 09:17:28 +08:00
|
|
|
}
|
|
|
|
|
2012-01-06 02:28:46 +08:00
|
|
|
std::string sys::getDefaultTargetTriple() {
|
|
|
|
StringRef TargetTripleString(LLVM_DEFAULT_TARGET_TRIPLE);
|
|
|
|
std::pair<StringRef, StringRef> ArchSplit = TargetTripleString.split('-');
|
|
|
|
|
2014-09-24 12:44:50 +08:00
|
|
|
// Normalize the arch, since the target triple may not actually match the
|
|
|
|
// target.
|
2009-09-03 09:10:13 +08:00
|
|
|
std::string Arch = ArchSplit.first;
|
2012-01-06 02:28:46 +08:00
|
|
|
|
2009-09-03 09:10:13 +08:00
|
|
|
std::string Triple(Arch);
|
|
|
|
Triple += '-';
|
|
|
|
Triple += ArchSplit.second;
|
2009-04-01 01:30:15 +08:00
|
|
|
|
|
|
|
// Force i<N>86 to i386.
|
2010-11-30 02:16:10 +08:00
|
|
|
if (Triple[0] == 'i' && isdigit(Triple[1]) &&
|
2009-04-01 01:30:15 +08:00
|
|
|
Triple[2] == '8' && Triple[3] == '6')
|
|
|
|
Triple[1] = '3';
|
|
|
|
|
|
|
|
// On darwin, we want to update the version to match that of the
|
2011-11-02 05:32:20 +08:00
|
|
|
// target.
|
2009-04-01 01:30:15 +08:00
|
|
|
std::string::size_type DarwinDashIdx = Triple.find("-darwin");
|
|
|
|
if (DarwinDashIdx != std::string::npos) {
|
|
|
|
Triple.resize(DarwinDashIdx + strlen("-darwin"));
|
2011-04-20 23:44:33 +08:00
|
|
|
Triple += getOSVersion();
|
2009-04-01 01:30:15 +08:00
|
|
|
}
|
|
|
|
|
2014-03-30 11:22:37 +08:00
|
|
|
return Triple::normalize(Triple);
|
2008-10-02 09:17:28 +08:00
|
|
|
}
|