1 //===- TypeDatabase.cpp --------------------------------------- *- C++ --*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm/DebugInfo/CodeView/TypeDatabase.h"
13 using namespace llvm::codeview;
16 struct SimpleTypeEntry {
22 /// The names here all end in "*". If the simple type is a pointer type, we
23 /// return the whole name. Otherwise we lop off the last character in our
25 static const SimpleTypeEntry SimpleTypeNames[] = {
26 {"void*", SimpleTypeKind::Void},
27 {"<not translated>*", SimpleTypeKind::NotTranslated},
28 {"HRESULT*", SimpleTypeKind::HResult},
29 {"signed char*", SimpleTypeKind::SignedCharacter},
30 {"unsigned char*", SimpleTypeKind::UnsignedCharacter},
31 {"char*", SimpleTypeKind::NarrowCharacter},
32 {"wchar_t*", SimpleTypeKind::WideCharacter},
33 {"char16_t*", SimpleTypeKind::Character16},
34 {"char32_t*", SimpleTypeKind::Character32},
35 {"__int8*", SimpleTypeKind::SByte},
36 {"unsigned __int8*", SimpleTypeKind::Byte},
37 {"short*", SimpleTypeKind::Int16Short},
38 {"unsigned short*", SimpleTypeKind::UInt16Short},
39 {"__int16*", SimpleTypeKind::Int16},
40 {"unsigned __int16*", SimpleTypeKind::UInt16},
41 {"long*", SimpleTypeKind::Int32Long},
42 {"unsigned long*", SimpleTypeKind::UInt32Long},
43 {"int*", SimpleTypeKind::Int32},
44 {"unsigned*", SimpleTypeKind::UInt32},
45 {"__int64*", SimpleTypeKind::Int64Quad},
46 {"unsigned __int64*", SimpleTypeKind::UInt64Quad},
47 {"__int64*", SimpleTypeKind::Int64},
48 {"unsigned __int64*", SimpleTypeKind::UInt64},
49 {"__int128*", SimpleTypeKind::Int128},
50 {"unsigned __int128*", SimpleTypeKind::UInt128},
51 {"__half*", SimpleTypeKind::Float16},
52 {"float*", SimpleTypeKind::Float32},
53 {"float*", SimpleTypeKind::Float32PartialPrecision},
54 {"__float48*", SimpleTypeKind::Float48},
55 {"double*", SimpleTypeKind::Float64},
56 {"long double*", SimpleTypeKind::Float80},
57 {"__float128*", SimpleTypeKind::Float128},
58 {"_Complex float*", SimpleTypeKind::Complex32},
59 {"_Complex double*", SimpleTypeKind::Complex64},
60 {"_Complex long double*", SimpleTypeKind::Complex80},
61 {"_Complex __float128*", SimpleTypeKind::Complex128},
62 {"bool*", SimpleTypeKind::Boolean8},
63 {"__bool16*", SimpleTypeKind::Boolean16},
64 {"__bool32*", SimpleTypeKind::Boolean32},
65 {"__bool64*", SimpleTypeKind::Boolean64},
68 /// Gets the type index for the next type record.
69 TypeIndex TypeDatabase::getNextTypeIndex() const {
70 return TypeIndex(TypeIndex::FirstNonSimpleIndex + CVUDTNames.size());
73 /// Records the name of a type, and reserves its type index.
74 void TypeDatabase::recordType(StringRef Name, const CVType &Data) {
75 CVUDTNames.push_back(Name);
76 TypeRecords.push_back(Data);
79 /// Saves the name in a StringSet and creates a stable StringRef.
80 StringRef TypeDatabase::saveTypeName(StringRef TypeName) {
81 return TypeNameStorage.save(TypeName);
84 StringRef TypeDatabase::getTypeName(TypeIndex Index) const {
85 if (Index.isNoneType())
88 if (Index.isSimple()) {
89 // This is a simple type.
90 for (const auto &SimpleTypeName : SimpleTypeNames) {
91 if (SimpleTypeName.Kind == Index.getSimpleKind()) {
92 if (Index.getSimpleMode() == SimpleTypeMode::Direct)
93 return SimpleTypeName.Name.drop_back(1);
94 // Otherwise, this is a pointer type. We gloss over the distinction
95 // between near, far, 64, 32, etc, and just give a pointer type.
96 return SimpleTypeName.Name;
99 return "<unknown simple type>";
102 uint32_t I = Index.getIndex() - TypeIndex::FirstNonSimpleIndex;
103 if (I < CVUDTNames.size())
104 return CVUDTNames[I];
106 return "<unknown UDT>";
109 const CVType &TypeDatabase::getTypeRecord(TypeIndex Index) const {
110 return TypeRecords[Index.getIndex() - TypeIndex::FirstNonSimpleIndex];
113 bool TypeDatabase::containsTypeIndex(TypeIndex Index) const {
114 uint32_t I = Index.getIndex() - TypeIndex::FirstNonSimpleIndex;
115 return I < CVUDTNames.size();
118 uint32_t TypeDatabase::size() const { return CVUDTNames.size(); }