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 //----------------------------------------------------------------------
87 eCore_ppc64_ppc970_64,
99 eCore_x86_64_x86_64h, // Haswell enabled x86_64
100 eCore_hexagon_generic,
101 eCore_hexagon_hexagonv4,
102 eCore_hexagon_hexagonv5,
115 // The following constants are used for wildcard matching only
124 kCore_arm_first = eCore_arm_generic,
125 kCore_arm_last = eCore_arm_xscale,
127 kCore_thumb_first = eCore_thumb,
128 kCore_thumb_last = eCore_thumbv7em,
130 kCore_ppc_first = eCore_ppc_generic,
131 kCore_ppc_last = eCore_ppc_ppc970,
133 kCore_ppc64_first = eCore_ppc64_generic,
134 kCore_ppc64_last = eCore_ppc64_ppc970_64,
136 kCore_x86_32_first = eCore_x86_32_i386,
137 kCore_x86_32_last = eCore_x86_32_i686,
139 kCore_x86_64_first = eCore_x86_64_x86_64,
140 kCore_x86_64_last = eCore_x86_64_x86_64h,
142 kCore_hexagon_first = eCore_hexagon_generic,
143 kCore_hexagon_last = eCore_hexagon_hexagonv5,
145 kCore_kalimba_first = eCore_kalimba,
146 kCore_kalimba_last = eCore_kalimba5
149 //------------------------------------------------------------------
150 /// Default constructor.
152 /// Default constructor that initializes the object with invalid
153 /// cpu type and subtype values.
154 //------------------------------------------------------------------
157 //------------------------------------------------------------------
158 /// Constructor over triple.
160 /// Constructs an ArchSpec with properties consistent with the given
162 //------------------------------------------------------------------
164 ArchSpec (const llvm::Triple &triple);
166 ArchSpec (const char *triple_cstr);
168 ArchSpec (const char *triple_cstr, Platform *platform);
169 //------------------------------------------------------------------
170 /// Constructor over architecture name.
172 /// Constructs an ArchSpec with properties consistent with the given
173 /// object type and architecture name.
174 //------------------------------------------------------------------
176 ArchSpec (ArchitectureType arch_type,
178 uint32_t cpu_subtype);
180 //------------------------------------------------------------------
182 //------------------------------------------------------------------
185 //------------------------------------------------------------------
186 /// Assignment operator.
188 /// @param[in] rhs another ArchSpec object to copy.
190 /// @return A const reference to this object.
191 //------------------------------------------------------------------
193 operator= (const ArchSpec& rhs);
196 AutoComplete (const char *name,
197 StringList &matches);
199 //------------------------------------------------------------------
200 /// Returns a static string representing the current architecture.
202 /// @return A static string correcponding to the current
204 //------------------------------------------------------------------
206 GetArchitectureName () const;
208 //------------------------------------------------------------------
209 /// Clears the object state.
211 /// Clears the object state back to a default invalid state.
212 //------------------------------------------------------------------
216 //------------------------------------------------------------------
217 /// Returns the size in bytes of an address of the current
220 /// @return The byte size of an address of the current architecture.
221 //------------------------------------------------------------------
223 GetAddressByteSize () const;
225 //------------------------------------------------------------------
226 /// Returns a machine family for the current architecture.
228 /// @return An LLVM arch type.
229 //------------------------------------------------------------------
230 llvm::Triple::ArchType
233 //------------------------------------------------------------------
234 /// Returns the distribution id of the architecture.
236 /// This will be something like "ubuntu", "fedora", etc. on Linux.
238 /// @return A ConstString ref containing the distribution id,
239 /// potentially empty.
240 //------------------------------------------------------------------
242 GetDistributionId () const;
244 //------------------------------------------------------------------
245 /// Set the distribution id of the architecture.
247 /// This will be something like "ubuntu", "fedora", etc. on Linux.
248 /// This should be the same value returned by
249 /// HostInfo::GetDistributionId ().
250 ///------------------------------------------------------------------
252 SetDistributionId (const char* distribution_id);
254 //------------------------------------------------------------------
255 /// Tests if this ArchSpec is valid.
257 /// @return True if the current architecture is valid, false
259 //------------------------------------------------------------------
263 return m_core >= eCore_arm_generic && m_core < kNumCores;
267 TripleVendorWasSpecified() const
269 return !m_triple.getVendorName().empty();
273 TripleOSWasSpecified() const
275 return !m_triple.getOSName().empty();
278 //------------------------------------------------------------------
279 /// Sets this ArchSpec according to the given architecture name.
281 /// The architecture name can be one of the generic system default
284 /// @li \c LLDB_ARCH_DEFAULT - The arch the current system defaults
285 /// to when a program is launched without any extra
286 /// attributes or settings.
287 /// @li \c LLDB_ARCH_DEFAULT_32BIT - The default host architecture
288 /// for 32 bit (if any).
289 /// @li \c LLDB_ARCH_DEFAULT_64BIT - The default host architecture
290 /// for 64 bit (if any).
292 /// Alternatively, if the object type of this ArchSpec has been
293 /// configured, a concrete architecture can be specified to set
294 /// the CPU type ("x86_64" for example).
296 /// Finally, an encoded object and archetecture format is accepted.
297 /// The format contains an object type (like "macho" or "elf"),
298 /// followed by a platform dependent encoding of CPU type and
299 /// subtype. For example:
301 /// "macho" : Specifies an object type of MachO.
302 /// "macho-16-6" : MachO specific encoding for ARMv6.
303 /// "elf-43 : ELF specific encoding for Sparc V9.
305 /// @param[in] arch_name The name of an architecture.
307 /// @return True if @p arch_name was successfully translated, false
309 //------------------------------------------------------------------
311 // SetArchitecture (const llvm::StringRef& arch_name);
314 // SetArchitecture (const char *arch_name);
316 //------------------------------------------------------------------
317 /// Change the architecture object type and CPU type.
319 /// @param[in] arch_type The object type of this ArchSpec.
321 /// @param[in] cpu The required CPU type.
323 /// @return True if the object and CPU type were successfully set.
324 //------------------------------------------------------------------
326 SetArchitecture (ArchitectureType arch_type,
330 //------------------------------------------------------------------
331 /// Returns the byte order for the architecture specification.
333 /// @return The endian enumeration for the current endianness of
334 /// the architecture specification
335 //------------------------------------------------------------------
337 GetByteOrder () const;
339 //------------------------------------------------------------------
340 /// Sets this ArchSpec's byte order.
342 /// In the common case there is no need to call this method as the
343 /// byte order can almost always be determined by the architecture.
344 /// However, many CPU's are bi-endian (ARM, Alpha, PowerPC, etc)
345 /// and the default/assumed byte order may be incorrect.
346 //------------------------------------------------------------------
348 SetByteOrder (lldb::ByteOrder byte_order)
350 m_byte_order = byte_order;
354 GetMinimumOpcodeByteSize() const;
357 GetMaximumOpcodeByteSize() const;
366 GetMachOCPUType () const;
369 GetMachOCPUSubType () const;
371 //------------------------------------------------------------------
372 /// Architecture data byte width accessor
374 /// @return the size in 8-bit (host) bytes of a minimum addressable
375 /// unit from the Architecture's data bus
376 //------------------------------------------------------------------
378 GetDataByteSize() const;
380 //------------------------------------------------------------------
381 /// Architecture code byte width accessor
383 /// @return the size in 8-bit (host) bytes of a minimum addressable
384 /// unit from the Architecture's code bus
385 //------------------------------------------------------------------
387 GetCodeByteSize() const;
389 //------------------------------------------------------------------
390 /// Architecture tripple accessor.
392 /// @return A triple describing this ArchSpec.
393 //------------------------------------------------------------------
400 //------------------------------------------------------------------
401 /// Architecture tripple accessor.
403 /// @return A triple describing this ArchSpec.
404 //------------------------------------------------------------------
411 //------------------------------------------------------------------
412 /// Architecture tripple setter.
414 /// Configures this ArchSpec according to the given triple. If the
415 /// triple has unknown components in all of the vendor, OS, and
416 /// the optional environment field (i.e. "i386-unknown-unknown")
417 /// then default values are taken from the host. Architecture and
418 /// environment components are used to further resolve the CPU type
419 /// and subtype, endian characteristics, etc.
421 /// @return A triple describing this ArchSpec.
422 //------------------------------------------------------------------
424 SetTriple (const llvm::Triple &triple);
427 SetTriple (const char *triple_cstr);
430 SetTriple (const char *triple_cstr,
433 //------------------------------------------------------------------
434 /// Returns the default endianness of the architecture.
436 /// @return The endian enumeration for the default endianness of
437 /// the architecture.
438 //------------------------------------------------------------------
440 GetDefaultEndian () const;
442 //------------------------------------------------------------------
443 /// Compare an ArchSpec to another ArchSpec, requiring an exact cpu
444 /// type match between them.
445 /// e.g. armv7s is not an exact match with armv7 - this would return false
447 /// @return true if the two ArchSpecs match.
448 //------------------------------------------------------------------
450 IsExactMatch (const ArchSpec& rhs) const;
452 //------------------------------------------------------------------
453 /// Compare an ArchSpec to another ArchSpec, requiring a compatible
454 /// cpu type match between them.
455 /// e.g. armv7s is compatible with armv7 - this method would return true
457 /// @return true if the two ArchSpecs are compatible
458 //------------------------------------------------------------------
460 IsCompatibleMatch (const ArchSpec& rhs) const;
464 IsEqualTo (const ArchSpec& rhs, bool exact_match) const;
466 llvm::Triple m_triple;
468 lldb::ByteOrder m_byte_order;
470 ConstString m_distribution_id;
472 // Called when m_def or m_entry are changed. Fills in all remaining
473 // members with default values.
475 CoreUpdated (bool update_triple);
478 //------------------------------------------------------------------
479 /// @fn bool operator< (const ArchSpec& lhs, const ArchSpec& rhs)
480 /// @brief Less than operator.
482 /// Tests two ArchSpec objects to see if \a lhs is less than \a
485 /// @param[in] lhs The Left Hand Side ArchSpec object to compare.
486 /// @param[in] rhs The Left Hand Side ArchSpec object to compare.
488 /// @return true if \a lhs is less than \a rhs
489 //------------------------------------------------------------------
490 bool operator< (const ArchSpec& lhs, const ArchSpec& rhs);
492 } // namespace lldb_private
494 #endif // #if defined(__cplusplus)
495 #endif // #ifndef liblldb_ArchSpec_h_