Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:45

0001 //===- TpiStreamBuilder.h - PDB Tpi Stream Creation -------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_DEBUGINFO_PDB_NATIVE_TPISTREAMBUILDER_H
0010 #define LLVM_DEBUGINFO_PDB_NATIVE_TPISTREAMBUILDER_H
0011 
0012 #include "llvm/DebugInfo/CodeView/CVRecord.h"
0013 #include "llvm/DebugInfo/CodeView/TypeIndex.h"
0014 #include "llvm/DebugInfo/PDB/Native/RawConstants.h"
0015 #include "llvm/Support/Allocator.h"
0016 #include "llvm/Support/BinaryStreamRef.h"
0017 #include "llvm/Support/Error.h"
0018 
0019 #include <vector>
0020 
0021 namespace llvm {
0022 class BinaryByteStream;
0023 template <typename T> struct BinaryItemTraits;
0024 
0025 template <> struct BinaryItemTraits<llvm::codeview::CVType> {
0026   static size_t length(const codeview::CVType &Item) { return Item.length(); }
0027   static ArrayRef<uint8_t> bytes(const codeview::CVType &Item) {
0028     return Item.data();
0029   }
0030 };
0031 
0032 namespace msf {
0033 class MSFBuilder;
0034 struct MSFLayout;
0035 }
0036 namespace pdb {
0037 struct TpiStreamHeader;
0038 
0039 class TpiStreamBuilder {
0040 public:
0041   explicit TpiStreamBuilder(msf::MSFBuilder &Msf, uint32_t StreamIdx);
0042   ~TpiStreamBuilder();
0043 
0044   TpiStreamBuilder(const TpiStreamBuilder &) = delete;
0045   TpiStreamBuilder &operator=(const TpiStreamBuilder &) = delete;
0046 
0047   void setVersionHeader(PdbRaw_TpiVer Version);
0048   void addTypeRecord(ArrayRef<uint8_t> Type, std::optional<uint32_t> Hash);
0049   void addTypeRecords(ArrayRef<uint8_t> Types, ArrayRef<uint16_t> Sizes,
0050                       ArrayRef<uint32_t> Hashes);
0051 
0052   Error finalizeMsfLayout();
0053 
0054   uint32_t getRecordCount() const { return TypeRecordCount; }
0055 
0056   Error commit(const msf::MSFLayout &Layout, WritableBinaryStreamRef Buffer);
0057 
0058   uint32_t calculateSerializedLength();
0059 
0060 private:
0061   void updateTypeIndexOffsets(ArrayRef<uint16_t> Sizes);
0062 
0063   uint32_t calculateHashBufferSize() const;
0064   uint32_t calculateIndexOffsetSize() const;
0065   Error finalize();
0066 
0067   msf::MSFBuilder &Msf;
0068   BumpPtrAllocator &Allocator;
0069 
0070   uint32_t TypeRecordCount = 0;
0071   size_t TypeRecordBytes = 0;
0072 
0073   PdbRaw_TpiVer VerHeader = PdbRaw_TpiVer::PdbTpiV80;
0074   std::vector<ArrayRef<uint8_t>> TypeRecBuffers;
0075   std::vector<uint32_t> TypeHashes;
0076   std::vector<codeview::TypeIndexOffset> TypeIndexOffsets;
0077   uint32_t HashStreamIndex = kInvalidStreamIndex;
0078   std::unique_ptr<BinaryByteStream> HashValueStream;
0079 
0080   const TpiStreamHeader *Header;
0081   uint32_t Idx;
0082 };
0083 } // namespace pdb
0084 }
0085 
0086 #endif