Added an abstract superclass, MCDisassembler, for
[oota-llvm.git] / lib / Support / MemoryObject.cpp
1 //===- MemoryObject.cpp - Abstract memory interface -------------*- 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/MemoryObject.h"
11
12 namespace llvm {
13   
14   MemoryObject::~MemoryObject() {
15   }
16   
17   int MemoryObject::readBytes(uint64_t address,
18                               uint64_t size,
19                               uint8_t* buf,
20                               uint64_t* copied) const {
21     uint64_t current = address;
22     uint64_t limit = getBase() + getExtent();
23     
24     while (current - address < size && current < limit) {
25       if (readByte(current, &buf[(current - address)]))
26         return -1;
27       
28       current++;
29     }
30     
31     if (copied)
32       *copied = current - address;
33     
34     return 0;
35   }
36
37 }