6208772532c3fe8065c218423b301ac3087080ff
[oota-llvm.git] / include / llvm / Support / MemoryObject.h
1 //===- MemoryObject.h - 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 #ifndef LLVM_SUPPORT_MEMORYOBJECT_H
11 #define LLVM_SUPPORT_MEMORYOBJECT_H
12
13 #include "llvm/Support/DataTypes.h"
14
15 namespace llvm {
16
17 /// Abstract base class for contiguous addressable memory. Necessary for cases
18 /// in which the memory is in another process, in a file, or on a remote
19 /// machine. All size and offset parameters are uint64_ts, to allow 32-bit
20 /// processes access to 64-bit address spaces.
21 class MemoryObject {
22 public:
23   virtual ~MemoryObject();
24
25   /// Returns the size of the region in bytes.  (The region is contiguous, so
26   /// the highest valid address of the region is getExtent() - 1).
27   ///
28   /// @result         - The size of the region.
29   virtual uint64_t getExtent() const = 0;
30
31   /// Tries to read a contiguous range of bytes from the region, up to the end
32   /// of the region. You should override this function if there is a quicker way
33   /// than going back and forth with individual bytes.
34   ///
35   /// @param address  - The address of the first byte, in the same space as
36   ///                   getBase().
37   /// @param size     - The number of bytes to copy.
38   /// @param buf      - A pointer to a buffer to be filled in.  Must be non-NULL
39   ///                   and large enough to hold size bytes.
40   /// @result         - 0 if successful; -1 if not.  Failure may be due to a
41   ///                   bounds violation or an implementation-specific error.
42   virtual int readBytes(uint64_t address, uint64_t size,
43                         uint8_t *buf) const = 0;
44 };
45
46 }
47
48 #endif