ArchSpec.h revision 269024
1//===-- ArchSpec.h ----------------------------------------------*- 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 liblldb_ArchSpec_h_ 11#define liblldb_ArchSpec_h_ 12 13#if defined(__cplusplus) 14 15#include "lldb/lldb-private.h" 16#include "lldb/Core/ConstString.h" 17#include "llvm/ADT/StringRef.h" 18#include "llvm/ADT/Triple.h" 19 20namespace lldb_private { 21 22struct CoreDefinition; 23 24//---------------------------------------------------------------------- 25/// @class ArchSpec ArchSpec.h "lldb/Core/ArchSpec.h" 26/// @brief An architecture specification class. 27/// 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//---------------------------------------------------------------------- 33class ArchSpec 34{ 35public: 36 enum Core 37 { 38 eCore_arm_generic, 39 eCore_arm_armv4, 40 eCore_arm_armv4t, 41 eCore_arm_armv5, 42 eCore_arm_armv5e, 43 eCore_arm_armv5t, 44 eCore_arm_armv6, 45 eCore_arm_armv6m, 46 eCore_arm_armv7, 47 eCore_arm_armv7f, 48 eCore_arm_armv7s, 49 eCore_arm_armv7k, 50 eCore_arm_armv7m, 51 eCore_arm_armv7em, 52 eCore_arm_xscale, 53 eCore_thumb, 54 eCore_thumbv4t, 55 eCore_thumbv5, 56 eCore_thumbv5e, 57 eCore_thumbv6, 58 eCore_thumbv6m, 59 eCore_thumbv7, 60 eCore_thumbv7f, 61 eCore_thumbv7s, 62 eCore_thumbv7k, 63 eCore_thumbv7m, 64 eCore_thumbv7em, 65 66 eCore_mips64, 67 68 eCore_ppc_generic, 69 eCore_ppc_ppc601, 70 eCore_ppc_ppc602, 71 eCore_ppc_ppc603, 72 eCore_ppc_ppc603e, 73 eCore_ppc_ppc603ev, 74 eCore_ppc_ppc604, 75 eCore_ppc_ppc604e, 76 eCore_ppc_ppc620, 77 eCore_ppc_ppc750, 78 eCore_ppc_ppc7400, 79 eCore_ppc_ppc7450, 80 eCore_ppc_ppc970, 81 82 eCore_ppc64_generic, 83 eCore_ppc64_ppc970_64, 84 85 eCore_sparc_generic, 86 87 eCore_sparc9_generic, 88 89 eCore_x86_32_i386, 90 eCore_x86_32_i486, 91 eCore_x86_32_i486sx, 92 93 eCore_x86_64_x86_64, 94 eCore_x86_64_x86_64h, // Haswell enabled x86_64 95 eCore_hexagon_generic, 96 eCore_hexagon_hexagonv4, 97 eCore_hexagon_hexagonv5, 98 99 eCore_uknownMach32, 100 eCore_uknownMach64, 101 kNumCores, 102 103 kCore_invalid, 104 // The following constants are used for wildcard matching only 105 kCore_any, 106 kCore_arm_any, 107 kCore_ppc_any, 108 kCore_ppc64_any, 109 kCore_x86_32_any, 110 kCore_hexagon_any, 111 112 kCore_arm_first = eCore_arm_generic, 113 kCore_arm_last = eCore_arm_xscale, 114 115 kCore_thumb_first = eCore_thumb, 116 kCore_thumb_last = eCore_thumbv7em, 117 118 kCore_ppc_first = eCore_ppc_generic, 119 kCore_ppc_last = eCore_ppc_ppc970, 120 121 kCore_ppc64_first = eCore_ppc64_generic, 122 kCore_ppc64_last = eCore_ppc64_ppc970_64, 123 124 kCore_x86_32_first = eCore_x86_32_i386, 125 kCore_x86_32_last = eCore_x86_32_i486sx, 126 127 kCore_hexagon_first = eCore_hexagon_generic, 128 kCore_hexagon_last = eCore_hexagon_hexagonv5 129 }; 130 131 //------------------------------------------------------------------ 132 /// Default constructor. 133 /// 134 /// Default constructor that initializes the object with invalid 135 /// cpu type and subtype values. 136 //------------------------------------------------------------------ 137 ArchSpec (); 138 139 //------------------------------------------------------------------ 140 /// Constructor over triple. 141 /// 142 /// Constructs an ArchSpec with properties consistent with the given 143 /// Triple. 144 //------------------------------------------------------------------ 145 explicit 146 ArchSpec (const llvm::Triple &triple); 147 explicit 148 ArchSpec (const char *triple_cstr); 149 explicit 150 ArchSpec (const char *triple_cstr, Platform *platform); 151 //------------------------------------------------------------------ 152 /// Constructor over architecture name. 153 /// 154 /// Constructs an ArchSpec with properties consistent with the given 155 /// object type and architecture name. 156 //------------------------------------------------------------------ 157 explicit 158 ArchSpec (ArchitectureType arch_type, 159 uint32_t cpu_type, 160 uint32_t cpu_subtype); 161 162 //------------------------------------------------------------------ 163 /// Destructor. 164 //------------------------------------------------------------------ 165 ~ArchSpec (); 166 167 //------------------------------------------------------------------ 168 /// Assignment operator. 169 /// 170 /// @param[in] rhs another ArchSpec object to copy. 171 /// 172 /// @return A const reference to this object. 173 //------------------------------------------------------------------ 174 const ArchSpec& 175 operator= (const ArchSpec& rhs); 176 177 static size_t 178 AutoComplete (const char *name, 179 StringList &matches); 180 181 //------------------------------------------------------------------ 182 /// Returns a static string representing the current architecture. 183 /// 184 /// @return A static string correcponding to the current 185 /// architecture. 186 //------------------------------------------------------------------ 187 const char * 188 GetArchitectureName () const; 189 190 //------------------------------------------------------------------ 191 /// Clears the object state. 192 /// 193 /// Clears the object state back to a default invalid state. 194 //------------------------------------------------------------------ 195 void 196 Clear (); 197 198 //------------------------------------------------------------------ 199 /// Returns the size in bytes of an address of the current 200 /// architecture. 201 /// 202 /// @return The byte size of an address of the current architecture. 203 //------------------------------------------------------------------ 204 uint32_t 205 GetAddressByteSize () const; 206 207 //------------------------------------------------------------------ 208 /// Returns a machine family for the current architecture. 209 /// 210 /// @return An LLVM arch type. 211 //------------------------------------------------------------------ 212 llvm::Triple::ArchType 213 GetMachine () const; 214 215 //------------------------------------------------------------------ 216 /// Returns the distribution id of the architecture. 217 /// 218 /// This will be something like "ubuntu", "fedora", etc. on Linux. 219 /// 220 /// @return A ConstString ref containing the distribution id, 221 /// potentially empty. 222 //------------------------------------------------------------------ 223 const ConstString& 224 GetDistributionId () const; 225 226 //------------------------------------------------------------------ 227 /// Set the distribution id of the architecture. 228 /// 229 /// This will be something like "ubuntu", "fedora", etc. on Linux. 230 /// This should be the same value returned by 231 /// Host::GetDistributionId (). 232 ///------------------------------------------------------------------ 233 void 234 SetDistributionId (const char* distribution_id); 235 236 //------------------------------------------------------------------ 237 /// Tests if this ArchSpec is valid. 238 /// 239 /// @return True if the current architecture is valid, false 240 /// otherwise. 241 //------------------------------------------------------------------ 242 bool 243 IsValid () const 244 { 245 return m_core >= eCore_arm_generic && m_core < kNumCores; 246 } 247 248 bool 249 TripleVendorWasSpecified() const 250 { 251 return !m_triple.getVendorName().empty(); 252 } 253 254 bool 255 TripleOSWasSpecified() const 256 { 257 return !m_triple.getOSName().empty(); 258 } 259 260 //------------------------------------------------------------------ 261 /// Sets this ArchSpec according to the given architecture name. 262 /// 263 /// The architecture name can be one of the generic system default 264 /// values: 265 /// 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). 273 /// 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). 277 /// 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: 282 /// 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. 286 /// 287 /// @param[in] arch_name The name of an architecture. 288 /// 289 /// @return True if @p arch_name was successfully translated, false 290 /// otherwise. 291 //------------------------------------------------------------------ 292// bool 293// SetArchitecture (const llvm::StringRef& arch_name); 294// 295// bool 296// SetArchitecture (const char *arch_name); 297 298 //------------------------------------------------------------------ 299 /// Change the architecture object type and CPU type. 300 /// 301 /// @param[in] arch_type The object type of this ArchSpec. 302 /// 303 /// @param[in] cpu The required CPU type. 304 /// 305 /// @return True if the object and CPU type were sucessfully set. 306 //------------------------------------------------------------------ 307 bool 308 SetArchitecture (ArchitectureType arch_type, 309 uint32_t cpu, 310 uint32_t sub); 311 312 //------------------------------------------------------------------ 313 /// Returns the byte order for the architecture specification. 314 /// 315 /// @return The endian enumeration for the current endianness of 316 /// the architecture specification 317 //------------------------------------------------------------------ 318 lldb::ByteOrder 319 GetByteOrder () const; 320 321 //------------------------------------------------------------------ 322 /// Sets this ArchSpec's byte order. 323 /// 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 //------------------------------------------------------------------ 329 void 330 SetByteOrder (lldb::ByteOrder byte_order) 331 { 332 m_byte_order = byte_order; 333 } 334 335 uint32_t 336 GetMinimumOpcodeByteSize() const; 337 338 uint32_t 339 GetMaximumOpcodeByteSize() const; 340 341 Core 342 GetCore () const 343 { 344 return m_core; 345 } 346 347 uint32_t 348 GetMachOCPUType () const; 349 350 uint32_t 351 GetMachOCPUSubType () const; 352 353 //------------------------------------------------------------------ 354 /// Architecture tripple accessor. 355 /// 356 /// @return A triple describing this ArchSpec. 357 //------------------------------------------------------------------ 358 llvm::Triple & 359 GetTriple () 360 { 361 return m_triple; 362 } 363 364 //------------------------------------------------------------------ 365 /// Architecture tripple accessor. 366 /// 367 /// @return A triple describing this ArchSpec. 368 //------------------------------------------------------------------ 369 const llvm::Triple & 370 GetTriple () const 371 { 372 return m_triple; 373 } 374 375 //------------------------------------------------------------------ 376 /// Architecture tripple setter. 377 /// 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. 384 /// 385 /// @return A triple describing this ArchSpec. 386 //------------------------------------------------------------------ 387 bool 388 SetTriple (const llvm::Triple &triple); 389 390 bool 391 SetTriple (const char *triple_cstr); 392 393 bool 394 SetTriple (const char *triple_cstr, 395 Platform *platform); 396 397 //------------------------------------------------------------------ 398 /// Returns the default endianness of the architecture. 399 /// 400 /// @return The endian enumeration for the default endianness of 401 /// the architecture. 402 //------------------------------------------------------------------ 403 lldb::ByteOrder 404 GetDefaultEndian () const; 405 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 410 /// 411 /// @return true if the two ArchSpecs match. 412 //------------------------------------------------------------------ 413 bool 414 IsExactMatch (const ArchSpec& rhs) const; 415 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 420 /// 421 /// @return true if the two ArchSpecs are compatible 422 //------------------------------------------------------------------ 423 bool 424 IsCompatibleMatch (const ArchSpec& rhs) const; 425 426protected: 427 bool 428 IsEqualTo (const ArchSpec& rhs, bool exact_match) const; 429 430 llvm::Triple m_triple; 431 Core m_core; 432 lldb::ByteOrder m_byte_order; 433 434 ConstString m_distribution_id; 435 436 // Called when m_def or m_entry are changed. Fills in all remaining 437 // members with default values. 438 void 439 CoreUpdated (bool update_triple); 440}; 441 442//------------------------------------------------------------------ 443/// @fn bool operator< (const ArchSpec& lhs, const ArchSpec& rhs) 444/// @brief Less than operator. 445/// 446/// Tests two ArchSpec objects to see if \a lhs is less than \a 447/// rhs. 448/// 449/// @param[in] lhs The Left Hand Side ArchSpec object to compare. 450/// @param[in] rhs The Left Hand Side ArchSpec object to compare. 451/// 452/// @return true if \a lhs is less than \a rhs 453//------------------------------------------------------------------ 454bool operator< (const ArchSpec& lhs, const ArchSpec& rhs); 455 456} // namespace lldb_private 457 458#endif // #if defined(__cplusplus) 459#endif // #ifndef liblldb_ArchSpec_h_ 460