diff options
author | Zachary Turner <zturner@google.com> | 2017-02-28 00:04:07 +0000 |
---|---|---|
committer | Zachary Turner <zturner@google.com> | 2017-02-28 00:04:07 +0000 |
commit | 695ed56ba5d3bd3b86c6a4ed6d79b89eb8fbd2f4 (patch) | |
tree | caf35bd7345bb071545ef39b636b40ffafc41504 /llvm/lib/DebugInfo/CodeView | |
parent | 59cd89332010b22e82c3110d558ff37948c4df1e (diff) | |
download | bcm5719-llvm-695ed56ba5d3bd3b86c6a4ed6d79b89eb8fbd2f4.tar.gz bcm5719-llvm-695ed56ba5d3bd3b86c6a4ed6d79b89eb8fbd2f4.zip |
[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
Diffstat (limited to 'llvm/lib/DebugInfo/CodeView')
-rw-r--r-- | llvm/lib/DebugInfo/CodeView/CVTypeDumper.cpp | 2 | ||||
-rw-r--r-- | llvm/lib/DebugInfo/CodeView/CVTypeVisitor.cpp | 4 | ||||
-rw-r--r-- | llvm/lib/DebugInfo/CodeView/CodeViewRecordIO.cpp | 44 | ||||
-rw-r--r-- | llvm/lib/DebugInfo/CodeView/RecordSerialization.cpp | 24 | ||||
-rw-r--r-- | llvm/lib/DebugInfo/CodeView/TypeSerializer.cpp | 13 |
5 files changed, 40 insertions, 47 deletions
diff --git a/llvm/lib/DebugInfo/CodeView/CVTypeDumper.cpp b/llvm/lib/DebugInfo/CodeView/CVTypeDumper.cpp index 5e0ff63dc5a..a94516985b8 100644 --- a/llvm/lib/DebugInfo/CodeView/CVTypeDumper.cpp +++ b/llvm/lib/DebugInfo/CodeView/CVTypeDumper.cpp @@ -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())) diff --git a/llvm/lib/DebugInfo/CodeView/CVTypeVisitor.cpp b/llvm/lib/DebugInfo/CodeView/CVTypeVisitor.cpp index fa7406271e1..74c60c78b8b 100644 --- a/llvm/lib/DebugInfo/CodeView/CVTypeVisitor.cpp +++ b/llvm/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<uint8_t> Data) { - BinaryByteStream S(Data); + BinaryByteStream S(Data, llvm::support::little); BinaryStreamReader SR(S); return visitFieldListMemberStream(SR); } diff --git a/llvm/lib/DebugInfo/CodeView/CodeViewRecordIO.cpp b/llvm/lib/DebugInfo/CodeView/CodeViewRecordIO.cpp index 3b10f8ff120..a204d43ba13 100644 --- a/llvm/lib/DebugInfo/CodeView/CodeViewRecordIO.cpp +++ b/llvm/lib/DebugInfo/CodeView/CodeViewRecordIO.cpp @@ -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; } diff --git a/llvm/lib/DebugInfo/CodeView/RecordSerialization.cpp b/llvm/lib/DebugInfo/CodeView/RecordSerialization.cpp index d276aa0b84d..eaa70f2b181 100644 --- a/llvm/lib/DebugInfo/CodeView/RecordSerialization.cpp +++ b/llvm/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<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) { diff --git a/llvm/lib/DebugInfo/CodeView/TypeSerializer.cpp b/llvm/lib/DebugInfo/CodeView/TypeSerializer.cpp index 9074291efcc..4d0ce9e4da9 100644 --- a/llvm/lib/DebugInfo/CodeView/TypeSerializer.cpp +++ b/llvm/lib/DebugInfo/CodeView/TypeSerializer.cpp @@ -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); |