• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- TypeTableCollection.cpp -------------------------------- *- C++ --*-===//
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 //===----------------------------------------------------------------------===//
9 
10 #include "llvm/DebugInfo/CodeView/TypeTableCollection.h"
11 
12 #include "llvm/DebugInfo/CodeView/CVTypeVisitor.h"
13 #include "llvm/DebugInfo/CodeView/RecordName.h"
14 #include "llvm/Support/BinaryStreamReader.h"
15 
16 using namespace llvm;
17 using namespace llvm::codeview;
18 
TypeTableCollection(ArrayRef<ArrayRef<uint8_t>> Records)19 TypeTableCollection::TypeTableCollection(ArrayRef<ArrayRef<uint8_t>> Records)
20     : NameStorage(Allocator), Records(Records) {
21   Names.resize(Records.size());
22 }
23 
getFirst()24 Optional<TypeIndex> TypeTableCollection::getFirst() {
25   if (empty())
26     return None;
27   return TypeIndex::fromArrayIndex(0);
28 }
29 
getNext(TypeIndex Prev)30 Optional<TypeIndex> TypeTableCollection::getNext(TypeIndex Prev) {
31   assert(contains(Prev));
32   ++Prev;
33   if (Prev.toArrayIndex() == size())
34     return None;
35   return Prev;
36 }
37 
getType(TypeIndex Index)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);
45 }
46 
getTypeName(TypeIndex Index)47 StringRef TypeTableCollection::getTypeName(TypeIndex Index) {
48   if (Index.isNoneType() || Index.isSimple())
49     return TypeIndex::simpleTypeName(Index);
50 
51   uint32_t I = Index.toArrayIndex();
52   if (Names[I].data() == nullptr) {
53     StringRef Result = NameStorage.save(computeTypeName(*this, Index));
54     Names[I] = Result;
55   }
56   return Names[I];
57 }
58 
contains(TypeIndex Index)59 bool TypeTableCollection::contains(TypeIndex Index) {
60   return Index.toArrayIndex() <= size();
61 }
62 
size()63 uint32_t TypeTableCollection::size() { return Records.size(); }
64 
capacity()65 uint32_t TypeTableCollection::capacity() { return Records.size(); }
66