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