1 //===- AppendingTypeTableBuilder.cpp --------------------------------------===//
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/AppendingTypeTableBuilder.h"
11 #include "llvm/ADT/ArrayRef.h"
12 #include "llvm/ADT/DenseSet.h"
13 #include "llvm/ADT/STLExtras.h"
14 #include "llvm/DebugInfo/CodeView/CodeView.h"
15 #include "llvm/DebugInfo/CodeView/ContinuationRecordBuilder.h"
16 #include "llvm/DebugInfo/CodeView/RecordSerialization.h"
17 #include "llvm/DebugInfo/CodeView/TypeIndex.h"
18 #include "llvm/Support/Allocator.h"
19 #include "llvm/Support/BinaryByteStream.h"
20 #include "llvm/Support/BinaryStreamWriter.h"
21 #include "llvm/Support/Endian.h"
22 #include "llvm/Support/Error.h"
29 using namespace llvm::codeview
;
31 TypeIndex
AppendingTypeTableBuilder::nextTypeIndex() const {
32 return TypeIndex::fromArrayIndex(SeenRecords
.size());
35 AppendingTypeTableBuilder::AppendingTypeTableBuilder(BumpPtrAllocator
&Storage
)
36 : RecordStorage(Storage
) {}
38 AppendingTypeTableBuilder::~AppendingTypeTableBuilder() = default;
40 Optional
<TypeIndex
> AppendingTypeTableBuilder::getFirst() {
44 return TypeIndex(TypeIndex::FirstNonSimpleIndex
);
47 Optional
<TypeIndex
> AppendingTypeTableBuilder::getNext(TypeIndex Prev
) {
48 if (++Prev
== nextTypeIndex())
53 CVType
AppendingTypeTableBuilder::getType(TypeIndex Index
) {
55 Type
.RecordData
= SeenRecords
[Index
.toArrayIndex()];
56 const RecordPrefix
*P
=
57 reinterpret_cast<const RecordPrefix
*>(Type
.RecordData
.data());
58 Type
.Type
= static_cast<TypeLeafKind
>(uint16_t(P
->RecordKind
));
62 StringRef
AppendingTypeTableBuilder::getTypeName(TypeIndex Index
) {
63 llvm_unreachable("Method not implemented");
66 bool AppendingTypeTableBuilder::contains(TypeIndex Index
) {
67 if (Index
.isSimple() || Index
.isNoneType())
70 return Index
.toArrayIndex() < SeenRecords
.size();
73 uint32_t AppendingTypeTableBuilder::size() { return SeenRecords
.size(); }
75 uint32_t AppendingTypeTableBuilder::capacity() { return SeenRecords
.size(); }
77 ArrayRef
<ArrayRef
<uint8_t>> AppendingTypeTableBuilder::records() const {
81 void AppendingTypeTableBuilder::reset() { SeenRecords
.clear(); }
84 AppendingTypeTableBuilder::insertRecordBytes(ArrayRef
<uint8_t> &Record
) {
85 TypeIndex NewTI
= nextTypeIndex();
86 uint8_t *Stable
= RecordStorage
.Allocate
<uint8_t>(Record
.size());
87 memcpy(Stable
, Record
.data(), Record
.size());
88 Record
= ArrayRef
<uint8_t>(Stable
, Record
.size());
89 SeenRecords
.push_back(Record
);
94 AppendingTypeTableBuilder::insertRecord(ContinuationRecordBuilder
&Builder
) {
96 auto Fragments
= Builder
.end(nextTypeIndex());
97 assert(!Fragments
.empty());
98 for (auto C
: Fragments
)
99 TI
= insertRecordBytes(C
.RecordData
);