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 alpha: return "alpha";
25 case arm: return "arm";
26 case cellspu: return "cellspu";
27 case mips: return "mips";
28 case mipsel: return "mipsel";
29 case msp430: return "msp430";
30 case ppc64: return "powerpc64";
31 case ppc: return "powerpc";
32 case sparc: return "sparc";
33 case systemz: return "s390x";
34 case thumb: return "thumb";
35 case x86: return "i386";
36 case x86_64: return "x86_64";
37 case xcore: return "xcore";
43 const char *Triple::getVendorTypeName(VendorType Kind) {
45 case UnknownVendor: return "unknown";
47 case Apple: return "apple";
54 const char *Triple::getOSTypeName(OSType Kind) {
56 case UnknownOS: return "unknown";
58 case AuroraUX: return "auroraux";
59 case Cygwin: return "cygwin";
60 case Darwin: return "darwin";
61 case DragonFly: return "dragonfly";
62 case FreeBSD: return "freebsd";
63 case Linux: return "linux";
64 case MinGW32: return "mingw32";
65 case NetBSD: return "netbsd";
66 case OpenBSD: return "openbsd";
67 case Win32: return "win32";
75 void Triple::Parse() const {
76 assert(!isInitialized() && "Invalid parse call.");
78 StringRef ArchName = getArchName();
79 if (ArchName.size() == 4 && ArchName[0] == 'i' &&
80 ArchName[2] == '8' && ArchName[3] == '6' &&
81 ArchName[1] - '3' < 6) // i[3-9]86
83 else if (ArchName == "amd64" || ArchName == "x86_64")
85 else if (ArchName == "powerpc")
87 else if (ArchName == "powerpc64")
89 else if (ArchName == "arm" ||
90 ArchName.startswith("armv"))
92 else if (ArchName == "thumb" ||
93 ArchName.startswith("thumbv"))
95 else if (ArchName.startswith("alpha"))
97 else if (ArchName == "spu" || ArchName == "cellspu")
99 else if (ArchName == "msp430")
101 else if (ArchName == "mips" || ArchName == "mipsallegrex")
103 else if (ArchName == "mipsel" || ArchName == "mipsallegrexel" ||
106 else if (ArchName == "sparc")
108 else if (ArchName == "s390x")
113 StringRef VendorName = getVendorName();
114 if (VendorName == "apple")
116 else if (VendorName == "pc")
119 Vendor = UnknownVendor;
121 StringRef OSName = getOSName();
122 if (OSName.startswith("auroraux"))
124 else if (OSName.startswith("cygwin"))
126 else if (OSName.startswith("darwin"))
128 else if (OSName.startswith("dragonfly"))
130 else if (OSName.startswith("freebsd"))
132 else if (OSName.startswith("linux"))
134 else if (OSName.startswith("mingw32"))
136 else if (OSName.startswith("netbsd"))
138 else if (OSName.startswith("openbsd"))
140 else if (OSName.startswith("win32"))
145 assert(isInitialized() && "Failed to initialize!");
148 StringRef Triple::getArchName() const {
149 return StringRef(Data).split('-').first; // Isolate first component
152 StringRef Triple::getVendorName() const {
153 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
154 return Tmp.split('-').first; // Isolate second component
157 StringRef Triple::getOSName() const {
158 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
159 Tmp = Tmp.split('-').second; // Strip second component
160 return Tmp.split('-').first; // Isolate third component
163 StringRef Triple::getEnvironmentName() const {
164 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
165 Tmp = Tmp.split('-').second; // Strip second component
166 return Tmp.split('-').second; // Strip third component
169 StringRef Triple::getOSAndEnvironmentName() const {
170 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
171 return Tmp.split('-').second; // Strip second component
174 void Triple::setTriple(const Twine &Str) {
179 void Triple::setArch(ArchType Kind) {
180 setArchName(getArchTypeName(Kind));
183 void Triple::setVendor(VendorType Kind) {
184 setVendorName(getVendorTypeName(Kind));
187 void Triple::setOS(OSType Kind) {
188 setOSName(getOSTypeName(Kind));
191 void Triple::setArchName(const StringRef &Str) {
192 setTriple(Str + "-" + getVendorName() + "-" + getOSAndEnvironmentName());
195 void Triple::setVendorName(const StringRef &Str) {
196 setTriple(getArchName() + "-" + Str + "-" + getOSAndEnvironmentName());
199 void Triple::setOSName(const StringRef &Str) {
200 if (hasEnvironment())
201 setTriple(getArchName() + "-" + getVendorName() + "-" + Str +
202 "-" + getEnvironmentName());
204 setTriple(getArchName() + "-" + getVendorName() + "-" + Str);
207 void Triple::setEnvironmentName(const StringRef &Str) {
208 setTriple(getArchName() + "-" + getVendorName() + "-" + getOSName() +
212 void Triple::setOSAndEnvironmentName(const StringRef &Str) {
213 setTriple(getArchName() + "-" + getVendorName() + "-" + Str);