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
17 /// Triple - Helper class for working with target triples.
19 /// Target triples are strings in the format of:
20 /// ARCHITECTURE-VENDOR-OPERATING_SYSTEM
22 /// ARCHITECTURE-VENDOR-OPERATING_SYSTEM-ENVIRONMENT
24 /// This class is used for clients which want to support arbitrary
25 /// target triples, but also want to implement certain special
26 /// behavior for particular targets. This class isolates the mapping
27 /// from the components of the target triple to well known IDs.
29 /// See autoconf/config.guess for a glimpse into what they look like
39 x86_64, // amd64, x86_64
63 /// The parsed arch type (or InvalidArch if uninitialized).
64 mutable ArchType Arch;
66 /// The parsed vendor type.
67 mutable VendorType Vendor;
69 /// The parsed OS type.
72 bool isInitialized() const { return Arch != InvalidArch; }
76 /// @name Constructors
79 Triple() : Data(""), Arch(InvalidArch) {}
80 explicit Triple(const char *Str) : Data(Str), Arch(InvalidArch) {}
81 explicit Triple(const char *ArchStr, const char *VendorStr, const char *OSStr)
82 : Data(ArchStr), Arch(InvalidArch) {
90 /// @name Typed Component Access
93 /// getArch - Get the parsed architecture type of this triple.
94 ArchType getArch() const {
95 if (!isInitialized()) Parse();
99 /// getVendor - Get the parsed vendor type of this triple.
100 VendorType getVendor() const {
101 if (!isInitialized()) Parse();
105 /// getOS - Get the parsed operating system type of this triple.
106 OSType getOS() const {
107 if (!isInitialized()) Parse();
111 /// hasEnvironment - Does this triple have the optional environment
112 /// (fourth) component?
113 bool hasEnvironment() const {
114 return getEnvironmentName() != "";
118 /// @name Direct Component Access
121 const std::string &getTriple() const { return Data; }
123 // FIXME: Invent a lightweight string representation for these to
126 /// getArchName - Get the architecture (first) component of the
128 std::string getArchName() const;
130 /// getVendorName - Get the vendor (second) component of the triple.
131 std::string getVendorName() const;
133 /// getOSName - Get the operating system (third) component of the
135 std::string getOSName() const;
137 /// getEnvironmentName - Get the optional environment (fourth)
138 /// component of the triple, or "" if empty.
139 std::string getEnvironmentName() const;
141 /// getOSAndEnvironmentName - Get the operating system and optional
142 /// environment components as a single string (separated by a '-'
143 /// if the environment component is present).
144 std::string getOSAndEnvironmentName() const;
150 /// setArch - Set the architecture (first) component of the triple
152 void setArch(ArchType Kind);
154 /// setVendor - Set the vendor (second) component of the triple to a
156 void setVendor(VendorType Kind);
158 /// setOS - Set the operating system (third) component of the triple
160 void setOS(OSType Kind);
162 /// setTriple - Set all components to the new triple \arg Str.
163 void setTriple(const std::string &Str);
165 /// setArchName - Set the architecture (first) component of the
167 void setArchName(const std::string &Str);
169 /// setVendorName - Set the vendor (second) component of the triple
171 void setVendorName(const std::string &Str);
173 /// setOSName - Set the operating system (third) component of the
175 void setOSName(const std::string &Str);
177 /// setEnvironmentName - Set the optional environment (fourth)
178 /// component of the triple by name.
179 void setEnvironmentName(const std::string &Str);
181 /// setOSAndEnvironmentName - Set the operating system and optional
182 /// environment components with a single string.
183 void setOSAndEnvironmentName(const std::string &Str);
186 /// @name Static helpers for IDs.
189 /// getArchTypeName - Get the canonical name for the \arg Kind
191 static const char *getArchTypeName(ArchType Kind);
193 /// getVendorTypeName - Get the canonical name for the \arg Kind
195 static const char *getVendorTypeName(VendorType Kind);
197 /// getOSTypeName - Get the canonical name for the \arg Kind vendor.
198 static const char *getOSTypeName(OSType Kind);
203 } // End llvm namespace