1 //==- SymbolCache.h - Cache of native symbols and ids ------------*- 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 #ifndef LLVM_DEBUGINFO_PDB_NATIVE_SYMBOLCACHE_H
11 #define LLVM_DEBUGINFO_PDB_NATIVE_SYMBOLCACHE_H
13 #include "llvm/ADT/DenseMap.h"
14 #include "llvm/DebugInfo/CodeView/TypeDeserializer.h"
15 #include "llvm/DebugInfo/CodeView/TypeIndex.h"
16 #include "llvm/DebugInfo/CodeView/TypeRecord.h"
17 #include "llvm/DebugInfo/PDB/Native/NativeRawSymbol.h"
18 #include "llvm/Support/Allocator.h"
29 NativeSession &Session;
30 DbiStream *Dbi = nullptr;
32 std::vector<std::unique_ptr<NativeRawSymbol>> Cache;
33 DenseMap<codeview::TypeIndex, SymIndexId> TypeIndexToSymbolId;
34 DenseMap<std::pair<codeview::TypeIndex, uint32_t>, SymIndexId>
35 FieldListMembersToSymbolId;
36 std::vector<SymIndexId> Compilands;
38 SymIndexId createSymbolPlaceholder() {
39 SymIndexId Id = Cache.size();
40 Cache.push_back(nullptr);
44 template <typename ConcreteSymbolT, typename CVRecordT, typename... Args>
45 SymIndexId createSymbolForType(codeview::TypeIndex TI, codeview::CVType CVT,
46 Args &&... ConstructorArgs) {
49 codeview::TypeDeserializer::deserializeAs<CVRecordT>(CVT, Record)) {
50 consumeError(std::move(EC));
54 return createSymbol<ConcreteSymbolT>(
55 TI, std::move(Record), std::forward<Args>(ConstructorArgs)...);
58 SymIndexId createSymbolForModifiedType(codeview::TypeIndex ModifierTI,
59 codeview::CVType CVT);
61 SymIndexId createSimpleType(codeview::TypeIndex TI,
62 codeview::ModifierOptions Mods);
65 SymbolCache(NativeSession &Session, DbiStream *Dbi);
67 template <typename ConcreteSymbolT, typename... Args>
68 SymIndexId createSymbol(Args &&... ConstructorArgs) {
69 SymIndexId Id = Cache.size();
71 auto Result = llvm::make_unique<ConcreteSymbolT>(
72 Session, Id, std::forward<Args>(ConstructorArgs)...);
73 Cache.push_back(std::move(Result));
77 std::unique_ptr<IPDBEnumSymbols>
78 createTypeEnumerator(codeview::TypeLeafKind Kind);
80 SymIndexId findSymbolByTypeIndex(codeview::TypeIndex TI);
82 template <typename ConcreteSymbolT, typename... Args>
83 SymIndexId getOrCreateFieldListMember(codeview::TypeIndex FieldListTI,
85 Args &&... ConstructorArgs) {
86 SymIndexId SymId = Cache.size();
87 std::pair<codeview::TypeIndex, uint32_t> Key{FieldListTI, Index};
88 auto Result = FieldListMembersToSymbolId.try_emplace(Key, SymId);
90 auto NewSymbol = llvm::make_unique<ConcreteSymbolT>(
91 Session, SymId, std::forward<Args>(ConstructorArgs)...);
92 Cache.push_back(std::move(NewSymbol));
94 SymId = Result.first->second;
99 std::unique_ptr<PDBSymbolCompiland> getOrCreateCompiland(uint32_t Index);
100 uint32_t getNumCompilands() const;
102 std::unique_ptr<PDBSymbol> getSymbolById(SymIndexId SymbolId) const;
104 NativeRawSymbol &getNativeSymbolById(SymIndexId SymbolId) const;
106 template <typename ConcreteT>
107 ConcreteT &getNativeSymbolById(SymIndexId SymbolId) const {
108 return static_cast<ConcreteT &>(getNativeSymbolById(SymbolId));