1//===- TpiStream.cpp - PDB Type Info (TPI) Stream 2 Access ------*- 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#ifndef LLVM_DEBUGINFO_PDB_RAW_PDBTPISTREAM_H
10#define LLVM_DEBUGINFO_PDB_RAW_PDBTPISTREAM_H
11
12#include "llvm/DebugInfo/CodeView/TypeRecord.h"
13#include "llvm/DebugInfo/PDB/Native/HashTable.h"
14#include "llvm/DebugInfo/PDB/Native/RawConstants.h"
15#include "llvm/DebugInfo/PDB/Native/RawTypes.h"
16#include "llvm/DebugInfo/PDB/PDBTypes.h"
17#include "llvm/Support/BinaryStreamArray.h"
18#include "llvm/Support/BinaryStreamRef.h"
19#include "llvm/Support/raw_ostream.h"
20
21#include "llvm/Support/Error.h"
22
23namespace llvm {
24namespace codeview {
25class LazyRandomTypeCollection;
26}
27namespace msf {
28class MappedBlockStream;
29}
30namespace pdb {
31class PDBFile;
32
33class TpiStream {
34  friend class TpiStreamBuilder;
35
36public:
37  TpiStream(PDBFile &File, std::unique_ptr<msf::MappedBlockStream> Stream);
38  ~TpiStream();
39  Error reload();
40
41  PdbRaw_TpiVer getTpiVersion() const;
42
43  uint32_t TypeIndexBegin() const;
44  uint32_t TypeIndexEnd() const;
45  uint32_t getNumTypeRecords() const;
46  uint16_t getTypeHashStreamIndex() const;
47  uint16_t getTypeHashStreamAuxIndex() const;
48
49  uint32_t getHashKeySize() const;
50  uint32_t getNumHashBuckets() const;
51  FixedStreamArray<support::ulittle32_t> getHashValues() const;
52  FixedStreamArray<codeview::TypeIndexOffset> getTypeIndexOffsets() const;
53  HashTable<support::ulittle32_t> &getHashAdjusters();
54
55  codeview::CVTypeRange types(bool *HadError) const;
56  const codeview::CVTypeArray &typeArray() const { return TypeRecords; }
57
58  codeview::LazyRandomTypeCollection &typeCollection() { return *Types; }
59
60  Expected<codeview::TypeIndex>
61  findFullDeclForForwardRef(codeview::TypeIndex ForwardRefTI) const;
62
63  std::vector<codeview::TypeIndex> findRecordsByName(StringRef Name) const;
64
65  codeview::CVType getType(codeview::TypeIndex Index);
66
67  BinarySubstreamRef getTypeRecordsSubstream() const;
68
69  Error commit();
70
71  void buildHashMap();
72
73  bool supportsTypeLookup() const;
74
75private:
76  PDBFile &Pdb;
77  std::unique_ptr<msf::MappedBlockStream> Stream;
78
79  std::unique_ptr<codeview::LazyRandomTypeCollection> Types;
80
81  BinarySubstreamRef TypeRecordsSubstream;
82
83  codeview::CVTypeArray TypeRecords;
84
85  std::unique_ptr<BinaryStream> HashStream;
86  FixedStreamArray<support::ulittle32_t> HashValues;
87  FixedStreamArray<codeview::TypeIndexOffset> TypeIndexOffsets;
88  HashTable<support::ulittle32_t> HashAdjusters;
89
90  std::vector<std::vector<codeview::TypeIndex>> HashMap;
91
92  const TpiStreamHeader *Header;
93};
94}
95}
96
97#endif
98