]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/lib/DebugInfo/CodeView/TypeDatabase.cpp
Merge llvm, clang, lld, lldb, compiler-rt and libc++ r302418, and update
[FreeBSD/FreeBSD.git] / contrib / llvm / lib / DebugInfo / CodeView / TypeDatabase.cpp
1 //===- TypeDatabase.cpp --------------------------------------- *- 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 #include "llvm/DebugInfo/CodeView/TypeDatabase.h"
11
12 using namespace llvm;
13 using namespace llvm::codeview;
14
15 namespace {
16 struct SimpleTypeEntry {
17   StringRef Name;
18   SimpleTypeKind Kind;
19 };
20 }
21
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
24 /// StringRef.
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},
66 };
67
68 TypeDatabase::TypeDatabase(uint32_t ExpectedSize) : TypeNameStorage(Allocator) {
69   CVUDTNames.reserve(ExpectedSize);
70   TypeRecords.reserve(ExpectedSize);
71 }
72
73 /// Gets the type index for the next type record.
74 TypeIndex TypeDatabase::getNextTypeIndex() const {
75   return TypeIndex(TypeIndex::FirstNonSimpleIndex + CVUDTNames.size());
76 }
77
78 /// Records the name of a type, and reserves its type index.
79 void TypeDatabase::recordType(StringRef Name, const CVType &Data) {
80   CVUDTNames.push_back(Name);
81   TypeRecords.push_back(Data);
82 }
83
84 /// Saves the name in a StringSet and creates a stable StringRef.
85 StringRef TypeDatabase::saveTypeName(StringRef TypeName) {
86   return TypeNameStorage.save(TypeName);
87 }
88
89 StringRef TypeDatabase::getTypeName(TypeIndex Index) const {
90   if (Index.isNoneType())
91     return "<no type>";
92
93   if (Index.isSimple()) {
94     // This is a simple type.
95     for (const auto &SimpleTypeName : SimpleTypeNames) {
96       if (SimpleTypeName.Kind == Index.getSimpleKind()) {
97         if (Index.getSimpleMode() == SimpleTypeMode::Direct)
98           return SimpleTypeName.Name.drop_back(1);
99         // Otherwise, this is a pointer type. We gloss over the distinction
100         // between near, far, 64, 32, etc, and just give a pointer type.
101         return SimpleTypeName.Name;
102       }
103     }
104     return "<unknown simple type>";
105   }
106
107   uint32_t I = Index.getIndex() - TypeIndex::FirstNonSimpleIndex;
108   if (I < CVUDTNames.size())
109     return CVUDTNames[I];
110
111   return "<unknown UDT>";
112 }
113
114 const CVType &TypeDatabase::getTypeRecord(TypeIndex Index) const {
115   return TypeRecords[Index.getIndex() - TypeIndex::FirstNonSimpleIndex];
116 }
117
118 CVType &TypeDatabase::getTypeRecord(TypeIndex Index) {
119   return TypeRecords[Index.getIndex() - TypeIndex::FirstNonSimpleIndex];
120 }
121
122 bool TypeDatabase::containsTypeIndex(TypeIndex Index) const {
123   uint32_t I = Index.getIndex() - TypeIndex::FirstNonSimpleIndex;
124   return I < CVUDTNames.size();
125 }
126
127 uint32_t TypeDatabase::size() const { return CVUDTNames.size(); }