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.*, xscale
41 bfin, // Blackfin: bfin
42 cellspu, // CellSPU: spu, cellspu
43 mips, // MIPS: mips, mipsallegrex
44 mipsel, // MIPSEL: mipsel, mipsallegrexel, psp
45 msp430, // MPS430: msp430
46 pic16, // PIC16: pic16
48 ppc64, // PPC64: powerpc64
49 sparc, // Sparc: sparc
50 systemz, // SystemZ: s390x
51 thumb, // Thumb: thumb, thumbv.*
53 x86_64, // X86-64: amd64, x86_64
54 xcore, // XCore: xcore
84 /// The parsed arch type (or InvalidArch if uninitialized).
85 mutable ArchType Arch;
87 /// The parsed vendor type.
88 mutable VendorType Vendor;
90 /// The parsed OS type.
93 bool isInitialized() const { return Arch != InvalidArch; }
97 /// @name Constructors
100 Triple() : Data(), Arch(InvalidArch) {}
101 explicit Triple(const StringRef &Str) : Data(Str), Arch(InvalidArch) {}
102 explicit Triple(const char *ArchStr, const char *VendorStr, const char *OSStr)
103 : Data(ArchStr), Arch(InvalidArch) {
111 /// @name Typed Component Access
114 /// getArch - Get the parsed architecture type of this triple.
115 ArchType getArch() const {
116 if (!isInitialized()) Parse();
120 /// getVendor - Get the parsed vendor type of this triple.
121 VendorType getVendor() const {
122 if (!isInitialized()) Parse();
126 /// getOS - Get the parsed operating system type of this triple.
127 OSType getOS() const {
128 if (!isInitialized()) Parse();
132 /// hasEnvironment - Does this triple have the optional environment
133 /// (fourth) component?
134 bool hasEnvironment() const {
135 return getEnvironmentName() != "";
139 /// @name Direct Component Access
142 const std::string &getTriple() const { return Data; }
144 /// getArchName - Get the architecture (first) component of the
146 StringRef getArchName() const;
148 /// getVendorName - Get the vendor (second) component of the triple.
149 StringRef getVendorName() const;
151 /// getOSName - Get the operating system (third) component of the
153 StringRef getOSName() const;
155 /// getEnvironmentName - Get the optional environment (fourth)
156 /// component of the triple, or "" if empty.
157 StringRef getEnvironmentName() const;
159 /// getOSAndEnvironmentName - Get the operating system and optional
160 /// environment components as a single string (separated by a '-'
161 /// if the environment component is present).
162 StringRef getOSAndEnvironmentName() const;
165 /// getDarwinNumber - Parse the 'darwin number' out of the specific target
166 /// triple. For example, if we have darwin8.5 return 8,5,0. If any entry is
167 /// not defined, return 0's. This requires that the triple have an OSType of
168 /// darwin before it is called.
169 void getDarwinNumber(unsigned &Maj, unsigned &Min, unsigned &Revision) const;
171 /// getDarwinMajorNumber - Return just the major version number, this is
172 /// specialized because it is a common query.
173 unsigned getDarwinMajorNumber() const {
174 unsigned Maj, Min, Rev;
175 getDarwinNumber(Maj, Min, Rev);
183 /// setArch - Set the architecture (first) component of the triple
185 void setArch(ArchType Kind);
187 /// setVendor - Set the vendor (second) component of the triple to a
189 void setVendor(VendorType Kind);
191 /// setOS - Set the operating system (third) component of the triple
193 void setOS(OSType Kind);
195 /// setTriple - Set all components to the new triple \arg Str.
196 void setTriple(const Twine &Str);
198 /// setArchName - Set the architecture (first) component of the
200 void setArchName(const StringRef &Str);
202 /// setVendorName - Set the vendor (second) component of the triple
204 void setVendorName(const StringRef &Str);
206 /// setOSName - Set the operating system (third) component of the
208 void setOSName(const StringRef &Str);
210 /// setEnvironmentName - Set the optional environment (fourth)
211 /// component of the triple by name.
212 void setEnvironmentName(const StringRef &Str);
214 /// setOSAndEnvironmentName - Set the operating system and optional
215 /// environment components with a single string.
216 void setOSAndEnvironmentName(const StringRef &Str);
219 /// @name Static helpers for IDs.
222 /// getArchTypeName - Get the canonical name for the \arg Kind
224 static const char *getArchTypeName(ArchType Kind);
226 /// getVendorTypeName - Get the canonical name for the \arg Kind
228 static const char *getVendorTypeName(VendorType Kind);
230 /// getOSTypeName - Get the canonical name for the \arg Kind vendor.
231 static const char *getOSTypeName(OSType Kind);
233 /// getArchTypeForLLVMName - The canonical type for the given LLVM
234 /// architecture name (e.g., "x86").
235 static ArchType getArchTypeForLLVMName(const StringRef &Str);
240 } // End llvm namespace