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
95 eCore_hexagon_generic,
96 eCore_hexagon_hexagonv4,
97 eCore_hexagon_hexagonv5,
104 // The following constants are used for wildcard matching only
112 kCore_arm_first = eCore_arm_generic,
113 kCore_arm_last = eCore_arm_xscale,
115 kCore_thumb_first = eCore_thumb,
116 kCore_thumb_last = eCore_thumbv7em,
118 kCore_ppc_first = eCore_ppc_generic,
119 kCore_ppc_last = eCore_ppc_ppc970,
121 kCore_ppc64_first = eCore_ppc64_generic,
122 kCore_ppc64_last = eCore_ppc64_ppc970_64,
124 kCore_x86_32_first = eCore_x86_32_i386,
125 kCore_x86_32_last = eCore_x86_32_i486sx,
127 kCore_hexagon_first = eCore_hexagon_generic,
128 kCore_hexagon_last = eCore_hexagon_hexagonv5
131 //------------------------------------------------------------------
132 /// Default constructor.
134 /// Default constructor that initializes the object with invalid
135 /// cpu type and subtype values.
136 //------------------------------------------------------------------
139 //------------------------------------------------------------------
140 /// Constructor over triple.
142 /// Constructs an ArchSpec with properties consistent with the given
144 //------------------------------------------------------------------
146 ArchSpec (const llvm::Triple &triple);
148 ArchSpec (const char *triple_cstr);
150 ArchSpec (const char *triple_cstr, Platform *platform);
151 //------------------------------------------------------------------
152 /// Constructor over architecture name.
154 /// Constructs an ArchSpec with properties consistent with the given
155 /// object type and architecture name.
156 //------------------------------------------------------------------
158 ArchSpec (ArchitectureType arch_type,
160 uint32_t cpu_subtype);
162 //------------------------------------------------------------------
164 //------------------------------------------------------------------
167 //------------------------------------------------------------------
168 /// Assignment operator.
170 /// @param[in] rhs another ArchSpec object to copy.
172 /// @return A const reference to this object.
173 //------------------------------------------------------------------
175 operator= (const ArchSpec& rhs);
178 AutoComplete (const char *name,
179 StringList &matches);
181 //------------------------------------------------------------------
182 /// Returns a static string representing the current architecture.
184 /// @return A static string correcponding to the current
186 //------------------------------------------------------------------
188 GetArchitectureName () const;
190 //------------------------------------------------------------------
191 /// Clears the object state.
193 /// Clears the object state back to a default invalid state.
194 //------------------------------------------------------------------
198 //------------------------------------------------------------------
199 /// Returns the size in bytes of an address of the current
202 /// @return The byte size of an address of the current architecture.
203 //------------------------------------------------------------------
205 GetAddressByteSize () const;
207 //------------------------------------------------------------------
208 /// Returns a machine family for the current architecture.
210 /// @return An LLVM arch type.
211 //------------------------------------------------------------------
212 llvm::Triple::ArchType
215 //------------------------------------------------------------------
216 /// Returns the distribution id of the architecture.
218 /// This will be something like "ubuntu", "fedora", etc. on Linux.
220 /// @return A ConstString ref containing the distribution id,
221 /// potentially empty.
222 //------------------------------------------------------------------
224 GetDistributionId () const;
226 //------------------------------------------------------------------
227 /// Set the distribution id of the architecture.
229 /// This will be something like "ubuntu", "fedora", etc. on Linux.
230 /// This should be the same value returned by
231 /// Host::GetDistributionId ().
232 ///------------------------------------------------------------------
234 SetDistributionId (const char* distribution_id);
236 //------------------------------------------------------------------
237 /// Tests if this ArchSpec is valid.
239 /// @return True if the current architecture is valid, false
241 //------------------------------------------------------------------
245 return m_core >= eCore_arm_generic && m_core < kNumCores;
249 TripleVendorWasSpecified() const
251 return !m_triple.getVendorName().empty();
255 TripleOSWasSpecified() const
257 return !m_triple.getOSName().empty();
260 //------------------------------------------------------------------
261 /// Sets this ArchSpec according to the given architecture name.
263 /// The architecture name can be one of the generic system default
266 /// @li \c LLDB_ARCH_DEFAULT - The arch the current system defaults
267 /// to when a program is launched without any extra
268 /// attributes or settings.
269 /// @li \c LLDB_ARCH_DEFAULT_32BIT - The default host architecture
270 /// for 32 bit (if any).
271 /// @li \c LLDB_ARCH_DEFAULT_64BIT - The default host architecture
272 /// for 64 bit (if any).
274 /// Alternatively, if the object type of this ArchSpec has been
275 /// configured, a concrete architecture can be specified to set
276 /// the CPU type ("x86_64" for example).
278 /// Finally, an encoded object and archetecture format is accepted.
279 /// The format contains an object type (like "macho" or "elf"),
280 /// followed by a platform dependent encoding of CPU type and
281 /// subtype. For example:
283 /// "macho" : Specifies an object type of MachO.
284 /// "macho-16-6" : MachO specific encoding for ARMv6.
285 /// "elf-43 : ELF specific encoding for Sparc V9.
287 /// @param[in] arch_name The name of an architecture.
289 /// @return True if @p arch_name was successfully translated, false
291 //------------------------------------------------------------------
293 // SetArchitecture (const llvm::StringRef& arch_name);
296 // SetArchitecture (const char *arch_name);
298 //------------------------------------------------------------------
299 /// Change the architecture object type and CPU type.
301 /// @param[in] arch_type The object type of this ArchSpec.
303 /// @param[in] cpu The required CPU type.
305 /// @return True if the object and CPU type were sucessfully set.
306 //------------------------------------------------------------------
308 SetArchitecture (ArchitectureType arch_type,
312 //------------------------------------------------------------------
313 /// Returns the byte order for the architecture specification.
315 /// @return The endian enumeration for the current endianness of
316 /// the architecture specification
317 //------------------------------------------------------------------
319 GetByteOrder () const;
321 //------------------------------------------------------------------
322 /// Sets this ArchSpec's byte order.
324 /// In the common case there is no need to call this method as the
325 /// byte order can almost always be determined by the architecture.
326 /// However, many CPU's are bi-endian (ARM, Alpha, PowerPC, etc)
327 /// and the default/assumed byte order may be incorrect.
328 //------------------------------------------------------------------
330 SetByteOrder (lldb::ByteOrder byte_order)
332 m_byte_order = byte_order;
336 GetMinimumOpcodeByteSize() const;
339 GetMaximumOpcodeByteSize() const;
348 GetMachOCPUType () const;
351 GetMachOCPUSubType () const;
353 //------------------------------------------------------------------
354 /// Architecture tripple accessor.
356 /// @return A triple describing this ArchSpec.
357 //------------------------------------------------------------------
364 //------------------------------------------------------------------
365 /// Architecture tripple accessor.
367 /// @return A triple describing this ArchSpec.
368 //------------------------------------------------------------------
375 //------------------------------------------------------------------
376 /// Architecture tripple setter.
378 /// Configures this ArchSpec according to the given triple. If the
379 /// triple has unknown components in all of the vendor, OS, and
380 /// the optional environment field (i.e. "i386-unknown-unknown")
381 /// then default values are taken from the host. Architecture and
382 /// environment components are used to further resolve the CPU type
383 /// and subtype, endian characteristics, etc.
385 /// @return A triple describing this ArchSpec.
386 //------------------------------------------------------------------
388 SetTriple (const llvm::Triple &triple);
391 SetTriple (const char *triple_cstr);
394 SetTriple (const char *triple_cstr,
397 //------------------------------------------------------------------
398 /// Returns the default endianness of the architecture.
400 /// @return The endian enumeration for the default endianness of
401 /// the architecture.
402 //------------------------------------------------------------------
404 GetDefaultEndian () const;
406 //------------------------------------------------------------------
407 /// Compare an ArchSpec to another ArchSpec, requiring an exact cpu
408 /// type match between them.
409 /// e.g. armv7s is not an exact match with armv7 - this would return false
411 /// @return true if the two ArchSpecs match.
412 //------------------------------------------------------------------
414 IsExactMatch (const ArchSpec& rhs) const;
416 //------------------------------------------------------------------
417 /// Compare an ArchSpec to another ArchSpec, requiring a compatible
418 /// cpu type match between them.
419 /// e.g. armv7s is compatible with armv7 - this method would return true
421 /// @return true if the two ArchSpecs are compatible
422 //------------------------------------------------------------------
424 IsCompatibleMatch (const ArchSpec& rhs) const;
428 IsEqualTo (const ArchSpec& rhs, bool exact_match) const;
430 llvm::Triple m_triple;
432 lldb::ByteOrder m_byte_order;
434 ConstString m_distribution_id;
436 // Called when m_def or m_entry are changed. Fills in all remaining
437 // members with default values.
439 CoreUpdated (bool update_triple);
442 //------------------------------------------------------------------
443 /// @fn bool operator< (const ArchSpec& lhs, const ArchSpec& rhs)
444 /// @brief Less than operator.
446 /// Tests two ArchSpec objects to see if \a lhs is less than \a
449 /// @param[in] lhs The Left Hand Side ArchSpec object to compare.
450 /// @param[in] rhs The Left Hand Side ArchSpec object to compare.
452 /// @return true if \a lhs is less than \a rhs
453 //------------------------------------------------------------------
454 bool operator< (const ArchSpec& lhs, const ArchSpec& rhs);
456 } // namespace lldb_private
458 #endif // #if defined(__cplusplus)
459 #endif // #ifndef liblldb_ArchSpec_h_