summaryrefslogtreecommitdiff
path: root/lib/DebugInfo/MSF
diff options
context:
space:
mode:
authorZachary Turner <zturner@google.com>2017-03-02 20:52:51 +0000
committerZachary Turner <zturner@google.com>2017-03-02 20:52:51 +0000
commitf3491b21c5eb0a936daf3a28e047bfc84f36a5e9 (patch)
tree4ad2c49047e9aa75a7e679cccd0639b4aceedb6e /lib/DebugInfo/MSF
parente1c51407af94a581ceaa3631ee10cc83635bf120 (diff)
[Support] Move Stream library from MSF -> Support.
After several smaller patches to get most of the core improvements finished up, this patch is a straight move and header fixup of the source. Differential Revision: https://reviews.llvm.org/D30266 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@296810 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/DebugInfo/MSF')
-rw-r--r--lib/DebugInfo/MSF/BinaryStreamError.cpp56
-rw-r--r--lib/DebugInfo/MSF/BinaryStreamReader.cpp95
-rw-r--r--lib/DebugInfo/MSF/BinaryStreamWriter.cpp59
-rw-r--r--lib/DebugInfo/MSF/CMakeLists.txt3
-rw-r--r--lib/DebugInfo/MSF/MappedBlockStream.cpp2
5 files changed, 1 insertions, 214 deletions
diff --git a/lib/DebugInfo/MSF/BinaryStreamError.cpp b/lib/DebugInfo/MSF/BinaryStreamError.cpp
deleted file mode 100644
index 097a59e768b..00000000000
--- a/lib/DebugInfo/MSF/BinaryStreamError.cpp
+++ /dev/null
@@ -1,56 +0,0 @@
-//===- BinaryStreamError.cpp - Error extensions for streams -----*- C++ -*-===//
-//
-// 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/BinaryStreamError.h"
-#include "llvm/Support/ErrorHandling.h"
-
-using namespace llvm;
-
-char BinaryStreamError::ID = 0;
-
-BinaryStreamError::BinaryStreamError(stream_error_code C)
- : BinaryStreamError(C, "") {}
-
-BinaryStreamError::BinaryStreamError(StringRef Context)
- : BinaryStreamError(stream_error_code::unspecified, Context) {}
-
-BinaryStreamError::BinaryStreamError(stream_error_code C, StringRef Context)
- : Code(C) {
- ErrMsg = "Stream Error: ";
- switch (C) {
- case stream_error_code::unspecified:
- ErrMsg += "An unspecified error has occurred.";
- break;
- case stream_error_code::stream_too_short:
- ErrMsg += "The stream is too short to perform the requested operation.";
- break;
- case stream_error_code::invalid_array_size:
- ErrMsg += "The buffer size is not a multiple of the array element size.";
- break;
- case stream_error_code::invalid_offset:
- ErrMsg += "The specified offset is invalid for the current stream.";
- break;
- case stream_error_code::filesystem_error:
- ErrMsg += "An I/O error occurred on the file system.";
- break;
- }
-
- if (!Context.empty()) {
- ErrMsg += " ";
- ErrMsg += Context;
- }
-}
-
-void BinaryStreamError::log(raw_ostream &OS) const { OS << ErrMsg << "\n"; }
-
-StringRef BinaryStreamError::getErrorMessage() const { return ErrMsg; }
-
-std::error_code BinaryStreamError::convertToErrorCode() const {
- return inconvertibleErrorCode();
-}
diff --git a/lib/DebugInfo/MSF/BinaryStreamReader.cpp b/lib/DebugInfo/MSF/BinaryStreamReader.cpp
deleted file mode 100644
index b6d7ee9d0b0..00000000000
--- a/lib/DebugInfo/MSF/BinaryStreamReader.cpp
+++ /dev/null
@@ -1,95 +0,0 @@
-//===- BinaryStreamReader.cpp - Reads objects from a binary 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/BinaryStreamReader.h"
-
-#include "llvm/DebugInfo/MSF/BinaryStreamError.h"
-#include "llvm/DebugInfo/MSF/BinaryStreamRef.h"
-
-using namespace llvm;
-
-BinaryStreamReader::BinaryStreamReader(BinaryStreamRef S)
- : Stream(S), Offset(0) {}
-
-Error BinaryStreamReader::readLongestContiguousChunk(
- ArrayRef<uint8_t> &Buffer) {
- if (auto EC = Stream.readLongestContiguousChunk(Offset, Buffer))
- return EC;
- Offset += Buffer.size();
- return Error::success();
-}
-
-Error BinaryStreamReader::readBytes(ArrayRef<uint8_t> &Buffer, uint32_t Size) {
- if (auto EC = Stream.readBytes(Offset, Size, Buffer))
- return EC;
- Offset += Size;
- return Error::success();
-}
-
-Error BinaryStreamReader::readCString(StringRef &Dest) {
- // TODO: This could be made more efficient by using readLongestContiguousChunk
- // and searching for null terminators in the resulting buffer.
-
- 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;
- while (true) {
- if (auto EC = readObject(C))
- return EC;
- if (*C == '\0')
- break;
- ++Length;
- }
- // Now go back and request a reference for that many bytes.
- uint32_t NewOffset = getOffset();
- setOffset(OriginalOffset);
-
- if (auto EC = readFixedString(Dest, Length))
- return EC;
-
- // Now set the offset back to where it was after we calculated the length.
- setOffset(NewOffset);
- return Error::success();
-}
-
-Error BinaryStreamReader::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 BinaryStreamReader::readStreamRef(BinaryStreamRef &Ref) {
- return readStreamRef(Ref, bytesRemaining());
-}
-
-Error BinaryStreamReader::readStreamRef(BinaryStreamRef &Ref, uint32_t Length) {
- if (bytesRemaining() < Length)
- return make_error<BinaryStreamError>(stream_error_code::stream_too_short);
- Ref = Stream.slice(Offset, Length);
- Offset += Length;
- return Error::success();
-}
-
-Error BinaryStreamReader::skip(uint32_t Amount) {
- if (Amount > bytesRemaining())
- return make_error<BinaryStreamError>(stream_error_code::stream_too_short);
- Offset += Amount;
- return Error::success();
-}
-
-uint8_t BinaryStreamReader::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];
-}
diff --git a/lib/DebugInfo/MSF/BinaryStreamWriter.cpp b/lib/DebugInfo/MSF/BinaryStreamWriter.cpp
deleted file mode 100644
index 636a07a3f45..00000000000
--- a/lib/DebugInfo/MSF/BinaryStreamWriter.cpp
+++ /dev/null
@@ -1,59 +0,0 @@
-//===- BinaryStreamWriter.cpp - Writes objects to a BinaryStream ----------===//
-//
-// 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/BinaryStreamWriter.h"
-
-#include "llvm/DebugInfo/MSF/BinaryStreamReader.h"
-#include "llvm/DebugInfo/MSF/BinaryStreamRef.h"
-
-using namespace llvm;
-
-BinaryStreamWriter::BinaryStreamWriter(WritableBinaryStreamRef S)
- : Stream(S), Offset(0) {}
-
-Error BinaryStreamWriter::writeBytes(ArrayRef<uint8_t> Buffer) {
- if (auto EC = Stream.writeBytes(Offset, Buffer))
- return EC;
- Offset += Buffer.size();
- return Error::success();
-}
-
-Error BinaryStreamWriter::writeCString(StringRef Str) {
- if (auto EC = writeFixedString(Str))
- return EC;
- if (auto EC = writeObject('\0'))
- return EC;
-
- return Error::success();
-}
-
-Error BinaryStreamWriter::writeFixedString(StringRef Str) {
- return writeBytes(ArrayRef<uint8_t>(Str.bytes_begin(), Str.bytes_end()));
-}
-
-Error BinaryStreamWriter::writeStreamRef(BinaryStreamRef Ref) {
- return writeStreamRef(Ref, Ref.getLength());
-}
-
-Error BinaryStreamWriter::writeStreamRef(BinaryStreamRef Ref, uint32_t Length) {
- BinaryStreamReader SrcReader(Ref.slice(0, Length));
- // This is a bit tricky. If we just call readBytes, we are requiring that it
- // return us the entire stream as a contiguous buffer. There is no guarantee
- // this can be satisfied by returning a reference straight from the buffer, as
- // an implementation may not store all data in a single contiguous buffer. So
- // we iterate over each contiguous chunk, writing each one in succession.
- while (SrcReader.bytesRemaining() > 0) {
- ArrayRef<uint8_t> Chunk;
- if (auto EC = SrcReader.readLongestContiguousChunk(Chunk))
- return EC;
- if (auto EC = writeBytes(Chunk))
- return EC;
- }
- return Error::success();
-}
diff --git a/lib/DebugInfo/MSF/CMakeLists.txt b/lib/DebugInfo/MSF/CMakeLists.txt
index 5537b7008ce..6f38de336ee 100644
--- a/lib/DebugInfo/MSF/CMakeLists.txt
+++ b/lib/DebugInfo/MSF/CMakeLists.txt
@@ -1,7 +1,4 @@
add_llvm_library(LLVMDebugInfoMSF
- BinaryStreamError.cpp
- BinaryStreamReader.cpp
- BinaryStreamWriter.cpp
MappedBlockStream.cpp
MSFBuilder.cpp
MSFCommon.cpp
diff --git a/lib/DebugInfo/MSF/MappedBlockStream.cpp b/lib/DebugInfo/MSF/MappedBlockStream.cpp
index 242088c9391..57953cfa338 100644
--- a/lib/DebugInfo/MSF/MappedBlockStream.cpp
+++ b/lib/DebugInfo/MSF/MappedBlockStream.cpp
@@ -9,10 +9,10 @@
#include "llvm/DebugInfo/MSF/MappedBlockStream.h"
-#include "llvm/DebugInfo/MSF/BinaryStreamError.h"
#include "llvm/DebugInfo/MSF/IMSFFile.h"
#include "llvm/DebugInfo/MSF/MSFCommon.h"
#include "llvm/DebugInfo/MSF/MSFStreamLayout.h"
+#include "llvm/Support/BinaryStreamError.h"
using namespace llvm;
using namespace llvm::msf;