summaryrefslogtreecommitdiffstats
path: root/llvm/lib/DebugInfo/PDB/Raw/ByteStream.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/DebugInfo/PDB/Raw/ByteStream.cpp')
-rw-r--r--llvm/lib/DebugInfo/PDB/Raw/ByteStream.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/llvm/lib/DebugInfo/PDB/Raw/ByteStream.cpp b/llvm/lib/DebugInfo/PDB/Raw/ByteStream.cpp
new file mode 100644
index 00000000000..20abe4c0d97
--- /dev/null
+++ b/llvm/lib/DebugInfo/PDB/Raw/ByteStream.cpp
@@ -0,0 +1,60 @@
+//===- ByteStream.cpp - Reads stream data from a byte sequence ------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/DebugInfo/PDB/Raw/ByteStream.h"
+#include "llvm/DebugInfo/PDB/Raw/StreamReader.h"
+
+using namespace llvm;
+
+ByteStream::ByteStream() : Owned(false) {}
+
+ByteStream::ByteStream(MutableArrayRef<uint8_t> Bytes) : Owned(false) {
+ initialize(Bytes);
+}
+
+ByteStream::ByteStream(uint32_t Length) : Owned(false) { initialize(Length); }
+
+ByteStream::~ByteStream() { reset(); }
+
+void ByteStream::reset() {
+ if (Owned)
+ delete[] Data.data();
+ Owned = false;
+ Data = MutableArrayRef<uint8_t>();
+}
+
+void ByteStream::initialize(MutableArrayRef<uint8_t> Bytes) {
+ reset();
+ Data = Bytes;
+ Owned = false;
+}
+
+void ByteStream::initialize(uint32_t Length) {
+ reset();
+ Data = MutableArrayRef<uint8_t>(new uint8_t[Length], Length);
+ Owned = true;
+}
+
+std::error_code ByteStream::initialize(StreamReader &Reader, uint32_t Length) {
+ initialize(Length);
+ std::error_code EC = Reader.readBytes(Data);
+ if (EC)
+ reset();
+ return EC;
+}
+
+std::error_code ByteStream::readBytes(uint32_t Offset,
+ MutableArrayRef<uint8_t> Buffer) const {
+ if (Data.size() < Buffer.size() + Offset)
+ return std::make_error_code(std::errc::bad_address);
+ ::memcpy(Buffer.data(), Data.data() + Offset, Buffer.size());
+ return std::error_code();
+}
+
+uint32_t ByteStream::getLength() const { return Data.size(); }
OpenPOWER on IntegriCloud