Update for API change.
[oota-llvm.git] / include / llvm / ADT / Triple.h
1 //===-- llvm/ADT/Triple.h - Target triple helper class ----------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef LLVM_ADT_TRIPLE_H
11 #define LLVM_ADT_TRIPLE_H
12
13 #include "llvm/ADT/StringRef.h"
14 #include <string>
15
16 namespace llvm {
17 class StringRef;
18 class Twine;
19
20 /// Triple - Helper class for working with target triples.
21 ///
22 /// Target triples are strings in the format of:
23 ///   ARCHITECTURE-VENDOR-OPERATING_SYSTEM
24 /// or
25 ///   ARCHITECTURE-VENDOR-OPERATING_SYSTEM-ENVIRONMENT
26 ///
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.
31 ///
32 /// See autoconf/config.guess for a glimpse into what they look like
33 /// in practice.
34 class Triple {
35 public:
36   enum ArchType {
37     UnknownArch,
38     
39     alpha,   // alpha
40     arm,     // arm, armv.*
41     cellspu, // spu, cellspu
42     mips,    // mips, mipsallegrex
43     mipsel,  // mipsel, mipsallegrexel, psp
44     msp430,  // msp430
45     ppc,     // powerpc
46     ppc64,   // powerpc64
47     sparc,   // sparc
48     systemz, // s390x
49     thumb,   // thumb, thumbv.*
50     x86,     // i[3-9]86
51     x86_64,  // amd64, x86_64
52
53     InvalidArch
54   };
55   enum VendorType {
56     UnknownVendor,
57
58     Apple, 
59     PC
60   };
61   enum OSType {
62     UnknownOS,
63
64     AuroraUX,
65     Cygwin,
66     Darwin,
67     DragonFly,
68     FreeBSD,
69     Linux,
70     MinGW32,
71     NetBSD,
72     OpenBSD,
73     Win32
74   };
75   
76 private:
77   std::string Data;
78
79   /// The parsed arch type (or InvalidArch if uninitialized).
80   mutable ArchType Arch;
81
82   /// The parsed vendor type.
83   mutable VendorType Vendor;
84
85   /// The parsed OS type.
86   mutable OSType OS;
87
88   bool isInitialized() const { return Arch != InvalidArch; }
89   void Parse() const;
90
91 public:
92   /// @name Constructors
93   /// @{
94   
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) {
99     Data += '-';
100     Data += VendorStr;
101     Data += '-';
102     Data += OSStr;
103   }
104
105   /// @}
106   /// @name Typed Component Access
107   /// @{
108   
109   /// getArch - Get the parsed architecture type of this triple.
110   ArchType getArch() const { 
111     if (!isInitialized()) Parse(); 
112     return Arch;
113   }
114   
115   /// getVendor - Get the parsed vendor type of this triple.
116   VendorType getVendor() const { 
117     if (!isInitialized()) Parse(); 
118     return Vendor;
119   }
120   
121   /// getOS - Get the parsed operating system type of this triple.
122   OSType getOS() const { 
123     if (!isInitialized()) Parse(); 
124     return OS;
125   }
126
127   /// hasEnvironment - Does this triple have the optional environment
128   /// (fourth) component?
129   bool hasEnvironment() const {
130     return getEnvironmentName() != "";
131   }
132
133   /// @}
134   /// @name Direct Component Access
135   /// @{
136
137   const std::string &getTriple() const { return Data; }
138
139   /// getArchName - Get the architecture (first) component of the
140   /// triple.
141   StringRef getArchName() const;
142
143   /// getVendorName - Get the vendor (second) component of the triple.
144   StringRef getVendorName() const;
145
146   /// getOSName - Get the operating system (third) component of the
147   /// triple.
148   StringRef getOSName() const;
149
150   /// getEnvironmentName - Get the optional environment (fourth)
151   /// component of the triple, or "" if empty.
152   StringRef getEnvironmentName() const;
153
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;
158
159   /// @}
160   /// @name Mutators
161   /// @{
162
163   /// setArch - Set the architecture (first) component of the triple
164   /// to a known type.
165   void setArch(ArchType Kind);
166
167   /// setVendor - Set the vendor (second) component of the triple to a
168   /// known type.
169   void setVendor(VendorType Kind);
170
171   /// setOS - Set the operating system (third) component of the triple
172   /// to a known type.
173   void setOS(OSType Kind);
174
175   /// setTriple - Set all components to the new triple \arg Str.
176   void setTriple(const Twine &Str);
177
178   /// setArchName - Set the architecture (first) component of the
179   /// triple by name.
180   void setArchName(const StringRef &Str);
181
182   /// setVendorName - Set the vendor (second) component of the triple
183   /// by name.
184   void setVendorName(const StringRef &Str);
185
186   /// setOSName - Set the operating system (third) component of the
187   /// triple by name.
188   void setOSName(const StringRef &Str);
189
190   /// setEnvironmentName - Set the optional environment (fourth)
191   /// component of the triple by name.
192   void setEnvironmentName(const StringRef &Str);
193
194   /// setOSAndEnvironmentName - Set the operating system and optional
195   /// environment components with a single string.
196   void setOSAndEnvironmentName(const StringRef &Str);
197
198   /// @}
199   /// @name Static helpers for IDs.
200   /// @{
201
202   /// getArchTypeName - Get the canonical name for the \arg Kind
203   /// architecture.
204   static const char *getArchTypeName(ArchType Kind);
205
206   /// getVendorTypeName - Get the canonical name for the \arg Kind
207   /// vendor.
208   static const char *getVendorTypeName(VendorType Kind);
209
210   /// getOSTypeName - Get the canonical name for the \arg Kind vendor.
211   static const char *getOSTypeName(OSType Kind);
212
213   /// @}
214 };
215
216 } // End llvm namespace
217
218
219 #endif