Ahmed Bougacha | ef99356 | 2013-05-24 01:07:04 +0000 | [diff] [blame^] | 1 | //===- 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 | |
| 12 | using namespace llvm; |
| 13 | |
| 14 | int 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 | |
| 21 | int StringRefMemoryObject::readBytes(uint64_t Addr, |
| 22 | uint64_t Size, |
| 23 | uint8_t *Buf, |
| 24 | uint64_t *Copied) const { |
| 25 | if (Addr >= Base + getExtent() || Addr < Base) |
| 26 | return -1; |
| 27 | uint64_t Offset = Addr - Base; |
| 28 | if (Size > getExtent() - Offset) |
| 29 | Size = getExtent() - Offset; |
| 30 | memcpy(Buf, Bytes.data() + Offset, Size); |
| 31 | if (Copied) |
| 32 | *Copied = Size; |
| 33 | return 0; |
| 34 | } |