#ifndef LLVM_DEBUGINFO_CODEVIEW_TYPEINDEX_H
#define LLVM_DEBUGINFO_CODEVIEW_TYPEINDEX_H
#include "llvm/ADT/DenseMapInfo.h"
#include "llvm/Support/Endian.h"
#include <cassert>
#include <cinttypes>
namespace llvm {
class ScopedPrinter;
class StringRef;
namespace codeview {
class TypeCollection;
enum class SimpleTypeKind : uint32_t {
None = 0x0000, Void = 0x0003, NotTranslated = 0x0007, HResult = 0x0008,
SignedCharacter = 0x0010, UnsignedCharacter = 0x0020, NarrowCharacter = 0x0070, WideCharacter = 0x0071, Character16 = 0x007a, Character32 = 0x007b, Character8 = 0x007c,
SByte = 0x0068, Byte = 0x0069, Int16Short = 0x0011, UInt16Short = 0x0021, Int16 = 0x0072, UInt16 = 0x0073, Int32Long = 0x0012, UInt32Long = 0x0022, Int32 = 0x0074, UInt32 = 0x0075, Int64Quad = 0x0013, UInt64Quad = 0x0023, Int64 = 0x0076, UInt64 = 0x0077, Int128Oct = 0x0014, UInt128Oct = 0x0024, Int128 = 0x0078, UInt128 = 0x0079,
Float16 = 0x0046, Float32 = 0x0040, Float32PartialPrecision = 0x0045, Float48 = 0x0044, Float64 = 0x0041, Float80 = 0x0042, Float128 = 0x0043,
Complex16 = 0x0056, Complex32 = 0x0050, Complex32PartialPrecision = 0x0055, Complex48 = 0x0054, Complex64 = 0x0051, Complex80 = 0x0052, Complex128 = 0x0053,
Boolean8 = 0x0030, Boolean16 = 0x0031, Boolean32 = 0x0032, Boolean64 = 0x0033, Boolean128 = 0x0034, };
enum class SimpleTypeMode : uint32_t {
Direct = 0x00000000, NearPointer = 0x00000100, FarPointer = 0x00000200, HugePointer = 0x00000300, NearPointer32 = 0x00000400, FarPointer32 = 0x00000500, NearPointer64 = 0x00000600, NearPointer128 = 0x00000700 };
class TypeIndex {
public:
static const uint32_t FirstNonSimpleIndex = 0x1000;
static const uint32_t SimpleKindMask = 0x000000ff;
static const uint32_t SimpleModeMask = 0x00000700;
static const uint32_t DecoratedItemIdMask = 0x80000000;
public:
TypeIndex() : Index(static_cast<uint32_t>(SimpleTypeKind::None)) {}
explicit TypeIndex(uint32_t Index) : Index(Index) {}
explicit TypeIndex(SimpleTypeKind Kind)
: Index(static_cast<uint32_t>(Kind)) {}
TypeIndex(SimpleTypeKind Kind, SimpleTypeMode Mode)
: Index(static_cast<uint32_t>(Kind) | static_cast<uint32_t>(Mode)) {}
uint32_t getIndex() const { return Index; }
void setIndex(uint32_t I) { Index = I; }
bool isSimple() const { return Index < FirstNonSimpleIndex; }
bool isDecoratedItemId() const { return !!(Index & DecoratedItemIdMask); }
bool isNoneType() const { return *this == None(); }
uint32_t toArrayIndex() const {
assert(!isSimple());
return (getIndex() & ~DecoratedItemIdMask) - FirstNonSimpleIndex;
}
static TypeIndex fromArrayIndex(uint32_t Index) {
return TypeIndex(Index + FirstNonSimpleIndex);
}
static TypeIndex fromDecoratedArrayIndex(bool IsItem, uint32_t Index) {
return TypeIndex((Index + FirstNonSimpleIndex) |
(IsItem ? DecoratedItemIdMask : 0));
}
TypeIndex removeDecoration() {
return TypeIndex(Index & ~DecoratedItemIdMask);
}
SimpleTypeKind getSimpleKind() const {
assert(isSimple());
return static_cast<SimpleTypeKind>(Index & SimpleKindMask);
}
SimpleTypeMode getSimpleMode() const {
assert(isSimple());
return static_cast<SimpleTypeMode>(Index & SimpleModeMask);
}
TypeIndex makeDirect() const { return TypeIndex{getSimpleKind()}; }
static TypeIndex None() { return TypeIndex(SimpleTypeKind::None); }
static TypeIndex Void() { return TypeIndex(SimpleTypeKind::Void); }
static TypeIndex VoidPointer32() {
return TypeIndex(SimpleTypeKind::Void, SimpleTypeMode::NearPointer32);
}
static TypeIndex VoidPointer64() {
return TypeIndex(SimpleTypeKind::Void, SimpleTypeMode::NearPointer64);
}
static TypeIndex NullptrT() {
return TypeIndex(SimpleTypeKind::Void, SimpleTypeMode::NearPointer);
}
static TypeIndex SignedCharacter() {
return TypeIndex(SimpleTypeKind::SignedCharacter);
}
static TypeIndex UnsignedCharacter() {
return TypeIndex(SimpleTypeKind::UnsignedCharacter);
}
static TypeIndex NarrowCharacter() {
return TypeIndex(SimpleTypeKind::NarrowCharacter);
}
static TypeIndex WideCharacter() {
return TypeIndex(SimpleTypeKind::WideCharacter);
}
static TypeIndex Int16Short() {
return TypeIndex(SimpleTypeKind::Int16Short);
}
static TypeIndex UInt16Short() {
return TypeIndex(SimpleTypeKind::UInt16Short);
}
static TypeIndex Int32() { return TypeIndex(SimpleTypeKind::Int32); }
static TypeIndex UInt32() { return TypeIndex(SimpleTypeKind::UInt32); }
static TypeIndex Int32Long() { return TypeIndex(SimpleTypeKind::Int32Long); }
static TypeIndex UInt32Long() {
return TypeIndex(SimpleTypeKind::UInt32Long);
}
static TypeIndex Int64() { return TypeIndex(SimpleTypeKind::Int64); }
static TypeIndex UInt64() { return TypeIndex(SimpleTypeKind::UInt64); }
static TypeIndex Int64Quad() { return TypeIndex(SimpleTypeKind::Int64Quad); }
static TypeIndex UInt64Quad() {
return TypeIndex(SimpleTypeKind::UInt64Quad);
}
static TypeIndex Float32() { return TypeIndex(SimpleTypeKind::Float32); }
static TypeIndex Float64() { return TypeIndex(SimpleTypeKind::Float64); }
TypeIndex &operator+=(unsigned N) {
Index += N;
return *this;
}
TypeIndex &operator++() {
Index += 1;
return *this;
}
TypeIndex operator++(int) {
TypeIndex Copy = *this;
operator++();
return Copy;
}
TypeIndex &operator-=(unsigned N) {
assert(Index >= N);
Index -= N;
return *this;
}
TypeIndex &operator--() {
Index -= 1;
return *this;
}
TypeIndex operator--(int) {
TypeIndex Copy = *this;
operator--();
return Copy;
}
friend inline bool operator==(const TypeIndex &A, const TypeIndex &B) {
return A.getIndex() == B.getIndex();
}
friend inline bool operator!=(const TypeIndex &A, const TypeIndex &B) {
return A.getIndex() != B.getIndex();
}
friend inline bool operator<(const TypeIndex &A, const TypeIndex &B) {
return A.getIndex() < B.getIndex();
}
friend inline bool operator<=(const TypeIndex &A, const TypeIndex &B) {
return A.getIndex() <= B.getIndex();
}
friend inline bool operator>(const TypeIndex &A, const TypeIndex &B) {
return A.getIndex() > B.getIndex();
}
friend inline bool operator>=(const TypeIndex &A, const TypeIndex &B) {
return A.getIndex() >= B.getIndex();
}
friend inline TypeIndex operator+(const TypeIndex &A, uint32_t N) {
TypeIndex Result(A);
Result += N;
return Result;
}
friend inline TypeIndex operator-(const TypeIndex &A, uint32_t N) {
assert(A.getIndex() >= N);
TypeIndex Result(A);
Result -= N;
return Result;
}
friend inline uint32_t operator-(const TypeIndex &A, const TypeIndex &B) {
assert(A >= B);
return A.toArrayIndex() - B.toArrayIndex();
}
static StringRef simpleTypeName(TypeIndex TI);
private:
support::ulittle32_t Index;
};
struct TypeIndexOffset {
TypeIndex Type;
support::ulittle32_t Offset;
};
void printTypeIndex(ScopedPrinter &Printer, StringRef FieldName, TypeIndex TI,
TypeCollection &Types);
}
template <> struct DenseMapInfo<codeview::TypeIndex> {
static inline codeview::TypeIndex getEmptyKey() {
return codeview::TypeIndex{DenseMapInfo<uint32_t>::getEmptyKey()};
}
static inline codeview::TypeIndex getTombstoneKey() {
return codeview::TypeIndex{DenseMapInfo<uint32_t>::getTombstoneKey()};
}
static unsigned getHashValue(const codeview::TypeIndex &TI) {
return DenseMapInfo<uint32_t>::getHashValue(TI.getIndex());
}
static bool isEqual(const codeview::TypeIndex &LHS,
const codeview::TypeIndex &RHS) {
return LHS == RHS;
}
};
}
#endif