1 //===--- Triple.cpp - Target triple helper class --------------------------===//
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 #include "llvm/ADT/Triple.h"
12 #include "llvm/ADT/Twine.h"
19 const char *Triple::getArchTypeName(ArchType Kind) {
21 case InvalidArch: return "<invalid>";
22 case UnknownArch: return "unknown";
24 case x86: return "i386";
25 case x86_64: return "x86_64";
26 case ppc: return "powerpc";
27 case ppc64: return "powerpc64";
33 const char *Triple::getVendorTypeName(VendorType Kind) {
35 case UnknownVendor: return "unknown";
37 case Apple: return "apple";
44 const char *Triple::getOSTypeName(OSType Kind) {
46 case UnknownOS: return "unknown";
48 case AuroraUX: return "auroraux";
49 case Darwin: return "darwin";
50 case DragonFly: return "dragonfly";
51 case FreeBSD: return "freebsd";
52 case Linux: return "linux";
53 case NetBSD: return "netbsd";
54 case OpenBSD: return "openbsd";
62 void Triple::Parse() const {
63 assert(!isInitialized() && "Invalid parse call.");
65 StringRef ArchName = getArchName();
66 if (ArchName.size() == 4 && ArchName[0] == 'i' &&
67 ArchName[2] == '8' && ArchName[3] == '6')
69 else if (ArchName == "amd64" || ArchName == "x86_64")
71 else if (ArchName == "powerpc")
73 else if (ArchName == "powerpc64")
78 StringRef VendorName = getVendorName();
79 if (VendorName == "apple")
81 else if (VendorName == "pc")
84 Vendor = UnknownVendor;
86 StringRef OSName = getOSName();
87 if (OSName.startswith("auroraux"))
89 else if (OSName.startswith("darwin"))
91 else if (OSName.startswith("dragonfly"))
93 else if (OSName.startswith("freebsd"))
95 else if (OSName.startswith("linux"))
97 else if (OSName.startswith("netbsd"))
99 else if (OSName.startswith("openbsd"))
104 assert(isInitialized() && "Failed to initialize!");
107 StringRef Triple::getArchName() const {
108 return StringRef(Data).split('-').first; // Isolate first component
111 StringRef Triple::getVendorName() const {
112 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
113 return Tmp.split('-').first; // Isolate second component
116 StringRef Triple::getOSName() const {
117 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
118 Tmp = Tmp.split('-').second; // Strip second component
119 return Tmp.split('-').first; // Isolate third component
122 StringRef Triple::getEnvironmentName() const {
123 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
124 Tmp = Tmp.split('-').second; // Strip second component
125 return Tmp.split('-').second; // Strip third component
128 StringRef Triple::getOSAndEnvironmentName() const {
129 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
130 return Tmp.split('-').second; // Strip second component
133 void Triple::setTriple(const Twine &Str) {
138 void Triple::setArch(ArchType Kind) {
139 setArchName(getArchTypeName(Kind));
142 void Triple::setVendor(VendorType Kind) {
143 setVendorName(getVendorTypeName(Kind));
146 void Triple::setOS(OSType Kind) {
147 setOSName(getOSTypeName(Kind));
150 void Triple::setArchName(const StringRef &Str) {
151 setTriple(Str + "-" + getVendorName() + "-" + getOSAndEnvironmentName());
154 void Triple::setVendorName(const StringRef &Str) {
155 setTriple(getArchName() + "-" + Str + "-" + getOSAndEnvironmentName());
158 void Triple::setOSName(const StringRef &Str) {
159 if (hasEnvironment())
160 setTriple(getArchName() + "-" + getVendorName() + "-" + Str +
161 "-" + getEnvironmentName());
163 setTriple(getArchName() + "-" + getVendorName() + "-" + Str);
166 void Triple::setEnvironmentName(const StringRef &Str) {
167 setTriple(getArchName() + "-" + getVendorName() + "-" + getOSName() +
171 void Triple::setOSAndEnvironmentName(const StringRef &Str) {
172 setTriple(getArchName() + "-" + getVendorName() + "-" + Str);