diff options
author | Zachary Turner <zturner@google.com> | 2016-10-20 18:31:19 +0000 |
---|---|---|
committer | Zachary Turner <zturner@google.com> | 2016-10-20 18:31:19 +0000 |
commit | 4d49eb9fa0bb4ddc87329192ca24ffebedd05e1b (patch) | |
tree | 79095d7ef7bcc737b2e8854662d25ffa834b0b9c /llvm/lib/DebugInfo/MSF | |
parent | f70a906a11d68f716a7337341b4dddb418081a3f (diff) | |
download | bcm5719-llvm-4d49eb9fa0bb4ddc87329192ca24ffebedd05e1b.tar.gz bcm5719-llvm-4d49eb9fa0bb4ddc87329192ca24ffebedd05e1b.zip |
[CodeView] Refactor serialization to use StreamInterface.
This was all using ArrayRef<>s before which presents a problem
when you want to serialize to or deserialize from an actual
PDB stream. An ArrayRef<> is really just a special case of
what can be handled with StreamInterface though (e.g. by using
a ByteStream), so changing this to use StreamInterface allows
us to plug in a PDB stream and get all the record serialization
and deserialization for free on a MappedBlockStream.
Subsequent patches will try to remove TypeTableBuilder and
TypeRecordBuilder in favor of class that operate on
Streams as well, which should allow us to completely merge
the reading and writing codepaths for both types and symbols.
Differential Revision: https://reviews.llvm.org/D25831
llvm-svn: 284762
Diffstat (limited to 'llvm/lib/DebugInfo/MSF')
-rw-r--r-- | llvm/lib/DebugInfo/MSF/StreamReader.cpp | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/llvm/lib/DebugInfo/MSF/StreamReader.cpp b/llvm/lib/DebugInfo/MSF/StreamReader.cpp index eb3d3e82d4d..b85fd14a3b7 100644 --- a/llvm/lib/DebugInfo/MSF/StreamReader.cpp +++ b/llvm/lib/DebugInfo/MSF/StreamReader.cpp @@ -31,6 +31,14 @@ Error StreamReader::readBytes(ArrayRef<uint8_t> &Buffer, uint32_t Size) { 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)) @@ -47,6 +55,46 @@ Error StreamReader::readInteger(uint32_t &Dest) { 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. @@ -91,3 +139,18 @@ Error StreamReader::readStreamRef(ReadableStreamRef &Ref, uint32_t Length) { Offset += Length; return Error::success(); } + +Error StreamReader::skip(uint32_t Amount) { + if (Amount > bytesRemaining()) + return make_error<MSFError>(msf_error_code::insufficient_buffer); + Offset += Amount; + return Error::success(); +} + +uint8_t StreamReader::peek() const { + ArrayRef<uint8_t> Buffer; + auto EC = Stream.readBytes(Offset, 1, Buffer); + assert(!EC && "Cannot peek an empty buffer!"); + llvm::consumeError(std::move(EC)); + return Buffer[0]; +} |