TpiStreamBuilder.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- TpiStreamBuilder.h - PDB Tpi Stream Creation -------------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_DEBUGINFO_PDB_NATIVE_TPISTREAMBUILDER_H
  14. #define LLVM_DEBUGINFO_PDB_NATIVE_TPISTREAMBUILDER_H
  15. #include "llvm/DebugInfo/CodeView/CVRecord.h"
  16. #include "llvm/DebugInfo/CodeView/TypeIndex.h"
  17. #include "llvm/DebugInfo/PDB/Native/RawConstants.h"
  18. #include "llvm/Support/Allocator.h"
  19. #include "llvm/Support/BinaryStreamRef.h"
  20. #include "llvm/Support/Error.h"
  21. #include <vector>
  22. namespace llvm {
  23. class BinaryByteStream;
  24. template <typename T> struct BinaryItemTraits;
  25. template <> struct BinaryItemTraits<llvm::codeview::CVType> {
  26. static size_t length(const codeview::CVType &Item) { return Item.length(); }
  27. static ArrayRef<uint8_t> bytes(const codeview::CVType &Item) {
  28. return Item.data();
  29. }
  30. };
  31. namespace msf {
  32. class MSFBuilder;
  33. struct MSFLayout;
  34. }
  35. namespace pdb {
  36. struct TpiStreamHeader;
  37. class TpiStreamBuilder {
  38. public:
  39. explicit TpiStreamBuilder(msf::MSFBuilder &Msf, uint32_t StreamIdx);
  40. ~TpiStreamBuilder();
  41. TpiStreamBuilder(const TpiStreamBuilder &) = delete;
  42. TpiStreamBuilder &operator=(const TpiStreamBuilder &) = delete;
  43. void setVersionHeader(PdbRaw_TpiVer Version);
  44. void addTypeRecord(ArrayRef<uint8_t> Type, std::optional<uint32_t> Hash);
  45. void addTypeRecords(ArrayRef<uint8_t> Types, ArrayRef<uint16_t> Sizes,
  46. ArrayRef<uint32_t> Hashes);
  47. Error finalizeMsfLayout();
  48. uint32_t getRecordCount() const { return TypeRecordCount; }
  49. Error commit(const msf::MSFLayout &Layout, WritableBinaryStreamRef Buffer);
  50. uint32_t calculateSerializedLength();
  51. private:
  52. void updateTypeIndexOffsets(ArrayRef<uint16_t> Sizes);
  53. uint32_t calculateHashBufferSize() const;
  54. uint32_t calculateIndexOffsetSize() const;
  55. Error finalize();
  56. msf::MSFBuilder &Msf;
  57. BumpPtrAllocator &Allocator;
  58. uint32_t TypeRecordCount = 0;
  59. size_t TypeRecordBytes = 0;
  60. PdbRaw_TpiVer VerHeader = PdbRaw_TpiVer::PdbTpiV80;
  61. std::vector<ArrayRef<uint8_t>> TypeRecBuffers;
  62. std::vector<uint32_t> TypeHashes;
  63. std::vector<codeview::TypeIndexOffset> TypeIndexOffsets;
  64. uint32_t HashStreamIndex = kInvalidStreamIndex;
  65. std::unique_ptr<BinaryByteStream> HashValueStream;
  66. const TpiStreamHeader *Header;
  67. uint32_t Idx;
  68. };
  69. } // namespace pdb
  70. }
  71. #endif
  72. #ifdef __GNUC__
  73. #pragma GCC diagnostic pop
  74. #endif