[ORC] Add std::tuple support to SimplePackedSerialization.
[llvm-project.git] / llvm / lib / DebugInfo / CodeView / AppendingTypeTableBuilder.cpp
blob4d8b15530b9ecb9797f07b421e2e46e93d1c9011
1 //===- AppendingTypeTableBuilder.cpp --------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "llvm/DebugInfo/CodeView/AppendingTypeTableBuilder.h"
10 #include "llvm/ADT/ArrayRef.h"
11 #include "llvm/ADT/DenseSet.h"
12 #include "llvm/ADT/STLExtras.h"
13 #include "llvm/DebugInfo/CodeView/CodeView.h"
14 #include "llvm/DebugInfo/CodeView/ContinuationRecordBuilder.h"
15 #include "llvm/DebugInfo/CodeView/RecordSerialization.h"
16 #include "llvm/DebugInfo/CodeView/TypeIndex.h"
17 #include "llvm/Support/Allocator.h"
18 #include "llvm/Support/BinaryByteStream.h"
19 #include "llvm/Support/BinaryStreamWriter.h"
20 #include "llvm/Support/Endian.h"
21 #include "llvm/Support/Error.h"
22 #include <algorithm>
23 #include <cassert>
24 #include <cstdint>
25 #include <cstring>
27 using namespace llvm;
28 using namespace llvm::codeview;
30 TypeIndex AppendingTypeTableBuilder::nextTypeIndex() const {
31 return TypeIndex::fromArrayIndex(SeenRecords.size());
34 AppendingTypeTableBuilder::AppendingTypeTableBuilder(BumpPtrAllocator &Storage)
35 : RecordStorage(Storage) {}
37 AppendingTypeTableBuilder::~AppendingTypeTableBuilder() = default;
39 Optional<TypeIndex> AppendingTypeTableBuilder::getFirst() {
40 if (empty())
41 return None;
43 return TypeIndex(TypeIndex::FirstNonSimpleIndex);
46 Optional<TypeIndex> AppendingTypeTableBuilder::getNext(TypeIndex Prev) {
47 if (++Prev == nextTypeIndex())
48 return None;
49 return Prev;
52 CVType AppendingTypeTableBuilder::getType(TypeIndex Index){
53 return CVType(SeenRecords[Index.toArrayIndex()]);
56 StringRef AppendingTypeTableBuilder::getTypeName(TypeIndex Index) {
57 llvm_unreachable("Method not implemented");
60 bool AppendingTypeTableBuilder::contains(TypeIndex Index) {
61 if (Index.isSimple() || Index.isNoneType())
62 return false;
64 return Index.toArrayIndex() < SeenRecords.size();
67 uint32_t AppendingTypeTableBuilder::size() { return SeenRecords.size(); }
69 uint32_t AppendingTypeTableBuilder::capacity() { return SeenRecords.size(); }
71 ArrayRef<ArrayRef<uint8_t>> AppendingTypeTableBuilder::records() const {
72 return SeenRecords;
75 void AppendingTypeTableBuilder::reset() { SeenRecords.clear(); }
77 static ArrayRef<uint8_t> stabilize(BumpPtrAllocator &RecordStorage,
78 ArrayRef<uint8_t> Record) {
79 uint8_t *Stable = RecordStorage.Allocate<uint8_t>(Record.size());
80 memcpy(Stable, Record.data(), Record.size());
81 return ArrayRef<uint8_t>(Stable, Record.size());
84 TypeIndex
85 AppendingTypeTableBuilder::insertRecordBytes(ArrayRef<uint8_t> &Record) {
86 TypeIndex NewTI = nextTypeIndex();
87 Record = stabilize(RecordStorage, Record);
88 SeenRecords.push_back(Record);
89 return NewTI;
92 TypeIndex
93 AppendingTypeTableBuilder::insertRecord(ContinuationRecordBuilder &Builder) {
94 TypeIndex TI;
95 auto Fragments = Builder.end(nextTypeIndex());
96 assert(!Fragments.empty());
97 for (auto C : Fragments)
98 TI = insertRecordBytes(C.RecordData);
99 return TI;
102 bool AppendingTypeTableBuilder::replaceType(TypeIndex &Index, CVType Data,
103 bool Stabilize) {
104 assert(Index.toArrayIndex() < SeenRecords.size() &&
105 "This function cannot be used to insert records!");
107 ArrayRef<uint8_t> Record = Data.data();
108 if (Stabilize)
109 Record = stabilize(RecordStorage, Record);
110 SeenRecords[Index.toArrayIndex()] = Record;
111 return true;