ArchSpec.h revision b170aee2daacc83e3d71c3e3acc9d56c89893a7b
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 "llvm/ADT/StringRef.h" 17#include "llvm/ADT/Triple.h" 18 19namespace lldb_private { 20 21struct CoreDefinition; 22 23//---------------------------------------------------------------------- 24/// @class ArchSpec ArchSpec.h "lldb/Core/ArchSpec.h" 25/// @brief An architecture specification class. 26/// 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//---------------------------------------------------------------------- 32class ArchSpec 33{ 34public: 35 enum Core 36 { 37 eCore_arm_generic, 38 eCore_arm_armv4, 39 eCore_arm_armv4t, 40 eCore_arm_armv5, 41 eCore_arm_armv5e, 42 eCore_arm_armv5t, 43 eCore_arm_armv6, 44 eCore_arm_armv7, 45 eCore_arm_armv7f, 46 eCore_arm_armv7k, 47 eCore_arm_armv7s, 48 eCore_arm_xscale, 49 eCore_thumb, 50 eCore_thumbv4t, 51 eCore_thumbv5, 52 eCore_thumbv5e, 53 eCore_thumbv6, 54 eCore_thumbv7, 55 eCore_thumbv7f, 56 eCore_thumbv7k, 57 eCore_thumbv7s, 58 59 eCore_ppc_generic, 60 eCore_ppc_ppc601, 61 eCore_ppc_ppc602, 62 eCore_ppc_ppc603, 63 eCore_ppc_ppc603e, 64 eCore_ppc_ppc603ev, 65 eCore_ppc_ppc604, 66 eCore_ppc_ppc604e, 67 eCore_ppc_ppc620, 68 eCore_ppc_ppc750, 69 eCore_ppc_ppc7400, 70 eCore_ppc_ppc7450, 71 eCore_ppc_ppc970, 72 73 eCore_ppc64_generic, 74 eCore_ppc64_ppc970_64, 75 76 eCore_sparc_generic, 77 78 eCore_sparc9_generic, 79 80 eCore_x86_32_i386, 81 eCore_x86_32_i486, 82 eCore_x86_32_i486sx, 83 84 eCore_x86_64_x86_64, 85 kNumCores, 86 87 kCore_invalid, 88 // The following constants are used for wildcard matching only 89 kCore_any, 90 kCore_arm_any, 91 kCore_ppc_any, 92 kCore_ppc64_any, 93 kCore_x86_32_any, 94 95 kCore_arm_first = eCore_arm_generic, 96 kCore_arm_last = eCore_arm_xscale, 97 98 kCore_thumb_first = eCore_thumb, 99 kCore_thumb_last = eCore_thumbv7s, 100 101 kCore_ppc_first = eCore_ppc_generic, 102 kCore_ppc_last = eCore_ppc_ppc970, 103 104 kCore_ppc64_first = eCore_ppc64_generic, 105 kCore_ppc64_last = eCore_ppc64_ppc970_64, 106 107 kCore_x86_32_first = eCore_x86_32_i386, 108 kCore_x86_32_last = eCore_x86_32_i486sx 109 }; 110 111 //------------------------------------------------------------------ 112 /// Default constructor. 113 /// 114 /// Default constructor that initializes the object with invalid 115 /// cpu type and subtype values. 116 //------------------------------------------------------------------ 117 ArchSpec (); 118 119 //------------------------------------------------------------------ 120 /// Constructor over triple. 121 /// 122 /// Constructs an ArchSpec with properties consistent with the given 123 /// Triple. 124 //------------------------------------------------------------------ 125 explicit 126 ArchSpec (const llvm::Triple &triple); 127 explicit 128 ArchSpec (const char *triple_cstr); 129 explicit 130 ArchSpec (const char *triple_cstr, Platform *platform); 131 //------------------------------------------------------------------ 132 /// Constructor over architecture name. 133 /// 134 /// Constructs an ArchSpec with properties consistent with the given 135 /// object type and architecture name. 136 //------------------------------------------------------------------ 137 explicit 138 ArchSpec (ArchitectureType arch_type, 139 uint32_t cpu_type, 140 uint32_t cpu_subtype); 141 142 //------------------------------------------------------------------ 143 /// Destructor. 144 /// 145 /// The destructor is virtual in case this class is subclassed. 146 //------------------------------------------------------------------ 147 virtual 148 ~ArchSpec (); 149 150 //------------------------------------------------------------------ 151 /// Assignment operator. 152 /// 153 /// @param[in] rhs another ArchSpec object to copy. 154 /// 155 /// @return A const reference to this object. 156 //------------------------------------------------------------------ 157 const ArchSpec& 158 operator= (const ArchSpec& rhs); 159 160 static uint32_t 161 AutoComplete (const char *name, 162 StringList &matches); 163 164 //------------------------------------------------------------------ 165 /// Returns a static string representing the current architecture. 166 /// 167 /// @return A static string correcponding to the current 168 /// architecture. 169 //------------------------------------------------------------------ 170 const char * 171 GetArchitectureName () const; 172 173 //------------------------------------------------------------------ 174 /// Clears the object state. 175 /// 176 /// Clears the object state back to a default invalid state. 177 //------------------------------------------------------------------ 178 void 179 Clear (); 180 181 //------------------------------------------------------------------ 182 /// Returns the size in bytes of an address of the current 183 /// architecture. 184 /// 185 /// @return The byte size of an address of the current architecture. 186 //------------------------------------------------------------------ 187 uint32_t 188 GetAddressByteSize () const; 189 190 //------------------------------------------------------------------ 191 /// Returns a machine family for the current architecture. 192 /// 193 /// @return An LLVM arch type. 194 //------------------------------------------------------------------ 195 llvm::Triple::ArchType 196 GetMachine () const; 197 198 //------------------------------------------------------------------ 199 /// Tests if this ArchSpec is valid. 200 /// 201 /// @return True if the current architecture is valid, false 202 /// otherwise. 203 //------------------------------------------------------------------ 204 bool 205 IsValid () const 206 { 207 return m_core >= eCore_arm_generic && m_core < kNumCores; 208 } 209 210 bool 211 TripleVendorWasSpecified() const 212 { 213 return !m_triple.getVendorName().empty(); 214 } 215 216 bool 217 TripleOSWasSpecified() const 218 { 219 return !m_triple.getOSName().empty(); 220 } 221 222 //------------------------------------------------------------------ 223 /// Sets this ArchSpec according to the given architecture name. 224 /// 225 /// The architecture name can be one of the generic system default 226 /// values: 227 /// 228 /// @li \c LLDB_ARCH_DEFAULT - The arch the current system defaults 229 /// to when a program is launched without any extra 230 /// attributes or settings. 231 /// @li \c LLDB_ARCH_DEFAULT_32BIT - The default host architecture 232 /// for 32 bit (if any). 233 /// @li \c LLDB_ARCH_DEFAULT_64BIT - The default host architecture 234 /// for 64 bit (if any). 235 /// 236 /// Alternatively, if the object type of this ArchSpec has been 237 /// configured, a concrete architecture can be specified to set 238 /// the CPU type ("x86_64" for example). 239 /// 240 /// Finally, an encoded object and archetecture format is accepted. 241 /// The format contains an object type (like "macho" or "elf"), 242 /// followed by a platform dependent encoding of CPU type and 243 /// subtype. For example: 244 /// 245 /// "macho" : Specifies an object type of MachO. 246 /// "macho-16-6" : MachO specific encoding for ARMv6. 247 /// "elf-43 : ELF specific encoding for Sparc V9. 248 /// 249 /// @param[in] arch_name The name of an architecture. 250 /// 251 /// @return True if @p arch_name was successfully translated, false 252 /// otherwise. 253 //------------------------------------------------------------------ 254// bool 255// SetArchitecture (const llvm::StringRef& arch_name); 256// 257// bool 258// SetArchitecture (const char *arch_name); 259 260 //------------------------------------------------------------------ 261 /// Change the architecture object type and CPU type. 262 /// 263 /// @param[in] arch_type The object type of this ArchSpec. 264 /// 265 /// @param[in] cpu The required CPU type. 266 /// 267 /// @return True if the object and CPU type were sucessfully set. 268 //------------------------------------------------------------------ 269 bool 270 SetArchitecture (ArchitectureType arch_type, 271 uint32_t cpu, 272 uint32_t sub); 273 274 //------------------------------------------------------------------ 275 /// Returns the byte order for the architecture specification. 276 /// 277 /// @return The endian enumeration for the current endianness of 278 /// the architecture specification 279 //------------------------------------------------------------------ 280 lldb::ByteOrder 281 GetByteOrder () const; 282 283 //------------------------------------------------------------------ 284 /// Sets this ArchSpec's byte order. 285 /// 286 /// In the common case there is no need to call this method as the 287 /// byte order can almost always be determined by the architecture. 288 /// However, many CPU's are bi-endian (ARM, Alpha, PowerPC, etc) 289 /// and the default/assumed byte order may be incorrect. 290 //------------------------------------------------------------------ 291 void 292 SetByteOrder (lldb::ByteOrder byte_order) 293 { 294 m_byte_order = byte_order; 295 } 296 297 uint32_t 298 GetMinimumOpcodeByteSize() const; 299 300 uint32_t 301 GetMaximumOpcodeByteSize() const; 302 303 Core 304 GetCore () const 305 { 306 return m_core; 307 } 308 309 uint32_t 310 GetMachOCPUType () const; 311 312 uint32_t 313 GetMachOCPUSubType () const; 314 315 //------------------------------------------------------------------ 316 /// Architecture tripple accessor. 317 /// 318 /// @return A triple describing this ArchSpec. 319 //------------------------------------------------------------------ 320 llvm::Triple & 321 GetTriple () 322 { 323 return m_triple; 324 } 325 326 //------------------------------------------------------------------ 327 /// Architecture tripple accessor. 328 /// 329 /// @return A triple describing this ArchSpec. 330 //------------------------------------------------------------------ 331 const llvm::Triple & 332 GetTriple () const 333 { 334 return m_triple; 335 } 336 337 //------------------------------------------------------------------ 338 /// Architecture tripple setter. 339 /// 340 /// Configures this ArchSpec according to the given triple. If the 341 /// triple has unknown components in all of the vendor, OS, and 342 /// the optional environment field (i.e. "i386-unknown-unknown") 343 /// then default values are taken from the host. Architecture and 344 /// environment components are used to further resolve the CPU type 345 /// and subtype, endian characteristics, etc. 346 /// 347 /// @return A triple describing this ArchSpec. 348 //------------------------------------------------------------------ 349 bool 350 SetTriple (const llvm::Triple &triple); 351 352 bool 353 SetTriple (const char *triple_cstr); 354 355 bool 356 SetTriple (const char *triple_cstr, 357 Platform *platform); 358 359 //------------------------------------------------------------------ 360 /// Returns the default endianness of the architecture. 361 /// 362 /// @return The endian enumeration for the default endianness of 363 /// the architecture. 364 //------------------------------------------------------------------ 365 lldb::ByteOrder 366 GetDefaultEndian () const; 367 368protected: 369 llvm::Triple m_triple; 370 Core m_core; 371 lldb::ByteOrder m_byte_order; 372 373 // Called when m_def or m_entry are changed. Fills in all remaining 374 // members with default values. 375 void 376 CoreUpdated (bool update_triple); 377}; 378 379 380//------------------------------------------------------------------ 381/// @fn bool operator== (const ArchSpec& lhs, const ArchSpec& rhs) 382/// @brief Equal to operator. 383/// 384/// Tests two ArchSpec objects to see if they are equal. 385/// 386/// @param[in] lhs The Left Hand Side ArchSpec object to compare. 387/// @param[in] rhs The Left Hand Side ArchSpec object to compare. 388/// 389/// @return true if \a lhs is equal to \a rhs 390//------------------------------------------------------------------ 391bool operator==(const ArchSpec& lhs, const ArchSpec& rhs); 392 393//------------------------------------------------------------------ 394/// @fn bool operator!= (const ArchSpec& lhs, const ArchSpec& rhs) 395/// @brief Not equal to operator. 396/// 397/// Tests two ArchSpec objects to see if they are not equal. 398/// 399/// @param[in] lhs The Left Hand Side ArchSpec object to compare. 400/// @param[in] rhs The Left Hand Side ArchSpec object to compare. 401/// 402/// @return true if \a lhs is not equal to \a rhs 403//------------------------------------------------------------------ 404bool operator!=(const ArchSpec& lhs, const ArchSpec& rhs); 405 406//------------------------------------------------------------------ 407/// @fn bool operator< (const ArchSpec& lhs, const ArchSpec& rhs) 408/// @brief Less than operator. 409/// 410/// Tests two ArchSpec objects to see if \a lhs is less than \a 411/// rhs. 412/// 413/// @param[in] lhs The Left Hand Side ArchSpec object to compare. 414/// @param[in] rhs The Left Hand Side ArchSpec object to compare. 415/// 416/// @return true if \a lhs is less than \a rhs 417//------------------------------------------------------------------ 418bool operator< (const ArchSpec& lhs, const ArchSpec& rhs); 419 420} // namespace lldb_private 421 422#endif // #if defined(__cplusplus) 423#endif // #ifndef liblldb_ArchSpec_h_ 424