1 //===- TypeTableCollection.cpp -------------------------------- *- C++ --*-===//
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/TypeTableCollection.h"
12 #include "llvm/DebugInfo/CodeView/CVTypeVisitor.h"
13 #include "llvm/DebugInfo/CodeView/RecordName.h"
14 #include "llvm/Support/BinaryStreamReader.h"
17 using namespace llvm::codeview
;
19 TypeTableCollection::TypeTableCollection(ArrayRef
<ArrayRef
<uint8_t>> Records
)
20 : NameStorage(Allocator
), Records(Records
) {
21 Names
.resize(Records
.size());
24 Optional
<TypeIndex
> TypeTableCollection::getFirst() {
27 return TypeIndex::fromArrayIndex(0);
30 Optional
<TypeIndex
> TypeTableCollection::getNext(TypeIndex Prev
) {
31 assert(contains(Prev
));
33 if (Prev
.toArrayIndex() == size())
38 CVType
TypeTableCollection::getType(TypeIndex Index
) {
39 assert(Index
.toArrayIndex() < Records
.size());
40 ArrayRef
<uint8_t> Bytes
= Records
[Index
.toArrayIndex()];
41 const RecordPrefix
*Prefix
=
42 reinterpret_cast<const RecordPrefix
*>(Bytes
.data());
43 TypeLeafKind Kind
= static_cast<TypeLeafKind
>(uint16_t(Prefix
->RecordKind
));
44 return CVType(Kind
, Bytes
);
47 StringRef
TypeTableCollection::getTypeName(TypeIndex Index
) {
48 if (Index
.isNoneType() || Index
.isSimple())
49 return TypeIndex::simpleTypeName(Index
);
51 uint32_t I
= Index
.toArrayIndex();
52 if (Names
[I
].data() == nullptr) {
53 StringRef Result
= NameStorage
.save(computeTypeName(*this, Index
));
59 bool TypeTableCollection::contains(TypeIndex Index
) {
60 return Index
.toArrayIndex() <= size();
63 uint32_t TypeTableCollection::size() { return Records
.size(); }
65 uint32_t TypeTableCollection::capacity() { return Records
.size(); }