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";
76 void Triple::Parse() const {
77 assert(!isInitialized() && "Invalid parse call.");
79 StringRef ArchName = getArchName();
80 if (ArchName.size() == 4 && ArchName[0] == 'i' &&
81 ArchName[2] == '8' && ArchName[3] == '6' &&
82 ArchName[1] - '3' < 6) // i[3-9]86
84 else if (ArchName == "amd64" || ArchName == "x86_64")
86 else if (ArchName == "powerpc")
88 else if (ArchName == "powerpc64")
90 else if (ArchName == "arm" ||
91 ArchName.startswith("armv"))
93 else if (ArchName == "thumb" ||
94 ArchName.startswith("thumbv"))
96 else if (ArchName.startswith("alpha"))
98 else if (ArchName == "spu" || ArchName == "cellspu")
100 else if (ArchName == "msp430")
102 else if (ArchName == "mips" || ArchName == "mipsallegrex")
104 else if (ArchName == "mipsel" || ArchName == "mipsallegrexel" ||
107 else if (ArchName == "sparc")
109 else if (ArchName == "s390x")
111 else if (ArchName == "bfin")
116 StringRef VendorName = getVendorName();
117 if (VendorName == "apple")
119 else if (VendorName == "pc")
122 Vendor = UnknownVendor;
124 StringRef OSName = getOSName();
125 if (OSName.startswith("auroraux"))
127 else if (OSName.startswith("cygwin"))
129 else if (OSName.startswith("darwin"))
131 else if (OSName.startswith("dragonfly"))
133 else if (OSName.startswith("freebsd"))
135 else if (OSName.startswith("linux"))
137 else if (OSName.startswith("mingw32"))
139 else if (OSName.startswith("netbsd"))
141 else if (OSName.startswith("openbsd"))
143 else if (OSName.startswith("win32"))
148 assert(isInitialized() && "Failed to initialize!");
151 StringRef Triple::getArchName() const {
152 return StringRef(Data).split('-').first; // Isolate first component
155 StringRef Triple::getVendorName() const {
156 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
157 return Tmp.split('-').first; // Isolate second component
160 StringRef Triple::getOSName() const {
161 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
162 Tmp = Tmp.split('-').second; // Strip second component
163 return Tmp.split('-').first; // Isolate third component
166 StringRef Triple::getEnvironmentName() const {
167 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
168 Tmp = Tmp.split('-').second; // Strip second component
169 return Tmp.split('-').second; // Strip third component
172 StringRef Triple::getOSAndEnvironmentName() const {
173 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
174 return Tmp.split('-').second; // Strip second component
177 void Triple::setTriple(const Twine &Str) {
182 void Triple::setArch(ArchType Kind) {
183 setArchName(getArchTypeName(Kind));
186 void Triple::setVendor(VendorType Kind) {
187 setVendorName(getVendorTypeName(Kind));
190 void Triple::setOS(OSType Kind) {
191 setOSName(getOSTypeName(Kind));
194 void Triple::setArchName(const StringRef &Str) {
195 setTriple(Str + "-" + getVendorName() + "-" + getOSAndEnvironmentName());
198 void Triple::setVendorName(const StringRef &Str) {
199 setTriple(getArchName() + "-" + Str + "-" + getOSAndEnvironmentName());
202 void Triple::setOSName(const StringRef &Str) {
203 if (hasEnvironment())
204 setTriple(getArchName() + "-" + getVendorName() + "-" + Str +
205 "-" + getEnvironmentName());
207 setTriple(getArchName() + "-" + getVendorName() + "-" + Str);
210 void Triple::setEnvironmentName(const StringRef &Str) {
211 setTriple(getArchName() + "-" + getVendorName() + "-" + getOSName() +
215 void Triple::setOSAndEnvironmentName(const StringRef &Str) {
216 setTriple(getArchName() + "-" + getVendorName() + "-" + Str);