1 //===- TypeIndex.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 LLVM_DEBUGINFO_CODEVIEW_TYPEINDEX_H 11 #define LLVM_DEBUGINFO_CODEVIEW_TYPEINDEX_H 12 13 #include "llvm/Support/Endian.h" 14 #include <cassert> 15 #include <cinttypes> 16 17 namespace llvm { 18 namespace codeview { 19 20 enum class SimpleTypeKind : uint32_t { 21 None = 0x0000, // uncharacterized type (no type) 22 Void = 0x0003, // void 23 NotTranslated = 0x0007, // type not translated by cvpack 24 HResult = 0x0008, // OLE/COM HRESULT 25 26 SignedCharacter = 0x0010, // 8 bit signed 27 UnsignedCharacter = 0x0020, // 8 bit unsigned 28 NarrowCharacter = 0x0070, // really a char 29 WideCharacter = 0x0071, // wide char 30 Character16 = 0x007a, // char16_t 31 Character32 = 0x007b, // char32_t 32 33 SByte = 0x0068, // 8 bit signed int 34 Byte = 0x0069, // 8 bit unsigned int 35 Int16Short = 0x0011, // 16 bit signed 36 UInt16Short = 0x0021, // 16 bit unsigned 37 Int16 = 0x0072, // 16 bit signed int 38 UInt16 = 0x0073, // 16 bit unsigned int 39 Int32Long = 0x0012, // 32 bit signed 40 UInt32Long = 0x0022, // 32 bit unsigned 41 Int32 = 0x0074, // 32 bit signed int 42 UInt32 = 0x0075, // 32 bit unsigned int 43 Int64Quad = 0x0013, // 64 bit signed 44 UInt64Quad = 0x0023, // 64 bit unsigned 45 Int64 = 0x0076, // 64 bit signed int 46 UInt64 = 0x0077, // 64 bit unsigned int 47 Int128Oct = 0x0014, // 128 bit signed int 48 UInt128Oct = 0x0024, // 128 bit unsigned int 49 Int128 = 0x0078, // 128 bit signed int 50 UInt128 = 0x0079, // 128 bit unsigned int 51 52 Float16 = 0x0046, // 16 bit real 53 Float32 = 0x0040, // 32 bit real 54 Float32PartialPrecision = 0x0045, // 32 bit PP real 55 Float48 = 0x0044, // 48 bit real 56 Float64 = 0x0041, // 64 bit real 57 Float80 = 0x0042, // 80 bit real 58 Float128 = 0x0043, // 128 bit real 59 60 Complex16 = 0x0056, // 16 bit complex 61 Complex32 = 0x0050, // 32 bit complex 62 Complex32PartialPrecision = 0x0055, // 32 bit PP complex 63 Complex48 = 0x0054, // 48 bit complex 64 Complex64 = 0x0051, // 64 bit complex 65 Complex80 = 0x0052, // 80 bit complex 66 Complex128 = 0x0053, // 128 bit complex 67 68 Boolean8 = 0x0030, // 8 bit boolean 69 Boolean16 = 0x0031, // 16 bit boolean 70 Boolean32 = 0x0032, // 32 bit boolean 71 Boolean64 = 0x0033, // 64 bit boolean 72 Boolean128 = 0x0034, // 128 bit boolean 73 }; 74 75 enum class SimpleTypeMode : uint32_t { 76 Direct = 0x00000000, // Not a pointer 77 NearPointer = 0x00000100, // Near pointer 78 FarPointer = 0x00000200, // Far pointer 79 HugePointer = 0x00000300, // Huge pointer 80 NearPointer32 = 0x00000400, // 32 bit near pointer 81 FarPointer32 = 0x00000500, // 32 bit far pointer 82 NearPointer64 = 0x00000600, // 64 bit near pointer 83 NearPointer128 = 0x00000700 // 128 bit near pointer 84 }; 85 86 /// A 32-bit type reference. Types are indexed by their order of appearance in 87 /// .debug$T plus 0x1000. Type indices less than 0x1000 are "simple" types, 88 /// composed of a SimpleTypeMode byte followed by a SimpleTypeKind byte. 89 class TypeIndex { 90 public: 91 static const uint32_t FirstNonSimpleIndex = 0x1000; 92 static const uint32_t SimpleKindMask = 0x000000ff; 93 static const uint32_t SimpleModeMask = 0x00000700; 94 95 public: 96 TypeIndex() : Index(static_cast<uint32_t>(SimpleTypeKind::None)) {} 97 explicit TypeIndex(uint32_t Index) : Index(Index) {} 98 explicit TypeIndex(SimpleTypeKind Kind) 99 : Index(static_cast<uint32_t>(Kind)) {} 100 TypeIndex(SimpleTypeKind Kind, SimpleTypeMode Mode) 101 : Index(static_cast<uint32_t>(Kind) | static_cast<uint32_t>(Mode)) {} 102 103 uint32_t getIndex() const { return Index; } 104 void setIndex(uint32_t I) { Index = I; } 105 bool isSimple() const { return Index < FirstNonSimpleIndex; } 106 107 bool isNoneType() const { return *this == None(); } 108 109 SimpleTypeKind getSimpleKind() const { 110 assert(isSimple()); 111 return static_cast<SimpleTypeKind>(Index & SimpleKindMask); 112 } 113 114 SimpleTypeMode getSimpleMode() const { 115 assert(isSimple()); 116 return static_cast<SimpleTypeMode>(Index & SimpleModeMask); 117 } 118 119 static TypeIndex None() { return TypeIndex(SimpleTypeKind::None); } 120 static TypeIndex Void() { return TypeIndex(SimpleTypeKind::Void); } 121 static TypeIndex VoidPointer32() { 122 return TypeIndex(SimpleTypeKind::Void, SimpleTypeMode::NearPointer32); 123 } 124 static TypeIndex VoidPointer64() { 125 return TypeIndex(SimpleTypeKind::Void, SimpleTypeMode::NearPointer64); 126 } 127 128 static TypeIndex SignedCharacter() { 129 return TypeIndex(SimpleTypeKind::SignedCharacter); 130 } 131 static TypeIndex UnsignedCharacter() { 132 return TypeIndex(SimpleTypeKind::UnsignedCharacter); 133 } 134 static TypeIndex NarrowCharacter() { 135 return TypeIndex(SimpleTypeKind::NarrowCharacter); 136 } 137 static TypeIndex WideCharacter() { 138 return TypeIndex(SimpleTypeKind::WideCharacter); 139 } 140 static TypeIndex Int16Short() { 141 return TypeIndex(SimpleTypeKind::Int16Short); 142 } 143 static TypeIndex UInt16Short() { 144 return TypeIndex(SimpleTypeKind::UInt16Short); 145 } 146 static TypeIndex Int32() { return TypeIndex(SimpleTypeKind::Int32); } 147 static TypeIndex UInt32() { return TypeIndex(SimpleTypeKind::UInt32); } 148 static TypeIndex Int32Long() { return TypeIndex(SimpleTypeKind::Int32Long); } 149 static TypeIndex UInt32Long() { 150 return TypeIndex(SimpleTypeKind::UInt32Long); 151 } 152 static TypeIndex Int64() { return TypeIndex(SimpleTypeKind::Int64); } 153 static TypeIndex UInt64() { return TypeIndex(SimpleTypeKind::UInt64); } 154 static TypeIndex Int64Quad() { return TypeIndex(SimpleTypeKind::Int64Quad); } 155 static TypeIndex UInt64Quad() { 156 return TypeIndex(SimpleTypeKind::UInt64Quad); 157 } 158 159 static TypeIndex Float32() { return TypeIndex(SimpleTypeKind::Float32); } 160 static TypeIndex Float64() { return TypeIndex(SimpleTypeKind::Float64); } 161 162 friend inline bool operator==(const TypeIndex &A, const TypeIndex &B) { 163 return A.getIndex() == B.getIndex(); 164 } 165 166 friend inline bool operator!=(const TypeIndex &A, const TypeIndex &B) { 167 return A.getIndex() != B.getIndex(); 168 } 169 170 friend inline bool operator<(const TypeIndex &A, const TypeIndex &B) { 171 return A.getIndex() < B.getIndex(); 172 } 173 174 friend inline bool operator<=(const TypeIndex &A, const TypeIndex &B) { 175 return A.getIndex() <= B.getIndex(); 176 } 177 178 friend inline bool operator>(const TypeIndex &A, const TypeIndex &B) { 179 return A.getIndex() > B.getIndex(); 180 } 181 182 friend inline bool operator>=(const TypeIndex &A, const TypeIndex &B) { 183 return A.getIndex() >= B.getIndex(); 184 } 185 186 private: 187 support::ulittle32_t Index; 188 }; 189 190 } 191 } 192 193 #endif 194