32 : Msf(Msf),
Allocator(Msf.getAllocator()), Header(nullptr), Idx(StreamIdx) {
44 size_t NewSize = TypeRecordBytes + Size;
45 constexpr
size_t EightKB = 8 * 1024;
46 if (NewSize / EightKB > TypeRecordBytes / EightKB || TypeRecordCount == 0) {
47 TypeIndexOffsets.push_back(
53 TypeRecordBytes = NewSize;
58 std::optional<uint32_t> Hash) {
60 "The type record's size is not a multiple of 4 bytes which will "
61 "cause misalignment in the output TPI stream!");
64 updateTypeIndexOffsets(
ArrayRef(&OneSize, 1));
66 TypeRecBuffers.push_back(
Record);
69 TypeHashes.push_back(*Hash);
81 assert(((Types.size() & 3) == 0) &&
82 "The type record's size is not a multiple of 4 bytes which will "
83 "cause misalignment in the output TPI stream!");
84 assert(Sizes.size() == Hashes.
size() &&
"sizes and hashes should be in sync");
85 assert(std::accumulate(Sizes.begin(), Sizes.end(), 0U) == Types.size() &&
86 "sizes of type records should sum to the size of the types");
87 updateTypeIndexOffsets(Sizes);
89 TypeRecBuffers.push_back(Types);
93 Error TpiStreamBuilder::finalize() {
99 H->Version = VerHeader;
102 H->TypeIndexEnd =
H->TypeIndexBegin + TypeRecordCount;
103 H->TypeRecordBytes = TypeRecordBytes;
105 H->HashStreamIndex = HashStreamIndex;
113 H->HashValueBuffer.Off = 0;
114 H->HashValueBuffer.Length = calculateHashBufferSize();
118 H->HashAdjBuffer.Off =
H->HashValueBuffer.Off +
H->HashValueBuffer.Length;
119 H->HashAdjBuffer.Length = 0;
121 H->IndexOffsetBuffer.Off =
H->HashAdjBuffer.Off +
H->HashAdjBuffer.Length;
122 H->IndexOffsetBuffer.Length = calculateIndexOffsetSize();
132 uint32_t TpiStreamBuilder::calculateHashBufferSize()
const {
133 assert((TypeRecordCount == TypeHashes.size() || TypeHashes.empty()) &&
134 "either all or no type records should have hashes");
138 uint32_t TpiStreamBuilder::calculateIndexOffsetSize()
const {
148 calculateHashBufferSize() + calculateIndexOffsetSize();
150 if (HashStreamSize == 0)
153 auto ExpectedIndex = Msf.
addStream(HashStreamSize);
155 return ExpectedIndex.takeError();
156 HashStreamIndex = *ExpectedIndex;
157 if (!TypeHashes.empty()) {
164 reinterpret_cast<const uint8_t *
>(HashBuffer.data()),
165 calculateHashBufferSize());
174 if (
auto EC = finalize())
177 auto InfoS = WritableMappedBlockStream::createIndexedStream(Layout, Buffer,
184 for (
auto Rec : TypeRecBuffers) {
185 assert(!Rec.empty() &&
"Attempting to write an empty type record shifts "
186 "all offsets in the TPI stream!");
187 assert(((Rec.size() & 3) == 0) &&
188 "The type record's size is not a multiple of 4 bytes which will "
189 "cause misalignment in the output TPI stream!");
195 auto HVS = WritableMappedBlockStream::createIndexedStream(
196 Layout, Buffer, HashStreamIndex, Allocator);
198 if (HashValueStream) {
203 for (
auto &IndexOffset : TypeIndexOffsets) {