summaryrefslogtreecommitdiffstats
path: root/llvm/lib/DebugInfo/PDB/Raw/StreamReader.cpp
blob: ed9c9d400afc19155cba54d9fdb2dc2dfc719cdd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//===- 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/PDB/Raw/StreamReader.h"
#include "llvm/DebugInfo/PDB/Raw/RawError.h"

using namespace llvm;
using namespace llvm::pdb;

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();
}
OpenPOWER on IntegriCloud