1 //===- TpiStreamBuilder.h - PDB Tpi Stream Creation -------------*- 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 #ifndef LLVM_DEBUGINFO_PDB_RAW_PDBTPISTREAMBUILDER_H
11 #define LLVM_DEBUGINFO_PDB_RAW_PDBTPISTREAMBUILDER_H
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"
26 class BinaryByteStream;
27 class WritableBinaryStreamRef;
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) {
46 struct TpiStreamHeader;
48 class TpiStreamBuilder {
50 explicit TpiStreamBuilder(msf::MSFBuilder &Msf, uint32_t StreamIdx);
53 TpiStreamBuilder(const TpiStreamBuilder &) = delete;
54 TpiStreamBuilder &operator=(const TpiStreamBuilder &) = delete;
56 void setVersionHeader(PdbRaw_TpiVer Version);
57 void addTypeRecord(ArrayRef<uint8_t> Type, Optional<uint32_t> Hash);
59 Error finalizeMsfLayout();
61 Error commit(const msf::MSFLayout &Layout, WritableBinaryStreamRef Buffer);
63 uint32_t calculateSerializedLength();
66 uint32_t calculateHashBufferSize() const;
67 uint32_t calculateIndexOffsetSize() const;
71 BumpPtrAllocator &Allocator;
73 size_t TypeRecordBytes = 0;
75 Optional<PdbRaw_TpiVer> VerHeader;
76 std::vector<ArrayRef<uint8_t>> TypeRecords;
77 std::vector<uint32_t> TypeHashes;
78 std::vector<TypeIndexOffset> TypeIndexOffsets;
79 uint32_t HashStreamIndex = kInvalidStreamIndex;
80 std::unique_ptr<BinaryByteStream> HashValueStream;
82 const TpiStreamHeader *Header;