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 sparc: return "sparc";
31 case systemz: return "s390x";
32 case thumb: return "thumb";
33 case x86: return "i386";
34 case x86_64: return "x86_64";
35 case ppc: return "powerpc";
36 case ppc64: return "powerpc64";
42 const char *Triple::getVendorTypeName(VendorType Kind) {
44 case UnknownVendor: return "unknown";
46 case Apple: return "apple";
53 const char *Triple::getOSTypeName(OSType Kind) {
55 case UnknownOS: return "unknown";
57 case AuroraUX: return "auroraux";
58 case Cygwin: return "cygwin";
59 case Darwin: return "darwin";
60 case DragonFly: return "dragonfly";
61 case FreeBSD: return "freebsd";
62 case Linux: return "linux";
63 case MinGW32: return "mingw32";
64 case NetBSD: return "netbsd";
65 case OpenBSD: return "openbsd";
66 case Win32: return "win32";
74 void Triple::Parse() const {
75 assert(!isInitialized() && "Invalid parse call.");
77 StringRef ArchName = getArchName();
78 if (ArchName.size() == 4 && ArchName[0] == 'i' &&
79 ArchName[2] == '8' && ArchName[3] == '6' &&
80 ArchName[1] - '3' < 6) // i[3-9]86
82 else if (ArchName == "amd64" || ArchName == "x86_64")
84 else if (ArchName == "powerpc")
86 else if (ArchName == "powerpc64")
88 else if (ArchName == "arm" ||
89 ArchName.startswith("armv"))
91 else if (ArchName == "thumb" ||
92 ArchName.startswith("thumbv"))
94 else if (ArchName.startswith("alpha"))
96 else if (ArchName == "spu" || ArchName == "cellspu")
98 else if (ArchName == "msp430")
100 else if (ArchName == "mips" || ArchName == "mipsallegrex")
102 else if (ArchName == "mipsel" || ArchName == "mipsallegrexel" ||
105 else if (ArchName == "sparc")
107 else if (ArchName == "s390x")
112 StringRef VendorName = getVendorName();
113 if (VendorName == "apple")
115 else if (VendorName == "pc")
118 Vendor = UnknownVendor;
120 StringRef OSName = getOSName();
121 if (OSName.startswith("auroraux"))
123 else if (OSName.startswith("cygwin"))
125 else if (OSName.startswith("darwin"))
127 else if (OSName.startswith("dragonfly"))
129 else if (OSName.startswith("freebsd"))
131 else if (OSName.startswith("linux"))
133 else if (OSName.startswith("mingw32"))
135 else if (OSName.startswith("netbsd"))
137 else if (OSName.startswith("openbsd"))
139 else if (OSName.startswith("win32"))
144 assert(isInitialized() && "Failed to initialize!");
147 StringRef Triple::getArchName() const {
148 return StringRef(Data).split('-').first; // Isolate first component
151 StringRef Triple::getVendorName() const {
152 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
153 return Tmp.split('-').first; // Isolate second component
156 StringRef Triple::getOSName() const {
157 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
158 Tmp = Tmp.split('-').second; // Strip second component
159 return Tmp.split('-').first; // Isolate third component
162 StringRef Triple::getEnvironmentName() const {
163 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
164 Tmp = Tmp.split('-').second; // Strip second component
165 return Tmp.split('-').second; // Strip third component
168 StringRef Triple::getOSAndEnvironmentName() const {
169 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
170 return Tmp.split('-').second; // Strip second component
173 void Triple::setTriple(const Twine &Str) {
178 void Triple::setArch(ArchType Kind) {
179 setArchName(getArchTypeName(Kind));
182 void Triple::setVendor(VendorType Kind) {
183 setVendorName(getVendorTypeName(Kind));
186 void Triple::setOS(OSType Kind) {
187 setOSName(getOSTypeName(Kind));
190 void Triple::setArchName(const StringRef &Str) {
191 setTriple(Str + "-" + getVendorName() + "-" + getOSAndEnvironmentName());
194 void Triple::setVendorName(const StringRef &Str) {
195 setTriple(getArchName() + "-" + Str + "-" + getOSAndEnvironmentName());
198 void Triple::setOSName(const StringRef &Str) {
199 if (hasEnvironment())
200 setTriple(getArchName() + "-" + getVendorName() + "-" + Str +
201 "-" + getEnvironmentName());
203 setTriple(getArchName() + "-" + getVendorName() + "-" + Str);
206 void Triple::setEnvironmentName(const StringRef &Str) {
207 setTriple(getArchName() + "-" + getVendorName() + "-" + getOSName() +
211 void Triple::setOSAndEnvironmentName(const StringRef &Str) {
212 setTriple(getArchName() + "-" + getVendorName() + "-" + Str);