Daniel Dunbar | 23e97b0 | 2009-04-01 21:53:23 +0000 | [diff] [blame] | 1 | //===--- Triple.cpp - Target triple helper class --------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "llvm/ADT/Triple.h" |
Jeffrey Yasskin | 0b22873 | 2009-10-06 21:45:26 +0000 | [diff] [blame] | 11 | #include "llvm/ADT/SmallString.h" |
Chandler Carruth | 06accda | 2012-02-12 09:27:38 +0000 | [diff] [blame] | 12 | #include "llvm/ADT/StringSwitch.h" |
Duncan Sands | 5754a45 | 2010-09-16 08:25:48 +0000 | [diff] [blame] | 13 | #include "llvm/ADT/STLExtras.h" |
David Blaikie | 4d6ccb5 | 2012-01-20 21:51:11 +0000 | [diff] [blame] | 14 | #include "llvm/Support/ErrorHandling.h" |
Mikhail Glushenkov | 7074875 | 2009-04-02 01:11:37 +0000 | [diff] [blame] | 15 | #include <cstring> |
Daniel Dunbar | 23e97b0 | 2009-04-01 21:53:23 +0000 | [diff] [blame] | 16 | using namespace llvm; |
| 17 | |
Daniel Dunbar | 23e97b0 | 2009-04-01 21:53:23 +0000 | [diff] [blame] | 18 | const char *Triple::getArchTypeName(ArchType Kind) { |
| 19 | switch (Kind) { |
| 20 | case InvalidArch: return "<invalid>"; |
| 21 | case UnknownArch: return "unknown"; |
Jim Grosbach | e509aa9 | 2010-12-17 02:10:59 +0000 | [diff] [blame] | 22 | |
Daniel Dunbar | 6337f15 | 2009-07-26 04:23:03 +0000 | [diff] [blame] | 23 | case arm: return "arm"; |
| 24 | case cellspu: return "cellspu"; |
Tony Linthicum | b4b5415 | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 25 | case hexagon: return "hexagon"; |
Daniel Dunbar | 6337f15 | 2009-07-26 04:23:03 +0000 | [diff] [blame] | 26 | case mips: return "mips"; |
| 27 | case mipsel: return "mipsel"; |
Akira Hatanaka | 7030368 | 2011-09-20 18:09:37 +0000 | [diff] [blame] | 28 | case mips64: return "mips64"; |
| 29 | case mips64el:return "mips64el"; |
Daniel Dunbar | 6337f15 | 2009-07-26 04:23:03 +0000 | [diff] [blame] | 30 | case msp430: return "msp430"; |
Daniel Dunbar | 8c2f1d7 | 2009-07-26 04:52:45 +0000 | [diff] [blame] | 31 | case ppc64: return "powerpc64"; |
| 32 | case ppc: return "powerpc"; |
Daniel Dunbar | 6337f15 | 2009-07-26 04:23:03 +0000 | [diff] [blame] | 33 | case sparc: return "sparc"; |
Chris Lattner | 87c06d6 | 2010-02-04 06:34:01 +0000 | [diff] [blame] | 34 | case sparcv9: return "sparcv9"; |
Eli Friedman | 74db89e | 2009-08-19 20:46:03 +0000 | [diff] [blame] | 35 | case tce: return "tce"; |
Daniel Dunbar | 6337f15 | 2009-07-26 04:23:03 +0000 | [diff] [blame] | 36 | case thumb: return "thumb"; |
| 37 | case x86: return "i386"; |
| 38 | case x86_64: return "x86_64"; |
Daniel Dunbar | 8c2f1d7 | 2009-07-26 04:52:45 +0000 | [diff] [blame] | 39 | case xcore: return "xcore"; |
Wesley Peck | a70f28c | 2010-02-23 19:15:24 +0000 | [diff] [blame] | 40 | case mblaze: return "mblaze"; |
Justin Holewinski | e1fee48 | 2011-04-20 15:37:17 +0000 | [diff] [blame] | 41 | case ptx32: return "ptx32"; |
| 42 | case ptx64: return "ptx64"; |
Ivan Krasin | 38fb2db | 2011-08-23 16:59:00 +0000 | [diff] [blame] | 43 | case le32: return "le32"; |
Tobias Grosser | 05d7138 | 2011-08-29 15:44:55 +0000 | [diff] [blame] | 44 | case amdil: return "amdil"; |
Daniel Dunbar | 23e97b0 | 2009-04-01 21:53:23 +0000 | [diff] [blame] | 45 | } |
| 46 | |
David Blaikie | 4d6ccb5 | 2012-01-20 21:51:11 +0000 | [diff] [blame] | 47 | llvm_unreachable("Invalid ArchType!"); |
Daniel Dunbar | 23e97b0 | 2009-04-01 21:53:23 +0000 | [diff] [blame] | 48 | } |
| 49 | |
Daniel Dunbar | 688b55b | 2009-08-24 09:53:06 +0000 | [diff] [blame] | 50 | const char *Triple::getArchTypePrefix(ArchType Kind) { |
| 51 | switch (Kind) { |
| 52 | default: |
| 53 | return 0; |
| 54 | |
Daniel Dunbar | 688b55b | 2009-08-24 09:53:06 +0000 | [diff] [blame] | 55 | case arm: |
| 56 | case thumb: return "arm"; |
| 57 | |
Daniel Dunbar | 688b55b | 2009-08-24 09:53:06 +0000 | [diff] [blame] | 58 | case cellspu: return "spu"; |
| 59 | |
| 60 | case ppc64: |
| 61 | case ppc: return "ppc"; |
| 62 | |
Wesley Peck | a70f28c | 2010-02-23 19:15:24 +0000 | [diff] [blame] | 63 | case mblaze: return "mblaze"; |
| 64 | |
Tony Linthicum | b4b5415 | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 65 | case hexagon: return "hexagon"; |
| 66 | |
Chris Lattner | 87c06d6 | 2010-02-04 06:34:01 +0000 | [diff] [blame] | 67 | case sparcv9: |
Daniel Dunbar | 688b55b | 2009-08-24 09:53:06 +0000 | [diff] [blame] | 68 | case sparc: return "sparc"; |
| 69 | |
| 70 | case x86: |
| 71 | case x86_64: return "x86"; |
Nick Lewycky | f7a3c50 | 2010-09-07 18:14:24 +0000 | [diff] [blame] | 72 | |
Daniel Dunbar | 688b55b | 2009-08-24 09:53:06 +0000 | [diff] [blame] | 73 | case xcore: return "xcore"; |
Nick Lewycky | f7a3c50 | 2010-09-07 18:14:24 +0000 | [diff] [blame] | 74 | |
Justin Holewinski | e1fee48 | 2011-04-20 15:37:17 +0000 | [diff] [blame] | 75 | case ptx32: return "ptx"; |
| 76 | case ptx64: return "ptx"; |
Ivan Krasin | 38fb2db | 2011-08-23 16:59:00 +0000 | [diff] [blame] | 77 | case le32: return "le32"; |
Tobias Grosser | 05d7138 | 2011-08-29 15:44:55 +0000 | [diff] [blame] | 78 | case amdil: return "amdil"; |
Daniel Dunbar | 688b55b | 2009-08-24 09:53:06 +0000 | [diff] [blame] | 79 | } |
| 80 | } |
| 81 | |
Daniel Dunbar | 23e97b0 | 2009-04-01 21:53:23 +0000 | [diff] [blame] | 82 | const char *Triple::getVendorTypeName(VendorType Kind) { |
| 83 | switch (Kind) { |
| 84 | case UnknownVendor: return "unknown"; |
| 85 | |
| 86 | case Apple: return "apple"; |
Chris Lattner | 56ce0f4 | 2009-08-14 18:48:13 +0000 | [diff] [blame] | 87 | case PC: return "pc"; |
John Thompson | 6046cff | 2011-03-15 21:51:56 +0000 | [diff] [blame] | 88 | case SCEI: return "scei"; |
Daniel Dunbar | 23e97b0 | 2009-04-01 21:53:23 +0000 | [diff] [blame] | 89 | } |
| 90 | |
David Blaikie | 4d6ccb5 | 2012-01-20 21:51:11 +0000 | [diff] [blame] | 91 | llvm_unreachable("Invalid VendorType!"); |
Daniel Dunbar | 23e97b0 | 2009-04-01 21:53:23 +0000 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | const char *Triple::getOSTypeName(OSType Kind) { |
| 95 | switch (Kind) { |
| 96 | case UnknownOS: return "unknown"; |
| 97 | |
Duncan Sands | 852cd11 | 2009-06-19 14:40:01 +0000 | [diff] [blame] | 98 | case AuroraUX: return "auroraux"; |
Daniel Dunbar | 6337f15 | 2009-07-26 04:23:03 +0000 | [diff] [blame] | 99 | case Cygwin: return "cygwin"; |
Daniel Dunbar | 23e97b0 | 2009-04-01 21:53:23 +0000 | [diff] [blame] | 100 | case Darwin: return "darwin"; |
Daniel Dunbar | 7eaf057 | 2009-05-22 02:24:11 +0000 | [diff] [blame] | 101 | case DragonFly: return "dragonfly"; |
Daniel Dunbar | 23e97b0 | 2009-04-01 21:53:23 +0000 | [diff] [blame] | 102 | case FreeBSD: return "freebsd"; |
Daniel Dunbar | 0dde4c0 | 2011-04-19 20:19:27 +0000 | [diff] [blame] | 103 | case IOS: return "ios"; |
Duncan Sands | 652b48b | 2011-07-26 15:30:04 +0000 | [diff] [blame] | 104 | case KFreeBSD: return "kfreebsd"; |
Daniel Dunbar | 23e97b0 | 2009-04-01 21:53:23 +0000 | [diff] [blame] | 105 | case Linux: return "linux"; |
Edward O'Callaghan | cc9fa81 | 2009-11-19 11:59:00 +0000 | [diff] [blame] | 106 | case Lv2: return "lv2"; |
Daniel Dunbar | 1af3947 | 2011-04-19 23:34:12 +0000 | [diff] [blame] | 107 | case MacOSX: return "macosx"; |
Daniel Dunbar | 6337f15 | 2009-07-26 04:23:03 +0000 | [diff] [blame] | 108 | case MinGW32: return "mingw32"; |
Chris Lattner | b8ac841 | 2009-07-13 20:22:23 +0000 | [diff] [blame] | 109 | case NetBSD: return "netbsd"; |
Duncan Sands | cd1267d | 2009-06-29 13:36:13 +0000 | [diff] [blame] | 110 | case OpenBSD: return "openbsd"; |
Edward O'Callaghan | e0fb75d | 2009-11-15 10:18:17 +0000 | [diff] [blame] | 111 | case Psp: return "psp"; |
Daniel Dunbar | fdb0b7b | 2009-08-18 04:43:27 +0000 | [diff] [blame] | 112 | case Solaris: return "solaris"; |
Daniel Dunbar | 6337f15 | 2009-07-26 04:23:03 +0000 | [diff] [blame] | 113 | case Win32: return "win32"; |
Chris Lattner | a43fc34 | 2009-10-16 02:06:30 +0000 | [diff] [blame] | 114 | case Haiku: return "haiku"; |
Chris Lattner | 29269d0 | 2010-07-07 15:52:27 +0000 | [diff] [blame] | 115 | case Minix: return "minix"; |
Douglas Gregor | 6ced1d1 | 2011-07-01 22:41:06 +0000 | [diff] [blame] | 116 | case RTEMS: return "rtems"; |
Ivan Krasin | fb23462 | 2011-08-18 22:54:21 +0000 | [diff] [blame] | 117 | case NativeClient: return "nacl"; |
Daniel Dunbar | 23e97b0 | 2009-04-01 21:53:23 +0000 | [diff] [blame] | 118 | } |
| 119 | |
David Blaikie | 4d6ccb5 | 2012-01-20 21:51:11 +0000 | [diff] [blame] | 120 | llvm_unreachable("Invalid OSType"); |
Daniel Dunbar | 23e97b0 | 2009-04-01 21:53:23 +0000 | [diff] [blame] | 121 | } |
| 122 | |
Duncan Sands | 5754a45 | 2010-09-16 08:25:48 +0000 | [diff] [blame] | 123 | const char *Triple::getEnvironmentTypeName(EnvironmentType Kind) { |
| 124 | switch (Kind) { |
| 125 | case UnknownEnvironment: return "unknown"; |
Renato Golin | 859f818 | 2011-01-21 18:25:47 +0000 | [diff] [blame] | 126 | case GNU: return "gnu"; |
Rafael Espindola | 8887a0f | 2012-01-18 23:35:29 +0000 | [diff] [blame] | 127 | case GNUEABIHF: return "gnueabihf"; |
Renato Golin | 859f818 | 2011-01-21 18:25:47 +0000 | [diff] [blame] | 128 | case GNUEABI: return "gnueabi"; |
| 129 | case EABI: return "eabi"; |
Evan Cheng | 2bffee2 | 2011-02-01 01:14:13 +0000 | [diff] [blame] | 130 | case MachO: return "macho"; |
Chandler Carruth | fd553c2 | 2012-01-10 19:46:00 +0000 | [diff] [blame] | 131 | case ANDROIDEABI: return "androideabi"; |
Duncan Sands | 5754a45 | 2010-09-16 08:25:48 +0000 | [diff] [blame] | 132 | } |
| 133 | |
David Blaikie | 4d6ccb5 | 2012-01-20 21:51:11 +0000 | [diff] [blame] | 134 | llvm_unreachable("Invalid EnvironmentType!"); |
Duncan Sands | 5754a45 | 2010-09-16 08:25:48 +0000 | [diff] [blame] | 135 | } |
| 136 | |
Daniel Dunbar | 2928c83 | 2009-11-06 10:58:06 +0000 | [diff] [blame] | 137 | Triple::ArchType Triple::getArchTypeForLLVMName(StringRef Name) { |
Chandler Carruth | 06accda | 2012-02-12 09:27:38 +0000 | [diff] [blame] | 138 | return StringSwitch<Triple::ArchType>(Name) |
| 139 | .Case("arm", arm) |
| 140 | .Case("cellspu", cellspu) |
| 141 | .Case("mips", mips) |
| 142 | .Case("mipsel", mipsel) |
| 143 | .Case("mips64", mips64) |
| 144 | .Case("mips64el", mips64el) |
| 145 | .Case("msp430", msp430) |
| 146 | .Case("ppc64", ppc64) |
| 147 | .Case("ppc32", ppc) |
| 148 | .Case("ppc", ppc) |
| 149 | .Case("mblaze", mblaze) |
| 150 | .Case("hexagon", hexagon) |
| 151 | .Case("sparc", sparc) |
| 152 | .Case("sparcv9", sparcv9) |
| 153 | .Case("tce", tce) |
| 154 | .Case("thumb", thumb) |
| 155 | .Case("x86", x86) |
| 156 | .Case("x86-64", x86_64) |
| 157 | .Case("xcore", xcore) |
| 158 | .Case("ptx32", ptx32) |
| 159 | .Case("ptx64", ptx64) |
| 160 | .Case("le32", le32) |
| 161 | .Case("amdil", amdil) |
| 162 | .Default(UnknownArch); |
Daniel Dunbar | 3c2d4bf | 2009-08-03 04:03:51 +0000 | [diff] [blame] | 163 | } |
| 164 | |
Daniel Dunbar | 2928c83 | 2009-11-06 10:58:06 +0000 | [diff] [blame] | 165 | Triple::ArchType Triple::getArchTypeForDarwinArchName(StringRef Str) { |
Daniel Dunbar | baf9b56 | 2009-09-08 23:32:51 +0000 | [diff] [blame] | 166 | // See arch(3) and llvm-gcc's driver-driver.c. We don't implement support for |
| 167 | // archs which Darwin doesn't use. |
| 168 | |
| 169 | // The matching this routine does is fairly pointless, since it is neither the |
| 170 | // complete architecture list, nor a reasonable subset. The problem is that |
| 171 | // historically the driver driver accepts this and also ties its -march= |
| 172 | // handling to the architecture name, so we need to be careful before removing |
| 173 | // support for it. |
| 174 | |
Daniel Dunbar | ed68788 | 2009-09-09 23:01:25 +0000 | [diff] [blame] | 175 | // This code must be kept in sync with Clang's Darwin specific argument |
| 176 | // translation. |
| 177 | |
Chandler Carruth | 06accda | 2012-02-12 09:27:38 +0000 | [diff] [blame] | 178 | return StringSwitch<ArchType>(Str) |
| 179 | .Cases("ppc", "ppc601", "ppc603", "ppc604", "ppc604e", Triple::ppc) |
| 180 | .Cases("ppc750", "ppc7400", "ppc7450", "ppc970", Triple::ppc) |
| 181 | .Case("ppc64", Triple::ppc64) |
| 182 | .Cases("i386", "i486", "i486SX", "i586", "i686", Triple::x86) |
| 183 | .Cases("pentium", "pentpro", "pentIIm3", "pentIIm5", "pentium4", |
| 184 | Triple::x86) |
| 185 | .Case("x86_64", Triple::x86_64) |
| 186 | // This is derived from the driver driver. |
| 187 | .Cases("arm", "armv4t", "armv5", "armv6", Triple::arm) |
| 188 | .Cases("armv7", "armv7f", "armv7k", "armv7s", "xscale", Triple::arm) |
| 189 | .Case("ptx32", Triple::ptx32) |
| 190 | .Case("ptx64", Triple::ptx64) |
| 191 | .Case("amdil", Triple::amdil) |
| 192 | .Default(Triple::UnknownArch); |
Daniel Dunbar | baf9b56 | 2009-09-08 23:32:51 +0000 | [diff] [blame] | 193 | } |
| 194 | |
Duncan Sands | bbdca3f | 2010-03-24 09:05:14 +0000 | [diff] [blame] | 195 | // Returns architecture name that is understood by the target assembler. |
Viktor Kutuzov | 51cdac0 | 2009-11-17 18:48:27 +0000 | [diff] [blame] | 196 | const char *Triple::getArchNameForAssembler() { |
Daniel Dunbar | e1fe09f | 2011-04-19 21:12:05 +0000 | [diff] [blame] | 197 | if (!isOSDarwin() && getVendor() != Triple::Apple) |
Viktor Kutuzov | 51cdac0 | 2009-11-17 18:48:27 +0000 | [diff] [blame] | 198 | return NULL; |
| 199 | |
Chandler Carruth | 06accda | 2012-02-12 09:27:38 +0000 | [diff] [blame] | 200 | return StringSwitch<const char*>(getArchName()) |
| 201 | .Case("i386", "i386") |
| 202 | .Case("x86_64", "x86_64") |
| 203 | .Case("powerpc", "ppc") |
| 204 | .Case("powerpc64", "ppc64") |
| 205 | .Cases("mblaze", "microblaze", "mblaze") |
| 206 | .Case("arm", "arm") |
| 207 | .Cases("armv4t", "thumbv4t", "armv4t") |
| 208 | .Cases("armv5", "armv5e", "thumbv5", "thumbv5e", "armv5") |
| 209 | .Cases("armv6", "thumbv6", "armv6") |
| 210 | .Cases("armv7", "thumbv7", "armv7") |
| 211 | .Case("ptx32", "ptx32") |
| 212 | .Case("ptx64", "ptx64") |
| 213 | .Case("le32", "le32") |
| 214 | .Case("amdil", "amdil") |
| 215 | .Default(NULL); |
Viktor Kutuzov | 51cdac0 | 2009-11-17 18:48:27 +0000 | [diff] [blame] | 216 | } |
| 217 | |
Duncan Sands | 335db22 | 2010-08-12 11:31:39 +0000 | [diff] [blame] | 218 | Triple::ArchType Triple::ParseArch(StringRef ArchName) { |
Chandler Carruth | 06accda | 2012-02-12 09:27:38 +0000 | [diff] [blame] | 219 | return StringSwitch<ArchType>(ArchName) |
| 220 | .Cases("i386", "i486", "i586", "i686", x86) |
| 221 | .Cases("i786", "i886", "i986", x86) // FIXME: Do we need to support these? |
| 222 | .Cases("amd64", "x86_64", x86_64) |
| 223 | .Case("powerpc", ppc) |
| 224 | .Cases("powerpc64", "ppu", ppc64) |
| 225 | .Case("mblaze", mblaze) |
| 226 | .Cases("arm", "xscale", arm) |
Chandler Carruth | 0a85771 | 2012-02-18 04:34:17 +0000 | [diff] [blame] | 227 | // FIXME: It would be good to replace these with explicit names for all the |
| 228 | // various suffixes supported. |
| 229 | .StartsWith("armv", arm) |
Chandler Carruth | 06accda | 2012-02-12 09:27:38 +0000 | [diff] [blame] | 230 | .Case("thumb", thumb) |
Chandler Carruth | 0a85771 | 2012-02-18 04:34:17 +0000 | [diff] [blame] | 231 | .StartsWith("thumbv", thumb) |
Chandler Carruth | 06accda | 2012-02-12 09:27:38 +0000 | [diff] [blame] | 232 | .Cases("spu", "cellspu", cellspu) |
| 233 | .Case("msp430", msp430) |
| 234 | .Cases("mips", "mipseb", "mipsallegrex", mips) |
| 235 | .Cases("mipsel", "mipsallegrexel", "psp", mipsel) |
| 236 | .Cases("mips64", "mips64eb", mips64) |
| 237 | .Case("mips64el", mips64el) |
| 238 | .Case("hexagon", hexagon) |
| 239 | .Case("sparc", sparc) |
| 240 | .Case("sparcv9", sparcv9) |
| 241 | .Case("tce", tce) |
| 242 | .Case("xcore", xcore) |
| 243 | .Case("ptx32", ptx32) |
| 244 | .Case("ptx64", ptx64) |
| 245 | .Case("le32", le32) |
| 246 | .Case("amdil", amdil) |
| 247 | .Default(UnknownArch); |
Duncan Sands | 335db22 | 2010-08-12 11:31:39 +0000 | [diff] [blame] | 248 | } |
Daniel Dunbar | 23e97b0 | 2009-04-01 21:53:23 +0000 | [diff] [blame] | 249 | |
Duncan Sands | 335db22 | 2010-08-12 11:31:39 +0000 | [diff] [blame] | 250 | Triple::VendorType Triple::ParseVendor(StringRef VendorName) { |
Chandler Carruth | 06accda | 2012-02-12 09:27:38 +0000 | [diff] [blame] | 251 | return StringSwitch<VendorType>(VendorName) |
| 252 | .Case("apple", Apple) |
| 253 | .Case("pc", PC) |
| 254 | .Case("scei", SCEI) |
| 255 | .Default(UnknownVendor); |
Duncan Sands | 335db22 | 2010-08-12 11:31:39 +0000 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | Triple::OSType Triple::ParseOS(StringRef OSName) { |
Benjamin Kramer | 61c2c12 | 2012-02-12 10:56:52 +0000 | [diff] [blame] | 259 | return StringSwitch<OSType>(OSName) |
| 260 | .StartsWith("auroraux", AuroraUX) |
| 261 | .StartsWith("cygwin", Cygwin) |
| 262 | .StartsWith("darwin", Darwin) |
| 263 | .StartsWith("dragonfly", DragonFly) |
| 264 | .StartsWith("freebsd", FreeBSD) |
| 265 | .StartsWith("ios", IOS) |
| 266 | .StartsWith("kfreebsd", KFreeBSD) |
| 267 | .StartsWith("linux", Linux) |
| 268 | .StartsWith("lv2", Lv2) |
| 269 | .StartsWith("macosx", MacOSX) |
| 270 | .StartsWith("mingw32", MinGW32) |
| 271 | .StartsWith("netbsd", NetBSD) |
| 272 | .StartsWith("openbsd", OpenBSD) |
| 273 | .StartsWith("psp", Psp) |
| 274 | .StartsWith("solaris", Solaris) |
| 275 | .StartsWith("win32", Win32) |
| 276 | .StartsWith("haiku", Haiku) |
| 277 | .StartsWith("minix", Minix) |
| 278 | .StartsWith("rtems", RTEMS) |
| 279 | .StartsWith("nacl", NativeClient) |
| 280 | .Default(UnknownOS); |
Duncan Sands | 335db22 | 2010-08-12 11:31:39 +0000 | [diff] [blame] | 281 | } |
| 282 | |
Duncan Sands | 5754a45 | 2010-09-16 08:25:48 +0000 | [diff] [blame] | 283 | Triple::EnvironmentType Triple::ParseEnvironment(StringRef EnvironmentName) { |
Benjamin Kramer | 61c2c12 | 2012-02-12 10:56:52 +0000 | [diff] [blame] | 284 | return StringSwitch<EnvironmentType>(EnvironmentName) |
| 285 | .StartsWith("eabi", EABI) |
| 286 | .StartsWith("gnueabihf", GNUEABIHF) |
| 287 | .StartsWith("gnueabi", GNUEABI) |
| 288 | .StartsWith("gnu", GNU) |
| 289 | .StartsWith("macho", MachO) |
| 290 | .StartsWith("androideabi", ANDROIDEABI) |
| 291 | .Default(UnknownEnvironment); |
Duncan Sands | 5754a45 | 2010-09-16 08:25:48 +0000 | [diff] [blame] | 292 | } |
| 293 | |
Duncan Sands | 335db22 | 2010-08-12 11:31:39 +0000 | [diff] [blame] | 294 | void Triple::Parse() const { |
| 295 | assert(!isInitialized() && "Invalid parse call."); |
| 296 | |
| 297 | Arch = ParseArch(getArchName()); |
| 298 | Vendor = ParseVendor(getVendorName()); |
| 299 | OS = ParseOS(getOSName()); |
Duncan Sands | ae200c6 | 2011-02-02 10:08:38 +0000 | [diff] [blame] | 300 | Environment = ParseEnvironment(getEnvironmentName()); |
Daniel Dunbar | 651aa68 | 2009-08-18 19:26:55 +0000 | [diff] [blame] | 301 | |
Daniel Dunbar | 23e97b0 | 2009-04-01 21:53:23 +0000 | [diff] [blame] | 302 | assert(isInitialized() && "Failed to initialize!"); |
| 303 | } |
| 304 | |
Chandler Carruth | cceb8f4 | 2012-02-20 00:02:47 +0000 | [diff] [blame] | 305 | /// \brief Construct a triple from the string representation provided. |
| 306 | /// |
| 307 | /// This doesn't actually parse the string representation eagerly. Instead it |
| 308 | /// stores it, and tracks the fact that it hasn't been parsed. The first time |
| 309 | /// any of the structural queries are made, the string is parsed and the |
| 310 | /// results cached in various members. |
| 311 | Triple::Triple(const Twine &Str) : Data(Str.str()), Arch(InvalidArch) {} |
| 312 | |
| 313 | /// \brief Construct a triple from string representations of the architecture, |
| 314 | /// vendor, and OS. |
| 315 | /// |
| 316 | /// This doesn't actually use these already distinct strings to setup the |
| 317 | /// triple information. Instead it joins them into a canonical form of a triple |
| 318 | /// string, and lazily parses it on use. |
| 319 | Triple::Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr) |
| 320 | : Data((ArchStr + Twine('-') + VendorStr + Twine('-') + OSStr).str()), |
| 321 | Arch(InvalidArch) { |
| 322 | } |
| 323 | |
| 324 | /// \brief Construct a triple from string representations of the architecture, |
| 325 | /// vendor, OS, and environment. |
| 326 | /// |
| 327 | /// This doesn't actually use these already distinct strings to setup the |
| 328 | /// triple information. Instead it joins them into a canonical form of a triple |
| 329 | /// string, and lazily parses it on use. |
| 330 | Triple::Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr, |
| 331 | const Twine &EnvironmentStr) |
| 332 | : Data((ArchStr + Twine('-') + VendorStr + Twine('-') + OSStr + Twine('-') + |
| 333 | EnvironmentStr).str()), |
| 334 | Arch(InvalidArch) { |
| 335 | } |
| 336 | |
Duncan Sands | 335db22 | 2010-08-12 11:31:39 +0000 | [diff] [blame] | 337 | std::string Triple::normalize(StringRef Str) { |
| 338 | // Parse into components. |
| 339 | SmallVector<StringRef, 4> Components; |
| 340 | for (size_t First = 0, Last = 0; Last != StringRef::npos; First = Last + 1) { |
| 341 | Last = Str.find('-', First); |
| 342 | Components.push_back(Str.slice(First, Last)); |
| 343 | } |
| 344 | |
| 345 | // If the first component corresponds to a known architecture, preferentially |
| 346 | // use it for the architecture. If the second component corresponds to a |
| 347 | // known vendor, preferentially use it for the vendor, etc. This avoids silly |
| 348 | // component movement when a component parses as (eg) both a valid arch and a |
| 349 | // valid os. |
| 350 | ArchType Arch = UnknownArch; |
| 351 | if (Components.size() > 0) |
| 352 | Arch = ParseArch(Components[0]); |
| 353 | VendorType Vendor = UnknownVendor; |
| 354 | if (Components.size() > 1) |
| 355 | Vendor = ParseVendor(Components[1]); |
| 356 | OSType OS = UnknownOS; |
| 357 | if (Components.size() > 2) |
| 358 | OS = ParseOS(Components[2]); |
Duncan Sands | 5754a45 | 2010-09-16 08:25:48 +0000 | [diff] [blame] | 359 | EnvironmentType Environment = UnknownEnvironment; |
| 360 | if (Components.size() > 3) |
| 361 | Environment = ParseEnvironment(Components[3]); |
Duncan Sands | 335db22 | 2010-08-12 11:31:39 +0000 | [diff] [blame] | 362 | |
| 363 | // Note which components are already in their final position. These will not |
| 364 | // be moved. |
Duncan Sands | 5754a45 | 2010-09-16 08:25:48 +0000 | [diff] [blame] | 365 | bool Found[4]; |
Duncan Sands | 335db22 | 2010-08-12 11:31:39 +0000 | [diff] [blame] | 366 | Found[0] = Arch != UnknownArch; |
| 367 | Found[1] = Vendor != UnknownVendor; |
| 368 | Found[2] = OS != UnknownOS; |
Duncan Sands | 5754a45 | 2010-09-16 08:25:48 +0000 | [diff] [blame] | 369 | Found[3] = Environment != UnknownEnvironment; |
Duncan Sands | 335db22 | 2010-08-12 11:31:39 +0000 | [diff] [blame] | 370 | |
| 371 | // If they are not there already, permute the components into their canonical |
| 372 | // positions by seeing if they parse as a valid architecture, and if so moving |
| 373 | // the component to the architecture position etc. |
Duncan Sands | 5754a45 | 2010-09-16 08:25:48 +0000 | [diff] [blame] | 374 | for (unsigned Pos = 0; Pos != array_lengthof(Found); ++Pos) { |
Duncan Sands | 335db22 | 2010-08-12 11:31:39 +0000 | [diff] [blame] | 375 | if (Found[Pos]) |
| 376 | continue; // Already in the canonical position. |
| 377 | |
| 378 | for (unsigned Idx = 0; Idx != Components.size(); ++Idx) { |
| 379 | // Do not reparse any components that already matched. |
Duncan Sands | 5754a45 | 2010-09-16 08:25:48 +0000 | [diff] [blame] | 380 | if (Idx < array_lengthof(Found) && Found[Idx]) |
Duncan Sands | 335db22 | 2010-08-12 11:31:39 +0000 | [diff] [blame] | 381 | continue; |
| 382 | |
| 383 | // Does this component parse as valid for the target position? |
| 384 | bool Valid = false; |
| 385 | StringRef Comp = Components[Idx]; |
| 386 | switch (Pos) { |
Craig Topper | 8581438 | 2012-02-07 05:05:23 +0000 | [diff] [blame] | 387 | default: llvm_unreachable("unexpected component type!"); |
Duncan Sands | 335db22 | 2010-08-12 11:31:39 +0000 | [diff] [blame] | 388 | case 0: |
| 389 | Arch = ParseArch(Comp); |
| 390 | Valid = Arch != UnknownArch; |
| 391 | break; |
| 392 | case 1: |
| 393 | Vendor = ParseVendor(Comp); |
| 394 | Valid = Vendor != UnknownVendor; |
| 395 | break; |
| 396 | case 2: |
| 397 | OS = ParseOS(Comp); |
Duncan Sands | ae200c6 | 2011-02-02 10:08:38 +0000 | [diff] [blame] | 398 | Valid = OS != UnknownOS; |
Duncan Sands | 335db22 | 2010-08-12 11:31:39 +0000 | [diff] [blame] | 399 | break; |
Duncan Sands | 5754a45 | 2010-09-16 08:25:48 +0000 | [diff] [blame] | 400 | case 3: |
| 401 | Environment = ParseEnvironment(Comp); |
| 402 | Valid = Environment != UnknownEnvironment; |
| 403 | break; |
Duncan Sands | 335db22 | 2010-08-12 11:31:39 +0000 | [diff] [blame] | 404 | } |
| 405 | if (!Valid) |
| 406 | continue; // Nope, try the next component. |
| 407 | |
| 408 | // Move the component to the target position, pushing any non-fixed |
| 409 | // components that are in the way to the right. This tends to give |
| 410 | // good results in the common cases of a forgotten vendor component |
| 411 | // or a wrongly positioned environment. |
| 412 | if (Pos < Idx) { |
| 413 | // Insert left, pushing the existing components to the right. For |
| 414 | // example, a-b-i386 -> i386-a-b when moving i386 to the front. |
| 415 | StringRef CurrentComponent(""); // The empty component. |
| 416 | // Replace the component we are moving with an empty component. |
| 417 | std::swap(CurrentComponent, Components[Idx]); |
| 418 | // Insert the component being moved at Pos, displacing any existing |
| 419 | // components to the right. |
| 420 | for (unsigned i = Pos; !CurrentComponent.empty(); ++i) { |
| 421 | // Skip over any fixed components. |
Duncan Sands | 5754a45 | 2010-09-16 08:25:48 +0000 | [diff] [blame] | 422 | while (i < array_lengthof(Found) && Found[i]) ++i; |
Duncan Sands | 335db22 | 2010-08-12 11:31:39 +0000 | [diff] [blame] | 423 | // Place the component at the new position, getting the component |
| 424 | // that was at this position - it will be moved right. |
| 425 | std::swap(CurrentComponent, Components[i]); |
| 426 | } |
| 427 | } else if (Pos > Idx) { |
| 428 | // Push right by inserting empty components until the component at Idx |
| 429 | // reaches the target position Pos. For example, pc-a -> -pc-a when |
| 430 | // moving pc to the second position. |
| 431 | do { |
| 432 | // Insert one empty component at Idx. |
| 433 | StringRef CurrentComponent(""); // The empty component. |
Duncan Sands | ae200c6 | 2011-02-02 10:08:38 +0000 | [diff] [blame] | 434 | for (unsigned i = Idx; i < Components.size();) { |
Duncan Sands | 335db22 | 2010-08-12 11:31:39 +0000 | [diff] [blame] | 435 | // Place the component at the new position, getting the component |
| 436 | // that was at this position - it will be moved right. |
| 437 | std::swap(CurrentComponent, Components[i]); |
| 438 | // If it was placed on top of an empty component then we are done. |
| 439 | if (CurrentComponent.empty()) |
| 440 | break; |
Duncan Sands | ae200c6 | 2011-02-02 10:08:38 +0000 | [diff] [blame] | 441 | // Advance to the next component, skipping any fixed components. |
Anders Carlsson | 15ec695 | 2011-02-05 18:19:35 +0000 | [diff] [blame] | 442 | while (++i < array_lengthof(Found) && Found[i]) |
| 443 | ; |
Duncan Sands | 335db22 | 2010-08-12 11:31:39 +0000 | [diff] [blame] | 444 | } |
| 445 | // The last component was pushed off the end - append it. |
| 446 | if (!CurrentComponent.empty()) |
| 447 | Components.push_back(CurrentComponent); |
| 448 | |
| 449 | // Advance Idx to the component's new position. |
Duncan Sands | 5754a45 | 2010-09-16 08:25:48 +0000 | [diff] [blame] | 450 | while (++Idx < array_lengthof(Found) && Found[Idx]) {} |
Duncan Sands | 335db22 | 2010-08-12 11:31:39 +0000 | [diff] [blame] | 451 | } while (Idx < Pos); // Add more until the final position is reached. |
| 452 | } |
| 453 | assert(Pos < Components.size() && Components[Pos] == Comp && |
| 454 | "Component moved wrong!"); |
| 455 | Found[Pos] = true; |
| 456 | break; |
| 457 | } |
| 458 | } |
| 459 | |
| 460 | // Special case logic goes here. At this point Arch, Vendor and OS have the |
| 461 | // correct values for the computed components. |
| 462 | |
| 463 | // Stick the corrected components back together to form the normalized string. |
| 464 | std::string Normalized; |
| 465 | for (unsigned i = 0, e = Components.size(); i != e; ++i) { |
| 466 | if (i) Normalized += '-'; |
| 467 | Normalized += Components[i]; |
| 468 | } |
| 469 | return Normalized; |
| 470 | } |
| 471 | |
Daniel Dunbar | a14d225 | 2009-07-26 03:31:47 +0000 | [diff] [blame] | 472 | StringRef Triple::getArchName() const { |
| 473 | return StringRef(Data).split('-').first; // Isolate first component |
Daniel Dunbar | 23e97b0 | 2009-04-01 21:53:23 +0000 | [diff] [blame] | 474 | } |
| 475 | |
Daniel Dunbar | a14d225 | 2009-07-26 03:31:47 +0000 | [diff] [blame] | 476 | StringRef Triple::getVendorName() const { |
| 477 | StringRef Tmp = StringRef(Data).split('-').second; // Strip first component |
| 478 | return Tmp.split('-').first; // Isolate second component |
Daniel Dunbar | 23e97b0 | 2009-04-01 21:53:23 +0000 | [diff] [blame] | 479 | } |
| 480 | |
Daniel Dunbar | a14d225 | 2009-07-26 03:31:47 +0000 | [diff] [blame] | 481 | StringRef Triple::getOSName() const { |
| 482 | StringRef Tmp = StringRef(Data).split('-').second; // Strip first component |
| 483 | Tmp = Tmp.split('-').second; // Strip second component |
| 484 | return Tmp.split('-').first; // Isolate third component |
Daniel Dunbar | 23e97b0 | 2009-04-01 21:53:23 +0000 | [diff] [blame] | 485 | } |
| 486 | |
Daniel Dunbar | a14d225 | 2009-07-26 03:31:47 +0000 | [diff] [blame] | 487 | StringRef Triple::getEnvironmentName() const { |
| 488 | StringRef Tmp = StringRef(Data).split('-').second; // Strip first component |
| 489 | Tmp = Tmp.split('-').second; // Strip second component |
| 490 | return Tmp.split('-').second; // Strip third component |
Daniel Dunbar | 23e97b0 | 2009-04-01 21:53:23 +0000 | [diff] [blame] | 491 | } |
| 492 | |
Daniel Dunbar | a14d225 | 2009-07-26 03:31:47 +0000 | [diff] [blame] | 493 | StringRef Triple::getOSAndEnvironmentName() const { |
| 494 | StringRef Tmp = StringRef(Data).split('-').second; // Strip first component |
| 495 | return Tmp.split('-').second; // Strip second component |
Daniel Dunbar | 23e97b0 | 2009-04-01 21:53:23 +0000 | [diff] [blame] | 496 | } |
| 497 | |
Chris Lattner | dfc17f7 | 2009-08-12 06:19:40 +0000 | [diff] [blame] | 498 | static unsigned EatNumber(StringRef &Str) { |
| 499 | assert(!Str.empty() && Str[0] >= '0' && Str[0] <= '9' && "Not a number"); |
Daniel Dunbar | 087d6a5 | 2011-04-19 20:24:34 +0000 | [diff] [blame] | 500 | unsigned Result = 0; |
Jim Grosbach | e509aa9 | 2010-12-17 02:10:59 +0000 | [diff] [blame] | 501 | |
Daniel Dunbar | 087d6a5 | 2011-04-19 20:24:34 +0000 | [diff] [blame] | 502 | do { |
| 503 | // Consume the leading digit. |
Chris Lattner | dfc17f7 | 2009-08-12 06:19:40 +0000 | [diff] [blame] | 504 | Result = Result*10 + (Str[0] - '0'); |
Daniel Dunbar | 087d6a5 | 2011-04-19 20:24:34 +0000 | [diff] [blame] | 505 | |
Chris Lattner | dfc17f7 | 2009-08-12 06:19:40 +0000 | [diff] [blame] | 506 | // Eat the digit. |
| 507 | Str = Str.substr(1); |
Daniel Dunbar | 087d6a5 | 2011-04-19 20:24:34 +0000 | [diff] [blame] | 508 | } while (!Str.empty() && Str[0] >= '0' && Str[0] <= '9'); |
Jim Grosbach | e509aa9 | 2010-12-17 02:10:59 +0000 | [diff] [blame] | 509 | |
Chris Lattner | dfc17f7 | 2009-08-12 06:19:40 +0000 | [diff] [blame] | 510 | return Result; |
| 511 | } |
| 512 | |
Daniel Dunbar | 087d6a5 | 2011-04-19 20:24:34 +0000 | [diff] [blame] | 513 | void Triple::getOSVersion(unsigned &Major, unsigned &Minor, |
| 514 | unsigned &Micro) const { |
Chris Lattner | dfc17f7 | 2009-08-12 06:19:40 +0000 | [diff] [blame] | 515 | StringRef OSName = getOSName(); |
Jim Grosbach | e509aa9 | 2010-12-17 02:10:59 +0000 | [diff] [blame] | 516 | |
Daniel Dunbar | 087d6a5 | 2011-04-19 20:24:34 +0000 | [diff] [blame] | 517 | // Assume that the OS portion of the triple starts with the canonical name. |
| 518 | StringRef OSTypeName = getOSTypeName(getOS()); |
| 519 | if (OSName.startswith(OSTypeName)) |
| 520 | OSName = OSName.substr(OSTypeName.size()); |
Jim Grosbach | e509aa9 | 2010-12-17 02:10:59 +0000 | [diff] [blame] | 521 | |
Daniel Dunbar | 087d6a5 | 2011-04-19 20:24:34 +0000 | [diff] [blame] | 522 | // Any unset version defaults to 0. |
| 523 | Major = Minor = Micro = 0; |
Chris Lattner | dfc17f7 | 2009-08-12 06:19:40 +0000 | [diff] [blame] | 524 | |
Daniel Dunbar | 087d6a5 | 2011-04-19 20:24:34 +0000 | [diff] [blame] | 525 | // Parse up to three components. |
| 526 | unsigned *Components[3] = { &Major, &Minor, &Micro }; |
| 527 | for (unsigned i = 0; i != 3; ++i) { |
| 528 | if (OSName.empty() || OSName[0] < '0' || OSName[0] > '9') |
| 529 | break; |
Chris Lattner | dfc17f7 | 2009-08-12 06:19:40 +0000 | [diff] [blame] | 530 | |
Daniel Dunbar | 087d6a5 | 2011-04-19 20:24:34 +0000 | [diff] [blame] | 531 | // Consume the leading number. |
| 532 | *Components[i] = EatNumber(OSName); |
Jim Grosbach | e509aa9 | 2010-12-17 02:10:59 +0000 | [diff] [blame] | 533 | |
Daniel Dunbar | 087d6a5 | 2011-04-19 20:24:34 +0000 | [diff] [blame] | 534 | // Consume the separator, if present. |
| 535 | if (OSName.startswith(".")) |
| 536 | OSName = OSName.substr(1); |
| 537 | } |
Chris Lattner | dfc17f7 | 2009-08-12 06:19:40 +0000 | [diff] [blame] | 538 | } |
| 539 | |
Bob Wilson | bda59fd | 2012-01-31 22:32:29 +0000 | [diff] [blame] | 540 | bool Triple::getMacOSXVersion(unsigned &Major, unsigned &Minor, |
| 541 | unsigned &Micro) const { |
| 542 | getOSVersion(Major, Minor, Micro); |
| 543 | |
| 544 | switch (getOS()) { |
Craig Topper | 8581438 | 2012-02-07 05:05:23 +0000 | [diff] [blame] | 545 | default: llvm_unreachable("unexpected OS for Darwin triple"); |
Bob Wilson | bda59fd | 2012-01-31 22:32:29 +0000 | [diff] [blame] | 546 | case Darwin: |
| 547 | // Default to darwin8, i.e., MacOSX 10.4. |
| 548 | if (Major == 0) |
| 549 | Major = 8; |
| 550 | // Darwin version numbers are skewed from OS X versions. |
| 551 | if (Major < 4) |
| 552 | return false; |
| 553 | Micro = 0; |
| 554 | Minor = Major - 4; |
| 555 | Major = 10; |
| 556 | break; |
| 557 | case MacOSX: |
| 558 | // Default to 10.4. |
| 559 | if (Major == 0) { |
| 560 | Major = 10; |
| 561 | Minor = 4; |
| 562 | } |
| 563 | if (Major != 10) |
| 564 | return false; |
| 565 | break; |
| 566 | case IOS: |
| 567 | // Ignore the version from the triple. This is only handled because the |
| 568 | // the clang driver combines OS X and IOS support into a common Darwin |
| 569 | // toolchain that wants to know the OS X version number even when targeting |
| 570 | // IOS. |
| 571 | Major = 10; |
| 572 | Minor = 4; |
| 573 | Micro = 0; |
| 574 | break; |
| 575 | } |
| 576 | return true; |
| 577 | } |
| 578 | |
Daniel Dunbar | a14d225 | 2009-07-26 03:31:47 +0000 | [diff] [blame] | 579 | void Triple::setTriple(const Twine &Str) { |
| 580 | Data = Str.str(); |
Daniel Dunbar | 23e97b0 | 2009-04-01 21:53:23 +0000 | [diff] [blame] | 581 | Arch = InvalidArch; |
| 582 | } |
| 583 | |
| 584 | void Triple::setArch(ArchType Kind) { |
| 585 | setArchName(getArchTypeName(Kind)); |
| 586 | } |
| 587 | |
| 588 | void Triple::setVendor(VendorType Kind) { |
| 589 | setVendorName(getVendorTypeName(Kind)); |
| 590 | } |
| 591 | |
| 592 | void Triple::setOS(OSType Kind) { |
| 593 | setOSName(getOSTypeName(Kind)); |
| 594 | } |
| 595 | |
Duncan Sands | 5754a45 | 2010-09-16 08:25:48 +0000 | [diff] [blame] | 596 | void Triple::setEnvironment(EnvironmentType Kind) { |
| 597 | setEnvironmentName(getEnvironmentTypeName(Kind)); |
| 598 | } |
| 599 | |
Daniel Dunbar | 2928c83 | 2009-11-06 10:58:06 +0000 | [diff] [blame] | 600 | void Triple::setArchName(StringRef Str) { |
Jeffrey Yasskin | 0b22873 | 2009-10-06 21:45:26 +0000 | [diff] [blame] | 601 | // Work around a miscompilation bug for Twines in gcc 4.0.3. |
| 602 | SmallString<64> Triple; |
| 603 | Triple += Str; |
| 604 | Triple += "-"; |
| 605 | Triple += getVendorName(); |
| 606 | Triple += "-"; |
| 607 | Triple += getOSAndEnvironmentName(); |
| 608 | setTriple(Triple.str()); |
Daniel Dunbar | 23e97b0 | 2009-04-01 21:53:23 +0000 | [diff] [blame] | 609 | } |
| 610 | |
Daniel Dunbar | 2928c83 | 2009-11-06 10:58:06 +0000 | [diff] [blame] | 611 | void Triple::setVendorName(StringRef Str) { |
Daniel Dunbar | 23e97b0 | 2009-04-01 21:53:23 +0000 | [diff] [blame] | 612 | setTriple(getArchName() + "-" + Str + "-" + getOSAndEnvironmentName()); |
| 613 | } |
| 614 | |
Daniel Dunbar | 2928c83 | 2009-11-06 10:58:06 +0000 | [diff] [blame] | 615 | void Triple::setOSName(StringRef Str) { |
Daniel Dunbar | 23e97b0 | 2009-04-01 21:53:23 +0000 | [diff] [blame] | 616 | if (hasEnvironment()) |
| 617 | setTriple(getArchName() + "-" + getVendorName() + "-" + Str + |
| 618 | "-" + getEnvironmentName()); |
| 619 | else |
| 620 | setTriple(getArchName() + "-" + getVendorName() + "-" + Str); |
| 621 | } |
| 622 | |
Daniel Dunbar | 2928c83 | 2009-11-06 10:58:06 +0000 | [diff] [blame] | 623 | void Triple::setEnvironmentName(StringRef Str) { |
| 624 | setTriple(getArchName() + "-" + getVendorName() + "-" + getOSName() + |
Daniel Dunbar | 23e97b0 | 2009-04-01 21:53:23 +0000 | [diff] [blame] | 625 | "-" + Str); |
| 626 | } |
| 627 | |
Daniel Dunbar | 2928c83 | 2009-11-06 10:58:06 +0000 | [diff] [blame] | 628 | void Triple::setOSAndEnvironmentName(StringRef Str) { |
Daniel Dunbar | 23e97b0 | 2009-04-01 21:53:23 +0000 | [diff] [blame] | 629 | setTriple(getArchName() + "-" + getVendorName() + "-" + Str); |
| 630 | } |
Chandler Carruth | 6f72ac4 | 2012-01-31 04:52:32 +0000 | [diff] [blame] | 631 | |
| 632 | static unsigned getArchPointerBitWidth(llvm::Triple::ArchType Arch) { |
| 633 | switch (Arch) { |
| 634 | case llvm::Triple::UnknownArch: |
| 635 | case llvm::Triple::InvalidArch: |
| 636 | return 0; |
| 637 | |
| 638 | case llvm::Triple::msp430: |
| 639 | return 16; |
| 640 | |
| 641 | case llvm::Triple::amdil: |
| 642 | case llvm::Triple::arm: |
| 643 | case llvm::Triple::cellspu: |
| 644 | case llvm::Triple::hexagon: |
| 645 | case llvm::Triple::le32: |
| 646 | case llvm::Triple::mblaze: |
| 647 | case llvm::Triple::mips: |
| 648 | case llvm::Triple::mipsel: |
| 649 | case llvm::Triple::ppc: |
| 650 | case llvm::Triple::ptx32: |
| 651 | case llvm::Triple::sparc: |
| 652 | case llvm::Triple::tce: |
| 653 | case llvm::Triple::thumb: |
| 654 | case llvm::Triple::x86: |
| 655 | case llvm::Triple::xcore: |
| 656 | return 32; |
| 657 | |
| 658 | case llvm::Triple::mips64: |
| 659 | case llvm::Triple::mips64el: |
| 660 | case llvm::Triple::ppc64: |
| 661 | case llvm::Triple::ptx64: |
| 662 | case llvm::Triple::sparcv9: |
| 663 | case llvm::Triple::x86_64: |
| 664 | return 64; |
| 665 | } |
| 666 | llvm_unreachable("Invalid architecture value"); |
| 667 | } |
| 668 | |
| 669 | bool Triple::isArch64Bit() const { |
| 670 | return getArchPointerBitWidth(getArch()) == 64; |
| 671 | } |
| 672 | |
| 673 | bool Triple::isArch32Bit() const { |
| 674 | return getArchPointerBitWidth(getArch()) == 32; |
| 675 | } |
| 676 | |
| 677 | bool Triple::isArch16Bit() const { |
| 678 | return getArchPointerBitWidth(getArch()) == 16; |
| 679 | } |
Chandler Carruth | 7d5a289 | 2012-02-06 20:46:33 +0000 | [diff] [blame] | 680 | |
| 681 | Triple Triple::get32BitArchVariant() const { |
| 682 | Triple T(*this); |
| 683 | switch (getArch()) { |
| 684 | case Triple::UnknownArch: |
| 685 | case Triple::InvalidArch: |
| 686 | case Triple::msp430: |
| 687 | T.setArch(UnknownArch); |
| 688 | break; |
| 689 | |
| 690 | case Triple::amdil: |
| 691 | case Triple::arm: |
| 692 | case Triple::cellspu: |
| 693 | case Triple::hexagon: |
| 694 | case Triple::le32: |
| 695 | case Triple::mblaze: |
| 696 | case Triple::mips: |
| 697 | case Triple::mipsel: |
| 698 | case Triple::ppc: |
| 699 | case Triple::ptx32: |
| 700 | case Triple::sparc: |
| 701 | case Triple::tce: |
| 702 | case Triple::thumb: |
| 703 | case Triple::x86: |
| 704 | case Triple::xcore: |
| 705 | // Already 32-bit. |
| 706 | break; |
| 707 | |
| 708 | case Triple::mips64: T.setArch(Triple::mips); break; |
| 709 | case Triple::mips64el: T.setArch(Triple::mipsel); break; |
| 710 | case Triple::ppc64: T.setArch(Triple::ppc); break; |
| 711 | case Triple::ptx64: T.setArch(Triple::ptx32); break; |
| 712 | case Triple::sparcv9: T.setArch(Triple::sparc); break; |
| 713 | case Triple::x86_64: T.setArch(Triple::x86); break; |
| 714 | } |
| 715 | return T; |
| 716 | } |
| 717 | |
| 718 | Triple Triple::get64BitArchVariant() const { |
| 719 | Triple T(*this); |
| 720 | switch (getArch()) { |
| 721 | case Triple::InvalidArch: |
| 722 | case Triple::UnknownArch: |
| 723 | case Triple::amdil: |
| 724 | case Triple::arm: |
| 725 | case Triple::cellspu: |
| 726 | case Triple::hexagon: |
| 727 | case Triple::le32: |
| 728 | case Triple::mblaze: |
| 729 | case Triple::msp430: |
| 730 | case Triple::tce: |
| 731 | case Triple::thumb: |
| 732 | case Triple::xcore: |
| 733 | T.setArch(UnknownArch); |
| 734 | break; |
| 735 | |
| 736 | case Triple::mips64: |
| 737 | case Triple::mips64el: |
| 738 | case Triple::ppc64: |
| 739 | case Triple::ptx64: |
| 740 | case Triple::sparcv9: |
| 741 | case Triple::x86_64: |
| 742 | // Already 64-bit. |
| 743 | break; |
| 744 | |
| 745 | case Triple::mips: T.setArch(Triple::mips64); break; |
| 746 | case Triple::mipsel: T.setArch(Triple::mips64el); break; |
| 747 | case Triple::ppc: T.setArch(Triple::ppc64); break; |
| 748 | case Triple::ptx32: T.setArch(Triple::ptx64); break; |
| 749 | case Triple::sparc: T.setArch(Triple::sparcv9); break; |
| 750 | case Triple::x86: T.setArch(Triple::x86_64); break; |
| 751 | } |
| 752 | return T; |
| 753 | } |