[llvm] r295525 - Don't assume little endian in StreamReader / StreamWriter.
Zachary Turner via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 17 17:35:34 PST 2017
Author: zturner
Date: Fri Feb 17 19:35:33 2017
New Revision: 295525
URL: http://llvm.org/viewvc/llvm-project?rev=295525&view=rev
Log:
Don't assume little endian in StreamReader / StreamWriter.
In an effort to generalize this so it can be used by more than
just PDB code, we shouldn't assume little endian.
Modified:
llvm/trunk/include/llvm/DebugInfo/CodeView/CodeViewRecordIO.h
llvm/trunk/include/llvm/DebugInfo/CodeView/TypeSerializer.h
llvm/trunk/include/llvm/DebugInfo/MSF/StreamReader.h
llvm/trunk/include/llvm/DebugInfo/MSF/StreamWriter.h
llvm/trunk/lib/DebugInfo/CodeView/CVTypeVisitor.cpp
llvm/trunk/lib/DebugInfo/CodeView/CodeViewRecordIO.cpp
llvm/trunk/lib/DebugInfo/CodeView/RecordSerialization.cpp
llvm/trunk/lib/DebugInfo/CodeView/TypeSerializer.cpp
llvm/trunk/lib/DebugInfo/MSF/StreamReader.cpp
llvm/trunk/lib/DebugInfo/MSF/StreamWriter.cpp
llvm/trunk/lib/DebugInfo/PDB/Native/DbiStream.cpp
llvm/trunk/lib/DebugInfo/PDB/Native/DbiStreamBuilder.cpp
llvm/trunk/lib/DebugInfo/PDB/Native/HashTable.cpp
llvm/trunk/lib/DebugInfo/PDB/Native/ModStream.cpp
llvm/trunk/lib/DebugInfo/PDB/Native/NamedStreamMap.cpp
llvm/trunk/lib/DebugInfo/PDB/Native/PDBFile.cpp
llvm/trunk/lib/DebugInfo/PDB/Native/PDBFileBuilder.cpp
llvm/trunk/lib/DebugInfo/PDB/Native/StringTable.cpp
llvm/trunk/lib/DebugInfo/PDB/Native/StringTableBuilder.cpp
llvm/trunk/tools/llvm-readobj/COFFDumper.cpp
llvm/trunk/unittests/DebugInfo/PDB/MappedBlockStreamTest.cpp
Modified: llvm/trunk/include/llvm/DebugInfo/CodeView/CodeViewRecordIO.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/CodeView/CodeViewRecordIO.h?rev=295525&r1=295524&r2=295525&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/CodeView/CodeViewRecordIO.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/CodeView/CodeViewRecordIO.h Fri Feb 17 19:35:33 2017
@@ -59,9 +59,9 @@ public:
template <typename T> Error mapInteger(T &Value) {
if (isWriting())
- return Writer->writeInteger(Value);
+ return Writer->writeInteger(Value, llvm::support::little);
- return Reader->readInteger(Value);
+ return Reader->readInteger(Value, llvm::support::little);
}
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))
+ if (auto EC = Writer->writeInteger(Size, llvm::support::little))
return EC;
for (auto &X : Items) {
@@ -101,7 +101,7 @@ public:
return EC;
}
} else {
- if (auto EC = Reader->readInteger(Size))
+ if (auto EC = Reader->readInteger(Size, llvm::support::little))
return EC;
for (SizeType I = 0; I < Size; ++I) {
typename T::value_type Item;
Modified: llvm/trunk/include/llvm/DebugInfo/CodeView/TypeSerializer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/CodeView/TypeSerializer.h?rev=295525&r1=295524&r2=295525&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/CodeView/TypeSerializer.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/CodeView/TypeSerializer.h Fri Feb 17 19:35:33 2017
@@ -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))
+ if (auto EC = Writer.writeEnum(CVR.Kind, llvm::support::little))
return EC;
if (auto EC = Mapping.visitKnownMember(CVR, Record))
Modified: llvm/trunk/include/llvm/DebugInfo/MSF/StreamReader.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/MSF/StreamReader.h?rev=295525&r1=295524&r2=295525&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/MSF/StreamReader.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/MSF/StreamReader.h Fri Feb 17 19:35:33 2017
@@ -29,28 +29,42 @@ public:
Error readLongestContiguousChunk(ArrayRef<uint8_t> &Buffer);
Error readBytes(ArrayRef<uint8_t> &Buffer, uint32_t Size);
- Error readInteger(uint8_t &Dest);
- Error readInteger(uint16_t &Dest);
- Error readInteger(uint32_t &Dest);
- Error readInteger(uint64_t &Dest);
- Error readInteger(int8_t &Dest);
- Error readInteger(int16_t &Dest);
- Error readInteger(int32_t &Dest);
- Error readInteger(int64_t &Dest);
+
+ template <typename T>
+ Error readInteger(T &Dest,
+ llvm::support::endianness Endian = llvm::support::native) {
+ static_assert(std::is_integral<T>::value,
+ "Cannot call readInteger with non-integral value!");
+
+ ArrayRef<uint8_t> Bytes;
+ if (auto EC = readBytes(Bytes, sizeof(T)))
+ return EC;
+
+ Dest = llvm::support::endian::read<T, llvm::support::unaligned>(
+ Bytes.data(), Endian);
+ return Error::success();
+ }
+
Error readZeroString(StringRef &Dest);
Error readFixedString(StringRef &Dest, uint32_t Length);
Error readStreamRef(ReadableStreamRef &Ref);
Error readStreamRef(ReadableStreamRef &Ref, uint32_t Length);
- template <typename T> Error readEnum(T &Dest) {
+ template <typename T>
+ Error readEnum(T &Dest,
+ llvm::support::endianness Endian = llvm::support::native) {
+ 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))
+ if (auto EC = readInteger(N, Endian))
return EC;
Dest = static_cast<T>(N);
return Error::success();
}
template <typename T> Error readObject(const T *&Dest) {
+ static_assert(std::is_trivially_copyable<T>::value,
+ "Can only read trivially copyable object types!");
ArrayRef<uint8_t> Buffer;
if (auto EC = readBytes(Buffer, sizeof(T)))
return EC;
@@ -60,6 +74,8 @@ public:
template <typename T>
Error readArray(ArrayRef<T> &Array, uint32_t NumElements) {
+ static_assert(std::is_trivially_copyable<T>::value,
+ "Can only read trivially copyable object types!");
ArrayRef<uint8_t> Bytes;
if (NumElements == 0) {
Array = ArrayRef<T>();
@@ -86,6 +102,8 @@ public:
template <typename T>
Error readArray(FixedStreamArray<T> &Array, uint32_t NumItems) {
+ static_assert(std::is_trivially_copyable<T>::value,
+ "Can only read trivially copyable object types!");
if (NumItems == 0) {
Array = FixedStreamArray<T>();
return Error::success();
Modified: llvm/trunk/include/llvm/DebugInfo/MSF/StreamWriter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/MSF/StreamWriter.h?rev=295525&r1=295524&r2=295525&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/MSF/StreamWriter.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/MSF/StreamWriter.h Fri Feb 17 19:35:33 2017
@@ -15,6 +15,7 @@
#include "llvm/DebugInfo/MSF/MSFError.h"
#include "llvm/DebugInfo/MSF/StreamArray.h"
#include "llvm/DebugInfo/MSF/StreamRef.h"
+#include "llvm/Support/Endian.h"
#include "llvm/Support/Error.h"
#include <cstdint>
#include <type_traits>
@@ -28,22 +29,31 @@ public:
explicit StreamWriter(WritableStreamRef Stream);
Error writeBytes(ArrayRef<uint8_t> Buffer);
- Error writeInteger(uint8_t Int);
- Error writeInteger(uint16_t Dest);
- Error writeInteger(uint32_t Dest);
- Error writeInteger(uint64_t Dest);
- Error writeInteger(int8_t Int);
- Error writeInteger(int16_t Dest);
- Error writeInteger(int32_t Dest);
- Error writeInteger(int64_t Dest);
+
+ template <typename T>
+ Error writeInteger(T Value,
+ llvm::support::endianness Endian = llvm::support::native) {
+ 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);
+ return writeBytes(Buffer);
+ }
+
Error writeZeroString(StringRef Str);
Error writeFixedString(StringRef Str);
Error writeStreamRef(ReadableStreamRef Ref);
Error writeStreamRef(ReadableStreamRef Ref, uint32_t Size);
- template <typename T> Error writeEnum(T Num) {
- return writeInteger(
- static_cast<typename std::underlying_type<T>::type>(Num));
+ template <typename T>
+ Error writeEnum(T Num,
+ llvm::support::endianness Endian = llvm::support::native) {
+ 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);
}
template <typename T> Error writeObject(const T &Obj) {
@@ -51,11 +61,15 @@ public:
"writeObject should not be used with pointers, to write "
"the pointed-to value dereference the pointer before calling "
"writeObject");
+ static_assert(std::is_trivially_copyable<T>::value,
+ "Can only serialize trivially copyable object types");
return writeBytes(
ArrayRef<uint8_t>(reinterpret_cast<const uint8_t *>(&Obj), sizeof(T)));
}
template <typename T> Error writeArray(ArrayRef<T> Array) {
+ static_assert(std::is_trivially_copyable<T>::value,
+ "Can only serialize trivially copyable object types");
if (Array.empty())
return Error::success();
@@ -73,6 +87,8 @@ public:
}
template <typename T> Error writeArray(FixedStreamArray<T> Array) {
+ static_assert(std::is_trivially_copyable<T>::value,
+ "Can only serialize trivially copyable object types");
return writeStreamRef(Array.getUnderlyingStream());
}
Modified: llvm/trunk/lib/DebugInfo/CodeView/CVTypeVisitor.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/CodeView/CVTypeVisitor.cpp?rev=295525&r1=295524&r2=295525&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/CodeView/CVTypeVisitor.cpp (original)
+++ llvm/trunk/lib/DebugInfo/CodeView/CVTypeVisitor.cpp Fri Feb 17 19:35:33 2017
@@ -182,7 +182,7 @@ Error CVTypeVisitor::visitFieldListMembe
TypeLeafKind Leaf;
while (!Reader.empty()) {
- if (auto EC = Reader.readEnum(Leaf))
+ if (auto EC = Reader.readEnum(Leaf, llvm::support::little))
return EC;
CVMemberRecord Record;
Modified: llvm/trunk/lib/DebugInfo/CodeView/CodeViewRecordIO.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/CodeView/CodeViewRecordIO.cpp?rev=295525&r1=295524&r2=295525&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/CodeView/CodeViewRecordIO.cpp (original)
+++ llvm/trunk/lib/DebugInfo/CodeView/CodeViewRecordIO.cpp Fri Feb 17 19:35:33 2017
@@ -87,13 +87,14 @@ Error CodeViewRecordIO::mapByteVectorTai
Error CodeViewRecordIO::mapInteger(TypeIndex &TypeInd) {
if (isWriting()) {
- if (auto EC = Writer->writeInteger(TypeInd.getIndex()))
+ if (auto EC =
+ Writer->writeInteger(TypeInd.getIndex(), llvm::support::little))
return EC;
return Error::success();
}
uint32_t I;
- if (auto EC = Reader->readInteger(I))
+ if (auto EC = Reader->readInteger(I, llvm::support::little))
return EC;
TypeInd.setIndex(I);
return Error::success();
@@ -176,7 +177,7 @@ Error CodeViewRecordIO::mapStringZVector
if (auto EC = mapStringZ(V))
return EC;
}
- if (auto EC = Writer->writeInteger(uint8_t(0)))
+ if (auto EC = Writer->writeInteger<uint8_t>(0, llvm::support::little))
return EC;
} else {
StringRef S;
@@ -194,24 +195,28 @@ Error CodeViewRecordIO::mapStringZVector
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(static_cast<uint16_t>(LF_CHAR)))
+ if (auto EC =
+ Writer->writeInteger<uint16_t>(LF_CHAR, llvm::support::little))
return EC;
- if (auto EC = Writer->writeInteger(static_cast<int8_t>(Value)))
+ if (auto EC = Writer->writeInteger<int8_t>(Value, llvm::support::little))
return EC;
} else if (Value >= std::numeric_limits<int16_t>::min()) {
- if (auto EC = Writer->writeInteger(static_cast<uint16_t>(LF_SHORT)))
+ if (auto EC =
+ Writer->writeInteger<uint16_t>(LF_SHORT, llvm::support::little))
return EC;
- if (auto EC = Writer->writeInteger(static_cast<int16_t>(Value)))
+ if (auto EC = Writer->writeInteger<int16_t>(Value, llvm::support::little))
return EC;
} else if (Value >= std::numeric_limits<int32_t>::min()) {
- if (auto EC = Writer->writeInteger(static_cast<uint16_t>(LF_LONG)))
+ if (auto EC =
+ Writer->writeInteger<uint16_t>(LF_LONG, llvm::support::little))
return EC;
- if (auto EC = Writer->writeInteger(static_cast<int32_t>(Value)))
+ if (auto EC = Writer->writeInteger<int32_t>(Value, llvm::support::little))
return EC;
} else {
- if (auto EC = Writer->writeInteger(static_cast<uint16_t>(LF_QUADWORD)))
+ if (auto EC =
+ Writer->writeInteger<uint16_t>(LF_QUADWORD, llvm::support::little))
return EC;
- if (auto EC = Writer->writeInteger(Value))
+ if (auto EC = Writer->writeInteger(Value, llvm::support::little))
return EC;
}
return Error::success();
@@ -219,22 +224,25 @@ Error CodeViewRecordIO::writeEncodedSign
Error CodeViewRecordIO::writeEncodedUnsignedInteger(const uint64_t &Value) {
if (Value < LF_NUMERIC) {
- if (auto EC = Writer->writeInteger(static_cast<uint16_t>(Value)))
+ if (auto EC = Writer->writeInteger<uint16_t>(Value, llvm::support::little))
return EC;
} else if (Value <= std::numeric_limits<uint16_t>::max()) {
- if (auto EC = Writer->writeInteger(static_cast<uint16_t>(LF_USHORT)))
+ if (auto EC =
+ Writer->writeInteger<uint16_t>(LF_USHORT, llvm::support::little))
return EC;
- if (auto EC = Writer->writeInteger(static_cast<uint16_t>(Value)))
+ if (auto EC = Writer->writeInteger<uint16_t>(Value, llvm::support::little))
return EC;
} else if (Value <= std::numeric_limits<uint32_t>::max()) {
- if (auto EC = Writer->writeInteger(static_cast<uint16_t>(LF_ULONG)))
+ if (auto EC =
+ Writer->writeInteger<uint16_t>(LF_ULONG, llvm::support::little))
return EC;
- if (auto EC = Writer->writeInteger(static_cast<uint32_t>(Value)))
+ if (auto EC = Writer->writeInteger<uint32_t>(Value, llvm::support::little))
return EC;
} else {
- if (auto EC = Writer->writeInteger(static_cast<uint16_t>(LF_UQUADWORD)))
+ if (auto EC =
+ Writer->writeInteger<uint16_t>(LF_UQUADWORD, llvm::support::little))
return EC;
- if (auto EC = Writer->writeInteger(Value))
+ if (auto EC = Writer->writeInteger(Value, llvm::support::little))
return EC;
}
Modified: llvm/trunk/lib/DebugInfo/CodeView/RecordSerialization.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/CodeView/RecordSerialization.cpp?rev=295525&r1=295524&r2=295525&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/CodeView/RecordSerialization.cpp (original)
+++ llvm/trunk/lib/DebugInfo/CodeView/RecordSerialization.cpp Fri Feb 17 19:35:33 2017
@@ -37,7 +37,7 @@ Error llvm::codeview::consume(msf::Strea
// Used to avoid overload ambiguity on APInt construtor.
bool FalseVal = false;
uint16_t Short;
- if (auto EC = Reader.readInteger(Short))
+ if (auto EC = Reader.readInteger(Short, llvm::support::little))
return EC;
if (Short < LF_NUMERIC) {
@@ -49,49 +49,49 @@ Error llvm::codeview::consume(msf::Strea
switch (Short) {
case LF_CHAR: {
int8_t N;
- if (auto EC = Reader.readInteger(N))
+ if (auto EC = Reader.readInteger(N, llvm::support::little))
return EC;
Num = APSInt(APInt(8, N, true), false);
return Error::success();
}
case LF_SHORT: {
int16_t N;
- if (auto EC = Reader.readInteger(N))
+ if (auto EC = Reader.readInteger(N, llvm::support::little))
return EC;
Num = APSInt(APInt(16, N, true), false);
return Error::success();
}
case LF_USHORT: {
uint16_t N;
- if (auto EC = Reader.readInteger(N))
+ if (auto EC = Reader.readInteger(N, llvm::support::little))
return EC;
Num = APSInt(APInt(16, N, false), true);
return Error::success();
}
case LF_LONG: {
int32_t N;
- if (auto EC = Reader.readInteger(N))
+ if (auto EC = Reader.readInteger(N, llvm::support::little))
return EC;
Num = APSInt(APInt(32, N, true), false);
return Error::success();
}
case LF_ULONG: {
uint32_t N;
- if (auto EC = Reader.readInteger(N))
+ if (auto EC = Reader.readInteger(N, llvm::support::little))
return EC;
Num = APSInt(APInt(32, N, FalseVal), true);
return Error::success();
}
case LF_QUADWORD: {
int64_t N;
- if (auto EC = Reader.readInteger(N))
+ if (auto EC = Reader.readInteger(N, llvm::support::little))
return EC;
Num = APSInt(APInt(64, N, true), false);
return Error::success();
}
case LF_UQUADWORD: {
uint64_t N;
- if (auto EC = Reader.readInteger(N))
+ if (auto EC = Reader.readInteger(N, llvm::support::little))
return EC;
Num = APSInt(APInt(64, N, false), true);
return Error::success();
@@ -124,7 +124,7 @@ Error llvm::codeview::consume_numeric(ms
}
Error llvm::codeview::consume(msf::StreamReader &Reader, uint32_t &Item) {
- return Reader.readInteger(Item);
+ return Reader.readInteger(Item, llvm::support::little);
}
Error llvm::codeview::consume(StringRef &Data, uint32_t &Item) {
@@ -137,7 +137,7 @@ Error llvm::codeview::consume(StringRef
}
Error llvm::codeview::consume(msf::StreamReader &Reader, int32_t &Item) {
- return Reader.readInteger(Item);
+ return Reader.readInteger(Item, llvm::support::little);
}
Error llvm::codeview::consume(msf::StreamReader &Reader, StringRef &Item) {
Modified: llvm/trunk/lib/DebugInfo/CodeView/TypeSerializer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/CodeView/TypeSerializer.cpp?rev=295525&r1=295524&r2=295525&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/CodeView/TypeSerializer.cpp (original)
+++ llvm/trunk/lib/DebugInfo/CodeView/TypeSerializer.cpp Fri Feb 17 19:35:33 2017
@@ -76,7 +76,7 @@ TypeSerializer::addPadding(MutableArrayR
int N = PaddingBytes;
while (PaddingBytes > 0) {
uint8_t Pad = static_cast<uint8_t>(LF_PAD0 + PaddingBytes);
- if (auto EC = Writer.writeInteger(Pad))
+ if (auto EC = Writer.writeInteger(Pad, llvm::support::little))
return std::move(EC);
--PaddingBytes;
}
@@ -207,11 +207,11 @@ Error TypeSerializer::visitMemberEnd(CVM
msf::StreamWriter CW(CS);
if (auto EC = CW.writeBytes(CopyData))
return EC;
- if (auto EC = CW.writeEnum(TypeLeafKind::LF_INDEX))
+ if (auto EC = CW.writeEnum(TypeLeafKind::LF_INDEX, llvm::support::little))
return EC;
- if (auto EC = CW.writeInteger(uint16_t(0)))
+ if (auto EC = CW.writeInteger<uint16_t>(0, llvm::support::little))
return EC;
- if (auto EC = CW.writeInteger(uint32_t(0xB0C0B0C0)))
+ if (auto EC = CW.writeInteger<uint32_t>(0xB0C0B0C0, llvm::support::little))
return EC;
FieldListSegments.push_back(SavedSegment);
Modified: llvm/trunk/lib/DebugInfo/MSF/StreamReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/MSF/StreamReader.cpp?rev=295525&r1=295524&r2=295525&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/MSF/StreamReader.cpp (original)
+++ llvm/trunk/lib/DebugInfo/MSF/StreamReader.cpp Fri Feb 17 19:35:33 2017
@@ -31,70 +31,6 @@ Error StreamReader::readBytes(ArrayRef<u
return Error::success();
}
-Error StreamReader::readInteger(uint8_t &Dest) {
- const uint8_t *P;
- if (auto EC = readObject(P))
- return EC;
- Dest = *P;
- return Error::success();
-}
-
-Error StreamReader::readInteger(uint16_t &Dest) {
- const support::ulittle16_t *P;
- if (auto EC = readObject(P))
- return EC;
- Dest = *P;
- return Error::success();
-}
-
-Error StreamReader::readInteger(uint32_t &Dest) {
- const support::ulittle32_t *P;
- if (auto EC = readObject(P))
- return EC;
- Dest = *P;
- return Error::success();
-}
-
-Error StreamReader::readInteger(uint64_t &Dest) {
- const support::ulittle64_t *P;
- if (auto EC = readObject(P))
- return EC;
- Dest = *P;
- return Error::success();
-}
-
-Error StreamReader::readInteger(int8_t &Dest) {
- const int8_t *P;
- if (auto EC = readObject(P))
- return EC;
- Dest = *P;
- return Error::success();
-}
-
-Error StreamReader::readInteger(int16_t &Dest) {
- const support::little16_t *P;
- if (auto EC = readObject(P))
- return EC;
- Dest = *P;
- return Error::success();
-}
-
-Error StreamReader::readInteger(int32_t &Dest) {
- const support::little32_t *P;
- if (auto EC = readObject(P))
- return EC;
- Dest = *P;
- return Error::success();
-}
-
-Error StreamReader::readInteger(int64_t &Dest) {
- const support::little64_t *P;
- if (auto EC = readObject(P))
- return EC;
- Dest = *P;
- return Error::success();
-}
-
Error StreamReader::readZeroString(StringRef &Dest) {
uint32_t Length = 0;
// First compute the length of the string by reading 1 byte at a time.
Modified: llvm/trunk/lib/DebugInfo/MSF/StreamWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/MSF/StreamWriter.cpp?rev=295525&r1=295524&r2=295525&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/MSF/StreamWriter.cpp (original)
+++ llvm/trunk/lib/DebugInfo/MSF/StreamWriter.cpp Fri Feb 17 19:35:33 2017
@@ -25,34 +25,6 @@ Error StreamWriter::writeBytes(ArrayRef<
return Error::success();
}
-Error StreamWriter::writeInteger(uint8_t Int) { return writeObject(Int); }
-
-Error StreamWriter::writeInteger(uint16_t Int) {
- return writeObject(support::ulittle16_t(Int));
-}
-
-Error StreamWriter::writeInteger(uint32_t Int) {
- return writeObject(support::ulittle32_t(Int));
-}
-
-Error StreamWriter::writeInteger(uint64_t Int) {
- return writeObject(support::ulittle64_t(Int));
-}
-
-Error StreamWriter::writeInteger(int8_t Int) { return writeObject(Int); }
-
-Error StreamWriter::writeInteger(int16_t Int) {
- return writeObject(support::little16_t(Int));
-}
-
-Error StreamWriter::writeInteger(int32_t Int) {
- return writeObject(support::little32_t(Int));
-}
-
-Error StreamWriter::writeInteger(int64_t Int) {
- return writeObject(support::little64_t(Int));
-}
-
Error StreamWriter::writeZeroString(StringRef Str) {
if (auto EC = writeFixedString(Str))
return EC;
Modified: llvm/trunk/lib/DebugInfo/PDB/Native/DbiStream.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Native/DbiStream.cpp?rev=295525&r1=295524&r2=295525&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/Native/DbiStream.cpp (original)
+++ llvm/trunk/lib/DebugInfo/PDB/Native/DbiStream.cpp Fri Feb 17 19:35:33 2017
@@ -236,7 +236,7 @@ Error DbiStream::initializeSectionContri
return Error::success();
StreamReader SCReader(SecContrSubstream);
- if (auto EC = SCReader.readEnum(SectionContribVersion))
+ if (auto EC = SCReader.readEnum(SectionContribVersion, llvm::support::little))
return EC;
if (SectionContribVersion == DbiSecContribVer60)
Modified: llvm/trunk/lib/DebugInfo/PDB/Native/DbiStreamBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Native/DbiStreamBuilder.cpp?rev=295525&r1=295524&r2=295525&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/Native/DbiStreamBuilder.cpp (original)
+++ llvm/trunk/lib/DebugInfo/PDB/Native/DbiStreamBuilder.cpp Fri Feb 17 19:35:33 2017
@@ -187,17 +187,21 @@ Error DbiStreamBuilder::generateFileInfo
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)) // NumModules
+ if (auto EC = MetadataWriter.writeInteger(
+ ModiCount, llvm::support::little)) // NumModules
return EC;
- if (auto EC = MetadataWriter.writeInteger(FileCount)) // NumSourceFiles
+ if (auto EC = MetadataWriter.writeInteger(
+ FileCount, llvm::support::little)) // NumSourceFiles
return EC;
for (uint16_t I = 0; I < ModiCount; ++I) {
- if (auto EC = MetadataWriter.writeInteger(I)) // Mod Indices
+ if (auto EC = MetadataWriter.writeInteger(
+ I, llvm::support::little)) // Mod Indices
return EC;
}
for (const auto MI : ModuleInfoList) {
FileCount = static_cast<uint16_t>(MI->SourceFiles.size());
- if (auto EC = MetadataWriter.writeInteger(FileCount)) // Mod File Counts
+ if (auto EC = MetadataWriter.writeInteger(
+ FileCount, llvm::support::little)) // Mod File Counts
return EC;
}
@@ -219,7 +223,8 @@ Error DbiStreamBuilder::generateFileInfo
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))
+ if (auto EC = MetadataWriter.writeInteger(Result->second,
+ llvm::support::little))
return EC;
}
}
@@ -373,7 +378,7 @@ Error DbiStreamBuilder::commit(const msf
return EC;
if (!SectionContribs.empty()) {
- if (auto EC = Writer.writeEnum(DbiSecContribVer60))
+ if (auto EC = Writer.writeEnum(DbiSecContribVer60, llvm::support::little))
return EC;
if (auto EC = Writer.writeArray(SectionContribs))
return EC;
@@ -392,7 +397,8 @@ Error DbiStreamBuilder::commit(const msf
return EC;
for (auto &Stream : DbgStreams)
- if (auto EC = Writer.writeInteger(Stream.StreamNumber))
+ if (auto EC =
+ Writer.writeInteger(Stream.StreamNumber, llvm::support::little))
return EC;
for (auto &Stream : DbgStreams) {
Modified: llvm/trunk/lib/DebugInfo/PDB/Native/HashTable.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Native/HashTable.cpp?rev=295525&r1=295524&r2=295525&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/Native/HashTable.cpp (original)
+++ llvm/trunk/lib/DebugInfo/PDB/Native/HashTable.cpp Fri Feb 17 19:35:33 2017
@@ -48,9 +48,9 @@ Error HashTable::load(msf::StreamReader
"Present bit vector interesects deleted!");
for (uint32_t P : Present) {
- if (auto EC = Stream.readInteger(Buckets[P].first))
+ if (auto EC = Stream.readInteger(Buckets[P].first, llvm::support::little))
return EC;
- if (auto EC = Stream.readInteger(Buckets[P].second))
+ if (auto EC = Stream.readInteger(Buckets[P].second, llvm::support::little))
return EC;
}
@@ -91,9 +91,9 @@ Error HashTable::commit(msf::StreamWrite
return EC;
for (const auto &Entry : *this) {
- if (auto EC = Writer.writeInteger(Entry.first))
+ if (auto EC = Writer.writeInteger(Entry.first, llvm::support::little))
return EC;
- if (auto EC = Writer.writeInteger(Entry.second))
+ if (auto EC = Writer.writeInteger(Entry.second, llvm::support::little))
return EC;
}
return Error::success();
@@ -212,7 +212,7 @@ void HashTable::grow() {
Error HashTable::readSparseBitVector(msf::StreamReader &Stream,
SparseBitVector<> &V) {
uint32_t NumWords;
- if (auto EC = Stream.readInteger(NumWords))
+ if (auto EC = Stream.readInteger(NumWords, llvm::support::little))
return joinErrors(
std::move(EC),
make_error<RawError>(raw_error_code::corrupt_file,
@@ -220,7 +220,7 @@ Error HashTable::readSparseBitVector(msf
for (uint32_t I = 0; I != NumWords; ++I) {
uint32_t Word;
- if (auto EC = Stream.readInteger(Word))
+ if (auto EC = Stream.readInteger(Word, llvm::support::little))
return joinErrors(std::move(EC),
make_error<RawError>(raw_error_code::corrupt_file,
"Expected hash table word"));
@@ -235,7 +235,7 @@ Error HashTable::writeSparseBitVector(ms
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))
+ if (auto EC = Writer.writeInteger(NumWords, llvm::support::little))
return joinErrors(
std::move(EC),
make_error<RawError>(raw_error_code::corrupt_file,
@@ -248,7 +248,7 @@ Error HashTable::writeSparseBitVector(ms
if (Vec.test(Idx))
Word |= (1 << WordIdx);
}
- if (auto EC = Writer.writeInteger(Word))
+ if (auto EC = Writer.writeInteger(Word, llvm::support::little))
return joinErrors(std::move(EC), make_error<RawError>(
raw_error_code::corrupt_file,
"Could not write linear map word"));
Modified: llvm/trunk/lib/DebugInfo/PDB/Native/ModStream.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Native/ModStream.cpp?rev=295525&r1=295524&r2=295525&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/Native/ModStream.cpp (original)
+++ llvm/trunk/lib/DebugInfo/PDB/Native/ModStream.cpp Fri Feb 17 19:35:33 2017
@@ -43,7 +43,7 @@ Error ModStream::reload() {
ReadableStreamRef S;
- if (auto EC = Reader.readInteger(Signature))
+ if (auto EC = Reader.readInteger(Signature, llvm::support::little))
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))
+ if (auto EC = Reader.readInteger(GlobalRefsSize, llvm::support::little))
return EC;
if (auto EC = Reader.readStreamRef(GlobalRefsSubstream, GlobalRefsSize))
return EC;
Modified: llvm/trunk/lib/DebugInfo/PDB/Native/NamedStreamMap.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Native/NamedStreamMap.cpp?rev=295525&r1=295524&r2=295525&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/Native/NamedStreamMap.cpp (original)
+++ llvm/trunk/lib/DebugInfo/PDB/Native/NamedStreamMap.cpp Fri Feb 17 19:35:33 2017
@@ -32,7 +32,7 @@ Error NamedStreamMap::load(StreamReader
FinalizedInfo.reset();
uint32_t StringBufferSize;
- if (auto EC = Stream.readInteger(StringBufferSize))
+ if (auto EC = Stream.readInteger(StringBufferSize, llvm::support::little))
return joinErrors(std::move(EC),
make_error<RawError>(raw_error_code::corrupt_file,
"Expected string buffer size"));
@@ -71,8 +71,8 @@ Error NamedStreamMap::commit(msf::Stream
assert(FinalizedInfo.hasValue());
// The first field is the number of bytes of string data.
- if (auto EC = Writer.writeInteger(
- FinalizedInfo->StringDataBytes)) // Number of bytes of string data
+ if (auto EC = Writer.writeInteger(FinalizedInfo->StringDataBytes,
+ llvm::support::little))
return EC;
// Now all of the string data itself.
Modified: llvm/trunk/lib/DebugInfo/PDB/Native/PDBFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Native/PDBFile.cpp?rev=295525&r1=295524&r2=295525&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/Native/PDBFile.cpp (original)
+++ llvm/trunk/lib/DebugInfo/PDB/Native/PDBFile.cpp Fri Feb 17 19:35:33 2017
@@ -186,7 +186,7 @@ Error PDBFile::parseStreamData() {
// been parsed, we can avoid this and reuse MappedBlockStream.
auto DS = MappedBlockStream::createDirectoryStream(ContainerLayout, *Buffer);
StreamReader Reader(*DS);
- if (auto EC = Reader.readInteger(NumStreams))
+ if (auto EC = Reader.readInteger(NumStreams, llvm::support::little))
return EC;
if (auto EC = Reader.readArray(ContainerLayout.StreamSizes, NumStreams))
Modified: llvm/trunk/lib/DebugInfo/PDB/Native/PDBFileBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Native/PDBFileBuilder.cpp?rev=295525&r1=295524&r2=295525&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/Native/PDBFileBuilder.cpp (original)
+++ llvm/trunk/lib/DebugInfo/PDB/Native/PDBFileBuilder.cpp Fri Feb 17 19:35:33 2017
@@ -132,8 +132,8 @@ Error PDBFileBuilder::commit(StringRef F
auto DirStream =
WritableMappedBlockStream::createDirectoryStream(Layout, Buffer);
StreamWriter DW(*DirStream);
- if (auto EC =
- DW.writeInteger(static_cast<uint32_t>(Layout.StreamSizes.size())))
+ if (auto EC = DW.writeInteger<uint32_t>(Layout.StreamSizes.size(),
+ llvm::support::little))
return EC;
if (auto EC = DW.writeArray(Layout.StreamSizes))
Modified: llvm/trunk/lib/DebugInfo/PDB/Native/StringTable.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Native/StringTable.cpp?rev=295525&r1=295524&r2=295525&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/Native/StringTable.cpp (original)
+++ llvm/trunk/lib/DebugInfo/PDB/Native/StringTable.cpp Fri Feb 17 19:35:33 2017
@@ -55,7 +55,7 @@ Error StringTable::load(StreamReader &St
return make_error<RawError>(raw_error_code::corrupt_file,
"Missing name count");
- if (auto EC = Stream.readInteger(NameCount))
+ if (auto EC = Stream.readInteger(NameCount, llvm::support::little))
return EC;
return Error::success();
}
Modified: llvm/trunk/lib/DebugInfo/PDB/Native/StringTableBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Native/StringTableBuilder.cpp?rev=295525&r1=295524&r2=295525&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/Native/StringTableBuilder.cpp (original)
+++ llvm/trunk/lib/DebugInfo/PDB/Native/StringTableBuilder.cpp Fri Feb 17 19:35:33 2017
@@ -74,7 +74,7 @@ Error StringTableBuilder::commit(msf::St
// Write a hash table.
uint32_t BucketCount = computeBucketCount(Strings.size());
- if (auto EC = Writer.writeInteger(BucketCount))
+ if (auto EC = Writer.writeInteger(BucketCount, llvm::support::little))
return EC;
std::vector<ulittle32_t> Buckets(BucketCount);
@@ -96,7 +96,8 @@ Error StringTableBuilder::commit(msf::St
if (auto EC = Writer.writeArray(ArrayRef<ulittle32_t>(Buckets)))
return EC;
- if (auto EC = Writer.writeInteger(static_cast<uint32_t>(Strings.size())))
+ if (auto EC = Writer.writeInteger(static_cast<uint32_t>(Strings.size()),
+ llvm::support::little))
return EC;
return Error::success();
}
Modified: llvm/trunk/tools/llvm-readobj/COFFDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/COFFDumper.cpp?rev=295525&r1=295524&r2=295525&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/COFFDumper.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/COFFDumper.cpp Fri Feb 17 19:35:33 2017
@@ -1015,7 +1015,7 @@ void COFFDumper::printCodeViewInlineeLin
msf::ByteStream S(Subsection);
msf::StreamReader SR(S);
uint32_t Signature;
- error(SR.readInteger(Signature));
+ error(SR.readInteger(Signature, llvm::support::little));
bool HasExtraFiles = Signature == unsigned(InlineeLinesSignature::ExtraFiles);
while (!SR.empty()) {
@@ -1028,12 +1028,12 @@ void COFFDumper::printCodeViewInlineeLin
if (HasExtraFiles) {
uint32_t ExtraFileCount;
- error(SR.readInteger(ExtraFileCount));
+ error(SR.readInteger(ExtraFileCount, llvm::support::little));
W.printNumber("ExtraFileCount", ExtraFileCount);
ListScope ExtraFiles(W, "ExtraFiles");
for (unsigned I = 0; I < ExtraFileCount; ++I) {
uint32_t FileID;
- error(SR.readInteger(FileID));
+ error(SR.readInteger(FileID, llvm::support::little));
printFileNameForOffset("FileID", FileID);
}
}
Modified: llvm/trunk/unittests/DebugInfo/PDB/MappedBlockStreamTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/DebugInfo/PDB/MappedBlockStreamTest.cpp?rev=295525&r1=295524&r2=295525&view=diff
==============================================================================
--- llvm/trunk/unittests/DebugInfo/PDB/MappedBlockStreamTest.cpp (original)
+++ llvm/trunk/unittests/DebugInfo/PDB/MappedBlockStreamTest.cpp Fri Feb 17 19:35:33 2017
@@ -325,8 +325,8 @@ TEST(MappedBlockStreamTest, TestWriteThe
StreamReader Reader(*S);
StreamWriter Writer(*S);
- EXPECT_NO_ERROR(Writer.writeInteger(u16[0]));
- EXPECT_NO_ERROR(Reader.readInteger(u16[1]));
+ EXPECT_NO_ERROR(Writer.writeInteger(u16[0], llvm::support::little));
+ EXPECT_NO_ERROR(Reader.readInteger(u16[1], llvm::support::little));
EXPECT_EQ(u16[0], u16[1]);
EXPECT_EQ(std::vector<uint8_t>({0, 0x7A, 0xEC, 0, 0, 0, 0, 0, 0, 0}),
DataBytes);
@@ -334,8 +334,8 @@ TEST(MappedBlockStreamTest, TestWriteThe
Reader.setOffset(0);
Writer.setOffset(0);
::memset(DataBytes.data(), 0, 10);
- EXPECT_NO_ERROR(Writer.writeInteger(u32[0]));
- EXPECT_NO_ERROR(Reader.readInteger(u32[1]));
+ EXPECT_NO_ERROR(Writer.writeInteger(u32[0], llvm::support::little));
+ EXPECT_NO_ERROR(Reader.readInteger(u32[1], llvm::support::little));
EXPECT_EQ(u32[0], u32[1]);
EXPECT_EQ(std::vector<uint8_t>({0x17, 0x5C, 0x50, 0, 0, 0, 0x35, 0, 0, 0}),
DataBytes);
@@ -343,8 +343,8 @@ TEST(MappedBlockStreamTest, TestWriteThe
Reader.setOffset(0);
Writer.setOffset(0);
::memset(DataBytes.data(), 0, 10);
- EXPECT_NO_ERROR(Writer.writeEnum(Enum[0]));
- EXPECT_NO_ERROR(Reader.readEnum(Enum[1]));
+ EXPECT_NO_ERROR(Writer.writeEnum(Enum[0], llvm::support::little));
+ EXPECT_NO_ERROR(Reader.readEnum(Enum[1], llvm::support::little));
EXPECT_EQ(Enum[0], Enum[1]);
EXPECT_EQ(std::vector<uint8_t>({0x2C, 0x60, 0x4A, 0, 0, 0, 0, 0, 0, 0}),
DataBytes);
More information about the llvm-commits
mailing list