LLVM  3.7.0
Triple.cpp
Go to the documentation of this file.
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"
11 #include "llvm/ADT/STLExtras.h"
12 #include "llvm/ADT/SmallString.h"
13 #include "llvm/ADT/StringSwitch.h"
16 #include "llvm/Support/Host.h"
17 #include <cstring>
18 using namespace llvm;
19 
21  switch (Kind) {
22  case UnknownArch: return "unknown";
23 
24  case aarch64: return "aarch64";
25  case aarch64_be: return "aarch64_be";
26  case arm: return "arm";
27  case armeb: return "armeb";
28  case bpfel: return "bpfel";
29  case bpfeb: return "bpfeb";
30  case hexagon: return "hexagon";
31  case mips: return "mips";
32  case mipsel: return "mipsel";
33  case mips64: return "mips64";
34  case mips64el: return "mips64el";
35  case msp430: return "msp430";
36  case ppc64: return "powerpc64";
37  case ppc64le: return "powerpc64le";
38  case ppc: return "powerpc";
39  case r600: return "r600";
40  case amdgcn: return "amdgcn";
41  case sparc: return "sparc";
42  case sparcv9: return "sparcv9";
43  case sparcel: return "sparcel";
44  case systemz: return "s390x";
45  case tce: return "tce";
46  case thumb: return "thumb";
47  case thumbeb: return "thumbeb";
48  case x86: return "i386";
49  case x86_64: return "x86_64";
50  case xcore: return "xcore";
51  case nvptx: return "nvptx";
52  case nvptx64: return "nvptx64";
53  case le32: return "le32";
54  case le64: return "le64";
55  case amdil: return "amdil";
56  case amdil64: return "amdil64";
57  case hsail: return "hsail";
58  case hsail64: return "hsail64";
59  case spir: return "spir";
60  case spir64: return "spir64";
61  case kalimba: return "kalimba";
62  case shave: return "shave";
63  case wasm32: return "wasm32";
64  case wasm64: return "wasm64";
65  }
66 
67  llvm_unreachable("Invalid ArchType!");
68 }
69 
71  switch (Kind) {
72  default:
73  return nullptr;
74 
75  case aarch64:
76  case aarch64_be: return "aarch64";
77 
78  case arm:
79  case armeb:
80  case thumb:
81  case thumbeb: return "arm";
82 
83  case ppc64:
84  case ppc64le:
85  case ppc: return "ppc";
86 
87  case mips:
88  case mipsel:
89  case mips64:
90  case mips64el: return "mips";
91 
92  case hexagon: return "hexagon";
93 
94  case amdgcn:
95  case r600: return "amdgpu";
96 
97  case bpfel:
98  case bpfeb: return "bpf";
99 
100  case sparcv9:
101  case sparcel:
102  case sparc: return "sparc";
103 
104  case systemz: return "s390";
105 
106  case x86:
107  case x86_64: return "x86";
108 
109  case xcore: return "xcore";
110 
111  case nvptx: return "nvptx";
112  case nvptx64: return "nvptx";
113 
114  case le32: return "le32";
115  case le64: return "le64";
116 
117  case amdil:
118  case amdil64: return "amdil";
119 
120  case hsail:
121  case hsail64: return "hsail";
122 
123  case spir:
124  case spir64: return "spir";
125  case kalimba: return "kalimba";
126  case shave: return "shave";
127  case wasm32: return "wasm32";
128  case wasm64: return "wasm64";
129  }
130 }
131 
133  switch (Kind) {
134  case UnknownVendor: return "unknown";
135 
136  case Apple: return "apple";
137  case PC: return "pc";
138  case SCEI: return "scei";
139  case BGP: return "bgp";
140  case BGQ: return "bgq";
141  case Freescale: return "fsl";
142  case IBM: return "ibm";
143  case ImaginationTechnologies: return "img";
144  case MipsTechnologies: return "mti";
145  case NVIDIA: return "nvidia";
146  case CSR: return "csr";
147  }
148 
149  llvm_unreachable("Invalid VendorType!");
150 }
151 
153  switch (Kind) {
154  case UnknownOS: return "unknown";
155 
156  case CloudABI: return "cloudabi";
157  case Darwin: return "darwin";
158  case DragonFly: return "dragonfly";
159  case FreeBSD: return "freebsd";
160  case IOS: return "ios";
161  case KFreeBSD: return "kfreebsd";
162  case Linux: return "linux";
163  case Lv2: return "lv2";
164  case MacOSX: return "macosx";
165  case NetBSD: return "netbsd";
166  case OpenBSD: return "openbsd";
167  case Solaris: return "solaris";
168  case Win32: return "windows";
169  case Haiku: return "haiku";
170  case Minix: return "minix";
171  case RTEMS: return "rtems";
172  case NaCl: return "nacl";
173  case CNK: return "cnk";
174  case Bitrig: return "bitrig";
175  case AIX: return "aix";
176  case CUDA: return "cuda";
177  case NVCL: return "nvcl";
178  case AMDHSA: return "amdhsa";
179  case PS4: return "ps4";
180  }
181 
182  llvm_unreachable("Invalid OSType");
183 }
184 
186  switch (Kind) {
187  case UnknownEnvironment: return "unknown";
188  case GNU: return "gnu";
189  case GNUEABIHF: return "gnueabihf";
190  case GNUEABI: return "gnueabi";
191  case GNUX32: return "gnux32";
192  case CODE16: return "code16";
193  case EABI: return "eabi";
194  case EABIHF: return "eabihf";
195  case Android: return "android";
196  case MSVC: return "msvc";
197  case Itanium: return "itanium";
198  case Cygnus: return "cygnus";
199  }
200 
201  llvm_unreachable("Invalid EnvironmentType!");
202 }
203 
205  if (ArchName.equals("bpf")) {
207  return Triple::bpfel;
208  else
209  return Triple::bpfeb;
210  } else if (ArchName.equals("bpf_be") || ArchName.equals("bpfeb")) {
211  return Triple::bpfeb;
212  } else if (ArchName.equals("bpf_le") || ArchName.equals("bpfel")) {
213  return Triple::bpfel;
214  } else {
215  return Triple::UnknownArch;
216  }
217 }
218 
220  Triple::ArchType BPFArch(parseBPFArch(Name));
222  .Case("aarch64", aarch64)
223  .Case("aarch64_be", aarch64_be)
224  .Case("arm64", aarch64) // "arm64" is an alias for "aarch64"
225  .Case("arm", arm)
226  .Case("armeb", armeb)
227  .StartsWith("bpf", BPFArch)
228  .Case("mips", mips)
229  .Case("mipsel", mipsel)
230  .Case("mips64", mips64)
231  .Case("mips64el", mips64el)
232  .Case("msp430", msp430)
233  .Case("ppc64", ppc64)
234  .Case("ppc32", ppc)
235  .Case("ppc", ppc)
236  .Case("ppc64le", ppc64le)
237  .Case("r600", r600)
238  .Case("amdgcn", amdgcn)
239  .Case("hexagon", hexagon)
240  .Case("sparc", sparc)
241  .Case("sparcel", sparcel)
242  .Case("sparcv9", sparcv9)
243  .Case("systemz", systemz)
244  .Case("tce", tce)
245  .Case("thumb", thumb)
246  .Case("thumbeb", thumbeb)
247  .Case("x86", x86)
248  .Case("x86-64", x86_64)
249  .Case("xcore", xcore)
250  .Case("nvptx", nvptx)
251  .Case("nvptx64", nvptx64)
252  .Case("le32", le32)
253  .Case("le64", le64)
254  .Case("amdil", amdil)
255  .Case("amdil64", amdil64)
256  .Case("hsail", hsail)
257  .Case("hsail64", hsail64)
258  .Case("spir", spir)
259  .Case("spir64", spir64)
260  .Case("kalimba", kalimba)
261  .Case("shave", shave)
262  .Case("wasm32", wasm32)
263  .Case("wasm64", wasm64)
265 }
266 
268  unsigned ISA = ARMTargetParser::parseArchISA(ArchName);
269  unsigned ENDIAN = ARMTargetParser::parseArchEndian(ArchName);
270 
272  switch (ENDIAN) {
273  case ARM::EK_LITTLE: {
274  switch (ISA) {
275  case ARM::IK_ARM:
276  arch = Triple::arm;
277  break;
278  case ARM::IK_THUMB:
279  arch = Triple::thumb;
280  break;
281  case ARM::IK_AARCH64:
282  arch = Triple::aarch64;
283  break;
284  }
285  break;
286  }
287  case ARM::EK_BIG: {
288  switch (ISA) {
289  case ARM::IK_ARM:
290  arch = Triple::armeb;
291  break;
292  case ARM::IK_THUMB:
293  arch = Triple::thumbeb;
294  break;
295  case ARM::IK_AARCH64:
296  arch = Triple::aarch64_be;
297  break;
298  }
299  break;
300  }
301  }
302 
303  ArchName = ARMTargetParser::getCanonicalArchName(ArchName);
304  if (ArchName.empty())
305  return Triple::UnknownArch;
306 
307  // Thumb only exists in v4+
308  if (ISA == ARM::IK_THUMB &&
309  (ArchName.startswith("v2") || ArchName.startswith("v3")))
310  return Triple::UnknownArch;
311 
312  // Thumb only for v6m
313  unsigned Profile = ARMTargetParser::parseArchProfile(ArchName);
314  unsigned Version = ARMTargetParser::parseArchVersion(ArchName);
315  if (Profile == ARM::PK_M && Version == 6) {
316  if (ENDIAN == ARM::EK_BIG)
317  return Triple::thumbeb;
318  else
319  return Triple::thumb;
320  }
321 
322  return arch;
323 }
324 
326  Triple::ArchType ARMArch(parseARMArch(ArchName));
327  Triple::ArchType BPFArch(parseBPFArch(ArchName));
328 
329  return StringSwitch<Triple::ArchType>(ArchName)
330  .Cases("i386", "i486", "i586", "i686", Triple::x86)
331  // FIXME: Do we need to support these?
332  .Cases("i786", "i886", "i986", Triple::x86)
333  .Cases("amd64", "x86_64", "x86_64h", Triple::x86_64)
334  .Case("powerpc", Triple::ppc)
335  .Cases("powerpc64", "ppu", Triple::ppc64)
336  .Case("powerpc64le", Triple::ppc64le)
337  .Case("xscale", Triple::arm)
338  .Case("xscaleeb", Triple::armeb)
339  .StartsWith("arm", ARMArch)
340  .StartsWith("thumb", ARMArch)
341  .StartsWith("aarch64", ARMArch)
342  .Case("msp430", Triple::msp430)
343  .Cases("mips", "mipseb", "mipsallegrex", Triple::mips)
344  .Cases("mipsel", "mipsallegrexel", Triple::mipsel)
345  .Cases("mips64", "mips64eb", Triple::mips64)
346  .Case("mips64el", Triple::mips64el)
347  .Case("r600", Triple::r600)
348  .Case("amdgcn", Triple::amdgcn)
349  .StartsWith("bpf", BPFArch)
350  .Case("hexagon", Triple::hexagon)
351  .Case("s390x", Triple::systemz)
352  .Case("sparc", Triple::sparc)
353  .Case("sparcel", Triple::sparcel)
354  .Cases("sparcv9", "sparc64", Triple::sparcv9)
355  .Case("tce", Triple::tce)
356  .Case("xcore", Triple::xcore)
357  .Case("nvptx", Triple::nvptx)
358  .Case("nvptx64", Triple::nvptx64)
359  .Case("le32", Triple::le32)
360  .Case("le64", Triple::le64)
361  .Case("amdil", Triple::amdil)
362  .Case("amdil64", Triple::amdil64)
363  .Case("hsail", Triple::hsail)
364  .Case("hsail64", Triple::hsail64)
365  .Case("spir", Triple::spir)
366  .Case("spir64", Triple::spir64)
367  .StartsWith("kalimba", Triple::kalimba)
368  .Case("shave", Triple::shave)
369  .Case("wasm32", Triple::wasm32)
370  .Case("wasm64", Triple::wasm64)
372 }
373 
375  return StringSwitch<Triple::VendorType>(VendorName)
376  .Case("apple", Triple::Apple)
377  .Case("pc", Triple::PC)
378  .Case("scei", Triple::SCEI)
379  .Case("bgp", Triple::BGP)
380  .Case("bgq", Triple::BGQ)
381  .Case("fsl", Triple::Freescale)
382  .Case("ibm", Triple::IBM)
385  .Case("nvidia", Triple::NVIDIA)
386  .Case("csr", Triple::CSR)
388 }
389 
391  return StringSwitch<Triple::OSType>(OSName)
392  .StartsWith("cloudabi", Triple::CloudABI)
393  .StartsWith("darwin", Triple::Darwin)
394  .StartsWith("dragonfly", Triple::DragonFly)
395  .StartsWith("freebsd", Triple::FreeBSD)
396  .StartsWith("ios", Triple::IOS)
397  .StartsWith("kfreebsd", Triple::KFreeBSD)
398  .StartsWith("linux", Triple::Linux)
399  .StartsWith("lv2", Triple::Lv2)
400  .StartsWith("macosx", Triple::MacOSX)
401  .StartsWith("netbsd", Triple::NetBSD)
402  .StartsWith("openbsd", Triple::OpenBSD)
403  .StartsWith("solaris", Triple::Solaris)
404  .StartsWith("win32", Triple::Win32)
405  .StartsWith("windows", Triple::Win32)
406  .StartsWith("haiku", Triple::Haiku)
407  .StartsWith("minix", Triple::Minix)
408  .StartsWith("rtems", Triple::RTEMS)
409  .StartsWith("nacl", Triple::NaCl)
410  .StartsWith("cnk", Triple::CNK)
411  .StartsWith("bitrig", Triple::Bitrig)
412  .StartsWith("aix", Triple::AIX)
413  .StartsWith("cuda", Triple::CUDA)
414  .StartsWith("nvcl", Triple::NVCL)
415  .StartsWith("amdhsa", Triple::AMDHSA)
416  .StartsWith("ps4", Triple::PS4)
418 }
419 
421  return StringSwitch<Triple::EnvironmentType>(EnvironmentName)
422  .StartsWith("eabihf", Triple::EABIHF)
423  .StartsWith("eabi", Triple::EABI)
424  .StartsWith("gnueabihf", Triple::GNUEABIHF)
425  .StartsWith("gnueabi", Triple::GNUEABI)
426  .StartsWith("gnux32", Triple::GNUX32)
427  .StartsWith("code16", Triple::CODE16)
428  .StartsWith("gnu", Triple::GNU)
429  .StartsWith("android", Triple::Android)
430  .StartsWith("msvc", Triple::MSVC)
431  .StartsWith("itanium", Triple::Itanium)
432  .StartsWith("cygnus", Triple::Cygnus)
434 }
435 
437  return StringSwitch<Triple::ObjectFormatType>(EnvironmentName)
438  .EndsWith("coff", Triple::COFF)
439  .EndsWith("elf", Triple::ELF)
440  .EndsWith("macho", Triple::MachO)
442 }
443 
445  StringRef ARMSubArch = ARMTargetParser::getCanonicalArchName(SubArchName);
446 
447  // For now, this is the small part. Early return.
448  if (ARMSubArch.empty())
449  return StringSwitch<Triple::SubArchType>(SubArchName)
450  .EndsWith("kalimba3", Triple::KalimbaSubArch_v3)
451  .EndsWith("kalimba4", Triple::KalimbaSubArch_v4)
452  .EndsWith("kalimba5", Triple::KalimbaSubArch_v5)
454 
455  // ARM sub arch.
456  switch(ARMTargetParser::parseArch(ARMSubArch)) {
457  case ARM::AK_ARMV4:
458  return Triple::NoSubArch;
459  case ARM::AK_ARMV4T:
460  return Triple::ARMSubArch_v4t;
461  case ARM::AK_ARMV5:
462  case ARM::AK_ARMV5T:
463  case ARM::AK_ARMV5E:
464  return Triple::ARMSubArch_v5;
465  case ARM::AK_ARMV5TE:
466  case ARM::AK_IWMMXT:
467  case ARM::AK_IWMMXT2:
468  case ARM::AK_XSCALE:
469  case ARM::AK_ARMV5TEJ:
471  case ARM::AK_ARMV6:
472  case ARM::AK_ARMV6J:
473  case ARM::AK_ARMV6Z:
474  return Triple::ARMSubArch_v6;
475  case ARM::AK_ARMV6K:
476  case ARM::AK_ARMV6ZK:
477  case ARM::AK_ARMV6HL:
478  return Triple::ARMSubArch_v6k;
479  case ARM::AK_ARMV6T2:
481  case ARM::AK_ARMV6M:
482  case ARM::AK_ARMV6SM:
483  return Triple::ARMSubArch_v6m;
484  case ARM::AK_ARMV7:
485  case ARM::AK_ARMV7A:
486  case ARM::AK_ARMV7R:
487  case ARM::AK_ARMV7L:
488  case ARM::AK_ARMV7HL:
489  return Triple::ARMSubArch_v7;
490  case ARM::AK_ARMV7M:
491  return Triple::ARMSubArch_v7m;
492  case ARM::AK_ARMV7S:
493  return Triple::ARMSubArch_v7s;
494  case ARM::AK_ARMV7EM:
496  case ARM::AK_ARMV8A:
497  return Triple::ARMSubArch_v8;
498  case ARM::AK_ARMV8_1A:
500  default:
501  return Triple::NoSubArch;
502  }
503 }
504 
506  switch (Kind) {
507  case Triple::UnknownObjectFormat: return "";
508  case Triple::COFF: return "coff";
509  case Triple::ELF: return "elf";
510  case Triple::MachO: return "macho";
511  }
512  llvm_unreachable("unknown object format type");
513 }
514 
516  switch (T.getArch()) {
517  default:
518  break;
519  case Triple::hexagon:
520  case Triple::mips:
521  case Triple::mipsel:
522  case Triple::mips64:
523  case Triple::mips64el:
524  case Triple::r600:
525  case Triple::amdgcn:
526  case Triple::sparc:
527  case Triple::sparcv9:
528  case Triple::systemz:
529  case Triple::xcore:
530  case Triple::ppc64le:
531  return Triple::ELF;
532 
533  case Triple::ppc:
534  case Triple::ppc64:
535  if (T.isOSDarwin())
536  return Triple::MachO;
537  return Triple::ELF;
538  }
539 
540  if (T.isOSDarwin())
541  return Triple::MachO;
542  else if (T.isOSWindows())
543  return Triple::COFF;
544  return Triple::ELF;
545 }
546 
547 /// \brief Construct a triple from the string representation provided.
548 ///
549 /// This stores the string representation and parses the various pieces into
550 /// enum members.
552  : Data(Str.str()),
553  Arch(parseArch(getArchName())),
554  SubArch(parseSubArch(getArchName())),
555  Vendor(parseVendor(getVendorName())),
556  OS(parseOS(getOSName())),
557  Environment(parseEnvironment(getEnvironmentName())),
558  ObjectFormat(parseFormat(getEnvironmentName())) {
559  if (ObjectFormat == Triple::UnknownObjectFormat)
560  ObjectFormat = getDefaultFormat(*this);
561 }
562 
563 /// \brief Construct a triple from string representations of the architecture,
564 /// vendor, and OS.
565 ///
566 /// This joins each argument into a canonical string representation and parses
567 /// them into enum members. It leaves the environment unknown and omits it from
568 /// the string representation.
569 Triple::Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr)
570  : Data((ArchStr + Twine('-') + VendorStr + Twine('-') + OSStr).str()),
571  Arch(parseArch(ArchStr.str())),
572  SubArch(parseSubArch(ArchStr.str())),
573  Vendor(parseVendor(VendorStr.str())),
574  OS(parseOS(OSStr.str())),
575  Environment(), ObjectFormat(Triple::UnknownObjectFormat) {
576  ObjectFormat = getDefaultFormat(*this);
577 }
578 
579 /// \brief Construct a triple from string representations of the architecture,
580 /// vendor, OS, and environment.
581 ///
582 /// This joins each argument into a canonical string representation and parses
583 /// them into enum members.
584 Triple::Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr,
585  const Twine &EnvironmentStr)
586  : Data((ArchStr + Twine('-') + VendorStr + Twine('-') + OSStr + Twine('-') +
587  EnvironmentStr).str()),
588  Arch(parseArch(ArchStr.str())),
589  SubArch(parseSubArch(ArchStr.str())),
590  Vendor(parseVendor(VendorStr.str())),
591  OS(parseOS(OSStr.str())),
592  Environment(parseEnvironment(EnvironmentStr.str())),
593  ObjectFormat(parseFormat(EnvironmentStr.str())) {
594  if (ObjectFormat == Triple::UnknownObjectFormat)
595  ObjectFormat = getDefaultFormat(*this);
596 }
597 
598 std::string Triple::normalize(StringRef Str) {
599  bool IsMinGW32 = false;
600  bool IsCygwin = false;
601 
602  // Parse into components.
603  SmallVector<StringRef, 4> Components;
604  Str.split(Components, "-");
605 
606  // If the first component corresponds to a known architecture, preferentially
607  // use it for the architecture. If the second component corresponds to a
608  // known vendor, preferentially use it for the vendor, etc. This avoids silly
609  // component movement when a component parses as (eg) both a valid arch and a
610  // valid os.
611  ArchType Arch = UnknownArch;
612  if (Components.size() > 0)
613  Arch = parseArch(Components[0]);
614  VendorType Vendor = UnknownVendor;
615  if (Components.size() > 1)
616  Vendor = parseVendor(Components[1]);
617  OSType OS = UnknownOS;
618  if (Components.size() > 2) {
619  OS = parseOS(Components[2]);
620  IsCygwin = Components[2].startswith("cygwin");
621  IsMinGW32 = Components[2].startswith("mingw");
622  }
623  EnvironmentType Environment = UnknownEnvironment;
624  if (Components.size() > 3)
625  Environment = parseEnvironment(Components[3]);
626  ObjectFormatType ObjectFormat = UnknownObjectFormat;
627  if (Components.size() > 4)
628  ObjectFormat = parseFormat(Components[4]);
629 
630  // Note which components are already in their final position. These will not
631  // be moved.
632  bool Found[4];
633  Found[0] = Arch != UnknownArch;
634  Found[1] = Vendor != UnknownVendor;
635  Found[2] = OS != UnknownOS;
636  Found[3] = Environment != UnknownEnvironment;
637 
638  // If they are not there already, permute the components into their canonical
639  // positions by seeing if they parse as a valid architecture, and if so moving
640  // the component to the architecture position etc.
641  for (unsigned Pos = 0; Pos != array_lengthof(Found); ++Pos) {
642  if (Found[Pos])
643  continue; // Already in the canonical position.
644 
645  for (unsigned Idx = 0; Idx != Components.size(); ++Idx) {
646  // Do not reparse any components that already matched.
647  if (Idx < array_lengthof(Found) && Found[Idx])
648  continue;
649 
650  // Does this component parse as valid for the target position?
651  bool Valid = false;
652  StringRef Comp = Components[Idx];
653  switch (Pos) {
654  default: llvm_unreachable("unexpected component type!");
655  case 0:
656  Arch = parseArch(Comp);
657  Valid = Arch != UnknownArch;
658  break;
659  case 1:
660  Vendor = parseVendor(Comp);
661  Valid = Vendor != UnknownVendor;
662  break;
663  case 2:
664  OS = parseOS(Comp);
665  IsCygwin = Comp.startswith("cygwin");
666  IsMinGW32 = Comp.startswith("mingw");
667  Valid = OS != UnknownOS || IsCygwin || IsMinGW32;
668  break;
669  case 3:
670  Environment = parseEnvironment(Comp);
671  Valid = Environment != UnknownEnvironment;
672  if (!Valid) {
673  ObjectFormat = parseFormat(Comp);
674  Valid = ObjectFormat != UnknownObjectFormat;
675  }
676  break;
677  }
678  if (!Valid)
679  continue; // Nope, try the next component.
680 
681  // Move the component to the target position, pushing any non-fixed
682  // components that are in the way to the right. This tends to give
683  // good results in the common cases of a forgotten vendor component
684  // or a wrongly positioned environment.
685  if (Pos < Idx) {
686  // Insert left, pushing the existing components to the right. For
687  // example, a-b-i386 -> i386-a-b when moving i386 to the front.
688  StringRef CurrentComponent(""); // The empty component.
689  // Replace the component we are moving with an empty component.
690  std::swap(CurrentComponent, Components[Idx]);
691  // Insert the component being moved at Pos, displacing any existing
692  // components to the right.
693  for (unsigned i = Pos; !CurrentComponent.empty(); ++i) {
694  // Skip over any fixed components.
695  while (i < array_lengthof(Found) && Found[i])
696  ++i;
697  // Place the component at the new position, getting the component
698  // that was at this position - it will be moved right.
699  std::swap(CurrentComponent, Components[i]);
700  }
701  } else if (Pos > Idx) {
702  // Push right by inserting empty components until the component at Idx
703  // reaches the target position Pos. For example, pc-a -> -pc-a when
704  // moving pc to the second position.
705  do {
706  // Insert one empty component at Idx.
707  StringRef CurrentComponent(""); // The empty component.
708  for (unsigned i = Idx; i < Components.size();) {
709  // Place the component at the new position, getting the component
710  // that was at this position - it will be moved right.
711  std::swap(CurrentComponent, Components[i]);
712  // If it was placed on top of an empty component then we are done.
713  if (CurrentComponent.empty())
714  break;
715  // Advance to the next component, skipping any fixed components.
716  while (++i < array_lengthof(Found) && Found[i])
717  ;
718  }
719  // The last component was pushed off the end - append it.
720  if (!CurrentComponent.empty())
721  Components.push_back(CurrentComponent);
722 
723  // Advance Idx to the component's new position.
724  while (++Idx < array_lengthof(Found) && Found[Idx])
725  ;
726  } while (Idx < Pos); // Add more until the final position is reached.
727  }
728  assert(Pos < Components.size() && Components[Pos] == Comp &&
729  "Component moved wrong!");
730  Found[Pos] = true;
731  break;
732  }
733  }
734 
735  // Special case logic goes here. At this point Arch, Vendor and OS have the
736  // correct values for the computed components.
737  std::string NormalizedEnvironment;
738  if (Environment == Triple::Android && Components[3].startswith("androideabi")) {
739  StringRef AndroidVersion = Components[3].drop_front(strlen("androideabi"));
740  if (AndroidVersion.empty()) {
741  Components[3] = "android";
742  } else {
743  NormalizedEnvironment = Twine("android", AndroidVersion).str();
744  Components[3] = NormalizedEnvironment;
745  }
746  }
747 
748  if (OS == Triple::Win32) {
749  Components.resize(4);
750  Components[2] = "windows";
751  if (Environment == UnknownEnvironment) {
752  if (ObjectFormat == UnknownObjectFormat || ObjectFormat == Triple::COFF)
753  Components[3] = "msvc";
754  else
755  Components[3] = getObjectFormatTypeName(ObjectFormat);
756  }
757  } else if (IsMinGW32) {
758  Components.resize(4);
759  Components[2] = "windows";
760  Components[3] = "gnu";
761  } else if (IsCygwin) {
762  Components.resize(4);
763  Components[2] = "windows";
764  Components[3] = "cygnus";
765  }
766  if (IsMinGW32 || IsCygwin ||
767  (OS == Triple::Win32 && Environment != UnknownEnvironment)) {
768  if (ObjectFormat != UnknownObjectFormat && ObjectFormat != Triple::COFF) {
769  Components.resize(5);
770  Components[4] = getObjectFormatTypeName(ObjectFormat);
771  }
772  }
773 
774  // Stick the corrected components back together to form the normalized string.
775  std::string Normalized;
776  for (unsigned i = 0, e = Components.size(); i != e; ++i) {
777  if (i) Normalized += '-';
778  Normalized += Components[i];
779  }
780  return Normalized;
781 }
782 
784  return StringRef(Data).split('-').first; // Isolate first component
785 }
786 
788  StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
789  return Tmp.split('-').first; // Isolate second component
790 }
791 
793  StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
794  Tmp = Tmp.split('-').second; // Strip second component
795  return Tmp.split('-').first; // Isolate third component
796 }
797 
799  StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
800  Tmp = Tmp.split('-').second; // Strip second component
801  return Tmp.split('-').second; // Strip third component
802 }
803 
805  StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
806  return Tmp.split('-').second; // Strip second component
807 }
808 
809 static unsigned EatNumber(StringRef &Str) {
810  assert(!Str.empty() && Str[0] >= '0' && Str[0] <= '9' && "Not a number");
811  unsigned Result = 0;
812 
813  do {
814  // Consume the leading digit.
815  Result = Result*10 + (Str[0] - '0');
816 
817  // Eat the digit.
818  Str = Str.substr(1);
819  } while (!Str.empty() && Str[0] >= '0' && Str[0] <= '9');
820 
821  return Result;
822 }
823 
824 static void parseVersionFromName(StringRef Name, unsigned &Major,
825  unsigned &Minor, unsigned &Micro) {
826  // Any unset version defaults to 0.
827  Major = Minor = Micro = 0;
828 
829  // Parse up to three components.
830  unsigned *Components[3] = {&Major, &Minor, &Micro};
831  for (unsigned i = 0; i != 3; ++i) {
832  if (Name.empty() || Name[0] < '0' || Name[0] > '9')
833  break;
834 
835  // Consume the leading number.
836  *Components[i] = EatNumber(Name);
837 
838  // Consume the separator, if present.
839  if (Name.startswith("."))
840  Name = Name.substr(1);
841  }
842 }
843 
844 void Triple::getEnvironmentVersion(unsigned &Major, unsigned &Minor,
845  unsigned &Micro) const {
846  StringRef EnvironmentName = getEnvironmentName();
847  StringRef EnvironmentTypeName = getEnvironmentTypeName(getEnvironment());
848  if (EnvironmentName.startswith(EnvironmentTypeName))
849  EnvironmentName = EnvironmentName.substr(EnvironmentTypeName.size());
850 
851  parseVersionFromName(EnvironmentName, Major, Minor, Micro);
852 }
853 
854 void Triple::getOSVersion(unsigned &Major, unsigned &Minor,
855  unsigned &Micro) const {
856  StringRef OSName = getOSName();
857  // Assume that the OS portion of the triple starts with the canonical name.
858  StringRef OSTypeName = getOSTypeName(getOS());
859  if (OSName.startswith(OSTypeName))
860  OSName = OSName.substr(OSTypeName.size());
861 
862  parseVersionFromName(OSName, Major, Minor, Micro);
863 }
864 
865 bool Triple::getMacOSXVersion(unsigned &Major, unsigned &Minor,
866  unsigned &Micro) const {
867  getOSVersion(Major, Minor, Micro);
868 
869  switch (getOS()) {
870  default: llvm_unreachable("unexpected OS for Darwin triple");
871  case Darwin:
872  // Default to darwin8, i.e., MacOSX 10.4.
873  if (Major == 0)
874  Major = 8;
875  // Darwin version numbers are skewed from OS X versions.
876  if (Major < 4)
877  return false;
878  Micro = 0;
879  Minor = Major - 4;
880  Major = 10;
881  break;
882  case MacOSX:
883  // Default to 10.4.
884  if (Major == 0) {
885  Major = 10;
886  Minor = 4;
887  }
888  if (Major != 10)
889  return false;
890  break;
891  case IOS:
892  // Ignore the version from the triple. This is only handled because the
893  // the clang driver combines OS X and IOS support into a common Darwin
894  // toolchain that wants to know the OS X version number even when targeting
895  // IOS.
896  Major = 10;
897  Minor = 4;
898  Micro = 0;
899  break;
900  }
901  return true;
902 }
903 
904 void Triple::getiOSVersion(unsigned &Major, unsigned &Minor,
905  unsigned &Micro) const {
906  switch (getOS()) {
907  default: llvm_unreachable("unexpected OS for Darwin triple");
908  case Darwin:
909  case MacOSX:
910  // Ignore the version from the triple. This is only handled because the
911  // the clang driver combines OS X and IOS support into a common Darwin
912  // toolchain that wants to know the iOS version number even when targeting
913  // OS X.
914  Major = 5;
915  Minor = 0;
916  Micro = 0;
917  break;
918  case IOS:
919  getOSVersion(Major, Minor, Micro);
920  // Default to 5.0 (or 7.0 for arm64).
921  if (Major == 0)
922  Major = (getArch() == aarch64) ? 7 : 5;
923  break;
924  }
925 }
926 
927 void Triple::setTriple(const Twine &Str) {
928  *this = Triple(Str);
929 }
930 
933 }
934 
937 }
938 
940  setOSName(getOSTypeName(Kind));
941 }
942 
944  if (ObjectFormat == getDefaultFormat(*this))
946 
948  getObjectFormatTypeName(ObjectFormat)).str());
949 }
950 
952  if (Environment == UnknownEnvironment)
954 
955  setEnvironmentName((getEnvironmentTypeName(Environment) + Twine("-") +
956  getObjectFormatTypeName(Kind)).str());
957 }
958 
960  // Work around a miscompilation bug for Twines in gcc 4.0.3.
962  Triple += Str;
963  Triple += "-";
964  Triple += getVendorName();
965  Triple += "-";
966  Triple += getOSAndEnvironmentName();
967  setTriple(Triple);
968 }
969 
971  setTriple(getArchName() + "-" + Str + "-" + getOSAndEnvironmentName());
972 }
973 
975  if (hasEnvironment())
976  setTriple(getArchName() + "-" + getVendorName() + "-" + Str +
977  "-" + getEnvironmentName());
978  else
979  setTriple(getArchName() + "-" + getVendorName() + "-" + Str);
980 }
981 
983  setTriple(getArchName() + "-" + getVendorName() + "-" + getOSName() +
984  "-" + Str);
985 }
986 
988  setTriple(getArchName() + "-" + getVendorName() + "-" + Str);
989 }
990 
992  switch (Arch) {
994  return 0;
995 
997  return 16;
998 
999  case llvm::Triple::arm:
1000  case llvm::Triple::armeb:
1001  case llvm::Triple::hexagon:
1002  case llvm::Triple::le32:
1003  case llvm::Triple::mips:
1004  case llvm::Triple::mipsel:
1005  case llvm::Triple::nvptx:
1006  case llvm::Triple::ppc:
1007  case llvm::Triple::r600:
1008  case llvm::Triple::sparc:
1009  case llvm::Triple::sparcel:
1010  case llvm::Triple::tce:
1011  case llvm::Triple::thumb:
1012  case llvm::Triple::thumbeb:
1013  case llvm::Triple::x86:
1014  case llvm::Triple::xcore:
1015  case llvm::Triple::amdil:
1016  case llvm::Triple::hsail:
1017  case llvm::Triple::spir:
1018  case llvm::Triple::kalimba:
1019  case llvm::Triple::shave:
1020  case llvm::Triple::wasm32:
1021  return 32;
1022 
1023  case llvm::Triple::aarch64:
1025  case llvm::Triple::amdgcn:
1026  case llvm::Triple::bpfel:
1027  case llvm::Triple::bpfeb:
1028  case llvm::Triple::le64:
1029  case llvm::Triple::mips64:
1031  case llvm::Triple::nvptx64:
1032  case llvm::Triple::ppc64:
1033  case llvm::Triple::ppc64le:
1034  case llvm::Triple::sparcv9:
1035  case llvm::Triple::systemz:
1036  case llvm::Triple::x86_64:
1037  case llvm::Triple::amdil64:
1038  case llvm::Triple::hsail64:
1039  case llvm::Triple::spir64:
1040  case llvm::Triple::wasm64:
1041  return 64;
1042  }
1043  llvm_unreachable("Invalid architecture value");
1044 }
1045 
1046 bool Triple::isArch64Bit() const {
1047  return getArchPointerBitWidth(getArch()) == 64;
1048 }
1049 
1050 bool Triple::isArch32Bit() const {
1051  return getArchPointerBitWidth(getArch()) == 32;
1052 }
1053 
1054 bool Triple::isArch16Bit() const {
1055  return getArchPointerBitWidth(getArch()) == 16;
1056 }
1057 
1059  Triple T(*this);
1060  switch (getArch()) {
1061  case Triple::UnknownArch:
1062  case Triple::aarch64:
1063  case Triple::aarch64_be:
1064  case Triple::amdgcn:
1065  case Triple::bpfel:
1066  case Triple::bpfeb:
1067  case Triple::msp430:
1068  case Triple::systemz:
1069  case Triple::ppc64le:
1070  T.setArch(UnknownArch);
1071  break;
1072 
1073  case Triple::amdil:
1074  case Triple::hsail:
1075  case Triple::spir:
1076  case Triple::arm:
1077  case Triple::armeb:
1078  case Triple::hexagon:
1079  case Triple::kalimba:
1080  case Triple::le32:
1081  case Triple::mips:
1082  case Triple::mipsel:
1083  case Triple::nvptx:
1084  case Triple::ppc:
1085  case Triple::r600:
1086  case Triple::sparc:
1087  case Triple::sparcel:
1088  case Triple::tce:
1089  case Triple::thumb:
1090  case Triple::thumbeb:
1091  case Triple::x86:
1092  case Triple::xcore:
1093  case Triple::shave:
1094  case Triple::wasm32:
1095  // Already 32-bit.
1096  break;
1097 
1098  case Triple::le64: T.setArch(Triple::le32); break;
1099  case Triple::mips64: T.setArch(Triple::mips); break;
1100  case Triple::mips64el: T.setArch(Triple::mipsel); break;
1101  case Triple::nvptx64: T.setArch(Triple::nvptx); break;
1102  case Triple::ppc64: T.setArch(Triple::ppc); break;
1103  case Triple::sparcv9: T.setArch(Triple::sparc); break;
1104  case Triple::x86_64: T.setArch(Triple::x86); break;
1105  case Triple::amdil64: T.setArch(Triple::amdil); break;
1106  case Triple::hsail64: T.setArch(Triple::hsail); break;
1107  case Triple::spir64: T.setArch(Triple::spir); break;
1108  case Triple::wasm64: T.setArch(Triple::wasm32); break;
1109  }
1110  return T;
1111 }
1112 
1114  Triple T(*this);
1115  switch (getArch()) {
1116  case Triple::UnknownArch:
1117  case Triple::arm:
1118  case Triple::armeb:
1119  case Triple::hexagon:
1120  case Triple::kalimba:
1121  case Triple::msp430:
1122  case Triple::r600:
1123  case Triple::tce:
1124  case Triple::thumb:
1125  case Triple::thumbeb:
1126  case Triple::xcore:
1127  case Triple::sparcel:
1128  case Triple::shave:
1129  T.setArch(UnknownArch);
1130  break;
1131 
1132  case Triple::aarch64:
1133  case Triple::aarch64_be:
1134  case Triple::bpfel:
1135  case Triple::bpfeb:
1136  case Triple::le64:
1137  case Triple::amdil64:
1138  case Triple::amdgcn:
1139  case Triple::hsail64:
1140  case Triple::spir64:
1141  case Triple::mips64:
1142  case Triple::mips64el:
1143  case Triple::nvptx64:
1144  case Triple::ppc64:
1145  case Triple::ppc64le:
1146  case Triple::sparcv9:
1147  case Triple::systemz:
1148  case Triple::x86_64:
1149  case Triple::wasm64:
1150  // Already 64-bit.
1151  break;
1152 
1153  case Triple::le32: T.setArch(Triple::le64); break;
1154  case Triple::mips: T.setArch(Triple::mips64); break;
1155  case Triple::mipsel: T.setArch(Triple::mips64el); break;
1156  case Triple::nvptx: T.setArch(Triple::nvptx64); break;
1157  case Triple::ppc: T.setArch(Triple::ppc64); break;
1158  case Triple::sparc: T.setArch(Triple::sparcv9); break;
1159  case Triple::x86: T.setArch(Triple::x86_64); break;
1160  case Triple::amdil: T.setArch(Triple::amdil64); break;
1161  case Triple::hsail: T.setArch(Triple::hsail64); break;
1162  case Triple::spir: T.setArch(Triple::spir64); break;
1163  case Triple::wasm32: T.setArch(Triple::wasm64); break;
1164  }
1165  return T;
1166 }
1167 
1169  Triple T(*this);
1170  switch (getArch()) {
1171  case Triple::UnknownArch:
1172  case Triple::amdgcn:
1173  case Triple::amdil64:
1174  case Triple::amdil:
1175  case Triple::hexagon:
1176  case Triple::hsail64:
1177  case Triple::hsail:
1178  case Triple::kalimba:
1179  case Triple::le32:
1180  case Triple::le64:
1181  case Triple::msp430:
1182  case Triple::nvptx64:
1183  case Triple::nvptx:
1184  case Triple::r600:
1185  case Triple::shave:
1186  case Triple::spir64:
1187  case Triple::spir:
1188  case Triple::wasm32:
1189  case Triple::wasm64:
1190  case Triple::x86:
1191  case Triple::x86_64:
1192  case Triple::xcore:
1193 
1194  // ARM is intentionally unsupported here, changing the architecture would
1195  // drop any arch suffixes.
1196  case Triple::arm:
1197  case Triple::thumb:
1198  T.setArch(UnknownArch);
1199  break;
1200 
1201  case Triple::aarch64_be:
1202  case Triple::armeb:
1203  case Triple::bpfeb:
1204  case Triple::mips64:
1205  case Triple::mips:
1206  case Triple::ppc64:
1207  case Triple::ppc:
1208  case Triple::sparc:
1209  case Triple::sparcv9:
1210  case Triple::systemz:
1211  case Triple::tce:
1212  case Triple::thumbeb:
1213  // Already big endian.
1214  break;
1215 
1216  case Triple::aarch64: T.setArch(Triple::aarch64_be); break;
1217  case Triple::bpfel: T.setArch(Triple::bpfeb); break;
1218  case Triple::mips64el:T.setArch(Triple::mips64); break;
1219  case Triple::mipsel: T.setArch(Triple::mips); break;
1220  case Triple::ppc64le: T.setArch(Triple::ppc64); break;
1221  case Triple::sparcel: T.setArch(Triple::sparc); break;
1222  }
1223  return T;
1224 }
1225 
1227  Triple T(*this);
1228  switch (getArch()) {
1229  case Triple::UnknownArch:
1230  case Triple::ppc:
1231  case Triple::sparcv9:
1232  case Triple::systemz:
1233  case Triple::tce:
1234 
1235  // ARM is intentionally unsupported here, changing the architecture would
1236  // drop any arch suffixes.
1237  case Triple::armeb:
1238  case Triple::thumbeb:
1239  T.setArch(UnknownArch);
1240  break;
1241 
1242  case Triple::aarch64:
1243  case Triple::amdgcn:
1244  case Triple::amdil64:
1245  case Triple::amdil:
1246  case Triple::arm:
1247  case Triple::bpfel:
1248  case Triple::hexagon:
1249  case Triple::hsail64:
1250  case Triple::hsail:
1251  case Triple::kalimba:
1252  case Triple::le32:
1253  case Triple::le64:
1254  case Triple::mips64el:
1255  case Triple::mipsel:
1256  case Triple::msp430:
1257  case Triple::nvptx64:
1258  case Triple::nvptx:
1259  case Triple::ppc64le:
1260  case Triple::r600:
1261  case Triple::shave:
1262  case Triple::sparcel:
1263  case Triple::spir64:
1264  case Triple::spir:
1265  case Triple::thumb:
1266  case Triple::wasm32:
1267  case Triple::wasm64:
1268  case Triple::x86:
1269  case Triple::x86_64:
1270  case Triple::xcore:
1271  // Already little endian.
1272  break;
1273 
1274  case Triple::aarch64_be: T.setArch(Triple::aarch64); break;
1275  case Triple::bpfeb: T.setArch(Triple::bpfel); break;
1276  case Triple::mips64: T.setArch(Triple::mips64el); break;
1277  case Triple::mips: T.setArch(Triple::mipsel); break;
1278  case Triple::ppc64: T.setArch(Triple::ppc64le); break;
1279  case Triple::sparc: T.setArch(Triple::sparcel); break;
1280  }
1281  return T;
1282 }
1283 
1285  if (MArch.empty())
1286  MArch = getArchName();
1288 
1289  // Some defaults are forced.
1290  switch (getOS()) {
1291  case llvm::Triple::FreeBSD:
1292  case llvm::Triple::NetBSD:
1293  if (!MArch.empty() && MArch == "v6")
1294  return "arm1176jzf-s";
1295  break;
1296  case llvm::Triple::Win32:
1297  // FIXME: this is invalid for WindowsCE
1298  return "cortex-a9";
1299  default:
1300  break;
1301  }
1302 
1303  if (MArch.empty())
1304  return nullptr;
1305 
1306  const char *CPU = ARMTargetParser::getDefaultCPU(MArch);
1307  if (CPU)
1308  return CPU;
1309 
1310  // If no specific architecture version is requested, return the minimum CPU
1311  // required by the OS and environment.
1312  switch (getOS()) {
1313  case llvm::Triple::NetBSD:
1314  switch (getEnvironment()) {
1316  case llvm::Triple::GNUEABI:
1317  case llvm::Triple::EABIHF:
1318  case llvm::Triple::EABI:
1319  return "arm926ej-s";
1320  default:
1321  return "strongarm";
1322  }
1323  case llvm::Triple::NaCl:
1324  return "cortex-a8";
1325  default:
1326  switch (getEnvironment()) {
1327  case llvm::Triple::EABIHF:
1329  return "arm1176jzf-s";
1330  default:
1331  return "arm7tdmi";
1332  }
1333  }
1334 
1335  llvm_unreachable("invalid arch name");
1336 }
OSType getOS() const
getOS - Get the parsed operating system type of this triple.
Definition: Triple.h:251
static const char * getObjectFormatTypeName(Triple::ObjectFormatType Kind)
Definition: Triple.cpp:505
size_t size() const
size - Get the string size.
Definition: StringRef.h:113
static void Found()
static Triple::ArchType parseBPFArch(StringRef ArchName)
Definition: Triple.cpp:204
void setVendor(VendorType Kind)
setVendor - Set the vendor (second) component of the triple to a known type.
Definition: Triple.cpp:935
static unsigned parseArch(StringRef Arch)
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
Definition: StringRef.h:450
StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
Definition: StringRef.h:405
static Triple::ArchType parseARMArch(StringRef ArchName)
Definition: Triple.cpp:267
const std::string & str() const
Definition: Triple.h:306
void setOS(OSType Kind)
setOS - Set the operating system (third) component of the triple to a known type. ...
Definition: Triple.cpp:939
void setEnvironment(EnvironmentType Kind)
setEnvironment - Set the environment (fourth) component of the triple to a known type.
Definition: Triple.cpp:943
StringSwitch & Case(const char(&S)[N], const T &Value)
Definition: StringSwitch.h:55
llvm::Triple getBigEndianArchVariant() const
Form a triple with a big endian variant of the current architecture.
Definition: Triple.cpp:1168
bool isOSWindows() const
Tests whether the OS is Windows.
Definition: Triple.h:464
static unsigned getArchPointerBitWidth(llvm::Triple::ArchType Arch)
Definition: Triple.cpp:991
std::string str() const
Return the twine contents as a std::string.
Definition: Twine.cpp:16
static unsigned EatNumber(StringRef &Str)
Definition: Triple.cpp:809
StringSwitch & EndsWith(const char(&S)[N], const T &Value)
Definition: StringSwitch.h:65
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:79
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:98
void setVendorName(StringRef Str)
setVendorName - Set the vendor (second) component of the triple by name.
Definition: Triple.cpp:970
static Triple::OSType parseOS(StringRef OSName)
Definition: Triple.cpp:390
Triple()
Default constructor is the same as an empty string and leaves all triple fields unknown.
Definition: Triple.h:210
bool isArch64Bit() const
Test whether the architecture is 64-bit.
Definition: Triple.cpp:1046
static const bool IsLittleEndianHost
Definition: Host.h:38
#define T
StringRef getOSAndEnvironmentName() const
getOSAndEnvironmentName - Get the operating system and optional environment components as a single st...
Definition: Triple.cpp:804
ArchType getArch() const
getArch - Get the parsed architecture type of this triple.
Definition: Triple.h:242
LLVM_CONSTEXPR size_t array_lengthof(T(&)[N])
Find the length of an array.
Definition: STLExtras.h:247
llvm::Triple get32BitArchVariant() const
Form a triple with a 32-bit variant of the current architecture.
Definition: Triple.cpp:1058
StringRef getEnvironmentName() const
getEnvironmentName - Get the optional environment (fourth) component of the triple, or "" if empty.
Definition: Triple.cpp:798
A switch()-like statement whose cases are string literals.
Definition: StringSwitch.h:42
void setObjectFormat(ObjectFormatType Kind)
setObjectFormat - Set the object file format
Definition: Triple.cpp:951
static Triple::ObjectFormatType parseFormat(StringRef EnvironmentName)
Definition: Triple.cpp:436
void setEnvironmentName(StringRef Str)
setEnvironmentName - Set the optional environment (fourth) component of the triple by name...
Definition: Triple.cpp:982
static const char * getDefaultCPU(StringRef Arch)
static const char * getVendorTypeName(VendorType Kind)
getVendorTypeName - Get the canonical name for the Kind vendor.
Definition: Triple.cpp:132
void setTriple(const Twine &Str)
setTriple - Set all components to the new triple Str.
Definition: Triple.cpp:927
static unsigned parseArchVersion(StringRef Arch)
void setArchName(StringRef Str)
setArchName - Set the architecture (first) component of the triple by name.
Definition: Triple.cpp:959
static Triple::ObjectFormatType getDefaultFormat(const Triple &T)
Definition: Triple.cpp:515
std::string normalize() const
Return the normalized form of this triple's string.
Definition: Triple.h:235
void getiOSVersion(unsigned &Major, unsigned &Minor, unsigned &Micro) const
getiOSVersion - Parse the version number as with getOSVersion.
Definition: Triple.cpp:904
static Triple::SubArchType parseSubArch(StringRef SubArchName)
Definition: Triple.cpp:444
void setOSName(StringRef Str)
setOSName - Set the operating system (third) component of the triple by name.
Definition: Triple.cpp:974
static const char * getArchTypePrefix(ArchType Kind)
getArchTypePrefix - Get the "prefix" canonical name for the Kind architecture.
Definition: Triple.cpp:70
static Triple::VendorType parseVendor(StringRef VendorName)
Definition: Triple.cpp:374
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
bool isOSDarwin() const
isOSDarwin - Is this a "Darwin" OS (OS X or iOS).
Definition: Triple.h:404
static const char * getEnvironmentTypeName(EnvironmentType Kind)
getEnvironmentTypeName - Get the canonical name for the Kind environment.
Definition: Triple.cpp:185
StringSwitch & StartsWith(const char(&S)[N], const T &Value)
Definition: StringSwitch.h:75
bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition: StringRef.h:215
llvm::Triple getLittleEndianArchVariant() const
Form a triple with a little endian variant of the current architecture.
Definition: Triple.cpp:1226
void getOSVersion(unsigned &Major, unsigned &Minor, unsigned &Micro) const
getOSVersion - Parse the version number from the OS name component of the triple, if present...
Definition: Triple.cpp:854
StringRef getOSName() const
getOSName - Get the operating system (third) component of the triple.
Definition: Triple.cpp:792
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:861
static unsigned parseArchEndian(StringRef Arch)
static ArchType getArchTypeForLLVMName(StringRef Str)
getArchTypeForLLVMName - The canonical type for the given LLVM architecture name (e.g., "x86").
Definition: Triple.cpp:219
static const char * getArchTypeName(ArchType Kind)
getArchTypeName - Get the canonical name for the Kind architecture.
Definition: Triple.cpp:20
cl::opt< std::string > MArch("march", cl::desc("Architecture to generate code for (see --version)"))
bool isArch16Bit() const
Test whether the architecture is 16-bit.
Definition: Triple.cpp:1054
R Default(const T &Value) const
Definition: StringSwitch.h:111
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Definition: BitVector.h:576
bool equals(StringRef RHS) const
equals - Check for string equality, this is more efficient than compare() when the relative ordering ...
Definition: StringRef.h:136
llvm::Triple get64BitArchVariant() const
Form a triple with a 64-bit variant of the current architecture.
Definition: Triple.cpp:1113
void setOSAndEnvironmentName(StringRef Str)
setOSAndEnvironmentName - Set the operating system and optional environment components with a single ...
Definition: Triple.cpp:987
static void parseVersionFromName(StringRef Name, unsigned &Major, unsigned &Minor, unsigned &Micro)
Definition: Triple.cpp:824
StringRef getArchName() const
getArchName - Get the architecture (first) component of the triple.
Definition: Triple.cpp:783
static unsigned parseArchProfile(StringRef Arch)
static unsigned parseArchISA(StringRef Arch)
bool getMacOSXVersion(unsigned &Major, unsigned &Minor, unsigned &Micro) const
getMacOSXVersion - Parse the version number as with getOSVersion and then translate generic "darwin" ...
Definition: Triple.cpp:865
bool hasEnvironment() const
hasEnvironment - Does this triple have the optional environment (fourth) component?
Definition: Triple.h:255
static Triple::ArchType parseArch(StringRef ArchName)
Definition: Triple.cpp:325
EnvironmentType getEnvironment() const
getEnvironment - Get the parsed environment type of this triple.
Definition: Triple.h:260
const char * getARMCPUForArch(StringRef Arch=StringRef()) const
Get the (LLVM) name of the minimum ARM CPU for the arch we are targeting.
Definition: Triple.cpp:1284
const ARM::ArchExtKind Kind
ObjectFormatType
Definition: Triple.h:175
StringSwitch & Cases(const char(&S0)[N0], const char(&S1)[N1], const T &Value)
Definition: StringSwitch.h:85
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:40
static Triple::EnvironmentType parseEnvironment(StringRef EnvironmentName)
Definition: Triple.cpp:420
static const char * getOSTypeName(OSType Kind)
getOSTypeName - Get the canonical name for the Kind operating system.
Definition: Triple.cpp:152
bool isArch32Bit() const
Test whether the architecture is 32-bit.
Definition: Triple.cpp:1050
void getEnvironmentVersion(unsigned &Major, unsigned &Minor, unsigned &Micro) const
Parse the version number from the OS name component of the triple, if present.
Definition: Triple.cpp:844
StringRef getVendorName() const
getVendorName - Get the vendor (second) component of the triple.
Definition: Triple.cpp:787
static StringRef getCanonicalArchName(StringRef Arch)
void setArch(ArchType Kind)
setArch - Set the architecture (first) component of the triple to a known type.
Definition: Triple.cpp:931
bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:110
void resize(size_type N)
Definition: SmallVector.h:376