[llvm-exegesis][NFC] Fix typo
[llvm-complete.git] / lib / DebugInfo / CodeView / AppendingTypeTableBuilder.cpp
blob8828671d9be9de99df3cb85abb8e26618a87222f
1 //===- AppendingTypeTableBuilder.cpp --------------------------------------===//
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 //===----------------------------------------------------------------------===//
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"
23 #include <algorithm>
24 #include <cassert>
25 #include <cstdint>
26 #include <cstring>
28 using namespace llvm;
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() {
41 if (empty())
42 return None;
44 return TypeIndex(TypeIndex::FirstNonSimpleIndex);
47 Optional<TypeIndex> AppendingTypeTableBuilder::getNext(TypeIndex Prev) {
48 if (++Prev == nextTypeIndex())
49 return None;
50 return Prev;
53 CVType AppendingTypeTableBuilder::getType(TypeIndex Index) {
54 CVType Type;
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));
59 return Type;
62 StringRef AppendingTypeTableBuilder::getTypeName(TypeIndex Index) {
63 llvm_unreachable("Method not implemented");
66 bool AppendingTypeTableBuilder::contains(TypeIndex Index) {
67 if (Index.isSimple() || Index.isNoneType())
68 return false;
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 {
78 return SeenRecords;
81 void AppendingTypeTableBuilder::reset() { SeenRecords.clear(); }
83 TypeIndex
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);
90 return NewTI;
93 TypeIndex
94 AppendingTypeTableBuilder::insertRecord(ContinuationRecordBuilder &Builder) {
95 TypeIndex TI;
96 auto Fragments = Builder.end(nextTypeIndex());
97 assert(!Fragments.empty());
98 for (auto C : Fragments)
99 TI = insertRecordBytes(C.RecordData);
100 return TI;