LLVM  10.0.0svn
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_RAW_PDBTPISTREAMBUILDER_H
10 #define LLVM_DEBUGINFO_PDB_RAW_PDBTPISTREAMBUILDER_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 
55  void setVersionHeader(PdbRaw_TpiVer Version);
56  void addTypeRecord(ArrayRef<uint8_t> Type, Optional<uint32_t> Hash);
57 
58  Error finalizeMsfLayout();
59 
60  uint32_t getRecordCount() const { return TypeRecords.size(); }
61 
62  Error commit(const msf::MSFLayout &Layout, WritableBinaryStreamRef Buffer);
63 
64  uint32_t calculateSerializedLength();
65 
66 private:
67  uint32_t calculateHashBufferSize() const;
68  uint32_t calculateIndexOffsetSize() const;
69  Error finalize();
70 
71  msf::MSFBuilder &Msf;
73 
74  size_t TypeRecordBytes = 0;
75 
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;
82 
83  const TpiStreamHeader *Header;
84  uint32_t Idx;
85 };
86 }
87 }
88 
89 #endif
This class represents lattice values for constants.
Definition: AllocatorList.h:23
arc branch finalize
static ArrayRef< uint8_t > bytes(const codeview::CVType &Item)
This file defines the MallocAllocator and BumpPtrAllocator interfaces.
uint32_t length() const
Definition: CVRecord.h:41
ArrayRef< uint8_t > data() const
Definition: CVRecord.h:50
const uint16_t kInvalidStreamIndex
Definition: RawConstants.h:19
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:140
Basic Register Allocator
static size_t length(const codeview::CVType &Item)
uint32_t getRecordCount() const
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
const uint64_t Version
Definition: InstrProf.h:984