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
64 /// The parsed arch type (or InvalidArch if uninitialized).
65 mutable ArchType Arch;
67 /// The parsed vendor type.
68 mutable VendorType Vendor;
70 /// The parsed OS type.
73 bool isInitialized() const { return Arch != InvalidArch; }
77 /// @name Constructors
80 Triple() : Data(""), Arch(InvalidArch) {}
81 explicit Triple(const char *Str) : Data(Str), Arch(InvalidArch) {}
82 explicit Triple(const char *ArchStr, const char *VendorStr, const char *OSStr)
83 : Data(ArchStr), Arch(InvalidArch) {
91 /// @name Typed Component Access
94 /// getArch - Get the parsed architecture type of this triple.
95 ArchType getArch() const {
96 if (!isInitialized()) Parse();
100 /// getVendor - Get the parsed vendor type of this triple.
101 VendorType getVendor() const {
102 if (!isInitialized()) Parse();
106 /// getOS - Get the parsed operating system type of this triple.
107 OSType getOS() const {
108 if (!isInitialized()) Parse();
112 /// hasEnvironment - Does this triple have the optional environment
113 /// (fourth) component?
114 bool hasEnvironment() const {
115 return getEnvironmentName() != "";
119 /// @name Direct Component Access
122 const std::string &getTriple() const { return Data; }
124 // FIXME: Invent a lightweight string representation for these to
127 /// getArchName - Get the architecture (first) component of the
129 std::string getArchName() const;
131 /// getVendorName - Get the vendor (second) component of the triple.
132 std::string getVendorName() const;
134 /// getOSName - Get the operating system (third) component of the
136 std::string getOSName() const;
138 /// getEnvironmentName - Get the optional environment (fourth)
139 /// component of the triple, or "" if empty.
140 std::string getEnvironmentName() const;
142 /// getOSAndEnvironmentName - Get the operating system and optional
143 /// environment components as a single string (separated by a '-'
144 /// if the environment component is present).
145 std::string getOSAndEnvironmentName() const;
151 /// setArch - Set the architecture (first) component of the triple
153 void setArch(ArchType Kind);
155 /// setVendor - Set the vendor (second) component of the triple to a
157 void setVendor(VendorType Kind);
159 /// setOS - Set the operating system (third) component of the triple
161 void setOS(OSType Kind);
163 /// setTriple - Set all components to the new triple \arg Str.
164 void setTriple(const std::string &Str);
166 /// setArchName - Set the architecture (first) component of the
168 void setArchName(const std::string &Str);
170 /// setVendorName - Set the vendor (second) component of the triple
172 void setVendorName(const std::string &Str);
174 /// setOSName - Set the operating system (third) component of the
176 void setOSName(const std::string &Str);
178 /// setEnvironmentName - Set the optional environment (fourth)
179 /// component of the triple by name.
180 void setEnvironmentName(const std::string &Str);
182 /// setOSAndEnvironmentName - Set the operating system and optional
183 /// environment components with a single string.
184 void setOSAndEnvironmentName(const std::string &Str);
187 /// @name Static helpers for IDs.
190 /// getArchTypeName - Get the canonical name for the \arg Kind
192 static const char *getArchTypeName(ArchType Kind);
194 /// getVendorTypeName - Get the canonical name for the \arg Kind
196 static const char *getVendorTypeName(VendorType Kind);
198 /// getOSTypeName - Get the canonical name for the \arg Kind vendor.
199 static const char *getOSTypeName(OSType Kind);
204 } // End llvm namespace