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"
20 /// Triple - Helper class for working with target triples.
22 /// Target triples are strings in the format of:
23 /// ARCHITECTURE-VENDOR-OPERATING_SYSTEM
25 /// ARCHITECTURE-VENDOR-OPERATING_SYSTEM-ENVIRONMENT
27 /// This class is used for clients which want to support arbitrary
28 /// target triples, but also want to implement certain special
29 /// behavior for particular targets. This class isolates the mapping
30 /// from the components of the target triple to well known IDs.
32 /// See autoconf/config.guess for a glimpse into what they look like
39 alpha, // Alpha: alpha
40 arm, // ARM; arm, armv.*
41 bfin, // Blackfin: bfin
42 cellspu, // CellSPU: spu, cellspu
43 mips, // MIPS: mips, mipsallegrex
44 mipsel, // MIPSEL: mipsel, mipsallegrexel, psp
45 msp430, // MPS430: msp430
47 ppc64, // PPC64: powerpc64
48 sparc, // Sparc: sparc
49 systemz, // SystemZ: s390x
50 thumb, // Thumb: thumb, thumbv.*
52 x86_64, // X86-64: amd64, x86_64
53 xcore, // XCore: xcore
81 /// The parsed arch type (or InvalidArch if uninitialized).
82 mutable ArchType Arch;
84 /// The parsed vendor type.
85 mutable VendorType Vendor;
87 /// The parsed OS type.
90 bool isInitialized() const { return Arch != InvalidArch; }
94 /// @name Constructors
97 Triple() : Data(), Arch(InvalidArch) {}
98 explicit Triple(const StringRef &Str) : Data(Str), Arch(InvalidArch) {}
99 explicit Triple(const char *ArchStr, const char *VendorStr, const char *OSStr)
100 : Data(ArchStr), Arch(InvalidArch) {
108 /// @name Typed Component Access
111 /// getArch - Get the parsed architecture type of this triple.
112 ArchType getArch() const {
113 if (!isInitialized()) Parse();
117 /// getVendor - Get the parsed vendor type of this triple.
118 VendorType getVendor() const {
119 if (!isInitialized()) Parse();
123 /// getOS - Get the parsed operating system type of this triple.
124 OSType getOS() const {
125 if (!isInitialized()) Parse();
129 /// hasEnvironment - Does this triple have the optional environment
130 /// (fourth) component?
131 bool hasEnvironment() const {
132 return getEnvironmentName() != "";
136 /// @name Direct Component Access
139 const std::string &getTriple() const { return Data; }
141 /// getArchName - Get the architecture (first) component of the
143 StringRef getArchName() const;
145 /// getVendorName - Get the vendor (second) component of the triple.
146 StringRef getVendorName() const;
148 /// getOSName - Get the operating system (third) component of the
150 StringRef getOSName() const;
152 /// getEnvironmentName - Get the optional environment (fourth)
153 /// component of the triple, or "" if empty.
154 StringRef getEnvironmentName() const;
156 /// getOSAndEnvironmentName - Get the operating system and optional
157 /// environment components as a single string (separated by a '-'
158 /// if the environment component is present).
159 StringRef getOSAndEnvironmentName() const;
162 /// getDarwinNumber - Parse the 'darwin number' out of the specific target
163 /// triple. For example, if we have darwin8.5 return 8,5,0. If any entry is
164 /// not defined, return 0's. This requires that the triple have an OSType of
165 /// darwin before it is called.
166 void getDarwinNumber(unsigned &Maj, unsigned &Min, unsigned &Revision) const;
168 /// getDarwinMajorNumber - Return just the major version number, this is
169 /// specialized because it is a common query.
170 unsigned getDarwinMajorNumber() const {
171 unsigned Maj, Min, Rev;
172 getDarwinNumber(Maj, Min, Rev);
180 /// setArch - Set the architecture (first) component of the triple
182 void setArch(ArchType Kind);
184 /// setVendor - Set the vendor (second) component of the triple to a
186 void setVendor(VendorType Kind);
188 /// setOS - Set the operating system (third) component of the triple
190 void setOS(OSType Kind);
192 /// setTriple - Set all components to the new triple \arg Str.
193 void setTriple(const Twine &Str);
195 /// setArchName - Set the architecture (first) component of the
197 void setArchName(const StringRef &Str);
199 /// setVendorName - Set the vendor (second) component of the triple
201 void setVendorName(const StringRef &Str);
203 /// setOSName - Set the operating system (third) component of the
205 void setOSName(const StringRef &Str);
207 /// setEnvironmentName - Set the optional environment (fourth)
208 /// component of the triple by name.
209 void setEnvironmentName(const StringRef &Str);
211 /// setOSAndEnvironmentName - Set the operating system and optional
212 /// environment components with a single string.
213 void setOSAndEnvironmentName(const StringRef &Str);
216 /// @name Static helpers for IDs.
219 /// getArchTypeName - Get the canonical name for the \arg Kind
221 static const char *getArchTypeName(ArchType Kind);
223 /// getVendorTypeName - Get the canonical name for the \arg Kind
225 static const char *getVendorTypeName(VendorType Kind);
227 /// getOSTypeName - Get the canonical name for the \arg Kind vendor.
228 static const char *getOSTypeName(OSType Kind);
230 /// getArchTypeForLLVMName - The canonical type for the given LLVM
231 /// architecture name (e.g., "x86").
232 static ArchType getArchTypeForLLVMName(const StringRef &Str);
237 } // End llvm namespace