blob: e035ed1d2ef31fd69a85b3e454a0647eafdca46f [file] [log] [blame]
Ahmed Bougachaef993562013-05-24 01:07:04 +00001//===- lib/Support/StringRefMemoryObject.cpp --------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "llvm/Support/StringRefMemoryObject.h"
11
12using namespace llvm;
13
14int StringRefMemoryObject::readByte(uint64_t Addr, uint8_t *Byte) const {
15 if (Addr >= Base + getExtent() || Addr < Base)
16 return -1;
17 *Byte = Bytes[Addr - Base];
18 return 0;
19}
20
21int StringRefMemoryObject::readBytes(uint64_t Addr,
22 uint64_t Size,
Benjamin Kramer49a6a8d2013-05-24 10:54:58 +000023 uint8_t *Buf) const {
Ahmed Bougachaef993562013-05-24 01:07:04 +000024 uint64_t Offset = Addr - Base;
Benjamin Kramer49a6a8d2013-05-24 10:54:58 +000025 if (Addr >= Base + getExtent() || Offset + Size > getExtent() || Addr < Base)
26 return -1;
Ahmed Bougachaef993562013-05-24 01:07:04 +000027 memcpy(Buf, Bytes.data() + Offset, Size);
Ahmed Bougachaef993562013-05-24 01:07:04 +000028 return 0;
29}