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 "llvm/ADT/StringRef.h"
17 #include "llvm/ADT/Triple.h"
19 namespace lldb_private {
21 struct CoreDefinition;
23 //----------------------------------------------------------------------
24 /// @class ArchSpec ArchSpec.h "lldb/Core/ArchSpec.h"
25 /// @brief An architecture specification class.
27 /// A class designed to be created from a cpu type and subtype, a
28 /// string representation, or an llvm::Triple. Keeping all of the
29 /// conversions of strings to architecture enumeration values confined
30 /// to this class allows new architecture support to be added easily.
31 //----------------------------------------------------------------------
78 eCore_ppc64_ppc970_64,
94 // The following constants are used for wildcard matching only
101 kCore_arm_first = eCore_arm_generic,
102 kCore_arm_last = eCore_arm_xscale,
104 kCore_thumb_first = eCore_thumb,
105 kCore_thumb_last = eCore_thumbv7em,
107 kCore_ppc_first = eCore_ppc_generic,
108 kCore_ppc_last = eCore_ppc_ppc970,
110 kCore_ppc64_first = eCore_ppc64_generic,
111 kCore_ppc64_last = eCore_ppc64_ppc970_64,
113 kCore_x86_32_first = eCore_x86_32_i386,
114 kCore_x86_32_last = eCore_x86_32_i486sx
117 //------------------------------------------------------------------
118 /// Default constructor.
120 /// Default constructor that initializes the object with invalid
121 /// cpu type and subtype values.
122 //------------------------------------------------------------------
125 //------------------------------------------------------------------
126 /// Constructor over triple.
128 /// Constructs an ArchSpec with properties consistent with the given
130 //------------------------------------------------------------------
132 ArchSpec (const llvm::Triple &triple);
134 ArchSpec (const char *triple_cstr);
136 ArchSpec (const char *triple_cstr, Platform *platform);
137 //------------------------------------------------------------------
138 /// Constructor over architecture name.
140 /// Constructs an ArchSpec with properties consistent with the given
141 /// object type and architecture name.
142 //------------------------------------------------------------------
144 ArchSpec (ArchitectureType arch_type,
146 uint32_t cpu_subtype);
148 //------------------------------------------------------------------
150 //------------------------------------------------------------------
153 //------------------------------------------------------------------
154 /// Assignment operator.
156 /// @param[in] rhs another ArchSpec object to copy.
158 /// @return A const reference to this object.
159 //------------------------------------------------------------------
161 operator= (const ArchSpec& rhs);
164 AutoComplete (const char *name,
165 StringList &matches);
167 //------------------------------------------------------------------
168 /// Returns a static string representing the current architecture.
170 /// @return A static string correcponding to the current
172 //------------------------------------------------------------------
174 GetArchitectureName () const;
176 //------------------------------------------------------------------
177 /// Clears the object state.
179 /// Clears the object state back to a default invalid state.
180 //------------------------------------------------------------------
184 //------------------------------------------------------------------
185 /// Returns the size in bytes of an address of the current
188 /// @return The byte size of an address of the current architecture.
189 //------------------------------------------------------------------
191 GetAddressByteSize () const;
193 //------------------------------------------------------------------
194 /// Returns a machine family for the current architecture.
196 /// @return An LLVM arch type.
197 //------------------------------------------------------------------
198 llvm::Triple::ArchType
201 //------------------------------------------------------------------
202 /// Tests if this ArchSpec is valid.
204 /// @return True if the current architecture is valid, false
206 //------------------------------------------------------------------
210 return m_core >= eCore_arm_generic && m_core < kNumCores;
214 TripleVendorWasSpecified() const
216 return !m_triple.getVendorName().empty();
220 TripleOSWasSpecified() const
222 return !m_triple.getOSName().empty();
225 //------------------------------------------------------------------
226 /// Sets this ArchSpec according to the given architecture name.
228 /// The architecture name can be one of the generic system default
231 /// @li \c LLDB_ARCH_DEFAULT - The arch the current system defaults
232 /// to when a program is launched without any extra
233 /// attributes or settings.
234 /// @li \c LLDB_ARCH_DEFAULT_32BIT - The default host architecture
235 /// for 32 bit (if any).
236 /// @li \c LLDB_ARCH_DEFAULT_64BIT - The default host architecture
237 /// for 64 bit (if any).
239 /// Alternatively, if the object type of this ArchSpec has been
240 /// configured, a concrete architecture can be specified to set
241 /// the CPU type ("x86_64" for example).
243 /// Finally, an encoded object and archetecture format is accepted.
244 /// The format contains an object type (like "macho" or "elf"),
245 /// followed by a platform dependent encoding of CPU type and
246 /// subtype. For example:
248 /// "macho" : Specifies an object type of MachO.
249 /// "macho-16-6" : MachO specific encoding for ARMv6.
250 /// "elf-43 : ELF specific encoding for Sparc V9.
252 /// @param[in] arch_name The name of an architecture.
254 /// @return True if @p arch_name was successfully translated, false
256 //------------------------------------------------------------------
258 // SetArchitecture (const llvm::StringRef& arch_name);
261 // SetArchitecture (const char *arch_name);
263 //------------------------------------------------------------------
264 /// Change the architecture object type and CPU type.
266 /// @param[in] arch_type The object type of this ArchSpec.
268 /// @param[in] cpu The required CPU type.
270 /// @return True if the object and CPU type were sucessfully set.
271 //------------------------------------------------------------------
273 SetArchitecture (ArchitectureType arch_type,
277 //------------------------------------------------------------------
278 /// Returns the byte order for the architecture specification.
280 /// @return The endian enumeration for the current endianness of
281 /// the architecture specification
282 //------------------------------------------------------------------
284 GetByteOrder () const;
286 //------------------------------------------------------------------
287 /// Sets this ArchSpec's byte order.
289 /// In the common case there is no need to call this method as the
290 /// byte order can almost always be determined by the architecture.
291 /// However, many CPU's are bi-endian (ARM, Alpha, PowerPC, etc)
292 /// and the default/assumed byte order may be incorrect.
293 //------------------------------------------------------------------
295 SetByteOrder (lldb::ByteOrder byte_order)
297 m_byte_order = byte_order;
301 GetMinimumOpcodeByteSize() const;
304 GetMaximumOpcodeByteSize() const;
313 GetMachOCPUType () const;
316 GetMachOCPUSubType () const;
318 //------------------------------------------------------------------
319 /// Architecture tripple accessor.
321 /// @return A triple describing this ArchSpec.
322 //------------------------------------------------------------------
329 //------------------------------------------------------------------
330 /// Architecture tripple accessor.
332 /// @return A triple describing this ArchSpec.
333 //------------------------------------------------------------------
340 //------------------------------------------------------------------
341 /// Architecture tripple setter.
343 /// Configures this ArchSpec according to the given triple. If the
344 /// triple has unknown components in all of the vendor, OS, and
345 /// the optional environment field (i.e. "i386-unknown-unknown")
346 /// then default values are taken from the host. Architecture and
347 /// environment components are used to further resolve the CPU type
348 /// and subtype, endian characteristics, etc.
350 /// @return A triple describing this ArchSpec.
351 //------------------------------------------------------------------
353 SetTriple (const llvm::Triple &triple);
356 SetTriple (const char *triple_cstr);
359 SetTriple (const char *triple_cstr,
362 //------------------------------------------------------------------
363 /// Returns the default endianness of the architecture.
365 /// @return The endian enumeration for the default endianness of
366 /// the architecture.
367 //------------------------------------------------------------------
369 GetDefaultEndian () const;
371 //------------------------------------------------------------------
372 /// Compare an ArchSpec to another ArchSpec, requiring an exact cpu
373 /// type match between them.
374 /// e.g. armv7s is not an exact match with armv7 - this would return false
376 /// @return true if the two ArchSpecs match.
377 //------------------------------------------------------------------
379 IsExactMatch (const ArchSpec& rhs) const;
381 //------------------------------------------------------------------
382 /// Compare an ArchSpec to another ArchSpec, requiring a compatible
383 /// cpu type match between them.
384 /// e.g. armv7s is compatible with armv7 - this method would return true
386 /// @return true if the two ArchSpecs are compatible
387 //------------------------------------------------------------------
389 IsCompatibleMatch (const ArchSpec& rhs) const;
393 IsEqualTo (const ArchSpec& rhs, bool exact_match) const;
395 llvm::Triple m_triple;
397 lldb::ByteOrder m_byte_order;
399 // Called when m_def or m_entry are changed. Fills in all remaining
400 // members with default values.
402 CoreUpdated (bool update_triple);
405 //------------------------------------------------------------------
406 /// @fn bool operator< (const ArchSpec& lhs, const ArchSpec& rhs)
407 /// @brief Less than operator.
409 /// Tests two ArchSpec objects to see if \a lhs is less than \a
412 /// @param[in] lhs The Left Hand Side ArchSpec object to compare.
413 /// @param[in] rhs The Left Hand Side ArchSpec object to compare.
415 /// @return true if \a lhs is less than \a rhs
416 //------------------------------------------------------------------
417 bool operator< (const ArchSpec& lhs, const ArchSpec& rhs);
419 } // namespace lldb_private
421 #endif // #if defined(__cplusplus)
422 #endif // #ifndef liblldb_ArchSpec_h_