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 sparcv9, // Sparcv9: Sparcv9
70 systemz, // SystemZ: s390x
71 tce, // TCE (http://tce.cs.tut.fi/): tce
72 thumb, // Thumb: thumb, thumbv.*
74 x86_64, // X86-64: amd64, x86_64
75 xcore, // XCore: xcore
76 mblaze, // MBlaze: mblaze
109 /// The parsed arch type (or InvalidArch if uninitialized).
110 mutable ArchType Arch;
112 /// The parsed vendor type.
113 mutable VendorType Vendor;
115 /// The parsed OS type.
118 bool isInitialized() const { return Arch != InvalidArch; }
122 /// @name Constructors
125 Triple() : Data(), Arch(InvalidArch) {}
126 explicit Triple(StringRef Str) : Data(Str), Arch(InvalidArch) {}
127 explicit Triple(StringRef ArchStr, StringRef VendorStr, StringRef OSStr)
128 : Data(ArchStr), Arch(InvalidArch) {
136 /// @name Typed Component Access
139 /// getArch - Get the parsed architecture type of this triple.
140 ArchType getArch() const {
141 if (!isInitialized()) Parse();
145 /// getVendor - Get the parsed vendor type of this triple.
146 VendorType getVendor() const {
147 if (!isInitialized()) Parse();
151 /// getOS - Get the parsed operating system type of this triple.
152 OSType getOS() const {
153 if (!isInitialized()) Parse();
157 /// hasEnvironment - Does this triple have the optional environment
158 /// (fourth) component?
159 bool hasEnvironment() const {
160 return getEnvironmentName() != "";
164 /// @name Direct Component Access
167 const std::string &str() const { return Data; }
169 const std::string &getTriple() const { return Data; }
171 /// getArchName - Get the architecture (first) component of the
173 StringRef getArchName() const;
175 /// getVendorName - Get the vendor (second) component of the triple.
176 StringRef getVendorName() const;
178 /// getOSName - Get the operating system (third) component of the
180 StringRef getOSName() const;
182 /// getEnvironmentName - Get the optional environment (fourth)
183 /// component of the triple, or "" if empty.
184 StringRef getEnvironmentName() const;
186 /// getOSAndEnvironmentName - Get the operating system and optional
187 /// environment components as a single string (separated by a '-'
188 /// if the environment component is present).
189 StringRef getOSAndEnvironmentName() const;
192 /// getDarwinNumber - Parse the 'darwin number' out of the specific target
193 /// triple. For example, if we have darwin8.5 return 8,5,0. If any entry is
194 /// not defined, return 0's. This requires that the triple have an OSType of
195 /// darwin before it is called.
196 void getDarwinNumber(unsigned &Maj, unsigned &Min, unsigned &Revision) const;
198 /// getDarwinMajorNumber - Return just the major version number, this is
199 /// specialized because it is a common query.
200 unsigned getDarwinMajorNumber() const {
201 unsigned Maj, Min, Rev;
202 getDarwinNumber(Maj, Min, Rev);
210 /// setArch - Set the architecture (first) component of the triple
212 void setArch(ArchType Kind);
214 /// setVendor - Set the vendor (second) component of the triple to a
216 void setVendor(VendorType Kind);
218 /// setOS - Set the operating system (third) component of the triple
220 void setOS(OSType Kind);
222 /// setTriple - Set all components to the new triple \arg Str.
223 void setTriple(const Twine &Str);
225 /// setArchName - Set the architecture (first) component of the
227 void setArchName(StringRef Str);
229 /// setVendorName - Set the vendor (second) component of the triple
231 void setVendorName(StringRef Str);
233 /// setOSName - Set the operating system (third) component of the
235 void setOSName(StringRef Str);
237 /// setEnvironmentName - Set the optional environment (fourth)
238 /// component of the triple by name.
239 void setEnvironmentName(StringRef Str);
241 /// setOSAndEnvironmentName - Set the operating system and optional
242 /// environment components with a single string.
243 void setOSAndEnvironmentName(StringRef Str);
245 /// getArchNameForAssembler - Get an architecture name that is understood by the
246 /// target assembler.
247 const char *getArchNameForAssembler();
250 /// @name Static helpers for IDs.
253 /// getArchTypeName - Get the canonical name for the \arg Kind
255 static const char *getArchTypeName(ArchType Kind);
257 /// getArchTypePrefix - Get the "prefix" canonical name for the \arg Kind
258 /// architecture. This is the prefix used by the architecture specific
259 /// builtins, and is suitable for passing to \see
260 /// Intrinsic::getIntrinsicForGCCBuiltin().
262 /// \return - The architecture prefix, or 0 if none is defined.
263 static const char *getArchTypePrefix(ArchType Kind);
265 /// getVendorTypeName - Get the canonical name for the \arg Kind
267 static const char *getVendorTypeName(VendorType Kind);
269 /// getOSTypeName - Get the canonical name for the \arg Kind vendor.
270 static const char *getOSTypeName(OSType Kind);
273 /// @name Static helpers for converting alternate architecture names.
276 /// getArchTypeForLLVMName - The canonical type for the given LLVM
277 /// architecture name (e.g., "x86").
278 static ArchType getArchTypeForLLVMName(StringRef Str);
280 /// getArchTypeForDarwinArchName - Get the architecture type for a "Darwin"
281 /// architecture name, for example as accepted by "gcc -arch" (see also
283 static ArchType getArchTypeForDarwinArchName(StringRef Str);
288 } // End llvm namespace