1198090Srdivacky//===- MemoryObject.h - Abstract memory interface ---------------*- C++ -*-===//
2198090Srdivacky//
3198090Srdivacky//                     The LLVM Compiler Infrastructure
4198090Srdivacky//
5198090Srdivacky// This file is distributed under the University of Illinois Open Source
6198090Srdivacky// License. See LICENSE.TXT for details.
7198090Srdivacky//
8198090Srdivacky//===----------------------------------------------------------------------===//
9198090Srdivacky
10252723Sdim#ifndef LLVM_SUPPORT_MEMORYOBJECT_H
11252723Sdim#define LLVM_SUPPORT_MEMORYOBJECT_H
12198090Srdivacky
13218893Sdim#include "llvm/Support/DataTypes.h"
14198090Srdivacky
15198090Srdivackynamespace llvm {
16198090Srdivacky
17198090Srdivacky/// MemoryObject - Abstract base class for contiguous addressable memory.
18198090Srdivacky///   Necessary for cases in which the memory is in another process, in a
19198090Srdivacky///   file, or on a remote machine.
20198090Srdivacky///   All size and offset parameters are uint64_ts, to allow 32-bit processes
21198090Srdivacky///   access to 64-bit address spaces.
22198090Srdivackyclass MemoryObject {
23198090Srdivackypublic:
24198090Srdivacky  /// Destructor      - Override as necessary.
25198090Srdivacky  virtual ~MemoryObject();
26235633Sdim
27198090Srdivacky  /// getBase         - Returns the lowest valid address in the region.
28198090Srdivacky  ///
29198090Srdivacky  /// @result         - The lowest valid address.
30198090Srdivacky  virtual uint64_t getBase() const = 0;
31235633Sdim
32198090Srdivacky  /// getExtent       - Returns the size of the region in bytes.  (The region is
33235633Sdim  ///                   contiguous, so the highest valid address of the region
34198090Srdivacky  ///                   is getBase() + getExtent() - 1).
35198090Srdivacky  ///
36198090Srdivacky  /// @result         - The size of the region.
37198090Srdivacky  virtual uint64_t getExtent() const = 0;
38235633Sdim
39198090Srdivacky  /// readByte        - Tries to read a single byte from the region.
40198090Srdivacky  ///
41198090Srdivacky  /// @param address  - The address of the byte, in the same space as getBase().
42198090Srdivacky  /// @param ptr      - A pointer to a byte to be filled in.  Must be non-NULL.
43198090Srdivacky  /// @result         - 0 if successful; -1 if not.  Failure may be due to a
44198090Srdivacky  ///                   bounds violation or an implementation-specific error.
45263509Sdim  virtual int readByte(uint64_t address, uint8_t *ptr) const = 0;
46235633Sdim
47198090Srdivacky  /// readBytes       - Tries to read a contiguous range of bytes from the
48198090Srdivacky  ///                   region, up to the end of the region.
49198090Srdivacky  ///                   You should override this function if there is a quicker
50198090Srdivacky  ///                   way than going back and forth with individual bytes.
51198090Srdivacky  ///
52198090Srdivacky  /// @param address  - The address of the first byte, in the same space as
53198090Srdivacky  ///                   getBase().
54263509Sdim  /// @param size     - The number of bytes to copy.
55198090Srdivacky  /// @param buf      - A pointer to a buffer to be filled in.  Must be non-NULL
56198090Srdivacky  ///                   and large enough to hold size bytes.
57198090Srdivacky  /// @result         - 0 if successful; -1 if not.  Failure may be due to a
58198090Srdivacky  ///                   bounds violation or an implementation-specific error.
59263509Sdim  virtual int readBytes(uint64_t address, uint64_t size, uint8_t *buf) const;
60198090Srdivacky};
61198090Srdivacky
62198090Srdivacky}
63198090Srdivacky
64198090Srdivacky#endif
65