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
41 cellspu, // spu, cellspu
42 mips, // mips, mipsallegrex
43 mipsel, // mipsel, mipsallegrexel, psp
49 thumb, // thumb, thumbv.*
51 x86_64, // amd64, x86_64
79 /// The parsed arch type (or InvalidArch if uninitialized).
80 mutable ArchType Arch;
82 /// The parsed vendor type.
83 mutable VendorType Vendor;
85 /// The parsed OS type.
88 bool isInitialized() const { return Arch != InvalidArch; }
92 /// @name Constructors
95 Triple() : Data(""), Arch(InvalidArch) {}
96 explicit Triple(const char *Str) : Data(Str), Arch(InvalidArch) {}
97 explicit Triple(const char *ArchStr, const char *VendorStr, const char *OSStr)
98 : Data(ArchStr), Arch(InvalidArch) {
106 /// @name Typed Component Access
109 /// getArch - Get the parsed architecture type of this triple.
110 ArchType getArch() const {
111 if (!isInitialized()) Parse();
115 /// getVendor - Get the parsed vendor type of this triple.
116 VendorType getVendor() const {
117 if (!isInitialized()) Parse();
121 /// getOS - Get the parsed operating system type of this triple.
122 OSType getOS() const {
123 if (!isInitialized()) Parse();
127 /// hasEnvironment - Does this triple have the optional environment
128 /// (fourth) component?
129 bool hasEnvironment() const {
130 return getEnvironmentName() != "";
134 /// @name Direct Component Access
137 const std::string &getTriple() const { return Data; }
139 /// getArchName - Get the architecture (first) component of the
141 StringRef getArchName() const;
143 /// getVendorName - Get the vendor (second) component of the triple.
144 StringRef getVendorName() const;
146 /// getOSName - Get the operating system (third) component of the
148 StringRef getOSName() const;
150 /// getEnvironmentName - Get the optional environment (fourth)
151 /// component of the triple, or "" if empty.
152 StringRef getEnvironmentName() const;
154 /// getOSAndEnvironmentName - Get the operating system and optional
155 /// environment components as a single string (separated by a '-'
156 /// if the environment component is present).
157 StringRef getOSAndEnvironmentName() const;
163 /// setArch - Set the architecture (first) component of the triple
165 void setArch(ArchType Kind);
167 /// setVendor - Set the vendor (second) component of the triple to a
169 void setVendor(VendorType Kind);
171 /// setOS - Set the operating system (third) component of the triple
173 void setOS(OSType Kind);
175 /// setTriple - Set all components to the new triple \arg Str.
176 void setTriple(const Twine &Str);
178 /// setArchName - Set the architecture (first) component of the
180 void setArchName(const StringRef &Str);
182 /// setVendorName - Set the vendor (second) component of the triple
184 void setVendorName(const StringRef &Str);
186 /// setOSName - Set the operating system (third) component of the
188 void setOSName(const StringRef &Str);
190 /// setEnvironmentName - Set the optional environment (fourth)
191 /// component of the triple by name.
192 void setEnvironmentName(const StringRef &Str);
194 /// setOSAndEnvironmentName - Set the operating system and optional
195 /// environment components with a single string.
196 void setOSAndEnvironmentName(const StringRef &Str);
199 /// @name Static helpers for IDs.
202 /// getArchTypeName - Get the canonical name for the \arg Kind
204 static const char *getArchTypeName(ArchType Kind);
206 /// getVendorTypeName - Get the canonical name for the \arg Kind
208 static const char *getVendorTypeName(VendorType Kind);
210 /// getOSTypeName - Get the canonical name for the \arg Kind vendor.
211 static const char *getOSTypeName(OSType Kind);
216 } // End llvm namespace