diff options
author | Zachary Turner <zturner@google.com> | 2016-06-10 05:09:12 +0000 |
---|---|---|
committer | Zachary Turner <zturner@google.com> | 2016-06-10 05:09:12 +0000 |
commit | 5acb4ac6d7989e5f59dd6bc035cc1110b2c830dd (patch) | |
tree | 463ec56d93f2cc3a2ea42a1d798809a5290020ab /llvm/lib/DebugInfo/CodeView/ByteStream.cpp | |
parent | 6a77a1c01f5f3f76546afd97c9aa1d2747bb7b6e (diff) | |
download | bcm5719-llvm-5acb4ac6d7989e5f59dd6bc035cc1110b2c830dd.tar.gz bcm5719-llvm-5acb4ac6d7989e5f59dd6bc035cc1110b2c830dd.zip |
Add support for writing through StreamInterface.
This adds method and tests for writing to a PDB stream. With
this, even a PDB stream which is discontiguous can be treated
as a sequential stream of bytes for the purposes of writing.
Reviewed By: ruiu
Differential Revision: http://reviews.llvm.org/D21157
llvm-svn: 272369
Diffstat (limited to 'llvm/lib/DebugInfo/CodeView/ByteStream.cpp')
-rw-r--r-- | llvm/lib/DebugInfo/CodeView/ByteStream.cpp | 52 |
1 files changed, 45 insertions, 7 deletions
diff --git a/llvm/lib/DebugInfo/CodeView/ByteStream.cpp b/llvm/lib/DebugInfo/CodeView/ByteStream.cpp index c0ac0b7a8ff..83b2f8ec307 100644 --- a/llvm/lib/DebugInfo/CodeView/ByteStream.cpp +++ b/llvm/lib/DebugInfo/CodeView/ByteStream.cpp @@ -15,23 +15,61 @@ using namespace llvm; using namespace llvm::codeview; -ByteStream::ByteStream() {} +static Error writeBytes(uint32_t Offset, ArrayRef<uint8_t> Src, + ArrayRef<uint8_t> Dest) { + return make_error<CodeViewError>(cv_error_code::operation_unsupported, + "ByteStream is immutable."); +} -ByteStream::ByteStream(ArrayRef<uint8_t> Data) : Data(Data) {} +static Error writeBytes(uint32_t Offset, ArrayRef<uint8_t> Src, + MutableArrayRef<uint8_t> Dest) { + if (Dest.size() < Src.size()) + return make_error<CodeViewError>(cv_error_code::insufficient_buffer); + if (Offset > Src.size() - Dest.size()) + return make_error<CodeViewError>(cv_error_code::insufficient_buffer); -ByteStream::~ByteStream() {} + ::memcpy(Dest.data() + Offset, Src.data(), Src.size()); + return Error::success(); +} -Error ByteStream::readBytes(uint32_t Offset, uint32_t Size, - ArrayRef<uint8_t> &Buffer) const { +template <bool Writable> +Error ByteStream<Writable>::readBytes(uint32_t Offset, uint32_t Size, + ArrayRef<uint8_t> &Buffer) const { + if (Offset > Data.size()) + return make_error<CodeViewError>(cv_error_code::insufficient_buffer); if (Data.size() < Size + Offset) return make_error<CodeViewError>(cv_error_code::insufficient_buffer); Buffer = Data.slice(Offset, Size); return Error::success(); } -uint32_t ByteStream::getLength() const { return Data.size(); } +template <bool Writable> +Error ByteStream<Writable>::readLongestContiguousChunk( + uint32_t Offset, ArrayRef<uint8_t> &Buffer) const { + if (Offset >= Data.size()) + return make_error<CodeViewError>(cv_error_code::insufficient_buffer); + Buffer = Data.slice(Offset); + return Error::success(); +} + +template <bool Writable> +Error ByteStream<Writable>::writeBytes(uint32_t Offset, + ArrayRef<uint8_t> Buffer) const { + return ::writeBytes(Offset, Buffer, Data); +} + +template <bool Writable> uint32_t ByteStream<Writable>::getLength() const { + return Data.size(); +} -StringRef ByteStream::str() const { +template <bool Writable> StringRef ByteStream<Writable>::str() const { const char *CharData = reinterpret_cast<const char *>(Data.data()); return StringRef(CharData, Data.size()); } + +namespace llvm { +namespace codeview { +template class ByteStream<true>; +template class ByteStream<false>; +} +} |