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
42 cellspu, // spu, cellspu
43 mips, // mips, mipsallegrex
44 mipsel, // mipsel, mipsallegrexel, psp
50 thumb, // thumb, thumbv.*
52 x86_64, // amd64, x86_64
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 char *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;
165 /// setArch - Set the architecture (first) component of the triple
167 void setArch(ArchType Kind);
169 /// setVendor - Set the vendor (second) component of the triple to a
171 void setVendor(VendorType Kind);
173 /// setOS - Set the operating system (third) component of the triple
175 void setOS(OSType Kind);
177 /// setTriple - Set all components to the new triple \arg Str.
178 void setTriple(const Twine &Str);
180 /// setArchName - Set the architecture (first) component of the
182 void setArchName(const StringRef &Str);
184 /// setVendorName - Set the vendor (second) component of the triple
186 void setVendorName(const StringRef &Str);
188 /// setOSName - Set the operating system (third) component of the
190 void setOSName(const StringRef &Str);
192 /// setEnvironmentName - Set the optional environment (fourth)
193 /// component of the triple by name.
194 void setEnvironmentName(const StringRef &Str);
196 /// setOSAndEnvironmentName - Set the operating system and optional
197 /// environment components with a single string.
198 void setOSAndEnvironmentName(const StringRef &Str);
201 /// @name Static helpers for IDs.
204 /// getArchTypeName - Get the canonical name for the \arg Kind
206 static const char *getArchTypeName(ArchType Kind);
208 /// getVendorTypeName - Get the canonical name for the \arg Kind
210 static const char *getVendorTypeName(VendorType Kind);
212 /// getOSTypeName - Get the canonical name for the \arg Kind vendor.
213 static const char *getOSTypeName(OSType Kind);
218 } // End llvm namespace