diff options
author | Zachary Turner <zturner@google.com> | 2016-07-29 20:56:36 +0000 |
---|---|---|
committer | Zachary Turner <zturner@google.com> | 2016-07-29 20:56:36 +0000 |
commit | a3225b0451cc68788db10c62a66bb189817658b1 (patch) | |
tree | 8e91ca1dab5f2c9a04964eaa93fa0db40688ffaf /llvm/lib/DebugInfo/MSF/StreamReader.cpp | |
parent | ecbe2ea002cdc4c1da279121ed66c459f0c5a3e2 (diff) | |
download | llvm-a3225b0451cc68788db10c62a66bb189817658b1.zip llvm-a3225b0451cc68788db10c62a66bb189817658b1.tar.gz llvm-a3225b0451cc68788db10c62a66bb189817658b1.tar.bz2 |
[msf] Resubmit "Rename Msf -> MSF".
Previously this change was submitted from a Windows machine, so
changes made to the case of filenames and directory names did
not survive the commit, and as a result the CMake source file
names and the on-disk file names did not match on case-sensitive
file systems.
I'm resubmitting this patch from a Linux system, which hopefully
allows the case changes to make it through unfettered.
llvm-svn: 277213
Diffstat (limited to 'llvm/lib/DebugInfo/MSF/StreamReader.cpp')
-rw-r--r-- | llvm/lib/DebugInfo/MSF/StreamReader.cpp | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/llvm/lib/DebugInfo/MSF/StreamReader.cpp b/llvm/lib/DebugInfo/MSF/StreamReader.cpp new file mode 100644 index 0000000..eb3d3e8 --- /dev/null +++ b/llvm/lib/DebugInfo/MSF/StreamReader.cpp @@ -0,0 +1,93 @@ +//===- StreamReader.cpp - Reads bytes and objects from a stream -----------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/DebugInfo/MSF/StreamReader.h" + +#include "llvm/DebugInfo/MSF/MSFError.h" +#include "llvm/DebugInfo/MSF/StreamRef.h" + +using namespace llvm; +using namespace llvm::msf; + +StreamReader::StreamReader(ReadableStreamRef S) : Stream(S), Offset(0) {} + +Error StreamReader::readLongestContiguousChunk(ArrayRef<uint8_t> &Buffer) { + if (auto EC = Stream.readLongestContiguousChunk(Offset, Buffer)) + return EC; + Offset += Buffer.size(); + return Error::success(); +} + +Error StreamReader::readBytes(ArrayRef<uint8_t> &Buffer, uint32_t Size) { + if (auto EC = Stream.readBytes(Offset, Size, Buffer)) + return EC; + Offset += Size; + 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::readZeroString(StringRef &Dest) { + uint32_t Length = 0; + // First compute the length of the string by reading 1 byte at a time. + uint32_t OriginalOffset = getOffset(); + const char *C; + do { + if (auto EC = readObject(C)) + return EC; + if (*C != '\0') + ++Length; + } while (*C != '\0'); + // Now go back and request a reference for that many bytes. + uint32_t NewOffset = getOffset(); + setOffset(OriginalOffset); + + ArrayRef<uint8_t> Data; + if (auto EC = readBytes(Data, Length)) + return EC; + Dest = StringRef(reinterpret_cast<const char *>(Data.begin()), Data.size()); + + // Now set the offset back to where it was after we calculated the length. + setOffset(NewOffset); + return Error::success(); +} + +Error StreamReader::readFixedString(StringRef &Dest, uint32_t Length) { + ArrayRef<uint8_t> Bytes; + if (auto EC = readBytes(Bytes, Length)) + return EC; + Dest = StringRef(reinterpret_cast<const char *>(Bytes.begin()), Bytes.size()); + return Error::success(); +} + +Error StreamReader::readStreamRef(ReadableStreamRef &Ref) { + return readStreamRef(Ref, bytesRemaining()); +} + +Error StreamReader::readStreamRef(ReadableStreamRef &Ref, uint32_t Length) { + if (bytesRemaining() < Length) + return make_error<MSFError>(msf_error_code::insufficient_buffer); + Ref = Stream.slice(Offset, Length); + Offset += Length; + return Error::success(); +} |