summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZachary Turner <zturner@google.com>2017-06-23 16:38:40 +0000
committerZachary Turner <zturner@google.com>2017-06-23 16:38:40 +0000
commita1dcb85ddea649d7dd144b03ede60a9c94b985ca (patch)
tree3bb3a29d17d7f17e46b828784334ee29219625bc
parent6e85e92b6c63669c2c7f316fb744d828d17130cd (diff)
downloadbcm5719-llvm-a1dcb85ddea649d7dd144b03ede60a9c94b985ca.tar.gz
bcm5719-llvm-a1dcb85ddea649d7dd144b03ede60a9c94b985ca.zip
Add a BinarySubstreamRef, and a method to read one.
This is essentially just a BinaryStreamRef packaged with an offset and the logic for reading one is no different than the logic for reading a BinaryStreamRef, except that we save the current offset. llvm-svn: 306122
-rw-r--r--llvm/include/llvm/Support/BinaryStreamReader.h9
-rw-r--r--llvm/include/llvm/Support/BinaryStreamRef.h5
-rw-r--r--llvm/lib/Support/BinaryStreamReader.cpp6
3 files changed, 20 insertions, 0 deletions
diff --git a/llvm/include/llvm/Support/BinaryStreamReader.h b/llvm/include/llvm/Support/BinaryStreamReader.h
index 738c042add3..ae5ebb2c362 100644
--- a/llvm/include/llvm/Support/BinaryStreamReader.h
+++ b/llvm/include/llvm/Support/BinaryStreamReader.h
@@ -137,6 +137,15 @@ public:
/// returns an appropriate error code.
Error readStreamRef(BinaryStreamRef &Ref, uint32_t Length);
+ /// Read \p Length bytes from the underlying stream into \p Stream. This is
+ /// equivalent to calling getUnderlyingStream().slice(Offset, Length).
+ /// Updates the stream's offset to point after the newly read object. Never
+ /// causes a copy.
+ ///
+ /// \returns a success error code if the data was successfully read, otherwise
+ /// returns an appropriate error code.
+ Error readSubstream(BinarySubstreamRef &Stream, uint32_t Size);
+
/// Get a pointer to an object of type T from the underlying stream, as if by
/// memcpy, and store the result into \p Dest. It is up to the caller to
/// ensure that objects of type T can be safely treated in this manner.
diff --git a/llvm/include/llvm/Support/BinaryStreamRef.h b/llvm/include/llvm/Support/BinaryStreamRef.h
index e3bd4bf0860..e57783d82c8 100644
--- a/llvm/include/llvm/Support/BinaryStreamRef.h
+++ b/llvm/include/llvm/Support/BinaryStreamRef.h
@@ -166,6 +166,11 @@ public:
ArrayRef<uint8_t> &Buffer) const;
};
+struct BinarySubstreamRef {
+ uint32_t Offset; // Offset in the parent stream
+ BinaryStreamRef StreamData; // Stream Data
+};
+
class WritableBinaryStreamRef
: public BinaryStreamRefBase<WritableBinaryStreamRef,
WritableBinaryStream> {
diff --git a/llvm/lib/Support/BinaryStreamReader.cpp b/llvm/lib/Support/BinaryStreamReader.cpp
index bfb658cfa0b..e00527f2519 100644
--- a/llvm/lib/Support/BinaryStreamReader.cpp
+++ b/llvm/lib/Support/BinaryStreamReader.cpp
@@ -109,6 +109,12 @@ Error BinaryStreamReader::readStreamRef(BinaryStreamRef &Ref, uint32_t Length) {
return Error::success();
}
+Error BinaryStreamReader::readSubstream(BinarySubstreamRef &Stream,
+ uint32_t Size) {
+ Stream.Offset = getOffset();
+ return readStreamRef(Stream.StreamData, Size);
+}
+
Error BinaryStreamReader::skip(uint32_t Amount) {
if (Amount > bytesRemaining())
return make_error<BinaryStreamError>(stream_error_code::stream_too_short);
OpenPOWER on IntegriCloud