2016-04-29 19:22:58 +02:00
|
|
|
//===- StreamReader.h - Reads bytes and objects from a stream ---*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2016-05-25 22:37:03 +02:00
|
|
|
#ifndef LLVM_DEBUGINFO_CODEVIEW_STREAMREADER_H
|
|
|
|
#define LLVM_DEBUGINFO_CODEVIEW_STREAMREADER_H
|
2016-04-29 19:22:58 +02:00
|
|
|
|
2016-04-29 19:28:47 +02:00
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
2016-05-25 22:37:03 +02:00
|
|
|
#include "llvm/DebugInfo/CodeView/StreamInterface.h"
|
2016-04-29 19:22:58 +02:00
|
|
|
#include "llvm/Support/Endian.h"
|
2016-05-06 22:51:57 +02:00
|
|
|
#include "llvm/Support/Error.h"
|
2016-04-29 19:22:58 +02:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
namespace llvm {
|
2016-05-25 22:37:03 +02:00
|
|
|
namespace codeview {
|
|
|
|
|
2016-04-29 19:22:58 +02:00
|
|
|
class StreamReader {
|
|
|
|
public:
|
|
|
|
StreamReader(const StreamInterface &S);
|
|
|
|
|
2016-05-06 22:51:57 +02:00
|
|
|
Error readBytes(MutableArrayRef<uint8_t> Buffer);
|
|
|
|
Error readInteger(uint32_t &Dest);
|
|
|
|
Error readZeroString(std::string &Dest);
|
2016-04-29 19:22:58 +02:00
|
|
|
|
2016-05-06 22:51:57 +02:00
|
|
|
template <typename T> Error readObject(T *Dest) {
|
2016-04-29 19:22:58 +02:00
|
|
|
MutableArrayRef<uint8_t> Buffer(reinterpret_cast<uint8_t *>(Dest),
|
|
|
|
sizeof(T));
|
|
|
|
return readBytes(Buffer);
|
|
|
|
}
|
|
|
|
|
2016-05-06 22:51:57 +02:00
|
|
|
template <typename T> Error readArray(MutableArrayRef<T> Array) {
|
2016-05-25 22:37:03 +02:00
|
|
|
MutableArrayRef<uint8_t> Casted(reinterpret_cast<uint8_t *>(Array.data()),
|
|
|
|
Array.size() * sizeof(T));
|
2016-05-02 20:09:14 +02:00
|
|
|
return readBytes(Casted);
|
|
|
|
}
|
|
|
|
|
2016-05-06 22:51:57 +02:00
|
|
|
Error getArrayRef(ArrayRef<uint8_t> &Array, uint32_t Length);
|
2016-05-03 02:28:21 +02:00
|
|
|
|
2016-04-29 19:22:58 +02:00
|
|
|
void setOffset(uint32_t Off) { Offset = Off; }
|
|
|
|
uint32_t getOffset() const { return Offset; }
|
|
|
|
uint32_t getLength() const { return Stream.getLength(); }
|
|
|
|
uint32_t bytesRemaining() const { return getLength() - getOffset(); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
const StreamInterface &Stream;
|
|
|
|
uint32_t Offset;
|
|
|
|
};
|
2016-05-25 22:37:03 +02:00
|
|
|
} // namespace codeview
|
|
|
|
} // namespace llvm
|
2016-04-29 19:22:58 +02:00
|
|
|
|
2016-05-25 22:37:03 +02:00
|
|
|
#endif // LLVM_DEBUGINFO_CODEVIEW_STREAMREADER_H
|