summaryrefslogtreecommitdiffstats
path: root/llvm/lib/DebugInfo/CodeView
diff options
context:
space:
mode:
authorZachary Turner <zturner@google.com>2016-07-22 19:56:05 +0000
committerZachary Turner <zturner@google.com>2016-07-22 19:56:05 +0000
commitbac69d33d013a86277cf2acb9809819e1623c732 (patch)
tree407e63a631bcc61579f375eb47394b145a48b46e /llvm/lib/DebugInfo/CodeView
parentb8f95b5c6e77a36b5d5736cd167d244d64e53b87 (diff)
downloadbcm5719-llvm-bac69d33d013a86277cf2acb9809819e1623c732.tar.gz
bcm5719-llvm-bac69d33d013a86277cf2acb9809819e1623c732.zip
[msf] Create LLVMDebugInfoMsf
This provides a better layering of responsibilities among different aspects of PDB writing code. Some of the MSF related code was contained in CodeView, and some was in PDB prior to this. Further, we were often saying PDB when we meant MSF, and the two are actually independent of each other since in theory you can have other types of data besides PDB data in an MSF. So, this patch separates the MSF specific code into its own library, with no dependencies on anything else, and DebugInfoCodeView and DebugInfoPDB take dependencies on DebugInfoMsf. llvm-svn: 276458
Diffstat (limited to 'llvm/lib/DebugInfo/CodeView')
-rw-r--r--llvm/lib/DebugInfo/CodeView/ByteStream.cpp79
-rw-r--r--llvm/lib/DebugInfo/CodeView/CMakeLists.txt3
-rw-r--r--llvm/lib/DebugInfo/CodeView/CVTypeVisitor.cpp1
-rw-r--r--llvm/lib/DebugInfo/CodeView/LLVMBuild.txt2
-rw-r--r--llvm/lib/DebugInfo/CodeView/ModuleSubstream.cpp3
-rw-r--r--llvm/lib/DebugInfo/CodeView/ModuleSubstreamVisitor.cpp1
-rw-r--r--llvm/lib/DebugInfo/CodeView/StreamReader.cpp93
-rw-r--r--llvm/lib/DebugInfo/CodeView/StreamWriter.cpp78
-rw-r--r--llvm/lib/DebugInfo/CodeView/TypeDumper.cpp6
-rw-r--r--llvm/lib/DebugInfo/CodeView/TypeStreamMerger.cpp1
10 files changed, 8 insertions, 259 deletions
diff --git a/llvm/lib/DebugInfo/CodeView/ByteStream.cpp b/llvm/lib/DebugInfo/CodeView/ByteStream.cpp
deleted file mode 100644
index 2c43bc6958d..00000000000
--- a/llvm/lib/DebugInfo/CodeView/ByteStream.cpp
+++ /dev/null
@@ -1,79 +0,0 @@
-//===- 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/CodeView/ByteStream.h"
-#include "llvm/DebugInfo/CodeView/CodeViewError.h"
-#include "llvm/DebugInfo/CodeView/StreamReader.h"
-#include <cstring>
-
-using namespace llvm;
-using namespace llvm::codeview;
-
-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.");
-}
-
-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);
-
- ::memcpy(Dest.data() + Offset, Src.data(), Src.size());
- return Error::success();
-}
-
-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();
-}
-
-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();
-}
-
-template <bool Writable> Error ByteStream<Writable>::commit() const {
- return Error::success();
-}
-
-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>;
-}
-}
diff --git a/llvm/lib/DebugInfo/CodeView/CMakeLists.txt b/llvm/lib/DebugInfo/CodeView/CMakeLists.txt
index 47297a9131e..d8c21953967 100644
--- a/llvm/lib/DebugInfo/CodeView/CMakeLists.txt
+++ b/llvm/lib/DebugInfo/CodeView/CMakeLists.txt
@@ -1,5 +1,4 @@
add_llvm_library(LLVMDebugInfoCodeView
- ByteStream.cpp
CodeViewError.cpp
CVTypeVisitor.cpp
EnumTables.cpp
@@ -11,8 +10,6 @@ add_llvm_library(LLVMDebugInfoCodeView
ModuleSubstream.cpp
ModuleSubstreamVisitor.cpp
RecordSerialization.cpp
- StreamReader.cpp
- StreamWriter.cpp
SymbolDumper.cpp
TypeDumper.cpp
TypeRecord.cpp
diff --git a/llvm/lib/DebugInfo/CodeView/CVTypeVisitor.cpp b/llvm/lib/DebugInfo/CodeView/CVTypeVisitor.cpp
index 09f72214c52..f1f9acf570d 100644
--- a/llvm/lib/DebugInfo/CodeView/CVTypeVisitor.cpp
+++ b/llvm/lib/DebugInfo/CodeView/CVTypeVisitor.cpp
@@ -8,6 +8,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/DebugInfo/CodeView/CVTypeVisitor.h"
+#include "llvm/DebugInfo/CodeView/CodeViewError.h"
using namespace llvm;
using namespace llvm::codeview;
diff --git a/llvm/lib/DebugInfo/CodeView/LLVMBuild.txt b/llvm/lib/DebugInfo/CodeView/LLVMBuild.txt
index 4db23376fce..c1e35abf150 100644
--- a/llvm/lib/DebugInfo/CodeView/LLVMBuild.txt
+++ b/llvm/lib/DebugInfo/CodeView/LLVMBuild.txt
@@ -19,4 +19,4 @@
type = Library
name = DebugInfoCodeView
parent = DebugInfo
-required_libraries = Support
+required_libraries = Support DebugInfoMsf
diff --git a/llvm/lib/DebugInfo/CodeView/ModuleSubstream.cpp b/llvm/lib/DebugInfo/CodeView/ModuleSubstream.cpp
index 2e31ed6b5b7..5ab8212d3bd 100644
--- a/llvm/lib/DebugInfo/CodeView/ModuleSubstream.cpp
+++ b/llvm/lib/DebugInfo/CodeView/ModuleSubstream.cpp
@@ -9,10 +9,11 @@
#include "llvm/DebugInfo/CodeView/ModuleSubstream.h"
-#include "llvm/DebugInfo/CodeView/StreamReader.h"
+#include "llvm/DebugInfo/Msf/StreamReader.h"
using namespace llvm;
using namespace llvm::codeview;
+using namespace llvm::msf;
ModuleSubstream::ModuleSubstream() : Kind(ModuleSubstreamKind::None) {}
diff --git a/llvm/lib/DebugInfo/CodeView/ModuleSubstreamVisitor.cpp b/llvm/lib/DebugInfo/CodeView/ModuleSubstreamVisitor.cpp
index 6f237ee67fe..e4fe8d8053a 100644
--- a/llvm/lib/DebugInfo/CodeView/ModuleSubstreamVisitor.cpp
+++ b/llvm/lib/DebugInfo/CodeView/ModuleSubstreamVisitor.cpp
@@ -11,6 +11,7 @@
using namespace llvm;
using namespace llvm::codeview;
+using namespace llvm::msf;
Error IModuleSubstreamVisitor::visitSymbols(StreamRef Data) {
return visitUnknown(ModuleSubstreamKind::Symbols, Data);
diff --git a/llvm/lib/DebugInfo/CodeView/StreamReader.cpp b/llvm/lib/DebugInfo/CodeView/StreamReader.cpp
deleted file mode 100644
index 64e45487322..00000000000
--- a/llvm/lib/DebugInfo/CodeView/StreamReader.cpp
+++ /dev/null
@@ -1,93 +0,0 @@
-//===- 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/CodeView/StreamReader.h"
-
-#include "llvm/DebugInfo/CodeView/CodeViewError.h"
-#include "llvm/DebugInfo/CodeView/StreamRef.h"
-
-using namespace llvm;
-using namespace llvm::codeview;
-
-StreamReader::StreamReader(StreamRef 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(StreamRef &Ref) {
- return readStreamRef(Ref, bytesRemaining());
-}
-
-Error StreamReader::readStreamRef(StreamRef &Ref, uint32_t Length) {
- if (bytesRemaining() < Length)
- return make_error<CodeViewError>(cv_error_code::insufficient_buffer);
- Ref = Stream.slice(Offset, Length);
- Offset += Length;
- return Error::success();
-}
diff --git a/llvm/lib/DebugInfo/CodeView/StreamWriter.cpp b/llvm/lib/DebugInfo/CodeView/StreamWriter.cpp
deleted file mode 100644
index 90eafbb9c83..00000000000
--- a/llvm/lib/DebugInfo/CodeView/StreamWriter.cpp
+++ /dev/null
@@ -1,78 +0,0 @@
-//===- StreamWrite.cpp - Writes bytes and objects to 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/CodeView/StreamWriter.h"
-
-#include "llvm/DebugInfo/CodeView/CodeViewError.h"
-#include "llvm/DebugInfo/CodeView/StreamReader.h"
-#include "llvm/DebugInfo/CodeView/StreamRef.h"
-
-using namespace llvm;
-using namespace llvm::codeview;
-
-StreamWriter::StreamWriter(StreamRef S) : Stream(S), Offset(0) {}
-
-Error StreamWriter::writeBytes(ArrayRef<uint8_t> Buffer) {
- if (auto EC = Stream.writeBytes(Offset, Buffer))
- return EC;
- Offset += Buffer.size();
- return Error::success();
-}
-
-Error StreamWriter::writeInteger(uint16_t Int) {
- return writeObject(support::ulittle16_t(Int));
-}
-
-Error StreamWriter::writeInteger(uint32_t Int) {
- return writeObject(support::ulittle32_t(Int));
-}
-
-Error StreamWriter::writeZeroString(StringRef Str) {
- if (auto EC = writeFixedString(Str))
- return EC;
- if (auto EC = writeObject('\0'))
- return EC;
-
- return Error::success();
-}
-
-Error StreamWriter::writeFixedString(StringRef Str) {
- ArrayRef<uint8_t> Bytes(Str.bytes_begin(), Str.bytes_end());
- if (auto EC = Stream.writeBytes(Offset, Bytes))
- return EC;
-
- Offset += Str.size();
- return Error::success();
-}
-
-Error StreamWriter::writeStreamRef(StreamRef Ref) {
- if (auto EC = writeStreamRef(Ref, Ref.getLength()))
- return EC;
- // Don't increment Offset here, it is done by the overloaded call to
- // writeStreamRef.
- return Error::success();
-}
-
-Error StreamWriter::writeStreamRef(StreamRef Ref, uint32_t Length) {
- Ref = Ref.slice(0, Length);
-
- StreamReader SrcReader(Ref);
- // This is a bit tricky. If we just call readBytes, we are requiring that it
- // return us the entire stream as a contiguous buffer. For large streams this
- // will allocate a huge amount of space from the pool. Instead, iterate over
- // each contiguous chunk until we've consumed the entire stream.
- 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/llvm/lib/DebugInfo/CodeView/TypeDumper.cpp b/llvm/lib/DebugInfo/CodeView/TypeDumper.cpp
index 345e2a49888..cf5adb6b75e 100644
--- a/llvm/lib/DebugInfo/CodeView/TypeDumper.cpp
+++ b/llvm/lib/DebugInfo/CodeView/TypeDumper.cpp
@@ -12,7 +12,7 @@
#include "llvm/DebugInfo/CodeView/CVTypeVisitor.h"
#include "llvm/DebugInfo/CodeView/TypeIndex.h"
#include "llvm/DebugInfo/CodeView/TypeRecord.h"
-#include "llvm/DebugInfo/CodeView/ByteStream.h"
+#include "llvm/DebugInfo/Msf/ByteStream.h"
#include "llvm/Support/ScopedPrinter.h"
using namespace llvm;
@@ -681,9 +681,9 @@ Error CVTypeDumper::dump(const CVTypeArray &Types) {
}
Error CVTypeDumper::dump(ArrayRef<uint8_t> Data) {
- ByteStream<> Stream(Data);
+ msf::ByteStream<> Stream(Data);
CVTypeArray Types;
- StreamReader Reader(Stream);
+ msf::StreamReader Reader(Stream);
if (auto EC = Reader.readArray(Types, Reader.getLength()))
return EC;
diff --git a/llvm/lib/DebugInfo/CodeView/TypeStreamMerger.cpp b/llvm/lib/DebugInfo/CodeView/TypeStreamMerger.cpp
index ebfda2462be..8c2bc072cd9 100644
--- a/llvm/lib/DebugInfo/CodeView/TypeStreamMerger.cpp
+++ b/llvm/lib/DebugInfo/CodeView/TypeStreamMerger.cpp
@@ -12,7 +12,6 @@
#include "llvm/ADT/StringExtras.h"
#include "llvm/DebugInfo/CodeView/CVTypeVisitor.h"
#include "llvm/DebugInfo/CodeView/FieldListRecordBuilder.h"
-#include "llvm/DebugInfo/CodeView/StreamRef.h"
#include "llvm/DebugInfo/CodeView/TypeIndex.h"
#include "llvm/DebugInfo/CodeView/TypeRecord.h"
#include "llvm/DebugInfo/CodeView/TypeVisitorCallbacks.h"
OpenPOWER on IntegriCloud