Line data Source code
1 : //===- TpiStreamBuilder.h - PDB Tpi Stream Creation -------------*- 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 : #ifndef LLVM_DEBUGINFO_PDB_RAW_PDBTPISTREAMBUILDER_H
11 : #define LLVM_DEBUGINFO_PDB_RAW_PDBTPISTREAMBUILDER_H
12 :
13 : #include "llvm/ADT/Optional.h"
14 : #include "llvm/DebugInfo/CodeView/TypeRecord.h"
15 : #include "llvm/DebugInfo/PDB/Native/RawConstants.h"
16 : #include "llvm/DebugInfo/PDB/Native/RawTypes.h"
17 : #include "llvm/Support/Allocator.h"
18 : #include "llvm/Support/BinaryByteStream.h"
19 : #include "llvm/Support/BinaryItemStream.h"
20 : #include "llvm/Support/BinaryStreamRef.h"
21 : #include "llvm/Support/Error.h"
22 :
23 : #include <vector>
24 :
25 : namespace llvm {
26 : class BinaryByteStream;
27 : class WritableBinaryStreamRef;
28 :
29 : template <> struct BinaryItemTraits<llvm::codeview::CVType> {
30 : static size_t length(const codeview::CVType &Item) { return Item.length(); }
31 : static ArrayRef<uint8_t> bytes(const codeview::CVType &Item) {
32 : return Item.data();
33 : }
34 : };
35 :
36 : namespace codeview {
37 : class TypeRecord;
38 : }
39 : namespace msf {
40 : class MSFBuilder;
41 : struct MSFLayout;
42 : }
43 : namespace pdb {
44 : class PDBFile;
45 : class TpiStream;
46 : struct TpiStreamHeader;
47 :
48 222 : class TpiStreamBuilder {
49 : public:
50 : explicit TpiStreamBuilder(msf::MSFBuilder &Msf, uint32_t StreamIdx);
51 : ~TpiStreamBuilder();
52 :
53 : TpiStreamBuilder(const TpiStreamBuilder &) = delete;
54 : TpiStreamBuilder &operator=(const TpiStreamBuilder &) = delete;
55 :
56 : void setVersionHeader(PdbRaw_TpiVer Version);
57 : void addTypeRecord(ArrayRef<uint8_t> Type, Optional<uint32_t> Hash);
58 :
59 : Error finalizeMsfLayout();
60 :
61 222 : uint32_t getRecordCount() const { return TypeRecords.size(); }
62 :
63 : Error commit(const msf::MSFLayout &Layout, WritableBinaryStreamRef Buffer);
64 :
65 : uint32_t calculateSerializedLength();
66 :
67 : private:
68 : uint32_t calculateHashBufferSize() const;
69 : uint32_t calculateIndexOffsetSize() const;
70 : Error finalize();
71 :
72 : msf::MSFBuilder &Msf;
73 : BumpPtrAllocator &Allocator;
74 :
75 : size_t TypeRecordBytes = 0;
76 :
77 : PdbRaw_TpiVer VerHeader = PdbRaw_TpiVer::PdbTpiV80;
78 : std::vector<ArrayRef<uint8_t>> TypeRecords;
79 : std::vector<uint32_t> TypeHashes;
80 : std::vector<codeview::TypeIndexOffset> TypeIndexOffsets;
81 : uint32_t HashStreamIndex = kInvalidStreamIndex;
82 : std::unique_ptr<BinaryByteStream> HashValueStream;
83 :
84 : const TpiStreamHeader *Header;
85 : uint32_t Idx;
86 : };
87 : }
88 : }
89 :
90 : #endif
|