Recognize EABIHF as environment and use it for RTAPI + VFP.
[oota-llvm.git] / include / llvm / ADT / Triple.h
1 //===-- llvm/ADT/Triple.h - Target triple helper class ----------*- C++ -*-===//
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 #ifndef LLVM_ADT_TRIPLE_H
11 #define LLVM_ADT_TRIPLE_H
12
13 #include "llvm/ADT/Twine.h"
14
15 // Some system headers or GCC predefined macros conflict with identifiers in
16 // this file.  Undefine them here.
17 #undef NetBSD
18 #undef mips
19 #undef sparc
20
21 namespace llvm {
22
23 /// Triple - Helper class for working with autoconf configuration names. For
24 /// historical reasons, we also call these 'triples' (they used to contain
25 /// exactly three fields).
26 ///
27 /// Configuration names are strings in the canonical form:
28 ///   ARCHITECTURE-VENDOR-OPERATING_SYSTEM
29 /// or
30 ///   ARCHITECTURE-VENDOR-OPERATING_SYSTEM-ENVIRONMENT
31 ///
32 /// This class is used for clients which want to support arbitrary
33 /// configuration names, but also want to implement certain special
34 /// behavior for particular configurations. This class isolates the mapping
35 /// from the components of the configuration name to well known IDs.
36 ///
37 /// At its core the Triple class is designed to be a wrapper for a triple
38 /// string; the constructor does not change or normalize the triple string.
39 /// Clients that need to handle the non-canonical triples that users often
40 /// specify should use the normalize method.
41 ///
42 /// See autoconf/config.guess for a glimpse into what configuration names
43 /// look like in practice.
44 class Triple {
45 public:
46   enum ArchType {
47     UnknownArch,
48
49     arm,     // ARM: arm, armv.*, xscale
50     aarch64, // AArch64: aarch64
51     hexagon, // Hexagon: hexagon
52     mips,    // MIPS: mips, mipsallegrex
53     mipsel,  // MIPSEL: mipsel, mipsallegrexel
54     mips64,  // MIPS64: mips64
55     mips64el,// MIPS64EL: mips64el
56     msp430,  // MSP430: msp430
57     ppc,     // PPC: powerpc
58     ppc64,   // PPC64: powerpc64, ppu
59     ppc64le, // PPC64LE: powerpc64le
60     r600,    // R600: AMD GPUs HD2XXX - HD6XXX
61     sparc,   // Sparc: sparc
62     sparcv9, // Sparcv9: Sparcv9
63     systemz, // SystemZ: s390x
64     tce,     // TCE (http://tce.cs.tut.fi/): tce
65     thumb,   // Thumb: thumb, thumbv.*
66     x86,     // X86: i[3-9]86
67     x86_64,  // X86-64: amd64, x86_64
68     xcore,   // XCore: xcore
69     nvptx,   // NVPTX: 32-bit
70     nvptx64, // NVPTX: 64-bit
71     le32,    // le32: generic little-endian 32-bit CPU (PNaCl / Emscripten)
72     amdil,   // amdil: amd IL
73     spir,    // SPIR: standard portable IR for OpenCL 32-bit version
74     spir64   // SPIR: standard portable IR for OpenCL 64-bit version
75   };
76   enum VendorType {
77     UnknownVendor,
78
79     Apple,
80     PC,
81     SCEI,
82     BGP,
83     BGQ,
84     Freescale,
85     IBM,
86     NVIDIA
87   };
88   enum OSType {
89     UnknownOS,
90
91     AuroraUX,
92     Cygwin,
93     Darwin,
94     DragonFly,
95     FreeBSD,
96     IOS,
97     KFreeBSD,
98     Linux,
99     Lv2,        // PS3
100     MacOSX,
101     MinGW32,    // i*86-pc-mingw32, *-w64-mingw32
102     NetBSD,
103     OpenBSD,
104     Solaris,
105     Win32,
106     Haiku,
107     Minix,
108     RTEMS,
109     NaCl,       // Native Client
110     CNK,        // BG/P Compute-Node Kernel
111     Bitrig,
112     AIX,
113     CUDA,       // NVIDIA CUDA
114     NVCL        // NVIDIA OpenCL
115   };
116   enum EnvironmentType {
117     UnknownEnvironment,
118
119     GNU,
120     GNUEABI,
121     GNUEABIHF,
122     GNUX32,
123     EABI,
124     EABIHF,
125     MachO,
126     Android,
127     ELF
128   };
129
130 private:
131   std::string Data;
132
133   /// The parsed arch type.
134   ArchType Arch;
135
136   /// The parsed vendor type.
137   VendorType Vendor;
138
139   /// The parsed OS type.
140   OSType OS;
141
142   /// The parsed Environment type.
143   EnvironmentType Environment;
144
145 public:
146   /// @name Constructors
147   /// @{
148
149   /// \brief Default constructor is the same as an empty string and leaves all
150   /// triple fields unknown.
151   Triple() : Data(), Arch(), Vendor(), OS(), Environment() {}
152
153   explicit Triple(const Twine &Str);
154   Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr);
155   Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr,
156          const Twine &EnvironmentStr);
157
158   /// @}
159   /// @name Normalization
160   /// @{
161
162   /// normalize - Turn an arbitrary machine specification into the canonical
163   /// triple form (or something sensible that the Triple class understands if
164   /// nothing better can reasonably be done).  In particular, it handles the
165   /// common case in which otherwise valid components are in the wrong order.
166   static std::string normalize(StringRef Str);
167
168   /// @}
169   /// @name Typed Component Access
170   /// @{
171
172   /// getArch - Get the parsed architecture type of this triple.
173   ArchType getArch() const { return Arch; }
174
175   /// getVendor - Get the parsed vendor type of this triple.
176   VendorType getVendor() const { return Vendor; }
177
178   /// getOS - Get the parsed operating system type of this triple.
179   OSType getOS() const { return OS; }
180
181   /// hasEnvironment - Does this triple have the optional environment
182   /// (fourth) component?
183   bool hasEnvironment() const {
184     return getEnvironmentName() != "";
185   }
186
187   /// getEnvironment - Get the parsed environment type of this triple.
188   EnvironmentType getEnvironment() const { return Environment; }
189
190   /// getOSVersion - Parse the version number from the OS name component of the
191   /// triple, if present.
192   ///
193   /// For example, "fooos1.2.3" would return (1, 2, 3).
194   ///
195   /// If an entry is not defined, it will be returned as 0.
196   void getOSVersion(unsigned &Major, unsigned &Minor, unsigned &Micro) const;
197
198   /// getOSMajorVersion - Return just the major version number, this is
199   /// specialized because it is a common query.
200   unsigned getOSMajorVersion() const {
201     unsigned Maj, Min, Micro;
202     getOSVersion(Maj, Min, Micro);
203     return Maj;
204   }
205
206   /// getMacOSXVersion - Parse the version number as with getOSVersion and then
207   /// translate generic "darwin" versions to the corresponding OS X versions.
208   /// This may also be called with IOS triples but the OS X version number is
209   /// just set to a constant 10.4.0 in that case.  Returns true if successful.
210   bool getMacOSXVersion(unsigned &Major, unsigned &Minor,
211                         unsigned &Micro) const;
212
213   /// getiOSVersion - Parse the version number as with getOSVersion.  This should
214   /// only be called with IOS triples.
215   void getiOSVersion(unsigned &Major, unsigned &Minor,
216                      unsigned &Micro) const;
217
218   /// @}
219   /// @name Direct Component Access
220   /// @{
221
222   const std::string &str() const { return Data; }
223
224   const std::string &getTriple() const { return Data; }
225
226   /// getArchName - Get the architecture (first) component of the
227   /// triple.
228   StringRef getArchName() const;
229
230   /// getVendorName - Get the vendor (second) component of the triple.
231   StringRef getVendorName() const;
232
233   /// getOSName - Get the operating system (third) component of the
234   /// triple.
235   StringRef getOSName() const;
236
237   /// getEnvironmentName - Get the optional environment (fourth)
238   /// component of the triple, or "" if empty.
239   StringRef getEnvironmentName() const;
240
241   /// getOSAndEnvironmentName - Get the operating system and optional
242   /// environment components as a single string (separated by a '-'
243   /// if the environment component is present).
244   StringRef getOSAndEnvironmentName() const;
245
246   /// @}
247   /// @name Convenience Predicates
248   /// @{
249
250   /// \brief Test whether the architecture is 64-bit
251   ///
252   /// Note that this tests for 64-bit pointer width, and nothing else. Note
253   /// that we intentionally expose only three predicates, 64-bit, 32-bit, and
254   /// 16-bit. The inner details of pointer width for particular architectures
255   /// is not summed up in the triple, and so only a coarse grained predicate
256   /// system is provided.
257   bool isArch64Bit() const;
258
259   /// \brief Test whether the architecture is 32-bit
260   ///
261   /// Note that this tests for 32-bit pointer width, and nothing else.
262   bool isArch32Bit() const;
263
264   /// \brief Test whether the architecture is 16-bit
265   ///
266   /// Note that this tests for 16-bit pointer width, and nothing else.
267   bool isArch16Bit() const;
268
269   /// isOSVersionLT - Helper function for doing comparisons against version
270   /// numbers included in the target triple.
271   bool isOSVersionLT(unsigned Major, unsigned Minor = 0,
272                      unsigned Micro = 0) const {
273     unsigned LHS[3];
274     getOSVersion(LHS[0], LHS[1], LHS[2]);
275
276     if (LHS[0] != Major)
277       return LHS[0] < Major;
278     if (LHS[1] != Minor)
279       return LHS[1] < Minor;
280     if (LHS[2] != Micro)
281       return LHS[1] < Micro;
282
283     return false;
284   }
285
286   /// isMacOSXVersionLT - Comparison function for checking OS X version
287   /// compatibility, which handles supporting skewed version numbering schemes
288   /// used by the "darwin" triples.
289   unsigned isMacOSXVersionLT(unsigned Major, unsigned Minor = 0,
290                              unsigned Micro = 0) const {
291     assert(isMacOSX() && "Not an OS X triple!");
292
293     // If this is OS X, expect a sane version number.
294     if (getOS() == Triple::MacOSX)
295       return isOSVersionLT(Major, Minor, Micro);
296
297     // Otherwise, compare to the "Darwin" number.
298     assert(Major == 10 && "Unexpected major version");
299     return isOSVersionLT(Minor + 4, Micro, 0);
300   }
301
302   /// isMacOSX - Is this a Mac OS X triple. For legacy reasons, we support both
303   /// "darwin" and "osx" as OS X triples.
304   bool isMacOSX() const {
305     return getOS() == Triple::Darwin || getOS() == Triple::MacOSX;
306   }
307
308   /// Is this an iOS triple.
309   bool isiOS() const {
310     return getOS() == Triple::IOS;
311   }
312
313   /// isOSDarwin - Is this a "Darwin" OS (OS X or iOS).
314   bool isOSDarwin() const {
315     return isMacOSX() || isiOS();
316   }
317
318   /// \brief Tests for either Cygwin or MinGW OS
319   bool isOSCygMing() const {
320     return getOS() == Triple::Cygwin || getOS() == Triple::MinGW32;
321   }
322
323   /// \brief Is this a "Windows" OS targeting a "MSVCRT.dll" environment.
324   bool isOSMSVCRT() const {
325     return getOS() == Triple::Win32 || getOS() == Triple::MinGW32;
326   }
327
328   /// \brief Tests whether the OS is Windows.
329   bool isOSWindows() const {
330     return getOS() == Triple::Win32 || isOSCygMing();
331   }
332
333   /// \brief Tests whether the OS is NaCl (Native Client)
334   bool isOSNaCl() const {
335     return getOS() == Triple::NaCl;
336   }
337
338   /// \brief Tests whether the OS is Linux.
339   bool isOSLinux() const {
340     return getOS() == Triple::Linux;
341   }
342
343   /// \brief Tests whether the OS uses the ELF binary format.
344   bool isOSBinFormatELF() const {
345     return !isOSBinFormatMachO() && !isOSBinFormatCOFF();
346   }
347
348   /// \brief Tests whether the OS uses the COFF binary format.
349   bool isOSBinFormatCOFF() const {
350     return getEnvironment() != Triple::ELF &&
351            getEnvironment() != Triple::MachO && isOSWindows();
352   }
353
354   /// \brief Tests whether the environment is MachO.
355   bool isOSBinFormatMachO() const {
356     return getEnvironment() == Triple::MachO || isOSDarwin();
357   }
358
359   /// @}
360   /// @name Mutators
361   /// @{
362
363   /// setArch - Set the architecture (first) component of the triple
364   /// to a known type.
365   void setArch(ArchType Kind);
366
367   /// setVendor - Set the vendor (second) component of the triple to a
368   /// known type.
369   void setVendor(VendorType Kind);
370
371   /// setOS - Set the operating system (third) component of the triple
372   /// to a known type.
373   void setOS(OSType Kind);
374
375   /// setEnvironment - Set the environment (fourth) component of the triple
376   /// to a known type.
377   void setEnvironment(EnvironmentType Kind);
378
379   /// setTriple - Set all components to the new triple \p Str.
380   void setTriple(const Twine &Str);
381
382   /// setArchName - Set the architecture (first) component of the
383   /// triple by name.
384   void setArchName(StringRef Str);
385
386   /// setVendorName - Set the vendor (second) component of the triple
387   /// by name.
388   void setVendorName(StringRef Str);
389
390   /// setOSName - Set the operating system (third) component of the
391   /// triple by name.
392   void setOSName(StringRef Str);
393
394   /// setEnvironmentName - Set the optional environment (fourth)
395   /// component of the triple by name.
396   void setEnvironmentName(StringRef Str);
397
398   /// setOSAndEnvironmentName - Set the operating system and optional
399   /// environment components with a single string.
400   void setOSAndEnvironmentName(StringRef Str);
401
402   /// getArchNameForAssembler - Get an architecture name that is understood by
403   /// the target assembler.
404   const char *getArchNameForAssembler();
405
406   /// @}
407   /// @name Helpers to build variants of a particular triple.
408   /// @{
409
410   /// \brief Form a triple with a 32-bit variant of the current architecture.
411   ///
412   /// This can be used to move across "families" of architectures where useful.
413   ///
414   /// \returns A new triple with a 32-bit architecture or an unknown
415   ///          architecture if no such variant can be found.
416   llvm::Triple get32BitArchVariant() const;
417
418   /// \brief Form a triple with a 64-bit variant of the current architecture.
419   ///
420   /// This can be used to move across "families" of architectures where useful.
421   ///
422   /// \returns A new triple with a 64-bit architecture or an unknown
423   ///          architecture if no such variant can be found.
424   llvm::Triple get64BitArchVariant() const;
425
426   /// @}
427   /// @name Static helpers for IDs.
428   /// @{
429
430   /// getArchTypeName - Get the canonical name for the \p Kind architecture.
431   static const char *getArchTypeName(ArchType Kind);
432
433   /// getArchTypePrefix - Get the "prefix" canonical name for the \p Kind
434   /// architecture. This is the prefix used by the architecture specific
435   /// builtins, and is suitable for passing to \see
436   /// Intrinsic::getIntrinsicForGCCBuiltin().
437   ///
438   /// \return - The architecture prefix, or 0 if none is defined.
439   static const char *getArchTypePrefix(ArchType Kind);
440
441   /// getVendorTypeName - Get the canonical name for the \p Kind vendor.
442   static const char *getVendorTypeName(VendorType Kind);
443
444   /// getOSTypeName - Get the canonical name for the \p Kind operating system.
445   static const char *getOSTypeName(OSType Kind);
446
447   /// getEnvironmentTypeName - Get the canonical name for the \p Kind
448   /// environment.
449   static const char *getEnvironmentTypeName(EnvironmentType Kind);
450
451   /// @}
452   /// @name Static helpers for converting alternate architecture names.
453   /// @{
454
455   /// getArchTypeForLLVMName - The canonical type for the given LLVM
456   /// architecture name (e.g., "x86").
457   static ArchType getArchTypeForLLVMName(StringRef Str);
458
459   /// @}
460 };
461
462 } // End llvm namespace
463
464
465 #endif