37 : Allocator(Allocator), InjectedSourceHashTraits(Strings),
38 InjectedSourceTable(2, InjectedSourceHashTraits) {}
43 auto ExpectedMsf = MSFBuilder::create(Allocator, BlockSize);
45 return ExpectedMsf.takeError();
46 Msf = llvm::make_unique<MSFBuilder>(std::move(*ExpectedMsf));
54 Info = llvm::make_unique<InfoStreamBuilder>(*Msf, NamedStreams);
60 Dbi = llvm::make_unique<DbiStreamBuilder>(*Msf);
66 Tpi = llvm::make_unique<TpiStreamBuilder>(*Msf,
StreamTPI);
72 Ipi = llvm::make_unique<TpiStreamBuilder>(*Msf,
StreamIPI);
82 Gsi = llvm::make_unique<GSIStreamBuilder>(*Msf);
88 auto ExpectedStream = Msf->addStream(Size);
90 NamedStreams.
set(Name, *ExpectedStream);
91 return ExpectedStream;
99 NamedStreamData[*ExpectedIndex] =
Data;
104 std::unique_ptr<MemoryBuffer> Buffer) {
114 InjectedSourceDescriptor Desc;
115 Desc.Content = std::move(Buffer);
117 Desc.VNameIndex = VNI;
118 Desc.StreamName =
"/src/files/";
120 Desc.StreamName += VName;
122 InjectedSources.
push_back(std::move(Desc));
125 Error PDBFileBuilder::finalizeMsfLayout() {
127 if (Ipi && Ipi->getRecordCount() > 0) {
143 if (
auto EC = Gsi->finalizeMsfLayout())
146 Dbi->setPublicsStreamIndex(Gsi->getPublicsStreamIndex());
147 Dbi->setGlobalsStreamIndex(Gsi->getGlobalsStreamIndex());
148 Dbi->setSymbolRecordStreamIndex(Gsi->getRecordStreamIdx());
152 if (
auto EC = Tpi->finalizeMsfLayout())
156 if (
auto EC = Dbi->finalizeMsfLayout())
159 SN = allocateNamedStream(
"/names", StringsLen);
164 if (
auto EC = Ipi->finalizeMsfLayout())
171 if (
auto EC = Info->finalizeMsfLayout())
175 if (!InjectedSources.
empty()) {
176 for (
const auto &IS : InjectedSources) {
179 IS.Content->getBufferSize()));
184 Entry.
FileSize = IS.Content->getBufferSize();
185 Entry.
FileNI = IS.NameIndex;
193 InjectedSourceTable.set_as(VName, std::move(Entry));
198 InjectedSourceTable.calculateSerializedLength();
199 SN = allocateNamedStream(
"/src/headerblock", SrcHeaderBlockSize);
202 for (
const auto &IS : InjectedSources) {
203 SN = allocateNamedStream(IS.StreamName, IS.Content->getBufferSize());
212 if (
auto EC = Info->finalizeMsfLayout())
221 if (!NamedStreams.
get(Name, SN))
228 assert(!InjectedSourceTable.empty());
231 auto Stream = WritableMappedBlockStream::createIndexedStream(
232 Layout, MsfBuffer, SN, Allocator);
236 ::memset(&Header, 0,
sizeof(Header));
241 cantFail(InjectedSourceTable.commit(Writer));
248 if (InjectedSourceTable.empty())
251 commitSrcHeaderBlock(MsfBuffer, Layout);
253 for (
const auto &IS : InjectedSources) {
256 auto SourceStream = WritableMappedBlockStream::createIndexedStream(
257 Layout, MsfBuffer, SN, Allocator);
267 if (
auto EC = finalizeMsfLayout())
271 auto ExpectedMsfBuffer = Msf->commit(Filename, Layout);
272 if (!ExpectedMsfBuffer)
273 return ExpectedMsfBuffer.takeError();
278 return ExpectedSN.takeError();
280 auto NS = WritableMappedBlockStream::createIndexedStream(
281 Layout, Buffer, *ExpectedSN, Allocator);
283 if (
auto EC = Strings.
commit(NSWriter))
286 for (
const auto &NSE : NamedStreamData) {
287 if (NSE.second.empty())
290 auto NS = WritableMappedBlockStream::createIndexedStream(
291 Layout, Buffer, NSE.first, Allocator);
298 if (
auto EC = Info->commit(Layout, Buffer))
303 if (
auto EC = Dbi->commit(Layout, Buffer))
308 if (
auto EC = Tpi->commit(Layout, Buffer))
313 if (
auto EC = Ipi->commit(Layout, Buffer))
318 if (
auto EC = Gsi->commit(Layout, Buffer))
323 assert(!InfoStreamBlocks.empty());
324 uint64_t InfoStreamFileOffset =
329 commitInjectedSources(Buffer, Layout);
334 H->Age = Info->getAge();
335 H->Guid = Info->getGuid();
337 H->Signature = Sig.
hasValue() ? *Sig : time(
nullptr);
Error writeObject(const T &Obj)
Writes the object Obj to the underlying stream, as if by using memcpy.
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
void push_back(const T &Elt)
Error writeBytes(ArrayRef< uint8_t > Buffer)
Write the bytes specified in Buffer to the underlying stream.
void native(const Twine &path, SmallVectorImpl< char > &result, Style style=Style::native)
Convert path to the native form.
StringRef getStringForId(uint32_t Id) const
Compute iterated dominance frontiers using a linear time algorithm.
uint64_t blockToOffset(uint64_t BlockNumber, uint64_t BlockSize)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
PDBStringTableBuilder & getStringTableBuilder()
ArrayRef< uint8_t > arrayRefFromStringRef(StringRef Input)
Construct a string ref from an array ref of unsigned chars.
Error takeError()
Take ownership of the stored error.
void set(StringRef Stream, uint32_t StreamNo)
DbiStreamBuilder & getDbiBuilder()
Error commit(BinaryStreamWriter &Writer) const
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Error addNamedStream(StringRef Name, StringRef Data)
Tagged union holding either a T or a Error.
TpiStreamBuilder & getIpiBuilder()
Error commit(StringRef Filename)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
support::ulittle32_t BlockSize
uint32_t calculateSerializedSize() const
Error commit() override
For buffered streams, commits changes to the backing store.
Error initialize(uint32_t BlockSize)
Allocate memory in an ever growing pool, as if by bump-pointer.
uint32_t insert(StringRef S)
uint8_t * getBufferStart() const
Returns a pointer to the start of the buffer.
Provides write only access to a subclass of WritableBinaryStream.
uint32_t bytesRemaining() const
static const int BlockSize
static ErrorSuccess success()
Create a success value.
GSIStreamBuilder & getGsiBuilder()
InfoStreamBuilder & getInfoBuilder()
LLVM_NODISCARD bool empty() const
void addInjectedSource(StringRef Name, std::unique_ptr< MemoryBuffer > Buffer)
std::vector< ArrayRef< support::ulittle32_t > > StreamMap
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
bool get(StringRef Stream, uint32_t &StreamNo) const
LLVM_NODISCARD std::string lower() const
msf::MSFBuilder & getMsfBuilder()
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
void update(ArrayRef< char > Data)
Lightweight error class with error context and mandatory checking.
An implementation of WritableBinaryStream backed by an llvm FileOutputBuffer.
StringRef - Represent a constant reference to a string, i.e.
Expected< uint32_t > getNamedStreamIndex(StringRef Name) const
TpiStreamBuilder & getTpiBuilder()
A BinaryStream which can be read from as well as written to.