1 | //===- TypeTableCollection.cpp -------------------------------- *- C++ --*-===// |
---|---|
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 | //===----------------------------------------------------------------------===// |
8 | |
9 | #include "llvm/DebugInfo/CodeView/TypeTableCollection.h" |
10 | |
11 | #include "llvm/DebugInfo/CodeView/RecordName.h" |
12 | #include "llvm/DebugInfo/CodeView/TypeIndex.h" |
13 | #include "llvm/Support/ErrorHandling.h" |
14 | |
15 | using namespace llvm; |
16 | using namespace llvm::codeview; |
17 | |
18 | TypeTableCollection::TypeTableCollection(ArrayRef<ArrayRef<uint8_t>> Records) |
19 | : NameStorage(Allocator), Records(Records) { |
20 | Names.resize(new_size: Records.size()); |
21 | } |
22 | |
23 | std::optional<TypeIndex> TypeTableCollection::getFirst() { |
24 | if (empty()) |
25 | return std::nullopt; |
26 | return TypeIndex::fromArrayIndex(Index: 0); |
27 | } |
28 | |
29 | std::optional<TypeIndex> TypeTableCollection::getNext(TypeIndex Prev) { |
30 | assert(contains(Prev)); |
31 | ++Prev; |
32 | if (Prev.toArrayIndex() == size()) |
33 | return std::nullopt; |
34 | return Prev; |
35 | } |
36 | |
37 | CVType TypeTableCollection::getType(TypeIndex Index) { |
38 | assert(Index.toArrayIndex() < Records.size()); |
39 | return CVType(Records[Index.toArrayIndex()]); |
40 | } |
41 | |
42 | StringRef TypeTableCollection::getTypeName(TypeIndex Index) { |
43 | if (Index.isNoneType() || Index.isSimple()) |
44 | return TypeIndex::simpleTypeName(TI: Index); |
45 | |
46 | uint32_t I = Index.toArrayIndex(); |
47 | if (Names[I].data() == nullptr) { |
48 | StringRef Result = NameStorage.save(S: computeTypeName(Types&: *this, Index)); |
49 | Names[I] = Result; |
50 | } |
51 | return Names[I]; |
52 | } |
53 | |
54 | bool TypeTableCollection::contains(TypeIndex Index) { |
55 | return Index.toArrayIndex() <= size(); |
56 | } |
57 | |
58 | uint32_t TypeTableCollection::size() { return Records.size(); } |
59 | |
60 | uint32_t TypeTableCollection::capacity() { return Records.size(); } |
61 | |
62 | bool TypeTableCollection::replaceType(TypeIndex &Index, CVType Data, |
63 | bool Stabilize) { |
64 | llvm_unreachable("Method cannot be called"); |
65 | } |
66 |