LLVM API Documentation

StringRefMemoryObject.cpp
Go to the documentation of this file.
00001 //===- lib/Support/StringRefMemoryObject.cpp --------------------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 
00010 #include "llvm/Support/StringRefMemoryObject.h"
00011 
00012 using namespace llvm;
00013 
00014 int StringRefMemoryObject::readByte(uint64_t Addr, uint8_t *Byte) const {
00015   if (Addr >= Base + getExtent() || Addr < Base)
00016     return -1;
00017   *Byte = Bytes[Addr - Base];
00018   return 0;
00019 }
00020 
00021 int StringRefMemoryObject::readBytes(uint64_t Addr,
00022                                      uint64_t Size,
00023                                      uint8_t *Buf) const {
00024   uint64_t Offset = Addr - Base;
00025   if (Addr >= Base + getExtent() || Offset + Size > getExtent() || Addr < Base)
00026     return -1;
00027   memcpy(Buf, Bytes.data() + Offset, Size);
00028   return 0;
00029 }