• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- GSIStreamBuilder.h - PDB Publics/Globals 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_GSISTREAMBUILDER_H
11 #define LLVM_DEBUGINFO_PDB_RAW_GSISTREAMBUILDER_H
12 
13 #include "llvm/DebugInfo/CodeView/SymbolRecord.h"
14 #include "llvm/DebugInfo/PDB/Native/GlobalsStream.h"
15 #include "llvm/DebugInfo/PDB/Native/RawConstants.h"
16 #include "llvm/DebugInfo/PDB/Native/RawTypes.h"
17 #include "llvm/Support/BinaryByteStream.h"
18 #include "llvm/Support/BinaryItemStream.h"
19 #include "llvm/Support/BinaryStreamRef.h"
20 #include "llvm/Support/BinaryStreamWriter.h"
21 #include "llvm/Support/Endian.h"
22 #include "llvm/Support/Error.h"
23 
24 namespace llvm {
25 
26 template <> struct BinaryItemTraits<codeview::CVSymbol> {
27   static size_t length(const codeview::CVSymbol &Item) {
28     return Item.RecordData.size();
29   }
30   static ArrayRef<uint8_t> bytes(const codeview::CVSymbol &Item) {
31     return Item.RecordData;
32   }
33 };
34 
35 namespace msf {
36 class MSFBuilder;
37 struct MSFLayout;
38 } // namespace msf
39 namespace pdb {
40 struct GSIHashStreamBuilder;
41 
42 class GSIStreamBuilder {
43 
44 public:
45   explicit GSIStreamBuilder(msf::MSFBuilder &Msf);
46   ~GSIStreamBuilder();
47 
48   GSIStreamBuilder(const GSIStreamBuilder &) = delete;
49   GSIStreamBuilder &operator=(const GSIStreamBuilder &) = delete;
50 
51   Error finalizeMsfLayout();
52 
53   Error commit(const msf::MSFLayout &Layout, WritableBinaryStreamRef Buffer);
54 
55   uint32_t getPublicsStreamIndex() const;
56   uint32_t getGlobalsStreamIndex() const;
57   uint32_t getRecordStreamIdx() const { return RecordStreamIdx; }
58 
59   void addPublicSymbol(const codeview::PublicSym32 &Pub);
60 
61   void addGlobalSymbol(const codeview::ProcRefSym &Sym);
62   void addGlobalSymbol(const codeview::DataSym &Sym);
63   void addGlobalSymbol(const codeview::ConstantSym &Sym);
64   void addGlobalSymbol(const codeview::UDTSym &Sym);
65   void addGlobalSymbol(const codeview::CVSymbol &Sym);
66 
67 private:
68   uint32_t calculatePublicsHashStreamSize() const;
69   uint32_t calculateGlobalsHashStreamSize() const;
70   Error commitSymbolRecordStream(WritableBinaryStreamRef Stream);
71   Error commitPublicsHashStream(WritableBinaryStreamRef Stream);
72   Error commitGlobalsHashStream(WritableBinaryStreamRef Stream);
73 
74   uint32_t RecordStreamIdx = kInvalidStreamIndex;
75   msf::MSFBuilder &Msf;
76   std::unique_ptr<GSIHashStreamBuilder> PSH;
77   std::unique_ptr<GSIHashStreamBuilder> GSH;
78 };
79 } // namespace pdb
80 } // namespace llvm
81 
82 #endif
83