]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/include/llvm/DebugInfo/PDB/Native/TpiStreamBuilder.h
Merge ^/head r317808 through r317970.
[FreeBSD/FreeBSD.git] / contrib / llvm / include / llvm / DebugInfo / PDB / Native / TpiStreamBuilder.h
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 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   Error commit(const msf::MSFLayout &Layout, WritableBinaryStreamRef Buffer);
62
63   uint32_t calculateSerializedLength();
64
65 private:
66   uint32_t calculateHashBufferSize() const;
67   uint32_t calculateIndexOffsetSize() const;
68   Error finalize();
69
70   msf::MSFBuilder &Msf;
71   BumpPtrAllocator &Allocator;
72
73   size_t TypeRecordBytes = 0;
74
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;
81
82   const TpiStreamHeader *Header;
83   uint32_t Idx;
84 };
85 }
86 }
87
88 #endif