LLVM  14.0.0git
TpiStreamBuilder.h
Go to the documentation of this file.
1 //===- TpiStreamBuilder.h - PDB Tpi Stream Creation -------------*- 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_NATIVE_TPISTREAMBUILDER_H
10 #define LLVM_DEBUGINFO_PDB_NATIVE_TPISTREAMBUILDER_H
11 
12 #include "llvm/ADT/Optional.h"
16 #include "llvm/Support/Allocator.h"
20 #include "llvm/Support/Error.h"
21 
22 #include <vector>
23 
24 namespace llvm {
25 class BinaryByteStream;
26 class WritableBinaryStreamRef;
27 
28 template <> struct BinaryItemTraits<llvm::codeview::CVType> {
29  static size_t length(const codeview::CVType &Item) { return Item.length(); }
31  return Item.data();
32  }
33 };
34 
35 namespace codeview {
36 class TypeRecord;
37 }
38 namespace msf {
39 class MSFBuilder;
40 struct MSFLayout;
41 }
42 namespace pdb {
43 class PDBFile;
44 class TpiStream;
45 struct TpiStreamHeader;
46 
48 public:
49  explicit TpiStreamBuilder(msf::MSFBuilder &Msf, uint32_t StreamIdx);
51 
52  TpiStreamBuilder(const TpiStreamBuilder &) = delete;
53  TpiStreamBuilder &operator=(const TpiStreamBuilder &) = delete;
54 
58  ArrayRef<uint32_t> Hashes);
59 
61 
62  uint32_t getRecordCount() const { return TypeRecordCount; }
63 
64  Error commit(const msf::MSFLayout &Layout, WritableBinaryStreamRef Buffer);
65 
67 
68 private:
69  void updateTypeIndexOffsets(ArrayRef<uint16_t> Sizes);
70 
71  uint32_t calculateHashBufferSize() const;
72  uint32_t calculateIndexOffsetSize() const;
73  Error finalize();
74 
75  msf::MSFBuilder &Msf;
76  BumpPtrAllocator &Allocator;
77 
78  uint32_t TypeRecordCount = 0;
79  size_t TypeRecordBytes = 0;
80 
82  std::vector<ArrayRef<uint8_t>> TypeRecBuffers;
83  std::vector<uint32_t> TypeHashes;
84  std::vector<codeview::TypeIndexOffset> TypeIndexOffsets;
85  uint32_t HashStreamIndex = kInvalidStreamIndex;
86  std::unique_ptr<BinaryByteStream> HashValueStream;
87 
88  const TpiStreamHeader *Header;
89  uint32_t Idx;
90 };
91 }
92 }
93 
94 #endif
RawConstants.h
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
Optional.h
RawTypes.h
BinaryByteStream.h
llvm::pdb::TpiStreamBuilder::addTypeRecords
void addTypeRecords(ArrayRef< uint8_t > Types, ArrayRef< uint16_t > Sizes, ArrayRef< uint32_t > Hashes)
Definition: TpiStreamBuilder.cpp:76
Allocator.h
llvm::pdb::kInvalidStreamIndex
const uint16_t kInvalidStreamIndex
Definition: RawConstants.h:19
Error.h
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
llvm::pdb::TpiStreamBuilder::~TpiStreamBuilder
~TpiStreamBuilder()
llvm::Optional< uint32_t >
llvm::BinaryItemTraits< llvm::codeview::CVType >::bytes
static ArrayRef< uint8_t > bytes(const codeview::CVType &Item)
Definition: TpiStreamBuilder.h:30
llvm::pdb::PdbTpiV80
@ PdbTpiV80
Definition: RawConstants.h:64
llvm::msf::MSFBuilder
Definition: MSFBuilder.h:26
llvm::msf::MSFLayout
Definition: MSFCommon.h:51
llvm::pdb::TpiStreamBuilder::finalizeMsfLayout
Error finalizeMsfLayout()
Definition: TpiStreamBuilder.cpp:146
llvm::pdb::PdbRaw_TpiVer
PdbRaw_TpiVer
Definition: RawConstants.h:59
llvm::IndexedInstrProf::Version
const uint64_t Version
Definition: InstrProf.h:991
llvm::pdb::TpiStreamBuilder::getRecordCount
uint32_t getRecordCount() const
Definition: TpiStreamBuilder.h:62
BinaryItemStream.h
TypeRecord.h
llvm::BumpPtrAllocatorImpl
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:67
llvm::pdb::TpiStreamBuilder::calculateSerializedLength
uint32_t calculateSerializedLength()
Definition: TpiStreamBuilder.cpp:132
llvm::pdb::TpiStreamBuilder
Definition: TpiStreamBuilder.h:47
llvm::BinaryItemTraits< llvm::codeview::CVType >::length
static size_t length(const codeview::CVType &Item)
Definition: TpiStreamBuilder.h:29
llvm::ArrayRef< uint8_t >
BinaryStreamRef.h
llvm::codeview::CVRecord< TypeLeafKind >
uint32_t
llvm::pdb::TpiStreamBuilder::setVersionHeader
void setVersionHeader(PdbRaw_TpiVer Version)
Definition: TpiStreamBuilder.cpp:41
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
llvm::codeview::CVRecord::data
ArrayRef< uint8_t > data() const
Definition: CVRecord.h:49
llvm::pdb::TpiStreamBuilder::addTypeRecord
void addTypeRecord(ArrayRef< uint8_t > Type, Optional< uint32_t > Hash)
Definition: TpiStreamBuilder.cpp:61
llvm::pdb::TpiStreamBuilder::commit
Error commit(const msf::MSFLayout &Layout, WritableBinaryStreamRef Buffer)
Definition: TpiStreamBuilder.cpp:176
llvm::pdb::TpiStreamHeader
Definition: RawTypes.h:277
llvm::pdb::TpiStreamBuilder::operator=
TpiStreamBuilder & operator=(const TpiStreamBuilder &)=delete
llvm::BinaryItemTraits
Definition: BinaryItemStream.h:21
llvm::WritableBinaryStreamRef
Definition: BinaryStreamRef.h:221
llvm::pdb::TpiStreamBuilder::TpiStreamBuilder
TpiStreamBuilder(msf::MSFBuilder &Msf, uint32_t StreamIdx)
Definition: TpiStreamBuilder.cpp:35
llvm::codeview::CVRecord::length
uint32_t length() const
Definition: CVRecord.h:40