1317017Sdim//===- TpiStreamBuilder.h - PDB Tpi Stream Creation -------------*- C++ -*-===// 2317017Sdim// 3353358Sdim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4353358Sdim// See https://llvm.org/LICENSE.txt for license information. 5353358Sdim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6317017Sdim// 7317017Sdim//===----------------------------------------------------------------------===// 8317017Sdim 9317017Sdim#ifndef LLVM_DEBUGINFO_PDB_RAW_PDBTPISTREAMBUILDER_H 10317017Sdim#define LLVM_DEBUGINFO_PDB_RAW_PDBTPISTREAMBUILDER_H 11317017Sdim 12317017Sdim#include "llvm/ADT/Optional.h" 13317017Sdim#include "llvm/DebugInfo/CodeView/TypeRecord.h" 14317017Sdim#include "llvm/DebugInfo/PDB/Native/RawConstants.h" 15317017Sdim#include "llvm/DebugInfo/PDB/Native/RawTypes.h" 16317017Sdim#include "llvm/Support/Allocator.h" 17317017Sdim#include "llvm/Support/BinaryByteStream.h" 18317017Sdim#include "llvm/Support/BinaryItemStream.h" 19317017Sdim#include "llvm/Support/BinaryStreamRef.h" 20317017Sdim#include "llvm/Support/Error.h" 21317017Sdim 22317017Sdim#include <vector> 23317017Sdim 24317017Sdimnamespace llvm { 25317017Sdimclass BinaryByteStream; 26317017Sdimclass WritableBinaryStreamRef; 27317017Sdim 28317017Sdimtemplate <> struct BinaryItemTraits<llvm::codeview::CVType> { 29317017Sdim static size_t length(const codeview::CVType &Item) { return Item.length(); } 30317017Sdim static ArrayRef<uint8_t> bytes(const codeview::CVType &Item) { 31317017Sdim return Item.data(); 32317017Sdim } 33317017Sdim}; 34317017Sdim 35317017Sdimnamespace codeview { 36317017Sdimclass TypeRecord; 37317017Sdim} 38317017Sdimnamespace msf { 39317017Sdimclass MSFBuilder; 40317017Sdimstruct MSFLayout; 41317017Sdim} 42317017Sdimnamespace pdb { 43317017Sdimclass PDBFile; 44317017Sdimclass TpiStream; 45317017Sdimstruct TpiStreamHeader; 46317017Sdim 47317017Sdimclass TpiStreamBuilder { 48317017Sdimpublic: 49317017Sdim explicit TpiStreamBuilder(msf::MSFBuilder &Msf, uint32_t StreamIdx); 50317017Sdim ~TpiStreamBuilder(); 51317017Sdim 52317017Sdim TpiStreamBuilder(const TpiStreamBuilder &) = delete; 53317017Sdim TpiStreamBuilder &operator=(const TpiStreamBuilder &) = delete; 54317017Sdim 55317017Sdim void setVersionHeader(PdbRaw_TpiVer Version); 56317017Sdim void addTypeRecord(ArrayRef<uint8_t> Type, Optional<uint32_t> Hash); 57317017Sdim 58317017Sdim Error finalizeMsfLayout(); 59317017Sdim 60320041Sdim uint32_t getRecordCount() const { return TypeRecords.size(); } 61320041Sdim 62317017Sdim Error commit(const msf::MSFLayout &Layout, WritableBinaryStreamRef Buffer); 63317017Sdim 64317017Sdim uint32_t calculateSerializedLength(); 65317017Sdim 66317017Sdimprivate: 67317017Sdim uint32_t calculateHashBufferSize() const; 68317017Sdim uint32_t calculateIndexOffsetSize() const; 69317017Sdim Error finalize(); 70317017Sdim 71317017Sdim msf::MSFBuilder &Msf; 72317017Sdim BumpPtrAllocator &Allocator; 73317017Sdim 74317017Sdim size_t TypeRecordBytes = 0; 75317017Sdim 76318681Sdim PdbRaw_TpiVer VerHeader = PdbRaw_TpiVer::PdbTpiV80; 77317017Sdim std::vector<ArrayRef<uint8_t>> TypeRecords; 78317017Sdim std::vector<uint32_t> TypeHashes; 79318384Sdim std::vector<codeview::TypeIndexOffset> TypeIndexOffsets; 80317017Sdim uint32_t HashStreamIndex = kInvalidStreamIndex; 81317017Sdim std::unique_ptr<BinaryByteStream> HashValueStream; 82317017Sdim 83317017Sdim const TpiStreamHeader *Header; 84317017Sdim uint32_t Idx; 85317017Sdim}; 86317017Sdim} 87317017Sdim} 88317017Sdim 89317017Sdim#endif 90