diff options
author | Zachary Turner <zturner@google.com> | 2017-02-25 00:44:30 +0000 |
---|---|---|
committer | Zachary Turner <zturner@google.com> | 2017-02-25 00:44:30 +0000 |
commit | af299ea5d456aa2fc19d7fdb041a0452d209fd4c (patch) | |
tree | 2d863cba130306041941aeec5b44baa2e9c00ec1 /llvm/lib/DebugInfo/PDB/Native/DbiStreamBuilder.cpp | |
parent | 42de38076517bc68a2b97c55dcbac7ea8d80b11b (diff) | |
download | bcm5719-llvm-af299ea5d456aa2fc19d7fdb041a0452d209fd4c.tar.gz bcm5719-llvm-af299ea5d456aa2fc19d7fdb041a0452d209fd4c.zip |
[PDB] General improvements to Stream library.
This adds various new functionality and cleanup surrounding the
use of the Stream library. Major changes include:
* Renaming of all classes for more consistency / meaningfulness
* Addition of some new methods for reading multiple values at once.
* Full suite of unit tests for reader / writer functionality.
* Full set of doxygen comments for all classes.
* Streams now store their own endianness.
* Fixed some bugs in a few of the classes that were discovered
by the unit tests.
llvm-svn: 296215
Diffstat (limited to 'llvm/lib/DebugInfo/PDB/Native/DbiStreamBuilder.cpp')
-rw-r--r-- | llvm/lib/DebugInfo/PDB/Native/DbiStreamBuilder.cpp | 51 |
1 files changed, 24 insertions, 27 deletions
diff --git a/llvm/lib/DebugInfo/PDB/Native/DbiStreamBuilder.cpp b/llvm/lib/DebugInfo/PDB/Native/DbiStreamBuilder.cpp index 60687ac23b0..ac40330c5dc 100644 --- a/llvm/lib/DebugInfo/PDB/Native/DbiStreamBuilder.cpp +++ b/llvm/lib/DebugInfo/PDB/Native/DbiStreamBuilder.cpp @@ -11,6 +11,7 @@ #include "llvm/ADT/ArrayRef.h" #include "llvm/DebugInfo/MSF/BinaryStreamWriter.h" +#include "llvm/DebugInfo/MSF/BinaryStreamWriter.h" #include "llvm/DebugInfo/MSF/MSFBuilder.h" #include "llvm/DebugInfo/MSF/MappedBlockStream.h" #include "llvm/DebugInfo/PDB/Native/DbiStream.h" @@ -153,18 +154,19 @@ Error DbiStreamBuilder::generateModiSubstream() { uint32_t Size = calculateModiSubstreamSize(); auto Data = Allocator.Allocate<uint8_t>(Size); - ModInfoBuffer = MutableByteStream(MutableArrayRef<uint8_t>(Data, Size)); + ModInfoBuffer = MutableBinaryByteStream(MutableArrayRef<uint8_t>(Data, Size), + llvm::support::little); - StreamWriter ModiWriter(ModInfoBuffer); + BinaryStreamWriter ModiWriter(ModInfoBuffer); for (const auto &M : ModuleInfoList) { ModuleInfoHeader Layout = {}; Layout.ModDiStream = kInvalidStreamIndex; Layout.NumFiles = M->SourceFiles.size(); if (auto EC = ModiWriter.writeObject(Layout)) return EC; - if (auto EC = ModiWriter.writeZeroString(M->Mod)) + if (auto EC = ModiWriter.writeCString(M->Mod)) return EC; - if (auto EC = ModiWriter.writeZeroString(M->Obj)) + if (auto EC = ModiWriter.writeCString(M->Obj)) return EC; } if (ModiWriter.bytesRemaining() > sizeof(uint32_t)) @@ -179,29 +181,26 @@ Error DbiStreamBuilder::generateFileInfoSubstream() { auto Data = Allocator.Allocate<uint8_t>(Size); uint32_t NamesOffset = Size - NameSize; - FileInfoBuffer = MutableByteStream(MutableArrayRef<uint8_t>(Data, Size)); + FileInfoBuffer = MutableBinaryByteStream(MutableArrayRef<uint8_t>(Data, Size), + llvm::support::little); - WritableStreamRef MetadataBuffer = - WritableStreamRef(FileInfoBuffer).keep_front(NamesOffset); - StreamWriter MetadataWriter(MetadataBuffer); + WritableBinaryStreamRef MetadataBuffer = + WritableBinaryStreamRef(FileInfoBuffer).keep_front(NamesOffset); + BinaryStreamWriter MetadataWriter(MetadataBuffer); uint16_t ModiCount = std::min<uint32_t>(UINT16_MAX, ModuleInfos.size()); uint16_t FileCount = std::min<uint32_t>(UINT16_MAX, SourceFileNames.size()); - if (auto EC = MetadataWriter.writeInteger( - ModiCount, llvm::support::little)) // NumModules + if (auto EC = MetadataWriter.writeInteger(ModiCount)) // NumModules return EC; - if (auto EC = MetadataWriter.writeInteger( - FileCount, llvm::support::little)) // NumSourceFiles + if (auto EC = MetadataWriter.writeInteger(FileCount)) // NumSourceFiles return EC; for (uint16_t I = 0; I < ModiCount; ++I) { - if (auto EC = MetadataWriter.writeInteger( - I, llvm::support::little)) // Mod Indices + if (auto EC = MetadataWriter.writeInteger(I)) // Mod Indices return EC; } for (const auto MI : ModuleInfoList) { FileCount = static_cast<uint16_t>(MI->SourceFiles.size()); - if (auto EC = MetadataWriter.writeInteger( - FileCount, llvm::support::little)) // Mod File Counts + if (auto EC = MetadataWriter.writeInteger(FileCount)) // Mod File Counts return EC; } @@ -209,11 +208,11 @@ Error DbiStreamBuilder::generateFileInfoSubstream() { // A side effect of this is that this will actually compute the various // file name offsets, so we can then go back and write the FileNameOffsets // array to the other substream. - NamesBuffer = WritableStreamRef(FileInfoBuffer).drop_front(NamesOffset); - StreamWriter NameBufferWriter(NamesBuffer); + NamesBuffer = WritableBinaryStreamRef(FileInfoBuffer).drop_front(NamesOffset); + BinaryStreamWriter NameBufferWriter(NamesBuffer); for (auto &Name : SourceFileNames) { Name.second = NameBufferWriter.getOffset(); - if (auto EC = NameBufferWriter.writeZeroString(Name.getKey())) + if (auto EC = NameBufferWriter.writeCString(Name.getKey())) return EC; } @@ -223,8 +222,7 @@ Error DbiStreamBuilder::generateFileInfoSubstream() { if (Result == SourceFileNames.end()) return make_error<RawError>(raw_error_code::no_entry, "The source file was not found."); - if (auto EC = MetadataWriter.writeInteger(Result->second, - llvm::support::little)) + if (auto EC = MetadataWriter.writeInteger(Result->second)) return EC; } } @@ -363,14 +361,14 @@ std::vector<SecMapEntry> DbiStreamBuilder::createSectionMap( } Error DbiStreamBuilder::commit(const msf::MSFLayout &Layout, - const msf::WritableStream &Buffer) { + WritableBinaryStreamRef Buffer) { if (auto EC = finalize()) return EC; auto InfoS = WritableMappedBlockStream::createIndexedStream(Layout, Buffer, StreamDBI); - StreamWriter Writer(*InfoS); + BinaryStreamWriter Writer(*InfoS); if (auto EC = Writer.writeObject(*Header)) return EC; @@ -378,7 +376,7 @@ Error DbiStreamBuilder::commit(const msf::MSFLayout &Layout, return EC; if (!SectionContribs.empty()) { - if (auto EC = Writer.writeEnum(DbiSecContribVer60, llvm::support::little)) + if (auto EC = Writer.writeEnum(DbiSecContribVer60)) return EC; if (auto EC = Writer.writeArray(SectionContribs)) return EC; @@ -397,8 +395,7 @@ Error DbiStreamBuilder::commit(const msf::MSFLayout &Layout, return EC; for (auto &Stream : DbgStreams) - if (auto EC = - Writer.writeInteger(Stream.StreamNumber, llvm::support::little)) + if (auto EC = Writer.writeInteger(Stream.StreamNumber)) return EC; for (auto &Stream : DbgStreams) { @@ -406,7 +403,7 @@ Error DbiStreamBuilder::commit(const msf::MSFLayout &Layout, continue; auto WritableStream = WritableMappedBlockStream::createIndexedStream( Layout, Buffer, Stream.StreamNumber); - StreamWriter DbgStreamWriter(*WritableStream); + BinaryStreamWriter DbgStreamWriter(*WritableStream); if (auto EC = DbgStreamWriter.writeArray(Stream.Data)) return EC; } |