Line data Source code
1 : //===- TypeDatabase.h - A collection of CodeView type records ---*- 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_TYPEDATABASE_H
11 : #define LLVM_DEBUGINFO_CODEVIEW_TYPEDATABASE_H
12 :
13 : #include "llvm/ADT/BitVector.h"
14 : #include "llvm/ADT/SmallVector.h"
15 : #include "llvm/ADT/StringRef.h"
16 : #include "llvm/DebugInfo/CodeView/TypeCollection.h"
17 : #include "llvm/DebugInfo/CodeView/TypeIndex.h"
18 : #include "llvm/DebugInfo/CodeView/TypeRecord.h"
19 : #include "llvm/Support/Allocator.h"
20 : #include "llvm/Support/StringSaver.h"
21 :
22 : namespace llvm {
23 : namespace codeview {
24 1776 : class TypeDatabase : public TypeCollection {
25 : friend class RandomAccessTypeVisitor;
26 :
27 : public:
28 : explicit TypeDatabase(uint32_t Capacity);
29 :
30 : /// Records the name of a type, and reserves its type index.
31 : TypeIndex appendType(StringRef Name, const CVType &Data);
32 :
33 : /// Records the name of a type, and reserves its type index.
34 : void recordType(StringRef Name, TypeIndex Index, const CVType &Data);
35 :
36 : /// Saves the name in a StringSet and creates a stable StringRef.
37 : StringRef saveTypeName(StringRef TypeName);
38 :
39 : StringRef getTypeName(TypeIndex Index) const;
40 :
41 : const CVType &getTypeRecord(TypeIndex Index) const;
42 : CVType &getTypeRecord(TypeIndex Index);
43 :
44 : bool contains(TypeIndex Index) const;
45 : uint32_t size() const;
46 : uint32_t capacity() const;
47 : bool empty() const;
48 :
49 : CVType getType(TypeIndex Index) override;
50 : StringRef getTypeName(TypeIndex Index) override;
51 : bool contains(TypeIndex Index) override;
52 : uint32_t size() override;
53 : uint32_t capacity() override;
54 :
55 : Optional<TypeIndex> getFirst() override;
56 : Optional<TypeIndex> getNext(TypeIndex Prev) override;
57 :
58 : Optional<TypeIndex> largestTypeIndexLessThan(TypeIndex TI) const;
59 :
60 : private:
61 : TypeIndex getAppendIndex() const;
62 :
63 : void grow();
64 : void grow(TypeIndex Index);
65 :
66 : BumpPtrAllocator Allocator;
67 :
68 : uint32_t Count = 0;
69 : TypeIndex LargestTypeIndex;
70 :
71 : /// All user defined type records in .debug$T live in here. Type indices
72 : /// greater than 0x1000 are user defined. Subtract 0x1000 from the index to
73 : /// index into this vector.
74 : SmallVector<StringRef, 10> CVUDTNames;
75 : SmallVector<CVType, 10> TypeRecords;
76 :
77 : StringSaver TypeNameStorage;
78 :
79 : BitVector ValidRecords;
80 : };
81 : }
82 : }
83 :
84 : #endif
|