From: Zachary Turner Date: Tue, 28 Feb 2017 00:04:07 +0000 (+0000) Subject: [PDB] Make streams carry their own endianness. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d9b4aa7542481442163d72cfe450aa927471b6d1;p=llvm [PDB] Make streams carry their own endianness. Before the endianness was specified on each call to read or write of the StreamReader / StreamWriter, but in practice it's extremely rare for streams to have data encoded in multiple different endiannesses, so we should optimize for the 99% use case. This makes the code cleaner and more general, but otherwise has NFC. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@296415 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/DebugInfo/CodeView/CodeViewRecordIO.h b/include/llvm/DebugInfo/CodeView/CodeViewRecordIO.h index 2a72ddd7641..b7f621d2480 100644 --- a/include/llvm/DebugInfo/CodeView/CodeViewRecordIO.h +++ b/include/llvm/DebugInfo/CodeView/CodeViewRecordIO.h @@ -59,9 +59,9 @@ public: template Error mapInteger(T &Value) { if (isWriting()) - return Writer->writeInteger(Value, llvm::support::little); + return Writer->writeInteger(Value); - return Reader->readInteger(Value, llvm::support::little); + return Reader->readInteger(Value); } template Error mapEnum(T &Value) { @@ -93,7 +93,7 @@ public: SizeType Size; if (isWriting()) { Size = static_cast(Items.size()); - if (auto EC = Writer->writeInteger(Size, llvm::support::little)) + if (auto EC = Writer->writeInteger(Size)) return EC; for (auto &X : Items) { @@ -101,7 +101,7 @@ public: return EC; } } else { - if (auto EC = Reader->readInteger(Size, llvm::support::little)) + if (auto EC = Reader->readInteger(Size)) return EC; for (SizeType I = 0; I < Size; ++I) { typename T::value_type Item; diff --git a/include/llvm/DebugInfo/CodeView/SymbolDeserializer.h b/include/llvm/DebugInfo/CodeView/SymbolDeserializer.h index d7244de6b74..2a5f20d88ed 100644 --- a/include/llvm/DebugInfo/CodeView/SymbolDeserializer.h +++ b/include/llvm/DebugInfo/CodeView/SymbolDeserializer.h @@ -25,7 +25,8 @@ class SymbolVisitorDelegate; class SymbolDeserializer : public SymbolVisitorCallbacks { struct MappingInfo { explicit MappingInfo(ArrayRef RecordData) - : Stream(RecordData), Reader(Stream), Mapping(Reader) {} + : Stream(RecordData, llvm::support::little), Reader(Stream), + Mapping(Reader) {} BinaryByteStream Stream; BinaryStreamReader Reader; diff --git a/include/llvm/DebugInfo/CodeView/SymbolSerializer.h b/include/llvm/DebugInfo/CodeView/SymbolSerializer.h index b29393a7068..523b9aaeacb 100644 --- a/include/llvm/DebugInfo/CodeView/SymbolSerializer.h +++ b/include/llvm/DebugInfo/CodeView/SymbolSerializer.h @@ -12,18 +12,19 @@ #include "llvm/DebugInfo/CodeView/SymbolRecordMapping.h" #include "llvm/DebugInfo/CodeView/SymbolVisitorCallbacks.h" -#include "llvm/DebugInfo/MSF/BinaryByteStream.h" -#include "llvm/DebugInfo/MSF/BinaryStreamWriter.h" #include "llvm/ADT/Optional.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/iterator_range.h" +#include "llvm/DebugInfo/MSF/BinaryByteStream.h" +#include "llvm/DebugInfo/MSF/BinaryStreamWriter.h" #include "llvm/Support/Allocator.h" #include "llvm/Support/Error.h" namespace llvm { +class BinaryStreamWriter; namespace codeview { class SymbolSerializer : public SymbolVisitorCallbacks { diff --git a/include/llvm/DebugInfo/CodeView/TypeDeserializer.h b/include/llvm/DebugInfo/CodeView/TypeDeserializer.h index bc5be0498ff..92177a48d4c 100644 --- a/include/llvm/DebugInfo/CodeView/TypeDeserializer.h +++ b/include/llvm/DebugInfo/CodeView/TypeDeserializer.h @@ -29,7 +29,8 @@ namespace codeview { class TypeDeserializer : public TypeVisitorCallbacks { struct MappingInfo { explicit MappingInfo(ArrayRef RecordData) - : Stream(RecordData), Reader(Stream), Mapping(Reader) {} + : Stream(RecordData, llvm::support::little), Reader(Stream), + Mapping(Reader) {} BinaryByteStream Stream; BinaryStreamReader Reader; diff --git a/include/llvm/DebugInfo/CodeView/TypeSerializer.h b/include/llvm/DebugInfo/CodeView/TypeSerializer.h index c77d8edbc15..80867ecb41f 100644 --- a/include/llvm/DebugInfo/CodeView/TypeSerializer.h +++ b/include/llvm/DebugInfo/CodeView/TypeSerializer.h @@ -109,7 +109,7 @@ private: Error visitKnownMemberImpl(CVMemberRecord &CVR, RecordType &Record) { assert(CVR.Kind == static_cast(Record.getKind())); - if (auto EC = Writer.writeEnum(CVR.Kind, llvm::support::little)) + if (auto EC = Writer.writeEnum(CVR.Kind)) return EC; if (auto EC = Mapping.visitKnownMember(CVR, Record)) diff --git a/include/llvm/DebugInfo/MSF/BinaryByteStream.h b/include/llvm/DebugInfo/MSF/BinaryByteStream.h index 3403956b01a..caa1d7c295f 100644 --- a/include/llvm/DebugInfo/MSF/BinaryByteStream.h +++ b/include/llvm/DebugInfo/MSF/BinaryByteStream.h @@ -32,9 +32,12 @@ namespace llvm { class BinaryByteStream : public BinaryStream { public: BinaryByteStream() = default; - BinaryByteStream(ArrayRef Data) : Data(Data) {} - BinaryByteStream(StringRef Data) - : Data(Data.bytes_begin(), Data.bytes_end()) {} + BinaryByteStream(ArrayRef Data, llvm::support::endianness Endian) + : Endian(Endian), Data(Data) {} + BinaryByteStream(StringRef Data, llvm::support::endianness Endian) + : Endian(Endian), Data(Data.bytes_begin(), Data.bytes_end()) {} + + llvm::support::endianness getEndian() const override { return Endian; } Error readBytes(uint32_t Offset, uint32_t Size, ArrayRef &Buffer) override { @@ -67,6 +70,7 @@ public: } protected: + llvm::support::endianness Endian; ArrayRef Data; }; @@ -76,8 +80,10 @@ protected: /// will never cause a copy. class MemoryBufferByteStream : public BinaryByteStream { public: - explicit MemoryBufferByteStream(std::unique_ptr Buffer) - : BinaryByteStream(Buffer->getBuffer()), MemBuffer(std::move(Buffer)) {} + MemoryBufferByteStream(std::unique_ptr Buffer, + llvm::support::endianness Endian) + : BinaryByteStream(Buffer->getBuffer(), Endian), + MemBuffer(std::move(Buffer)) {} std::unique_ptr MemBuffer; }; @@ -89,8 +95,13 @@ public: class MutableBinaryByteStream : public WritableBinaryStream { public: MutableBinaryByteStream() = default; - MutableBinaryByteStream(MutableArrayRef Data) - : Data(Data), ImmutableStream(Data) {} + MutableBinaryByteStream(MutableArrayRef Data, + llvm::support::endianness Endian) + : Data(Data), ImmutableStream(Data, Endian) {} + + llvm::support::endianness getEndian() const override { + return ImmutableStream.getEndian(); + } Error readBytes(uint32_t Offset, uint32_t Size, ArrayRef &Buffer) override { @@ -135,9 +146,12 @@ class FileBufferByteStream : public WritableBinaryStream { private: class StreamImpl : public MutableBinaryByteStream { public: - StreamImpl(std::unique_ptr Buffer) - : MutableBinaryByteStream(MutableArrayRef( - Buffer->getBufferStart(), Buffer->getBufferEnd())), + StreamImpl(std::unique_ptr Buffer, + llvm::support::endianness Endian) + : MutableBinaryByteStream( + MutableArrayRef(Buffer->getBufferStart(), + Buffer->getBufferEnd()), + Endian), FileBuffer(std::move(Buffer)) {} Error commit() override { @@ -152,8 +166,13 @@ private: }; public: - explicit FileBufferByteStream(std::unique_ptr Buffer) - : Impl(std::move(Buffer)) {} + FileBufferByteStream(std::unique_ptr Buffer, + llvm::support::endianness Endian) + : Impl(std::move(Buffer), Endian) {} + + llvm::support::endianness getEndian() const override { + return Impl.getEndian(); + } Error readBytes(uint32_t Offset, uint32_t Size, ArrayRef &Buffer) override { @@ -179,4 +198,4 @@ private: } // end namespace llvm -#endif // LLVM_DEBUGINFO_MSF_BINARYBYTESTREAM_H +#endif // LLVM_DEBUGINFO_MSF_BYTESTREAM_H diff --git a/include/llvm/DebugInfo/MSF/BinaryItemStream.h b/include/llvm/DebugInfo/MSF/BinaryItemStream.h index f8cad8b2890..5d4ed5b5118 100644 --- a/include/llvm/DebugInfo/MSF/BinaryItemStream.h +++ b/include/llvm/DebugInfo/MSF/BinaryItemStream.h @@ -34,7 +34,10 @@ template struct BinaryItemTraits { template > class BinaryItemStream : public BinaryStream { public: - BinaryItemStream() = default; + explicit BinaryItemStream(llvm::support::endianness Endian) + : Endian(Endian) {} + + llvm::support::endianness getEndian() const override { return Endian; } Error readBytes(uint32_t Offset, uint32_t Size, ArrayRef &Buffer) override { @@ -83,6 +86,7 @@ private: return CurrentIndex; } + llvm::support::endianness Endian; ArrayRef Items; }; diff --git a/include/llvm/DebugInfo/MSF/BinaryStream.h b/include/llvm/DebugInfo/MSF/BinaryStream.h index 50c34e3cba0..5a9ca34367b 100644 --- a/include/llvm/DebugInfo/MSF/BinaryStream.h +++ b/include/llvm/DebugInfo/MSF/BinaryStream.h @@ -28,6 +28,8 @@ class BinaryStream { public: virtual ~BinaryStream() = default; + virtual llvm::support::endianness getEndian() const = 0; + /// \brief Given an offset into the stream and a number of bytes, attempt to /// read the bytes and set the output ArrayRef to point to data owned by the /// stream. diff --git a/include/llvm/DebugInfo/MSF/BinaryStreamReader.h b/include/llvm/DebugInfo/MSF/BinaryStreamReader.h index 59d3fbe6b31..507fa5b5689 100644 --- a/include/llvm/DebugInfo/MSF/BinaryStreamReader.h +++ b/include/llvm/DebugInfo/MSF/BinaryStreamReader.h @@ -12,8 +12,8 @@ #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/STLExtras.h" -#include "llvm/DebugInfo/MSF/BinaryStream.h" #include "llvm/DebugInfo/MSF/BinaryStreamArray.h" +#include "llvm/DebugInfo/MSF/BinaryStreamRef.h" #include "llvm/Support/Endian.h" #include "llvm/Support/Error.h" #include "llvm/Support/MathExtras.h" @@ -58,8 +58,7 @@ public: /// /// \returns a success error code if the data was successfully read, otherwise /// returns an appropriate error code. - template - Error readInteger(T &Dest, llvm::support::endianness Endian) { + template Error readInteger(T &Dest) { static_assert(std::is_integral::value, "Cannot call readInteger with non-integral value!"); @@ -68,17 +67,16 @@ public: return EC; Dest = llvm::support::endian::read( - Bytes.data(), Endian); + Bytes.data(), Stream.getEndian()); return Error::success(); } /// Similar to readInteger. - template - Error readEnum(T &Dest, llvm::support::endianness Endian) { + template Error readEnum(T &Dest) { static_assert(std::is_enum::value, "Cannot call readEnum with non-enum value!"); typename std::underlying_type::type N; - if (auto EC = readInteger(N, Endian)) + if (auto EC = readInteger(N)) return EC; Dest = static_cast(N); return Error::success(); diff --git a/include/llvm/DebugInfo/MSF/BinaryStreamRef.h b/include/llvm/DebugInfo/MSF/BinaryStreamRef.h index 4d302ff1952..7cbe4e3292f 100644 --- a/include/llvm/DebugInfo/MSF/BinaryStreamRef.h +++ b/include/llvm/DebugInfo/MSF/BinaryStreamRef.h @@ -26,6 +26,8 @@ public: BinaryStreamRefBase(StreamType &Stream, uint32_t Offset, uint32_t Length) : Stream(&Stream), ViewOffset(Offset), Length(Length) {} + llvm::support::endianness getEndian() const { return Stream->getEndian(); } + uint32_t getLength() const { return Length; } const StreamType *getStream() const { return Stream; } diff --git a/include/llvm/DebugInfo/MSF/BinaryStreamWriter.h b/include/llvm/DebugInfo/MSF/BinaryStreamWriter.h index 585f8f03eab..cd4660ef653 100644 --- a/include/llvm/DebugInfo/MSF/BinaryStreamWriter.h +++ b/include/llvm/DebugInfo/MSF/BinaryStreamWriter.h @@ -47,24 +47,22 @@ public: /// /// \returns a success error code if the data was successfully written, /// otherwise returns an appropriate error code. - template - Error writeInteger(T Value, llvm::support::endianness Endian) { + template Error writeInteger(T Value) { static_assert(std::is_integral::value, "Cannot call writeInteger with non-integral value!"); uint8_t Buffer[sizeof(T)]; - llvm::support::endian::write(Buffer, Value, - Endian); + llvm::support::endian::write( + Buffer, Value, Stream.getEndian()); return writeBytes(Buffer); } /// Similar to writeInteger - template - Error writeEnum(T Num, llvm::support::endianness Endian) { + template Error writeEnum(T Num) { static_assert(std::is_enum::value, "Cannot call writeEnum with non-Enum type"); using U = typename std::underlying_type::type; - return writeInteger(static_cast(Num), Endian); + return writeInteger(static_cast(Num)); } /// Write the the string \p Str to the underlying stream followed by a null diff --git a/include/llvm/DebugInfo/MSF/MappedBlockStream.h b/include/llvm/DebugInfo/MSF/MappedBlockStream.h index bcaedfd9aac..96342845378 100644 --- a/include/llvm/DebugInfo/MSF/MappedBlockStream.h +++ b/include/llvm/DebugInfo/MSF/MappedBlockStream.h @@ -56,6 +56,10 @@ public: static std::unique_ptr createDirectoryStream(const MSFLayout &Layout, BinaryStreamRef MsfData); + llvm::support::endianness getEndian() const override { + return llvm::support::little; + } + Error readBytes(uint32_t Offset, uint32_t Size, ArrayRef &Buffer) override; Error readLongestContiguousChunk(uint32_t Offset, @@ -113,6 +117,10 @@ public: static std::unique_ptr createFpmStream(const MSFLayout &Layout, WritableBinaryStreamRef MsfData); + llvm::support::endianness getEndian() const override { + return llvm::support::little; + } + Error readBytes(uint32_t Offset, uint32_t Size, ArrayRef &Buffer) override; Error readLongestContiguousChunk(uint32_t Offset, diff --git a/include/llvm/DebugInfo/PDB/Native/DbiStream.h b/include/llvm/DebugInfo/PDB/Native/DbiStream.h index 08739b697d6..38d338d6d83 100644 --- a/include/llvm/DebugInfo/PDB/Native/DbiStream.h +++ b/include/llvm/DebugInfo/PDB/Native/DbiStream.h @@ -12,6 +12,8 @@ #include "llvm/DebugInfo/CodeView/ModuleSubstream.h" #include "llvm/DebugInfo/MSF/BinaryStreamArray.h" +#include "llvm/DebugInfo/MSF/BinaryStreamArray.h" +#include "llvm/DebugInfo/MSF/BinaryStreamRef.h" #include "llvm/DebugInfo/MSF/BinaryStreamRef.h" #include "llvm/DebugInfo/MSF/MappedBlockStream.h" #include "llvm/DebugInfo/PDB/Native/ModInfo.h" diff --git a/include/llvm/DebugInfo/PDB/Native/InfoStreamBuilder.h b/include/llvm/DebugInfo/PDB/Native/InfoStreamBuilder.h index b08cf6ab960..4133662615b 100644 --- a/include/llvm/DebugInfo/PDB/Native/InfoStreamBuilder.h +++ b/include/llvm/DebugInfo/PDB/Native/InfoStreamBuilder.h @@ -19,7 +19,7 @@ #include "llvm/DebugInfo/PDB/PDBTypes.h" namespace llvm { -class BinaryStreamWriter; +class WritableBinaryStreamRef; namespace msf { class MSFBuilder; diff --git a/include/llvm/DebugInfo/PDB/Native/PDBFile.h b/include/llvm/DebugInfo/PDB/Native/PDBFile.h index c39e6a7750f..66e1aa7462b 100644 --- a/include/llvm/DebugInfo/PDB/Native/PDBFile.h +++ b/include/llvm/DebugInfo/PDB/Native/PDBFile.h @@ -11,8 +11,7 @@ #define LLVM_DEBUGINFO_PDB_RAW_PDBFILE_H #include "llvm/ADT/DenseMap.h" -#include "llvm/DebugInfo/MSF/BinaryStream.h" -#include "llvm/DebugInfo/MSF/BinaryStreamArray.h" +#include "llvm/DebugInfo/MSF/BinaryStreamRef.h" #include "llvm/DebugInfo/MSF/IMSFFile.h" #include "llvm/DebugInfo/MSF/MSFCommon.h" #include "llvm/Support/Allocator.h" @@ -24,6 +23,8 @@ namespace llvm { +class BinaryStream; + namespace msf { class MappedBlockStream; } diff --git a/include/llvm/DebugInfo/PDB/Native/PublicsStream.h b/include/llvm/DebugInfo/PDB/Native/PublicsStream.h index 284bbf62372..d828e70fcde 100644 --- a/include/llvm/DebugInfo/PDB/Native/PublicsStream.h +++ b/include/llvm/DebugInfo/PDB/Native/PublicsStream.h @@ -16,7 +16,6 @@ #include "llvm/DebugInfo/PDB/Native/RawConstants.h" #include "llvm/DebugInfo/PDB/Native/RawTypes.h" #include "llvm/DebugInfo/PDB/PDBTypes.h" - #include "llvm/Support/Error.h" namespace llvm { diff --git a/include/llvm/DebugInfo/PDB/Native/TpiStreamBuilder.h b/include/llvm/DebugInfo/PDB/Native/TpiStreamBuilder.h index 8f51aec0fd0..3a98c3a1c90 100644 --- a/include/llvm/DebugInfo/PDB/Native/TpiStreamBuilder.h +++ b/include/llvm/DebugInfo/PDB/Native/TpiStreamBuilder.h @@ -14,6 +14,7 @@ #include "llvm/DebugInfo/CodeView/TypeRecord.h" #include "llvm/DebugInfo/MSF/BinaryByteStream.h" #include "llvm/DebugInfo/MSF/BinaryItemStream.h" +#include "llvm/DebugInfo/MSF/BinaryStreamRef.h" #include "llvm/DebugInfo/PDB/Native/RawConstants.h" #include "llvm/Support/Allocator.h" #include "llvm/Support/Error.h" @@ -22,12 +23,7 @@ namespace llvm { class BinaryByteStream; -class BinaryStreamRef; -class WritableBinaryStream; - -namespace codeview { -class TypeRecord; -} +class WritableBinaryStreamRef; template <> struct BinaryItemTraits { static size_t length(const codeview::CVType &Item) { return Item.length(); } @@ -36,6 +32,9 @@ template <> struct BinaryItemTraits { } }; +namespace codeview { +class TypeRecord; +} namespace msf { class MSFBuilder; struct MSFLayout; diff --git a/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp b/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp index 75cd3d2296c..c1dfb900a8d 100644 --- a/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp +++ b/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp @@ -494,7 +494,7 @@ void CodeViewDebug::emitTypeInformation() { // comments. The MSVC linker doesn't do much type record validation, // so the first link of an invalid type record can succeed while // subsequent links will fail with LNK1285. - BinaryByteStream Stream(Record); + BinaryByteStream Stream(Record, llvm::support::little); CVTypeArray Types; BinaryStreamReader Reader(Stream); Error E = Reader.readArray(Types, Reader.getLength()); diff --git a/lib/DebugInfo/CodeView/CVTypeDumper.cpp b/lib/DebugInfo/CodeView/CVTypeDumper.cpp index 5e0ff63dc5a..a94516985b8 100644 --- a/lib/DebugInfo/CodeView/CVTypeDumper.cpp +++ b/lib/DebugInfo/CodeView/CVTypeDumper.cpp @@ -56,7 +56,7 @@ Error CVTypeDumper::dump(const CVTypeArray &Types, } Error CVTypeDumper::dump(ArrayRef Data, TypeVisitorCallbacks &Dumper) { - BinaryByteStream Stream(Data); + BinaryByteStream Stream(Data, llvm::support::little); CVTypeArray Types; BinaryStreamReader Reader(Stream); if (auto EC = Reader.readArray(Types, Reader.getLength())) diff --git a/lib/DebugInfo/CodeView/CVTypeVisitor.cpp b/lib/DebugInfo/CodeView/CVTypeVisitor.cpp index fa7406271e1..74c60c78b8b 100644 --- a/lib/DebugInfo/CodeView/CVTypeVisitor.cpp +++ b/lib/DebugInfo/CodeView/CVTypeVisitor.cpp @@ -182,7 +182,7 @@ Error CVTypeVisitor::visitFieldListMemberStream(BinaryStreamReader Reader) { TypeLeafKind Leaf; while (!Reader.empty()) { - if (auto EC = Reader.readEnum(Leaf, llvm::support::little)) + if (auto EC = Reader.readEnum(Leaf)) return EC; CVMemberRecord Record; @@ -195,7 +195,7 @@ Error CVTypeVisitor::visitFieldListMemberStream(BinaryStreamReader Reader) { } Error CVTypeVisitor::visitFieldListMemberStream(ArrayRef Data) { - BinaryByteStream S(Data); + BinaryByteStream S(Data, llvm::support::little); BinaryStreamReader SR(S); return visitFieldListMemberStream(SR); } diff --git a/lib/DebugInfo/CodeView/CodeViewRecordIO.cpp b/lib/DebugInfo/CodeView/CodeViewRecordIO.cpp index 3b10f8ff120..a204d43ba13 100644 --- a/lib/DebugInfo/CodeView/CodeViewRecordIO.cpp +++ b/lib/DebugInfo/CodeView/CodeViewRecordIO.cpp @@ -87,14 +87,13 @@ Error CodeViewRecordIO::mapByteVectorTail(std::vector &Bytes) { Error CodeViewRecordIO::mapInteger(TypeIndex &TypeInd) { if (isWriting()) { - if (auto EC = - Writer->writeInteger(TypeInd.getIndex(), llvm::support::little)) + if (auto EC = Writer->writeInteger(TypeInd.getIndex())) return EC; return Error::success(); } uint32_t I; - if (auto EC = Reader->readInteger(I, llvm::support::little)) + if (auto EC = Reader->readInteger(I)) return EC; TypeInd.setIndex(I); return Error::success(); @@ -177,7 +176,7 @@ Error CodeViewRecordIO::mapStringZVectorZ(std::vector &Value) { if (auto EC = mapStringZ(V)) return EC; } - if (auto EC = Writer->writeInteger(0, llvm::support::little)) + if (auto EC = Writer->writeInteger(0)) return EC; } else { StringRef S; @@ -195,28 +194,24 @@ Error CodeViewRecordIO::mapStringZVectorZ(std::vector &Value) { Error CodeViewRecordIO::writeEncodedSignedInteger(const int64_t &Value) { assert(Value < 0 && "Encoded integer is not signed!"); if (Value >= std::numeric_limits::min()) { - if (auto EC = - Writer->writeInteger(LF_CHAR, llvm::support::little)) + if (auto EC = Writer->writeInteger(LF_CHAR)) return EC; - if (auto EC = Writer->writeInteger(Value, llvm::support::little)) + if (auto EC = Writer->writeInteger(Value)) return EC; } else if (Value >= std::numeric_limits::min()) { - if (auto EC = - Writer->writeInteger(LF_SHORT, llvm::support::little)) + if (auto EC = Writer->writeInteger(LF_SHORT)) return EC; - if (auto EC = Writer->writeInteger(Value, llvm::support::little)) + if (auto EC = Writer->writeInteger(Value)) return EC; } else if (Value >= std::numeric_limits::min()) { - if (auto EC = - Writer->writeInteger(LF_LONG, llvm::support::little)) + if (auto EC = Writer->writeInteger(LF_LONG)) return EC; - if (auto EC = Writer->writeInteger(Value, llvm::support::little)) + if (auto EC = Writer->writeInteger(Value)) return EC; } else { - if (auto EC = - Writer->writeInteger(LF_QUADWORD, llvm::support::little)) + if (auto EC = Writer->writeInteger(LF_QUADWORD)) return EC; - if (auto EC = Writer->writeInteger(Value, llvm::support::little)) + if (auto EC = Writer->writeInteger(Value)) return EC; } return Error::success(); @@ -224,25 +219,22 @@ Error CodeViewRecordIO::writeEncodedSignedInteger(const int64_t &Value) { Error CodeViewRecordIO::writeEncodedUnsignedInteger(const uint64_t &Value) { if (Value < LF_NUMERIC) { - if (auto EC = Writer->writeInteger(Value, llvm::support::little)) + if (auto EC = Writer->writeInteger(Value)) return EC; } else if (Value <= std::numeric_limits::max()) { - if (auto EC = - Writer->writeInteger(LF_USHORT, llvm::support::little)) + if (auto EC = Writer->writeInteger(LF_USHORT)) return EC; - if (auto EC = Writer->writeInteger(Value, llvm::support::little)) + if (auto EC = Writer->writeInteger(Value)) return EC; } else if (Value <= std::numeric_limits::max()) { - if (auto EC = - Writer->writeInteger(LF_ULONG, llvm::support::little)) + if (auto EC = Writer->writeInteger(LF_ULONG)) return EC; - if (auto EC = Writer->writeInteger(Value, llvm::support::little)) + if (auto EC = Writer->writeInteger(Value)) return EC; } else { - if (auto EC = - Writer->writeInteger(LF_UQUADWORD, llvm::support::little)) + if (auto EC = Writer->writeInteger(LF_UQUADWORD)) return EC; - if (auto EC = Writer->writeInteger(Value, llvm::support::little)) + if (auto EC = Writer->writeInteger(Value)) return EC; } diff --git a/lib/DebugInfo/CodeView/RecordSerialization.cpp b/lib/DebugInfo/CodeView/RecordSerialization.cpp index d276aa0b84d..eaa70f2b181 100644 --- a/lib/DebugInfo/CodeView/RecordSerialization.cpp +++ b/lib/DebugInfo/CodeView/RecordSerialization.cpp @@ -37,7 +37,7 @@ Error llvm::codeview::consume(BinaryStreamReader &Reader, APSInt &Num) { // Used to avoid overload ambiguity on APInt construtor. bool FalseVal = false; uint16_t Short; - if (auto EC = Reader.readInteger(Short, llvm::support::little)) + if (auto EC = Reader.readInteger(Short)) return EC; if (Short < LF_NUMERIC) { @@ -49,49 +49,49 @@ Error llvm::codeview::consume(BinaryStreamReader &Reader, APSInt &Num) { switch (Short) { case LF_CHAR: { int8_t N; - if (auto EC = Reader.readInteger(N, llvm::support::little)) + if (auto EC = Reader.readInteger(N)) return EC; Num = APSInt(APInt(8, N, true), false); return Error::success(); } case LF_SHORT: { int16_t N; - if (auto EC = Reader.readInteger(N, llvm::support::little)) + if (auto EC = Reader.readInteger(N)) return EC; Num = APSInt(APInt(16, N, true), false); return Error::success(); } case LF_USHORT: { uint16_t N; - if (auto EC = Reader.readInteger(N, llvm::support::little)) + if (auto EC = Reader.readInteger(N)) return EC; Num = APSInt(APInt(16, N, false), true); return Error::success(); } case LF_LONG: { int32_t N; - if (auto EC = Reader.readInteger(N, llvm::support::little)) + if (auto EC = Reader.readInteger(N)) return EC; Num = APSInt(APInt(32, N, true), false); return Error::success(); } case LF_ULONG: { uint32_t N; - if (auto EC = Reader.readInteger(N, llvm::support::little)) + if (auto EC = Reader.readInteger(N)) return EC; Num = APSInt(APInt(32, N, FalseVal), true); return Error::success(); } case LF_QUADWORD: { int64_t N; - if (auto EC = Reader.readInteger(N, llvm::support::little)) + if (auto EC = Reader.readInteger(N)) return EC; Num = APSInt(APInt(64, N, true), false); return Error::success(); } case LF_UQUADWORD: { uint64_t N; - if (auto EC = Reader.readInteger(N, llvm::support::little)) + if (auto EC = Reader.readInteger(N)) return EC; Num = APSInt(APInt(64, N, false), true); return Error::success(); @@ -103,7 +103,7 @@ Error llvm::codeview::consume(BinaryStreamReader &Reader, APSInt &Num) { Error llvm::codeview::consume(StringRef &Data, APSInt &Num) { ArrayRef Bytes(Data.bytes_begin(), Data.bytes_end()); - BinaryByteStream S(Bytes); + BinaryByteStream S(Bytes, llvm::support::little); BinaryStreamReader SR(S); auto EC = consume(SR, Num); Data = Data.take_back(SR.bytesRemaining()); @@ -124,12 +124,12 @@ Error llvm::codeview::consume_numeric(BinaryStreamReader &Reader, } Error llvm::codeview::consume(BinaryStreamReader &Reader, uint32_t &Item) { - return Reader.readInteger(Item, llvm::support::little); + return Reader.readInteger(Item); } Error llvm::codeview::consume(StringRef &Data, uint32_t &Item) { ArrayRef Bytes(Data.bytes_begin(), Data.bytes_end()); - BinaryByteStream S(Bytes); + BinaryByteStream S(Bytes, llvm::support::little); BinaryStreamReader SR(S); auto EC = consume(SR, Item); Data = Data.take_back(SR.bytesRemaining()); @@ -137,7 +137,7 @@ Error llvm::codeview::consume(StringRef &Data, uint32_t &Item) { } Error llvm::codeview::consume(BinaryStreamReader &Reader, int32_t &Item) { - return Reader.readInteger(Item, llvm::support::little); + return Reader.readInteger(Item); } Error llvm::codeview::consume(BinaryStreamReader &Reader, StringRef &Item) { diff --git a/lib/DebugInfo/CodeView/TypeSerializer.cpp b/lib/DebugInfo/CodeView/TypeSerializer.cpp index 9074291efcc..4d0ce9e4da9 100644 --- a/lib/DebugInfo/CodeView/TypeSerializer.cpp +++ b/lib/DebugInfo/CodeView/TypeSerializer.cpp @@ -76,7 +76,7 @@ TypeSerializer::addPadding(MutableArrayRef Record) { int N = PaddingBytes; while (PaddingBytes > 0) { uint8_t Pad = static_cast(LF_PAD0 + PaddingBytes); - if (auto EC = Writer.writeInteger(Pad, llvm::support::little)) + if (auto EC = Writer.writeInteger(Pad)) return std::move(EC); --PaddingBytes; } @@ -85,7 +85,8 @@ TypeSerializer::addPadding(MutableArrayRef Record) { TypeSerializer::TypeSerializer(BumpPtrAllocator &Storage) : RecordStorage(Storage), LastTypeIndex(), - RecordBuffer(MaxRecordLength * 2), Stream(RecordBuffer), Writer(Stream), + RecordBuffer(MaxRecordLength * 2), + Stream(RecordBuffer, llvm::support::little), Writer(Stream), Mapping(Writer) { // RecordBuffer needs to be able to hold enough data so that if we are 1 // byte short of MaxRecordLen, and then we try to write MaxRecordLen bytes, @@ -203,15 +204,15 @@ Error TypeSerializer::visitMemberEnd(CVMemberRecord &Record) { uint8_t *SegmentBytes = RecordStorage.Allocate(LengthWithSize); auto SavedSegment = MutableArrayRef(SegmentBytes, LengthWithSize); - MutableBinaryByteStream CS(SavedSegment); + MutableBinaryByteStream CS(SavedSegment, llvm::support::little); BinaryStreamWriter CW(CS); if (auto EC = CW.writeBytes(CopyData)) return EC; - if (auto EC = CW.writeEnum(TypeLeafKind::LF_INDEX, llvm::support::little)) + if (auto EC = CW.writeEnum(TypeLeafKind::LF_INDEX)) return EC; - if (auto EC = CW.writeInteger(0, llvm::support::little)) + if (auto EC = CW.writeInteger(0)) return EC; - if (auto EC = CW.writeInteger(0xB0C0B0C0, llvm::support::little)) + if (auto EC = CW.writeInteger(0xB0C0B0C0)) return EC; FieldListSegments.push_back(SavedSegment); diff --git a/lib/DebugInfo/PDB/Native/DbiStream.cpp b/lib/DebugInfo/PDB/Native/DbiStream.cpp index 06c34325a57..6ad0c25f0ad 100644 --- a/lib/DebugInfo/PDB/Native/DbiStream.cpp +++ b/lib/DebugInfo/PDB/Native/DbiStream.cpp @@ -236,7 +236,7 @@ Error DbiStream::initializeSectionContributionData() { return Error::success(); BinaryStreamReader SCReader(SecContrSubstream); - if (auto EC = SCReader.readEnum(SectionContribVersion, llvm::support::little)) + if (auto EC = SCReader.readEnum(SectionContribVersion)) return EC; if (SectionContribVersion == DbiSecContribVer60) diff --git a/lib/DebugInfo/PDB/Native/DbiStreamBuilder.cpp b/lib/DebugInfo/PDB/Native/DbiStreamBuilder.cpp index f8d44320889..2dbdceb6571 100644 --- a/lib/DebugInfo/PDB/Native/DbiStreamBuilder.cpp +++ b/lib/DebugInfo/PDB/Native/DbiStreamBuilder.cpp @@ -153,7 +153,8 @@ Error DbiStreamBuilder::generateModiSubstream() { uint32_t Size = calculateModiSubstreamSize(); auto Data = Allocator.Allocate(Size); - ModInfoBuffer = MutableBinaryByteStream(MutableArrayRef(Data, Size)); + ModInfoBuffer = MutableBinaryByteStream(MutableArrayRef(Data, Size), + llvm::support::little); BinaryStreamWriter ModiWriter(ModInfoBuffer); for (const auto &M : ModuleInfoList) { @@ -179,8 +180,8 @@ Error DbiStreamBuilder::generateFileInfoSubstream() { auto Data = Allocator.Allocate(Size); uint32_t NamesOffset = Size - NameSize; - FileInfoBuffer = - MutableBinaryByteStream(MutableArrayRef(Data, Size)); + FileInfoBuffer = MutableBinaryByteStream(MutableArrayRef(Data, Size), + llvm::support::little); WritableBinaryStreamRef MetadataBuffer = WritableBinaryStreamRef(FileInfoBuffer).keep_front(NamesOffset); @@ -188,21 +189,17 @@ Error DbiStreamBuilder::generateFileInfoSubstream() { uint16_t ModiCount = std::min(UINT16_MAX, ModuleInfos.size()); uint16_t FileCount = std::min(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(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; } @@ -224,8 +221,7 @@ Error DbiStreamBuilder::generateFileInfoSubstream() { if (Result == SourceFileNames.end()) return make_error(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; } } @@ -379,7 +375,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; @@ -398,16 +394,15 @@ 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) { if (Stream.StreamNumber == kInvalidStreamIndex) continue; - auto WritableBinaryStream = WritableMappedBlockStream::createIndexedStream( + auto WritableStream = WritableMappedBlockStream::createIndexedStream( Layout, Buffer, Stream.StreamNumber); - BinaryStreamWriter DbgStreamWriter(*WritableBinaryStream); + BinaryStreamWriter DbgStreamWriter(*WritableStream); if (auto EC = DbgStreamWriter.writeArray(Stream.Data)) return EC; } diff --git a/lib/DebugInfo/PDB/Native/HashTable.cpp b/lib/DebugInfo/PDB/Native/HashTable.cpp index 535799706c8..ebf8c9c04db 100644 --- a/lib/DebugInfo/PDB/Native/HashTable.cpp +++ b/lib/DebugInfo/PDB/Native/HashTable.cpp @@ -48,9 +48,9 @@ Error HashTable::load(BinaryStreamReader &Stream) { "Present bit vector interesects deleted!"); for (uint32_t P : Present) { - if (auto EC = Stream.readInteger(Buckets[P].first, llvm::support::little)) + if (auto EC = Stream.readInteger(Buckets[P].first)) return EC; - if (auto EC = Stream.readInteger(Buckets[P].second, llvm::support::little)) + if (auto EC = Stream.readInteger(Buckets[P].second)) return EC; } @@ -91,9 +91,9 @@ Error HashTable::commit(BinaryStreamWriter &Writer) const { return EC; for (const auto &Entry : *this) { - if (auto EC = Writer.writeInteger(Entry.first, llvm::support::little)) + if (auto EC = Writer.writeInteger(Entry.first)) return EC; - if (auto EC = Writer.writeInteger(Entry.second, llvm::support::little)) + if (auto EC = Writer.writeInteger(Entry.second)) return EC; } return Error::success(); @@ -212,7 +212,7 @@ void HashTable::grow() { Error HashTable::readSparseBitVector(BinaryStreamReader &Stream, SparseBitVector<> &V) { uint32_t NumWords; - if (auto EC = Stream.readInteger(NumWords, llvm::support::little)) + if (auto EC = Stream.readInteger(NumWords)) return joinErrors( std::move(EC), make_error(raw_error_code::corrupt_file, @@ -220,7 +220,7 @@ Error HashTable::readSparseBitVector(BinaryStreamReader &Stream, for (uint32_t I = 0; I != NumWords; ++I) { uint32_t Word; - if (auto EC = Stream.readInteger(Word, llvm::support::little)) + if (auto EC = Stream.readInteger(Word)) return joinErrors(std::move(EC), make_error(raw_error_code::corrupt_file, "Expected hash table word")); @@ -235,7 +235,7 @@ Error HashTable::writeSparseBitVector(BinaryStreamWriter &Writer, SparseBitVector<> &Vec) { int ReqBits = Vec.find_last() + 1; uint32_t NumWords = alignTo(ReqBits, sizeof(uint32_t)) / sizeof(uint32_t); - if (auto EC = Writer.writeInteger(NumWords, llvm::support::little)) + if (auto EC = Writer.writeInteger(NumWords)) return joinErrors( std::move(EC), make_error(raw_error_code::corrupt_file, @@ -248,7 +248,7 @@ Error HashTable::writeSparseBitVector(BinaryStreamWriter &Writer, if (Vec.test(Idx)) Word |= (1 << WordIdx); } - if (auto EC = Writer.writeInteger(Word, llvm::support::little)) + if (auto EC = Writer.writeInteger(Word)) return joinErrors(std::move(EC), make_error( raw_error_code::corrupt_file, "Could not write linear map word")); diff --git a/lib/DebugInfo/PDB/Native/ModStream.cpp b/lib/DebugInfo/PDB/Native/ModStream.cpp index 0c2d2c32c6e..df9ec818a1d 100644 --- a/lib/DebugInfo/PDB/Native/ModStream.cpp +++ b/lib/DebugInfo/PDB/Native/ModStream.cpp @@ -43,7 +43,7 @@ Error ModStream::reload() { BinaryStreamRef S; - if (auto EC = Reader.readInteger(Signature, llvm::support::little)) + if (auto EC = Reader.readInteger(Signature)) return EC; if (auto EC = Reader.readArray(SymbolsSubstream, SymbolSize - 4)) return EC; @@ -58,7 +58,7 @@ Error ModStream::reload() { return EC; uint32_t GlobalRefsSize; - if (auto EC = Reader.readInteger(GlobalRefsSize, llvm::support::little)) + if (auto EC = Reader.readInteger(GlobalRefsSize)) return EC; if (auto EC = Reader.readStreamRef(GlobalRefsSubstream, GlobalRefsSize)) return EC; diff --git a/lib/DebugInfo/PDB/Native/NamedStreamMap.cpp b/lib/DebugInfo/PDB/Native/NamedStreamMap.cpp index 91cbf4bca07..1fa9bc443ec 100644 --- a/lib/DebugInfo/PDB/Native/NamedStreamMap.cpp +++ b/lib/DebugInfo/PDB/Native/NamedStreamMap.cpp @@ -31,7 +31,7 @@ Error NamedStreamMap::load(BinaryStreamReader &Stream) { FinalizedInfo.reset(); uint32_t StringBufferSize; - if (auto EC = Stream.readInteger(StringBufferSize, llvm::support::little)) + if (auto EC = Stream.readInteger(StringBufferSize)) return joinErrors(std::move(EC), make_error(raw_error_code::corrupt_file, "Expected string buffer size")); @@ -70,8 +70,7 @@ Error NamedStreamMap::commit(BinaryStreamWriter &Writer) const { assert(FinalizedInfo.hasValue()); // The first field is the number of bytes of string data. - if (auto EC = Writer.writeInteger(FinalizedInfo->StringDataBytes, - llvm::support::little)) + if (auto EC = Writer.writeInteger(FinalizedInfo->StringDataBytes)) return EC; // Now all of the string data itself. diff --git a/lib/DebugInfo/PDB/Native/NativeSession.cpp b/lib/DebugInfo/PDB/Native/NativeSession.cpp index 4c858253b79..dff53344545 100644 --- a/lib/DebugInfo/PDB/Native/NativeSession.cpp +++ b/lib/DebugInfo/PDB/Native/NativeSession.cpp @@ -45,7 +45,8 @@ Error NativeSession::createFromPdb(StringRef Path, return make_error(generic_error_code::invalid_path); std::unique_ptr Buffer = std::move(*ErrorOrBuffer); - auto Stream = llvm::make_unique(std::move(Buffer)); + auto Stream = llvm::make_unique( + std::move(Buffer), llvm::support::little); auto Allocator = llvm::make_unique(); auto File = llvm::make_unique(Path, std::move(Stream), *Allocator); diff --git a/lib/DebugInfo/PDB/Native/PDBFile.cpp b/lib/DebugInfo/PDB/Native/PDBFile.cpp index a08ecd0487e..03257c40829 100644 --- a/lib/DebugInfo/PDB/Native/PDBFile.cpp +++ b/lib/DebugInfo/PDB/Native/PDBFile.cpp @@ -186,7 +186,7 @@ Error PDBFile::parseStreamData() { // been parsed, we can avoid this and reuse MappedBlockStream. auto DS = MappedBlockStream::createDirectoryStream(ContainerLayout, *Buffer); BinaryStreamReader Reader(*DS); - if (auto EC = Reader.readInteger(NumStreams, llvm::support::little)) + if (auto EC = Reader.readInteger(NumStreams)) return EC; if (auto EC = Reader.readArray(ContainerLayout.StreamSizes, NumStreams)) diff --git a/lib/DebugInfo/PDB/Native/PDBFileBuilder.cpp b/lib/DebugInfo/PDB/Native/PDBFileBuilder.cpp index 104867d169b..18c0cdf03b8 100644 --- a/lib/DebugInfo/PDB/Native/PDBFileBuilder.cpp +++ b/lib/DebugInfo/PDB/Native/PDBFileBuilder.cpp @@ -118,7 +118,8 @@ Error PDBFileBuilder::commit(StringRef Filename) { if (OutFileOrError.getError()) return llvm::make_error(generic_error_code::invalid_path, Filename); - FileBufferByteStream Buffer(std::move(*OutFileOrError)); + FileBufferByteStream Buffer(std::move(*OutFileOrError), + llvm::support::little); BinaryStreamWriter Writer(Buffer); if (auto EC = Writer.writeObject(*Layout.SB)) @@ -132,8 +133,7 @@ Error PDBFileBuilder::commit(StringRef Filename) { auto DirStream = WritableMappedBlockStream::createDirectoryStream(Layout, Buffer); BinaryStreamWriter DW(*DirStream); - if (auto EC = DW.writeInteger(Layout.StreamSizes.size(), - llvm::support::little)) + if (auto EC = DW.writeInteger(Layout.StreamSizes.size())) return EC; if (auto EC = DW.writeArray(Layout.StreamSizes)) diff --git a/lib/DebugInfo/PDB/Native/StringTable.cpp b/lib/DebugInfo/PDB/Native/StringTable.cpp index e2b9ea20812..79a78c92598 100644 --- a/lib/DebugInfo/PDB/Native/StringTable.cpp +++ b/lib/DebugInfo/PDB/Native/StringTable.cpp @@ -54,7 +54,7 @@ Error StringTable::load(BinaryStreamReader &Stream) { return make_error(raw_error_code::corrupt_file, "Missing name count"); - if (auto EC = Stream.readInteger(NameCount, llvm::support::little)) + if (auto EC = Stream.readInteger(NameCount)) return EC; return Error::success(); } diff --git a/lib/DebugInfo/PDB/Native/StringTableBuilder.cpp b/lib/DebugInfo/PDB/Native/StringTableBuilder.cpp index 5432fe4b99e..9df97c9753e 100644 --- a/lib/DebugInfo/PDB/Native/StringTableBuilder.cpp +++ b/lib/DebugInfo/PDB/Native/StringTableBuilder.cpp @@ -74,7 +74,7 @@ Error StringTableBuilder::commit(BinaryStreamWriter &Writer) const { // Write a hash table. uint32_t BucketCount = computeBucketCount(Strings.size()); - if (auto EC = Writer.writeInteger(BucketCount, llvm::support::little)) + if (auto EC = Writer.writeInteger(BucketCount)) return EC; std::vector Buckets(BucketCount); @@ -96,8 +96,7 @@ Error StringTableBuilder::commit(BinaryStreamWriter &Writer) const { if (auto EC = Writer.writeArray(ArrayRef(Buckets))) return EC; - if (auto EC = Writer.writeInteger(static_cast(Strings.size()), - llvm::support::little)) + if (auto EC = Writer.writeInteger(static_cast(Strings.size()))) return EC; return Error::success(); } diff --git a/lib/DebugInfo/PDB/Native/SymbolStream.cpp b/lib/DebugInfo/PDB/Native/SymbolStream.cpp index 2d351b05b0b..d38edcb88b8 100644 --- a/lib/DebugInfo/PDB/Native/SymbolStream.cpp +++ b/lib/DebugInfo/PDB/Native/SymbolStream.cpp @@ -16,7 +16,6 @@ #include "llvm/DebugInfo/PDB/Native/PDBFile.h" #include "llvm/DebugInfo/PDB/Native/RawConstants.h" #include "llvm/DebugInfo/PDB/Native/RawError.h" - #include "llvm/Support/Endian.h" using namespace llvm; diff --git a/lib/DebugInfo/PDB/Native/TpiStreamBuilder.cpp b/lib/DebugInfo/PDB/Native/TpiStreamBuilder.cpp index 49412b1f95a..7d532ee56d8 100644 --- a/lib/DebugInfo/PDB/Native/TpiStreamBuilder.cpp +++ b/lib/DebugInfo/PDB/Native/TpiStreamBuilder.cpp @@ -34,7 +34,8 @@ using namespace llvm::pdb; using namespace llvm::support; TpiStreamBuilder::TpiStreamBuilder(MSFBuilder &Msf, uint32_t StreamIdx) - : Msf(Msf), Allocator(Msf.getAllocator()), Header(nullptr), Idx(StreamIdx) { + : Msf(Msf), Allocator(Msf.getAllocator()), + TypeRecordStream(llvm::support::little), Header(nullptr), Idx(StreamIdx) { } TpiStreamBuilder::~TpiStreamBuilder() = default; @@ -113,7 +114,8 @@ Error TpiStreamBuilder::finalizeMsfLayout() { } ArrayRef Bytes(reinterpret_cast(HashBuffer.data()), HashBufferSize); - HashValueStream = llvm::make_unique(Bytes); + HashValueStream = + llvm::make_unique(Bytes, llvm::support::little); return Error::success(); } diff --git a/tools/llvm-pdbdump/YamlTypeDumper.cpp b/tools/llvm-pdbdump/YamlTypeDumper.cpp index 50a488620ab..e2b901be868 100644 --- a/tools/llvm-pdbdump/YamlTypeDumper.cpp +++ b/tools/llvm-pdbdump/YamlTypeDumper.cpp @@ -573,7 +573,7 @@ struct MappingContextTraits Bytes(reinterpret_cast(Data.data()), Data.size()); - BinaryByteStream Stream(Bytes); + BinaryByteStream Stream(Bytes, llvm::support::little); CVTypeArray Types; BinaryStreamReader Reader(Stream); if (auto EC = Reader.readArray(Types, Reader.getLength())) { diff --git a/unittests/DebugInfo/PDB/HashTableTest.cpp b/unittests/DebugInfo/PDB/HashTableTest.cpp index 1e85257e713..fae7d375e17 100644 --- a/unittests/DebugInfo/PDB/HashTableTest.cpp +++ b/unittests/DebugInfo/PDB/HashTableTest.cpp @@ -19,6 +19,7 @@ using namespace llvm; using namespace llvm::pdb; +using namespace llvm::support; namespace { class HashTableInternals : public HashTable { @@ -147,7 +148,7 @@ TEST(HashTableTest, Serialization) { } std::vector Buffer(Table.calculateSerializedLength()); - MutableBinaryByteStream Stream(Buffer); + MutableBinaryByteStream Stream(Buffer, little); BinaryStreamWriter Writer(Stream); EXPECT_NO_ERROR(Table.commit(Writer)); // We should have written precisely the number of bytes we calculated earlier. diff --git a/unittests/DebugInfo/PDB/MappedBlockStreamTest.cpp b/unittests/DebugInfo/PDB/MappedBlockStreamTest.cpp index 20f5c412d88..42f38a2e2e4 100644 --- a/unittests/DebugInfo/PDB/MappedBlockStreamTest.cpp +++ b/unittests/DebugInfo/PDB/MappedBlockStreamTest.cpp @@ -23,6 +23,7 @@ using namespace llvm; using namespace llvm::msf; +using namespace llvm::support; namespace { @@ -37,6 +38,8 @@ public: uint32_t block_size() const { return 1; } uint32_t block_count() const { return Blocks.size(); } + endianness getEndian() const override { return little; } + Error readBytes(uint32_t Offset, uint32_t Size, ArrayRef &Buffer) override { if (Offset + Size > Data.size()) @@ -326,8 +329,8 @@ TEST(MappedBlockStreamTest, TestWriteThenRead) { BinaryStreamReader Reader(*S); BinaryStreamWriter Writer(*S); - EXPECT_NO_ERROR(Writer.writeInteger(u16[0], llvm::support::little)); - EXPECT_NO_ERROR(Reader.readInteger(u16[1], llvm::support::little)); + EXPECT_NO_ERROR(Writer.writeInteger(u16[0])); + EXPECT_NO_ERROR(Reader.readInteger(u16[1])); EXPECT_EQ(u16[0], u16[1]); EXPECT_EQ(std::vector({0, 0x7A, 0xEC, 0, 0, 0, 0, 0, 0, 0}), DataBytes); @@ -335,8 +338,8 @@ TEST(MappedBlockStreamTest, TestWriteThenRead) { Reader.setOffset(0); Writer.setOffset(0); ::memset(DataBytes.data(), 0, 10); - EXPECT_NO_ERROR(Writer.writeInteger(u32[0], llvm::support::little)); - EXPECT_NO_ERROR(Reader.readInteger(u32[1], llvm::support::little)); + EXPECT_NO_ERROR(Writer.writeInteger(u32[0])); + EXPECT_NO_ERROR(Reader.readInteger(u32[1])); EXPECT_EQ(u32[0], u32[1]); EXPECT_EQ(std::vector({0x17, 0x5C, 0x50, 0, 0, 0, 0x35, 0, 0, 0}), DataBytes); @@ -344,8 +347,8 @@ TEST(MappedBlockStreamTest, TestWriteThenRead) { Reader.setOffset(0); Writer.setOffset(0); ::memset(DataBytes.data(), 0, 10); - EXPECT_NO_ERROR(Writer.writeEnum(Enum[0], llvm::support::little)); - EXPECT_NO_ERROR(Reader.readEnum(Enum[1], llvm::support::little)); + EXPECT_NO_ERROR(Writer.writeEnum(Enum[0])); + EXPECT_NO_ERROR(Reader.readEnum(Enum[1])); EXPECT_EQ(Enum[0], Enum[1]); EXPECT_EQ(std::vector({0x2C, 0x60, 0x4A, 0, 0, 0, 0, 0, 0, 0}), DataBytes); @@ -400,7 +403,7 @@ TEST(MappedBlockStreamTest, TestWriteContiguousStreamRef) { F.block_size(), F.block_count(), F.layout(), F); // First write "Test Str" into the source stream. - MutableBinaryByteStream SourceStream(SrcData); + MutableBinaryByteStream SourceStream(SrcData, little); BinaryStreamWriter SourceWriter(SourceStream); EXPECT_NO_ERROR(SourceWriter.writeCString("Test Str")); EXPECT_EQ(SrcDataBytes, std::vector( diff --git a/unittests/DebugInfo/PDB/StringTableBuilderTest.cpp b/unittests/DebugInfo/PDB/StringTableBuilderTest.cpp index bc5420038e6..aecffbe9b01 100644 --- a/unittests/DebugInfo/PDB/StringTableBuilderTest.cpp +++ b/unittests/DebugInfo/PDB/StringTableBuilderTest.cpp @@ -19,6 +19,7 @@ using namespace llvm; using namespace llvm::pdb; +using namespace llvm::support; namespace { class StringTableBuilderTest : public ::testing::Test {}; @@ -33,12 +34,12 @@ TEST_F(StringTableBuilderTest, Simple) { EXPECT_EQ(9U, Builder.insert("baz")); std::vector Buffer(Builder.finalize()); - MutableBinaryByteStream OutStream(Buffer); + MutableBinaryByteStream OutStream(Buffer, little); BinaryStreamWriter Writer(OutStream); EXPECT_NO_ERROR(Builder.commit(Writer)); // Reads the contents back. - BinaryByteStream InStream(Buffer); + BinaryByteStream InStream(Buffer, little); BinaryStreamReader Reader(InStream); StringTable Table; EXPECT_NO_ERROR(Table.load(Reader));