1 //===-- llvm/ADT/Triple.h - Target triple helper class ----------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_ADT_TRIPLE_H
11 #define LLVM_ADT_TRIPLE_H
13 #include "llvm/ADT/StringRef.h"
16 // Some system headers or GCC predefined macros conflict with identifiers in
17 // this file. Undefine them here.
25 /// Triple - Helper class for working with target triples.
27 /// Target triples are strings in the format of:
28 /// ARCHITECTURE-VENDOR-OPERATING_SYSTEM
30 /// ARCHITECTURE-VENDOR-OPERATING_SYSTEM-ENVIRONMENT
32 /// This class is used for clients which want to support arbitrary
33 /// target triples, but also want to implement certain special
34 /// behavior for particular targets. This class isolates the mapping
35 /// from the components of the target triple to well known IDs.
37 /// At its core the Triple class is designed to be a wrapper for a triple
38 /// string; it does not normally change or normalize the triple string, instead
39 /// it provides additional APIs to parse normalized parts out of the triple.
41 /// One curiosity this implies is that for some odd triples the results of,
42 /// e.g., getOSName() can be very different from the result of getOS(). For
43 /// example, for 'i386-mingw32', getOS() will return MinGW32, but since
44 /// getOSName() is purely based on the string structure that will return the
47 /// Clients should generally avoid using getOSName() and related APIs unless
48 /// they are familiar with the triple format (this is particularly true when
49 /// rewriting a triple).
51 /// See autoconf/config.guess for a glimpse into what they look like in
58 alpha, // Alpha: alpha
59 arm, // ARM; arm, armv.*, xscale
60 bfin, // Blackfin: bfin
61 cellspu, // CellSPU: spu, cellspu
62 mips, // MIPS: mips, mipsallegrex
63 mipsel, // MIPSEL: mipsel, mipsallegrexel, psp
64 msp430, // MSP430: msp430
65 pic16, // PIC16: pic16
67 ppc64, // PPC64: powerpc64, ppu
68 sparc, // Sparc: sparc
69 systemz, // SystemZ: s390x
70 tce, // TCE (http://tce.cs.tut.fi/): tce
71 thumb, // Thumb: thumb, thumbv.*
73 x86_64, // X86-64: amd64, x86_64
74 xcore, // XCore: xcore
107 /// The parsed arch type (or InvalidArch if uninitialized).
108 mutable ArchType Arch;
110 /// The parsed vendor type.
111 mutable VendorType Vendor;
113 /// The parsed OS type.
116 bool isInitialized() const { return Arch != InvalidArch; }
120 /// @name Constructors
123 Triple() : Data(), Arch(InvalidArch) {}
124 explicit Triple(StringRef Str) : Data(Str), Arch(InvalidArch) {}
125 explicit Triple(StringRef ArchStr, StringRef VendorStr, StringRef OSStr)
126 : Data(ArchStr), Arch(InvalidArch) {
134 /// @name Typed Component Access
137 /// getArch - Get the parsed architecture type of this triple.
138 ArchType getArch() const {
139 if (!isInitialized()) Parse();
143 /// getVendor - Get the parsed vendor type of this triple.
144 VendorType getVendor() const {
145 if (!isInitialized()) Parse();
149 /// getOS - Get the parsed operating system type of this triple.
150 OSType getOS() const {
151 if (!isInitialized()) Parse();
155 /// hasEnvironment - Does this triple have the optional environment
156 /// (fourth) component?
157 bool hasEnvironment() const {
158 return getEnvironmentName() != "";
162 /// @name Direct Component Access
165 const std::string &str() const { return Data; }
167 const std::string &getTriple() const { return Data; }
169 /// getArchName - Get the architecture (first) component of the
171 StringRef getArchName() const;
173 /// getVendorName - Get the vendor (second) component of the triple.
174 StringRef getVendorName() const;
176 /// getOSName - Get the operating system (third) component of the
178 StringRef getOSName() const;
180 /// getEnvironmentName - Get the optional environment (fourth)
181 /// component of the triple, or "" if empty.
182 StringRef getEnvironmentName() const;
184 /// getOSAndEnvironmentName - Get the operating system and optional
185 /// environment components as a single string (separated by a '-'
186 /// if the environment component is present).
187 StringRef getOSAndEnvironmentName() const;
190 /// getDarwinNumber - Parse the 'darwin number' out of the specific target
191 /// triple. For example, if we have darwin8.5 return 8,5,0. If any entry is
192 /// not defined, return 0's. This requires that the triple have an OSType of
193 /// darwin before it is called.
194 void getDarwinNumber(unsigned &Maj, unsigned &Min, unsigned &Revision) const;
196 /// getDarwinMajorNumber - Return just the major version number, this is
197 /// specialized because it is a common query.
198 unsigned getDarwinMajorNumber() const {
199 unsigned Maj, Min, Rev;
200 getDarwinNumber(Maj, Min, Rev);
208 /// setArch - Set the architecture (first) component of the triple
210 void setArch(ArchType Kind);
212 /// setVendor - Set the vendor (second) component of the triple to a
214 void setVendor(VendorType Kind);
216 /// setOS - Set the operating system (third) component of the triple
218 void setOS(OSType Kind);
220 /// setTriple - Set all components to the new triple \arg Str.
221 void setTriple(const Twine &Str);
223 /// setArchName - Set the architecture (first) component of the
225 void setArchName(StringRef Str);
227 /// setVendorName - Set the vendor (second) component of the triple
229 void setVendorName(StringRef Str);
231 /// setOSName - Set the operating system (third) component of the
233 void setOSName(StringRef Str);
235 /// setEnvironmentName - Set the optional environment (fourth)
236 /// component of the triple by name.
237 void setEnvironmentName(StringRef Str);
239 /// setOSAndEnvironmentName - Set the operating system and optional
240 /// environment components with a single string.
241 void setOSAndEnvironmentName(StringRef Str);
243 /// getArchNameForAssembler - Get an architecture name that is understood by the
244 /// target assembler.
245 const char *getArchNameForAssembler();
248 /// @name Static helpers for IDs.
251 /// getArchTypeName - Get the canonical name for the \arg Kind
253 static const char *getArchTypeName(ArchType Kind);
255 /// getArchTypePrefix - Get the "prefix" canonical name for the \arg Kind
256 /// architecture. This is the prefix used by the architecture specific
257 /// builtins, and is suitable for passing to \see
258 /// Intrinsic::getIntrinsicForGCCBuiltin().
260 /// \return - The architecture prefix, or 0 if none is defined.
261 static const char *getArchTypePrefix(ArchType Kind);
263 /// getVendorTypeName - Get the canonical name for the \arg Kind
265 static const char *getVendorTypeName(VendorType Kind);
267 /// getOSTypeName - Get the canonical name for the \arg Kind vendor.
268 static const char *getOSTypeName(OSType Kind);
271 /// @name Static helpers for converting alternate architecture names.
274 /// getArchTypeForLLVMName - The canonical type for the given LLVM
275 /// architecture name (e.g., "x86").
276 static ArchType getArchTypeForLLVMName(StringRef Str);
278 /// getArchTypeForDarwinArchName - Get the architecture type for a "Darwin"
279 /// architecture name, for example as accepted by "gcc -arch" (see also
281 static ArchType getArchTypeForDarwinArchName(StringRef Str);
286 } // End llvm namespace