mirror of
https://github.com/RPCSX/llvm.git
synced 2025-04-16 15:10:53 +00:00

We have need to reuse this functionality, including making additional generic stream types that are smarter about how and when they copy memory versus referencing the original memory. So all of these structures belong in the common library rather than being pdb specific. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@270751 91177308-0d34-0410-b5e6-96231b3b80d8
52 lines
1.3 KiB
C++
52 lines
1.3 KiB
C++
//===- 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"
|
|
|
|
using namespace llvm;
|
|
using namespace llvm::codeview;
|
|
|
|
StreamReader::StreamReader(const StreamInterface &S) : Stream(S), Offset(0) {}
|
|
|
|
Error StreamReader::readBytes(MutableArrayRef<uint8_t> Buffer) {
|
|
if (auto EC = Stream.readBytes(Offset, Buffer))
|
|
return EC;
|
|
Offset += Buffer.size();
|
|
return Error::success();
|
|
}
|
|
|
|
Error StreamReader::readInteger(uint32_t &Dest) {
|
|
support::ulittle32_t P;
|
|
if (auto EC = readObject(&P))
|
|
return EC;
|
|
Dest = P;
|
|
return Error::success();
|
|
}
|
|
|
|
Error StreamReader::readZeroString(std::string &Dest) {
|
|
Dest.clear();
|
|
char C;
|
|
do {
|
|
if (auto EC = readObject(&C))
|
|
return EC;
|
|
if (C != '\0')
|
|
Dest.push_back(C);
|
|
} while (C != '\0');
|
|
return Error::success();
|
|
}
|
|
|
|
Error StreamReader::getArrayRef(ArrayRef<uint8_t> &Array, uint32_t Length) {
|
|
if (auto EC = Stream.getArrayRef(Offset, Array, Length))
|
|
return EC;
|
|
Offset += Length;
|
|
return Error::success();
|
|
}
|