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 bfin: return "bfin";
27 case cellspu: return "cellspu";
28 case mips: return "mips";
29 case mipsel: return "mipsel";
30 case msp430: return "msp430";
31 case ppc64: return "powerpc64";
32 case ppc: return "powerpc";
33 case sparc: return "sparc";
34 case systemz: return "s390x";
35 case thumb: return "thumb";
36 case x86: return "i386";
37 case x86_64: return "x86_64";
38 case xcore: return "xcore";
44 const char *Triple::getVendorTypeName(VendorType Kind) {
46 case UnknownVendor: return "unknown";
48 case Apple: return "apple";
55 const char *Triple::getOSTypeName(OSType Kind) {
57 case UnknownOS: return "unknown";
59 case AuroraUX: return "auroraux";
60 case Cygwin: return "cygwin";
61 case Darwin: return "darwin";
62 case DragonFly: return "dragonfly";
63 case FreeBSD: return "freebsd";
64 case Linux: return "linux";
65 case MinGW32: return "mingw32";
66 case NetBSD: return "netbsd";
67 case OpenBSD: return "openbsd";
68 case Win32: return "win32";
74 Triple::ArchType Triple::getArchTypeForLLVMName(const StringRef &Name) {
81 if (Name == "cellspu")
95 if (Name == "systemz")
101 if (Name == "x86_64")
111 void Triple::Parse() const {
112 assert(!isInitialized() && "Invalid parse call.");
114 StringRef ArchName = getArchName();
115 if (ArchName.size() == 4 && ArchName[0] == 'i' &&
116 ArchName[2] == '8' && ArchName[3] == '6' &&
117 ArchName[1] - '3' < 6) // i[3-9]86
119 else if (ArchName == "amd64" || ArchName == "x86_64")
121 else if (ArchName == "powerpc")
123 else if (ArchName == "powerpc64")
125 else if (ArchName == "arm" ||
126 ArchName.startswith("armv"))
128 else if (ArchName == "thumb" ||
129 ArchName.startswith("thumbv"))
131 else if (ArchName.startswith("alpha"))
133 else if (ArchName == "spu" || ArchName == "cellspu")
135 else if (ArchName == "msp430")
137 else if (ArchName == "mips" || ArchName == "mipsallegrex")
139 else if (ArchName == "mipsel" || ArchName == "mipsallegrexel" ||
142 else if (ArchName == "sparc")
144 else if (ArchName == "s390x")
146 else if (ArchName == "bfin")
151 StringRef VendorName = getVendorName();
152 if (VendorName == "apple")
154 else if (VendorName == "pc")
157 Vendor = UnknownVendor;
159 StringRef OSName = getOSName();
160 if (OSName.startswith("auroraux"))
162 else if (OSName.startswith("cygwin"))
164 else if (OSName.startswith("darwin"))
166 else if (OSName.startswith("dragonfly"))
168 else if (OSName.startswith("freebsd"))
170 else if (OSName.startswith("linux"))
172 else if (OSName.startswith("mingw32"))
174 else if (OSName.startswith("netbsd"))
176 else if (OSName.startswith("openbsd"))
178 else if (OSName.startswith("win32"))
183 assert(isInitialized() && "Failed to initialize!");
186 StringRef Triple::getArchName() const {
187 return StringRef(Data).split('-').first; // Isolate first component
190 StringRef Triple::getVendorName() const {
191 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
192 return Tmp.split('-').first; // Isolate second component
195 StringRef Triple::getOSName() const {
196 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
197 Tmp = Tmp.split('-').second; // Strip second component
198 return Tmp.split('-').first; // Isolate third component
201 StringRef Triple::getEnvironmentName() const {
202 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
203 Tmp = Tmp.split('-').second; // Strip second component
204 return Tmp.split('-').second; // Strip third component
207 StringRef Triple::getOSAndEnvironmentName() const {
208 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
209 return Tmp.split('-').second; // Strip second component
212 void Triple::setTriple(const Twine &Str) {
217 void Triple::setArch(ArchType Kind) {
218 setArchName(getArchTypeName(Kind));
221 void Triple::setVendor(VendorType Kind) {
222 setVendorName(getVendorTypeName(Kind));
225 void Triple::setOS(OSType Kind) {
226 setOSName(getOSTypeName(Kind));
229 void Triple::setArchName(const StringRef &Str) {
230 setTriple(Str + "-" + getVendorName() + "-" + getOSAndEnvironmentName());
233 void Triple::setVendorName(const StringRef &Str) {
234 setTriple(getArchName() + "-" + Str + "-" + getOSAndEnvironmentName());
237 void Triple::setOSName(const StringRef &Str) {
238 if (hasEnvironment())
239 setTriple(getArchName() + "-" + getVendorName() + "-" + Str +
240 "-" + getEnvironmentName());
242 setTriple(getArchName() + "-" + getVendorName() + "-" + Str);
245 void Triple::setEnvironmentName(const StringRef &Str) {
246 setTriple(getArchName() + "-" + getVendorName() + "-" + getOSName() +
250 void Triple::setOSAndEnvironmentName(const StringRef &Str) {
251 setTriple(getArchName() + "-" + getVendorName() + "-" + Str);