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