1 //===-- ArchSpec.h ----------------------------------------------*- 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 liblldb_ArchSpec_h_
11 #define liblldb_ArchSpec_h_
13 #if defined(__cplusplus)
15 #include "lldb/lldb-private.h"
16 #include "lldb/Core/ConstString.h"
17 #include "llvm/ADT/StringRef.h"
18 #include "llvm/ADT/Triple.h"
20 namespace lldb_private {
22 struct CoreDefinition;
24 //----------------------------------------------------------------------
25 /// @class ArchSpec ArchSpec.h "lldb/Core/ArchSpec.h"
26 /// @brief An architecture specification class.
28 /// A class designed to be created from a cpu type and subtype, a
29 /// string representation, or an llvm::Triple. Keeping all of the
30 /// conversions of strings to architecture enumeration values confined
31 /// to this class allows new architecture support to be added easily.
32 //----------------------------------------------------------------------
83 eCore_ppc64_ppc970_64,
94 eCore_x86_64_x86_64h, // Haswell enabled x86_64
100 // The following constants are used for wildcard matching only
107 kCore_arm_first = eCore_arm_generic,
108 kCore_arm_last = eCore_arm_xscale,
110 kCore_thumb_first = eCore_thumb,
111 kCore_thumb_last = eCore_thumbv7em,
113 kCore_ppc_first = eCore_ppc_generic,
114 kCore_ppc_last = eCore_ppc_ppc970,
116 kCore_ppc64_first = eCore_ppc64_generic,
117 kCore_ppc64_last = eCore_ppc64_ppc970_64,
119 kCore_x86_32_first = eCore_x86_32_i386,
120 kCore_x86_32_last = eCore_x86_32_i486sx
123 //------------------------------------------------------------------
124 /// Default constructor.
126 /// Default constructor that initializes the object with invalid
127 /// cpu type and subtype values.
128 //------------------------------------------------------------------
131 //------------------------------------------------------------------
132 /// Constructor over triple.
134 /// Constructs an ArchSpec with properties consistent with the given
136 //------------------------------------------------------------------
138 ArchSpec (const llvm::Triple &triple);
140 ArchSpec (const char *triple_cstr);
142 ArchSpec (const char *triple_cstr, Platform *platform);
143 //------------------------------------------------------------------
144 /// Constructor over architecture name.
146 /// Constructs an ArchSpec with properties consistent with the given
147 /// object type and architecture name.
148 //------------------------------------------------------------------
150 ArchSpec (ArchitectureType arch_type,
152 uint32_t cpu_subtype);
154 //------------------------------------------------------------------
156 //------------------------------------------------------------------
159 //------------------------------------------------------------------
160 /// Assignment operator.
162 /// @param[in] rhs another ArchSpec object to copy.
164 /// @return A const reference to this object.
165 //------------------------------------------------------------------
167 operator= (const ArchSpec& rhs);
170 AutoComplete (const char *name,
171 StringList &matches);
173 //------------------------------------------------------------------
174 /// Returns a static string representing the current architecture.
176 /// @return A static string correcponding to the current
178 //------------------------------------------------------------------
180 GetArchitectureName () const;
182 //------------------------------------------------------------------
183 /// Clears the object state.
185 /// Clears the object state back to a default invalid state.
186 //------------------------------------------------------------------
190 //------------------------------------------------------------------
191 /// Returns the size in bytes of an address of the current
194 /// @return The byte size of an address of the current architecture.
195 //------------------------------------------------------------------
197 GetAddressByteSize () const;
199 //------------------------------------------------------------------
200 /// Returns a machine family for the current architecture.
202 /// @return An LLVM arch type.
203 //------------------------------------------------------------------
204 llvm::Triple::ArchType
207 //------------------------------------------------------------------
208 /// Returns the distribution id of the architecture.
210 /// This will be something like "ubuntu", "fedora", etc. on Linux.
212 /// @return A ConstString ref containing the distribution id,
213 /// potentially empty.
214 //------------------------------------------------------------------
216 GetDistributionId () const;
218 //------------------------------------------------------------------
219 /// Set the distribution id of the architecture.
221 /// This will be something like "ubuntu", "fedora", etc. on Linux.
222 /// This should be the same value returned by
223 /// Host::GetDistributionId ().
224 ///------------------------------------------------------------------
226 SetDistributionId (const char* distribution_id);
228 //------------------------------------------------------------------
229 /// Tests if this ArchSpec is valid.
231 /// @return True if the current architecture is valid, false
233 //------------------------------------------------------------------
237 return m_core >= eCore_arm_generic && m_core < kNumCores;
241 TripleVendorWasSpecified() const
243 return !m_triple.getVendorName().empty();
247 TripleOSWasSpecified() const
249 return !m_triple.getOSName().empty();
252 //------------------------------------------------------------------
253 /// Sets this ArchSpec according to the given architecture name.
255 /// The architecture name can be one of the generic system default
258 /// @li \c LLDB_ARCH_DEFAULT - The arch the current system defaults
259 /// to when a program is launched without any extra
260 /// attributes or settings.
261 /// @li \c LLDB_ARCH_DEFAULT_32BIT - The default host architecture
262 /// for 32 bit (if any).
263 /// @li \c LLDB_ARCH_DEFAULT_64BIT - The default host architecture
264 /// for 64 bit (if any).
266 /// Alternatively, if the object type of this ArchSpec has been
267 /// configured, a concrete architecture can be specified to set
268 /// the CPU type ("x86_64" for example).
270 /// Finally, an encoded object and archetecture format is accepted.
271 /// The format contains an object type (like "macho" or "elf"),
272 /// followed by a platform dependent encoding of CPU type and
273 /// subtype. For example:
275 /// "macho" : Specifies an object type of MachO.
276 /// "macho-16-6" : MachO specific encoding for ARMv6.
277 /// "elf-43 : ELF specific encoding for Sparc V9.
279 /// @param[in] arch_name The name of an architecture.
281 /// @return True if @p arch_name was successfully translated, false
283 //------------------------------------------------------------------
285 // SetArchitecture (const llvm::StringRef& arch_name);
288 // SetArchitecture (const char *arch_name);
290 //------------------------------------------------------------------
291 /// Change the architecture object type and CPU type.
293 /// @param[in] arch_type The object type of this ArchSpec.
295 /// @param[in] cpu The required CPU type.
297 /// @return True if the object and CPU type were sucessfully set.
298 //------------------------------------------------------------------
300 SetArchitecture (ArchitectureType arch_type,
304 //------------------------------------------------------------------
305 /// Returns the byte order for the architecture specification.
307 /// @return The endian enumeration for the current endianness of
308 /// the architecture specification
309 //------------------------------------------------------------------
311 GetByteOrder () const;
313 //------------------------------------------------------------------
314 /// Sets this ArchSpec's byte order.
316 /// In the common case there is no need to call this method as the
317 /// byte order can almost always be determined by the architecture.
318 /// However, many CPU's are bi-endian (ARM, Alpha, PowerPC, etc)
319 /// and the default/assumed byte order may be incorrect.
320 //------------------------------------------------------------------
322 SetByteOrder (lldb::ByteOrder byte_order)
324 m_byte_order = byte_order;
328 GetMinimumOpcodeByteSize() const;
331 GetMaximumOpcodeByteSize() const;
340 GetMachOCPUType () const;
343 GetMachOCPUSubType () const;
345 //------------------------------------------------------------------
346 /// Architecture tripple accessor.
348 /// @return A triple describing this ArchSpec.
349 //------------------------------------------------------------------
356 //------------------------------------------------------------------
357 /// Architecture tripple accessor.
359 /// @return A triple describing this ArchSpec.
360 //------------------------------------------------------------------
367 //------------------------------------------------------------------
368 /// Architecture tripple setter.
370 /// Configures this ArchSpec according to the given triple. If the
371 /// triple has unknown components in all of the vendor, OS, and
372 /// the optional environment field (i.e. "i386-unknown-unknown")
373 /// then default values are taken from the host. Architecture and
374 /// environment components are used to further resolve the CPU type
375 /// and subtype, endian characteristics, etc.
377 /// @return A triple describing this ArchSpec.
378 //------------------------------------------------------------------
380 SetTriple (const llvm::Triple &triple);
383 SetTriple (const char *triple_cstr);
386 SetTriple (const char *triple_cstr,
389 //------------------------------------------------------------------
390 /// Returns the default endianness of the architecture.
392 /// @return The endian enumeration for the default endianness of
393 /// the architecture.
394 //------------------------------------------------------------------
396 GetDefaultEndian () const;
398 //------------------------------------------------------------------
399 /// Compare an ArchSpec to another ArchSpec, requiring an exact cpu
400 /// type match between them.
401 /// e.g. armv7s is not an exact match with armv7 - this would return false
403 /// @return true if the two ArchSpecs match.
404 //------------------------------------------------------------------
406 IsExactMatch (const ArchSpec& rhs) const;
408 //------------------------------------------------------------------
409 /// Compare an ArchSpec to another ArchSpec, requiring a compatible
410 /// cpu type match between them.
411 /// e.g. armv7s is compatible with armv7 - this method would return true
413 /// @return true if the two ArchSpecs are compatible
414 //------------------------------------------------------------------
416 IsCompatibleMatch (const ArchSpec& rhs) const;
420 IsEqualTo (const ArchSpec& rhs, bool exact_match) const;
422 llvm::Triple m_triple;
424 lldb::ByteOrder m_byte_order;
426 ConstString m_distribution_id;
428 // Called when m_def or m_entry are changed. Fills in all remaining
429 // members with default values.
431 CoreUpdated (bool update_triple);
434 //------------------------------------------------------------------
435 /// @fn bool operator< (const ArchSpec& lhs, const ArchSpec& rhs)
436 /// @brief Less than operator.
438 /// Tests two ArchSpec objects to see if \a lhs is less than \a
441 /// @param[in] lhs The Left Hand Side ArchSpec object to compare.
442 /// @param[in] rhs The Left Hand Side ArchSpec object to compare.
444 /// @return true if \a lhs is less than \a rhs
445 //------------------------------------------------------------------
446 bool operator< (const ArchSpec& lhs, const ArchSpec& rhs);
448 } // namespace lldb_private
450 #endif // #if defined(__cplusplus)
451 #endif // #ifndef liblldb_ArchSpec_h_