mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 20:51:52 +01:00
[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. llvm-svn: 296415
This commit is contained in:
parent
7c39ec2ebd
commit
cd226b0757
@ -59,9 +59,9 @@ public:
|
||||
|
||||
template <typename T> 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 <typename T> Error mapEnum(T &Value) {
|
||||
@ -93,7 +93,7 @@ public:
|
||||
SizeType Size;
|
||||
if (isWriting()) {
|
||||
Size = static_cast<SizeType>(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;
|
||||
|
@ -25,7 +25,8 @@ class SymbolVisitorDelegate;
|
||||
class SymbolDeserializer : public SymbolVisitorCallbacks {
|
||||
struct MappingInfo {
|
||||
explicit MappingInfo(ArrayRef<uint8_t> RecordData)
|
||||
: Stream(RecordData), Reader(Stream), Mapping(Reader) {}
|
||||
: Stream(RecordData, llvm::support::little), Reader(Stream),
|
||||
Mapping(Reader) {}
|
||||
|
||||
BinaryByteStream Stream;
|
||||
BinaryStreamReader Reader;
|
||||
|
@ -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 {
|
||||
|
@ -29,7 +29,8 @@ namespace codeview {
|
||||
class TypeDeserializer : public TypeVisitorCallbacks {
|
||||
struct MappingInfo {
|
||||
explicit MappingInfo(ArrayRef<uint8_t> RecordData)
|
||||
: Stream(RecordData), Reader(Stream), Mapping(Reader) {}
|
||||
: Stream(RecordData, llvm::support::little), Reader(Stream),
|
||||
Mapping(Reader) {}
|
||||
|
||||
BinaryByteStream Stream;
|
||||
BinaryStreamReader Reader;
|
||||
|
@ -109,7 +109,7 @@ private:
|
||||
Error visitKnownMemberImpl(CVMemberRecord &CVR, RecordType &Record) {
|
||||
assert(CVR.Kind == static_cast<TypeLeafKind>(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))
|
||||
|
@ -32,9 +32,12 @@ namespace llvm {
|
||||
class BinaryByteStream : public BinaryStream {
|
||||
public:
|
||||
BinaryByteStream() = default;
|
||||
BinaryByteStream(ArrayRef<uint8_t> Data) : Data(Data) {}
|
||||
BinaryByteStream(StringRef Data)
|
||||
: Data(Data.bytes_begin(), Data.bytes_end()) {}
|
||||
BinaryByteStream(ArrayRef<uint8_t> 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<uint8_t> &Buffer) override {
|
||||
@ -67,6 +70,7 @@ public:
|
||||
}
|
||||
|
||||
protected:
|
||||
llvm::support::endianness Endian;
|
||||
ArrayRef<uint8_t> Data;
|
||||
};
|
||||
|
||||
@ -76,8 +80,10 @@ protected:
|
||||
/// will never cause a copy.
|
||||
class MemoryBufferByteStream : public BinaryByteStream {
|
||||
public:
|
||||
explicit MemoryBufferByteStream(std::unique_ptr<MemoryBuffer> Buffer)
|
||||
: BinaryByteStream(Buffer->getBuffer()), MemBuffer(std::move(Buffer)) {}
|
||||
MemoryBufferByteStream(std::unique_ptr<MemoryBuffer> Buffer,
|
||||
llvm::support::endianness Endian)
|
||||
: BinaryByteStream(Buffer->getBuffer(), Endian),
|
||||
MemBuffer(std::move(Buffer)) {}
|
||||
|
||||
std::unique_ptr<MemoryBuffer> MemBuffer;
|
||||
};
|
||||
@ -89,8 +95,13 @@ public:
|
||||
class MutableBinaryByteStream : public WritableBinaryStream {
|
||||
public:
|
||||
MutableBinaryByteStream() = default;
|
||||
MutableBinaryByteStream(MutableArrayRef<uint8_t> Data)
|
||||
: Data(Data), ImmutableStream(Data) {}
|
||||
MutableBinaryByteStream(MutableArrayRef<uint8_t> 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<uint8_t> &Buffer) override {
|
||||
@ -135,9 +146,12 @@ class FileBufferByteStream : public WritableBinaryStream {
|
||||
private:
|
||||
class StreamImpl : public MutableBinaryByteStream {
|
||||
public:
|
||||
StreamImpl(std::unique_ptr<FileOutputBuffer> Buffer)
|
||||
: MutableBinaryByteStream(MutableArrayRef<uint8_t>(
|
||||
Buffer->getBufferStart(), Buffer->getBufferEnd())),
|
||||
StreamImpl(std::unique_ptr<FileOutputBuffer> Buffer,
|
||||
llvm::support::endianness Endian)
|
||||
: MutableBinaryByteStream(
|
||||
MutableArrayRef<uint8_t>(Buffer->getBufferStart(),
|
||||
Buffer->getBufferEnd()),
|
||||
Endian),
|
||||
FileBuffer(std::move(Buffer)) {}
|
||||
|
||||
Error commit() override {
|
||||
@ -152,8 +166,13 @@ private:
|
||||
};
|
||||
|
||||
public:
|
||||
explicit FileBufferByteStream(std::unique_ptr<FileOutputBuffer> Buffer)
|
||||
: Impl(std::move(Buffer)) {}
|
||||
FileBufferByteStream(std::unique_ptr<FileOutputBuffer> 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<uint8_t> &Buffer) override {
|
||||
@ -179,4 +198,4 @@ private:
|
||||
|
||||
} // end namespace llvm
|
||||
|
||||
#endif // LLVM_DEBUGINFO_MSF_BINARYBYTESTREAM_H
|
||||
#endif // LLVM_DEBUGINFO_MSF_BYTESTREAM_H
|
||||
|
@ -34,7 +34,10 @@ template <typename T> struct BinaryItemTraits {
|
||||
template <typename T, typename Traits = BinaryItemTraits<T>>
|
||||
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<uint8_t> &Buffer) override {
|
||||
@ -83,6 +86,7 @@ private:
|
||||
return CurrentIndex;
|
||||
}
|
||||
|
||||
llvm::support::endianness Endian;
|
||||
ArrayRef<T> Items;
|
||||
};
|
||||
|
||||
|
@ -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.
|
||||
|
@ -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 <typename T>
|
||||
Error readInteger(T &Dest, llvm::support::endianness Endian) {
|
||||
template <typename T> Error readInteger(T &Dest) {
|
||||
static_assert(std::is_integral<T>::value,
|
||||
"Cannot call readInteger with non-integral value!");
|
||||
|
||||
@ -68,17 +67,16 @@ public:
|
||||
return EC;
|
||||
|
||||
Dest = llvm::support::endian::read<T, llvm::support::unaligned>(
|
||||
Bytes.data(), Endian);
|
||||
Bytes.data(), Stream.getEndian());
|
||||
return Error::success();
|
||||
}
|
||||
|
||||
/// Similar to readInteger.
|
||||
template <typename T>
|
||||
Error readEnum(T &Dest, llvm::support::endianness Endian) {
|
||||
template <typename T> Error readEnum(T &Dest) {
|
||||
static_assert(std::is_enum<T>::value,
|
||||
"Cannot call readEnum with non-enum value!");
|
||||
typename std::underlying_type<T>::type N;
|
||||
if (auto EC = readInteger(N, Endian))
|
||||
if (auto EC = readInteger(N))
|
||||
return EC;
|
||||
Dest = static_cast<T>(N);
|
||||
return Error::success();
|
||||
|
@ -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; }
|
||||
|
||||
|
@ -47,24 +47,22 @@ public:
|
||||
///
|
||||
/// \returns a success error code if the data was successfully written,
|
||||
/// otherwise returns an appropriate error code.
|
||||
template <typename T>
|
||||
Error writeInteger(T Value, llvm::support::endianness Endian) {
|
||||
template <typename T> Error writeInteger(T Value) {
|
||||
static_assert(std::is_integral<T>::value,
|
||||
"Cannot call writeInteger with non-integral value!");
|
||||
uint8_t Buffer[sizeof(T)];
|
||||
llvm::support::endian::write<T, llvm::support::unaligned>(Buffer, Value,
|
||||
Endian);
|
||||
llvm::support::endian::write<T, llvm::support::unaligned>(
|
||||
Buffer, Value, Stream.getEndian());
|
||||
return writeBytes(Buffer);
|
||||
}
|
||||
|
||||
/// Similar to writeInteger
|
||||
template <typename T>
|
||||
Error writeEnum(T Num, llvm::support::endianness Endian) {
|
||||
template <typename T> Error writeEnum(T Num) {
|
||||
static_assert(std::is_enum<T>::value,
|
||||
"Cannot call writeEnum with non-Enum type");
|
||||
|
||||
using U = typename std::underlying_type<T>::type;
|
||||
return writeInteger<U>(static_cast<U>(Num), Endian);
|
||||
return writeInteger<U>(static_cast<U>(Num));
|
||||
}
|
||||
|
||||
/// Write the the string \p Str to the underlying stream followed by a null
|
||||
|
@ -56,6 +56,10 @@ public:
|
||||
static std::unique_ptr<MappedBlockStream>
|
||||
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<uint8_t> &Buffer) override;
|
||||
Error readLongestContiguousChunk(uint32_t Offset,
|
||||
@ -113,6 +117,10 @@ public:
|
||||
static std::unique_ptr<WritableMappedBlockStream>
|
||||
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<uint8_t> &Buffer) override;
|
||||
Error readLongestContiguousChunk(uint32_t Offset,
|
||||
|
@ -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"
|
||||
|
@ -19,7 +19,7 @@
|
||||
#include "llvm/DebugInfo/PDB/PDBTypes.h"
|
||||
|
||||
namespace llvm {
|
||||
class BinaryStreamWriter;
|
||||
class WritableBinaryStreamRef;
|
||||
|
||||
namespace msf {
|
||||
class MSFBuilder;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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<llvm::codeview::CVType> {
|
||||
static size_t length(const codeview::CVType &Item) { return Item.length(); }
|
||||
@ -36,6 +32,9 @@ template <> struct BinaryItemTraits<llvm::codeview::CVType> {
|
||||
}
|
||||
};
|
||||
|
||||
namespace codeview {
|
||||
class TypeRecord;
|
||||
}
|
||||
namespace msf {
|
||||
class MSFBuilder;
|
||||
struct MSFLayout;
|
||||
|
@ -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());
|
||||
|
@ -56,7 +56,7 @@ Error CVTypeDumper::dump(const CVTypeArray &Types,
|
||||
}
|
||||
|
||||
Error CVTypeDumper::dump(ArrayRef<uint8_t> 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()))
|
||||
|
@ -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<uint8_t> Data) {
|
||||
BinaryByteStream S(Data);
|
||||
BinaryByteStream S(Data, llvm::support::little);
|
||||
BinaryStreamReader SR(S);
|
||||
return visitFieldListMemberStream(SR);
|
||||
}
|
||||
|
@ -87,14 +87,13 @@ Error CodeViewRecordIO::mapByteVectorTail(std::vector<uint8_t> &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<StringRef> &Value) {
|
||||
if (auto EC = mapStringZ(V))
|
||||
return EC;
|
||||
}
|
||||
if (auto EC = Writer->writeInteger<uint8_t>(0, llvm::support::little))
|
||||
if (auto EC = Writer->writeInteger<uint8_t>(0))
|
||||
return EC;
|
||||
} else {
|
||||
StringRef S;
|
||||
@ -195,28 +194,24 @@ Error CodeViewRecordIO::mapStringZVectorZ(std::vector<StringRef> &Value) {
|
||||
Error CodeViewRecordIO::writeEncodedSignedInteger(const int64_t &Value) {
|
||||
assert(Value < 0 && "Encoded integer is not signed!");
|
||||
if (Value >= std::numeric_limits<int8_t>::min()) {
|
||||
if (auto EC =
|
||||
Writer->writeInteger<uint16_t>(LF_CHAR, llvm::support::little))
|
||||
if (auto EC = Writer->writeInteger<uint16_t>(LF_CHAR))
|
||||
return EC;
|
||||
if (auto EC = Writer->writeInteger<int8_t>(Value, llvm::support::little))
|
||||
if (auto EC = Writer->writeInteger<int8_t>(Value))
|
||||
return EC;
|
||||
} else if (Value >= std::numeric_limits<int16_t>::min()) {
|
||||
if (auto EC =
|
||||
Writer->writeInteger<uint16_t>(LF_SHORT, llvm::support::little))
|
||||
if (auto EC = Writer->writeInteger<uint16_t>(LF_SHORT))
|
||||
return EC;
|
||||
if (auto EC = Writer->writeInteger<int16_t>(Value, llvm::support::little))
|
||||
if (auto EC = Writer->writeInteger<int16_t>(Value))
|
||||
return EC;
|
||||
} else if (Value >= std::numeric_limits<int32_t>::min()) {
|
||||
if (auto EC =
|
||||
Writer->writeInteger<uint16_t>(LF_LONG, llvm::support::little))
|
||||
if (auto EC = Writer->writeInteger<uint16_t>(LF_LONG))
|
||||
return EC;
|
||||
if (auto EC = Writer->writeInteger<int32_t>(Value, llvm::support::little))
|
||||
if (auto EC = Writer->writeInteger<int32_t>(Value))
|
||||
return EC;
|
||||
} else {
|
||||
if (auto EC =
|
||||
Writer->writeInteger<uint16_t>(LF_QUADWORD, llvm::support::little))
|
||||
if (auto EC = Writer->writeInteger<uint16_t>(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<uint16_t>(Value, llvm::support::little))
|
||||
if (auto EC = Writer->writeInteger<uint16_t>(Value))
|
||||
return EC;
|
||||
} else if (Value <= std::numeric_limits<uint16_t>::max()) {
|
||||
if (auto EC =
|
||||
Writer->writeInteger<uint16_t>(LF_USHORT, llvm::support::little))
|
||||
if (auto EC = Writer->writeInteger<uint16_t>(LF_USHORT))
|
||||
return EC;
|
||||
if (auto EC = Writer->writeInteger<uint16_t>(Value, llvm::support::little))
|
||||
if (auto EC = Writer->writeInteger<uint16_t>(Value))
|
||||
return EC;
|
||||
} else if (Value <= std::numeric_limits<uint32_t>::max()) {
|
||||
if (auto EC =
|
||||
Writer->writeInteger<uint16_t>(LF_ULONG, llvm::support::little))
|
||||
if (auto EC = Writer->writeInteger<uint16_t>(LF_ULONG))
|
||||
return EC;
|
||||
if (auto EC = Writer->writeInteger<uint32_t>(Value, llvm::support::little))
|
||||
if (auto EC = Writer->writeInteger<uint32_t>(Value))
|
||||
return EC;
|
||||
} else {
|
||||
if (auto EC =
|
||||
Writer->writeInteger<uint16_t>(LF_UQUADWORD, llvm::support::little))
|
||||
if (auto EC = Writer->writeInteger<uint16_t>(LF_UQUADWORD))
|
||||
return EC;
|
||||
if (auto EC = Writer->writeInteger(Value, llvm::support::little))
|
||||
if (auto EC = Writer->writeInteger(Value))
|
||||
return EC;
|
||||
}
|
||||
|
||||
|
@ -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<uint8_t> 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<uint8_t> 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) {
|
||||
|
@ -76,7 +76,7 @@ TypeSerializer::addPadding(MutableArrayRef<uint8_t> Record) {
|
||||
int N = PaddingBytes;
|
||||
while (PaddingBytes > 0) {
|
||||
uint8_t Pad = static_cast<uint8_t>(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<uint8_t> 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<uint8_t>(LengthWithSize);
|
||||
auto SavedSegment = MutableArrayRef<uint8_t>(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<uint16_t>(0, llvm::support::little))
|
||||
if (auto EC = CW.writeInteger<uint16_t>(0))
|
||||
return EC;
|
||||
if (auto EC = CW.writeInteger<uint32_t>(0xB0C0B0C0, llvm::support::little))
|
||||
if (auto EC = CW.writeInteger<uint32_t>(0xB0C0B0C0))
|
||||
return EC;
|
||||
FieldListSegments.push_back(SavedSegment);
|
||||
|
||||
|
@ -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)
|
||||
|
@ -153,7 +153,8 @@ Error DbiStreamBuilder::generateModiSubstream() {
|
||||
uint32_t Size = calculateModiSubstreamSize();
|
||||
auto Data = Allocator.Allocate<uint8_t>(Size);
|
||||
|
||||
ModInfoBuffer = MutableBinaryByteStream(MutableArrayRef<uint8_t>(Data, Size));
|
||||
ModInfoBuffer = MutableBinaryByteStream(MutableArrayRef<uint8_t>(Data, Size),
|
||||
llvm::support::little);
|
||||
|
||||
BinaryStreamWriter ModiWriter(ModInfoBuffer);
|
||||
for (const auto &M : ModuleInfoList) {
|
||||
@ -179,8 +180,8 @@ Error DbiStreamBuilder::generateFileInfoSubstream() {
|
||||
auto Data = Allocator.Allocate<uint8_t>(Size);
|
||||
uint32_t NamesOffset = Size - NameSize;
|
||||
|
||||
FileInfoBuffer =
|
||||
MutableBinaryByteStream(MutableArrayRef<uint8_t>(Data, Size));
|
||||
FileInfoBuffer = MutableBinaryByteStream(MutableArrayRef<uint8_t>(Data, Size),
|
||||
llvm::support::little);
|
||||
|
||||
WritableBinaryStreamRef MetadataBuffer =
|
||||
WritableBinaryStreamRef(FileInfoBuffer).keep_front(NamesOffset);
|
||||
@ -188,21 +189,17 @@ Error DbiStreamBuilder::generateFileInfoSubstream() {
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@ -224,8 +221,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;
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
|
@ -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<RawError>(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<RawError>(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<RawError>(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<RawError>(
|
||||
raw_error_code::corrupt_file,
|
||||
"Could not write linear map word"));
|
||||
|
@ -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;
|
||||
|
@ -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<RawError>(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.
|
||||
|
@ -45,7 +45,8 @@ Error NativeSession::createFromPdb(StringRef Path,
|
||||
return make_error<GenericError>(generic_error_code::invalid_path);
|
||||
|
||||
std::unique_ptr<MemoryBuffer> Buffer = std::move(*ErrorOrBuffer);
|
||||
auto Stream = llvm::make_unique<MemoryBufferByteStream>(std::move(Buffer));
|
||||
auto Stream = llvm::make_unique<MemoryBufferByteStream>(
|
||||
std::move(Buffer), llvm::support::little);
|
||||
|
||||
auto Allocator = llvm::make_unique<BumpPtrAllocator>();
|
||||
auto File = llvm::make_unique<PDBFile>(Path, std::move(Stream), *Allocator);
|
||||
|
@ -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))
|
||||
|
@ -118,7 +118,8 @@ Error PDBFileBuilder::commit(StringRef Filename) {
|
||||
if (OutFileOrError.getError())
|
||||
return llvm::make_error<pdb::GenericError>(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<uint32_t>(Layout.StreamSizes.size(),
|
||||
llvm::support::little))
|
||||
if (auto EC = DW.writeInteger<uint32_t>(Layout.StreamSizes.size()))
|
||||
return EC;
|
||||
|
||||
if (auto EC = DW.writeArray(Layout.StreamSizes))
|
||||
|
@ -54,7 +54,7 @@ Error StringTable::load(BinaryStreamReader &Stream) {
|
||||
return make_error<RawError>(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();
|
||||
}
|
||||
|
@ -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<ulittle32_t> Buckets(BucketCount);
|
||||
|
||||
@ -96,8 +96,7 @@ Error StringTableBuilder::commit(BinaryStreamWriter &Writer) const {
|
||||
|
||||
if (auto EC = Writer.writeArray(ArrayRef<ulittle32_t>(Buckets)))
|
||||
return EC;
|
||||
if (auto EC = Writer.writeInteger(static_cast<uint32_t>(Strings.size()),
|
||||
llvm::support::little))
|
||||
if (auto EC = Writer.writeInteger(static_cast<uint32_t>(Strings.size())))
|
||||
return EC;
|
||||
return Error::success();
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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<uint8_t> Bytes(reinterpret_cast<const uint8_t *>(HashBuffer.data()),
|
||||
HashBufferSize);
|
||||
HashValueStream = llvm::make_unique<BinaryByteStream>(Bytes);
|
||||
HashValueStream =
|
||||
llvm::make_unique<BinaryByteStream>(Bytes, llvm::support::little);
|
||||
return Error::success();
|
||||
}
|
||||
|
||||
|
@ -573,7 +573,7 @@ struct MappingContextTraits<pdb::yaml::PdbTpiFieldListRecord,
|
||||
assert(IO.outputting());
|
||||
codeview::TypeVisitorCallbackPipeline Pipeline;
|
||||
|
||||
BinaryByteStream Data(Obj.Record.Data);
|
||||
BinaryByteStream Data(Obj.Record.Data, llvm::support::little);
|
||||
BinaryStreamReader FieldReader(Data);
|
||||
codeview::FieldListDeserializer Deserializer(FieldReader);
|
||||
|
||||
|
@ -840,7 +840,7 @@ void COFFDumper::printCodeViewSymbolSection(StringRef SectionName,
|
||||
}
|
||||
case ModuleSubstreamKind::FrameData: {
|
||||
// First four bytes is a relocation against the function.
|
||||
BinaryByteStream S(Contents);
|
||||
BinaryByteStream S(Contents, llvm::support::little);
|
||||
BinaryStreamReader SR(S);
|
||||
const uint32_t *CodePtr;
|
||||
error(SR.readObject(CodePtr));
|
||||
@ -965,7 +965,7 @@ void COFFDumper::printCodeViewSymbolsSubsection(StringRef Subsection,
|
||||
|
||||
CVSymbolDumper CVSD(W, TypeDB, std::move(CODD),
|
||||
opts::CodeViewSubsectionBytes);
|
||||
BinaryByteStream Stream(BinaryData);
|
||||
BinaryByteStream Stream(BinaryData, llvm::support::little);
|
||||
CVSymbolArray Symbols;
|
||||
BinaryStreamReader Reader(Stream);
|
||||
if (auto EC = Reader.readArray(Symbols, Reader.getLength())) {
|
||||
@ -982,7 +982,7 @@ void COFFDumper::printCodeViewSymbolsSubsection(StringRef Subsection,
|
||||
}
|
||||
|
||||
void COFFDumper::printCodeViewFileChecksums(StringRef Subsection) {
|
||||
BinaryByteStream S(Subsection);
|
||||
BinaryByteStream S(Subsection, llvm::support::little);
|
||||
BinaryStreamReader SR(S);
|
||||
while (!SR.empty()) {
|
||||
DictScope S(W, "FileChecksum");
|
||||
@ -1011,10 +1011,10 @@ void COFFDumper::printCodeViewFileChecksums(StringRef Subsection) {
|
||||
}
|
||||
|
||||
void COFFDumper::printCodeViewInlineeLines(StringRef Subsection) {
|
||||
BinaryByteStream S(Subsection);
|
||||
BinaryByteStream S(Subsection, llvm::support::little);
|
||||
BinaryStreamReader SR(S);
|
||||
uint32_t Signature;
|
||||
error(SR.readInteger(Signature, llvm::support::little));
|
||||
error(SR.readInteger(Signature));
|
||||
bool HasExtraFiles = Signature == unsigned(InlineeLinesSignature::ExtraFiles);
|
||||
|
||||
while (!SR.empty()) {
|
||||
@ -1027,12 +1027,12 @@ void COFFDumper::printCodeViewInlineeLines(StringRef Subsection) {
|
||||
|
||||
if (HasExtraFiles) {
|
||||
uint32_t ExtraFileCount;
|
||||
error(SR.readInteger(ExtraFileCount, llvm::support::little));
|
||||
error(SR.readInteger(ExtraFileCount));
|
||||
W.printNumber("ExtraFileCount", ExtraFileCount);
|
||||
ListScope ExtraFiles(W, "ExtraFiles");
|
||||
for (unsigned I = 0; I < ExtraFileCount; ++I) {
|
||||
uint32_t FileID;
|
||||
error(SR.readInteger(FileID, llvm::support::little));
|
||||
error(SR.readInteger(FileID));
|
||||
printFileNameForOffset("FileID", FileID);
|
||||
}
|
||||
}
|
||||
@ -1077,7 +1077,7 @@ void COFFDumper::mergeCodeViewTypes(TypeTableBuilder &CVTypes) {
|
||||
error(object_error::parse_failed);
|
||||
ArrayRef<uint8_t> Bytes(reinterpret_cast<const uint8_t *>(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())) {
|
||||
|
@ -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<uint8_t> 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.
|
||||
|
@ -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<uint8_t> &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<uint8_t>({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<uint8_t>({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<uint8_t>({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<uint8_t>(
|
||||
|
@ -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<uint8_t> 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));
|
||||
|
Loading…
x
Reference in New Issue
Block a user