1 //===- TpiStreamBuilder.h - PDB Tpi Stream Creation -------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_DEBUGINFO_PDB_RAW_PDBTPISTREAMBUILDER_H
10 #define LLVM_DEBUGINFO_PDB_RAW_PDBTPISTREAMBUILDER_H
12 #include "llvm/ADT/Optional.h"
13 #include "llvm/DebugInfo/CodeView/TypeRecord.h"
14 #include "llvm/DebugInfo/PDB/Native/RawConstants.h"
15 #include "llvm/DebugInfo/PDB/Native/RawTypes.h"
16 #include "llvm/Support/Allocator.h"
17 #include "llvm/Support/BinaryByteStream.h"
18 #include "llvm/Support/BinaryItemStream.h"
19 #include "llvm/Support/BinaryStreamRef.h"
20 #include "llvm/Support/Error.h"
25 class BinaryByteStream;
26 class WritableBinaryStreamRef;
28 template <> struct BinaryItemTraits<llvm::codeview::CVType> {
29 static size_t length(const codeview::CVType &Item) { return Item.length(); }
30 static ArrayRef<uint8_t> bytes(const codeview::CVType &Item) {
45 struct TpiStreamHeader;
47 class TpiStreamBuilder {
49 explicit TpiStreamBuilder(msf::MSFBuilder &Msf, uint32_t StreamIdx);
52 TpiStreamBuilder(const TpiStreamBuilder &) = delete;
53 TpiStreamBuilder &operator=(const TpiStreamBuilder &) = delete;
55 void setVersionHeader(PdbRaw_TpiVer Version);
56 void addTypeRecord(ArrayRef<uint8_t> Type, Optional<uint32_t> Hash);
58 Error finalizeMsfLayout();
60 uint32_t getRecordCount() const { return TypeRecords.size(); }
62 Error commit(const msf::MSFLayout &Layout, WritableBinaryStreamRef Buffer);
64 uint32_t calculateSerializedLength();
67 uint32_t calculateHashBufferSize() const;
68 uint32_t calculateIndexOffsetSize() const;
72 BumpPtrAllocator &Allocator;
74 size_t TypeRecordBytes = 0;
76 PdbRaw_TpiVer VerHeader = PdbRaw_TpiVer::PdbTpiV80;
77 std::vector<ArrayRef<uint8_t>> TypeRecords;
78 std::vector<uint32_t> TypeHashes;
79 std::vector<codeview::TypeIndexOffset> TypeIndexOffsets;
80 uint32_t HashStreamIndex = kInvalidStreamIndex;
81 std::unique_ptr<BinaryByteStream> HashValueStream;
83 const TpiStreamHeader *Header;