Add lvxl
[oota-llvm.git] / include / llvm / System / Memory.h
1 //===- llvm/System/Memory.h - Memory Support --------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by Reid Spencer and is distributed under the
6 // University of Illinois Open Source License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file declares the llvm::sys::Memory class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_SYSTEM_MEMORY_H
15 #define LLVM_SYSTEM_MEMORY_H
16
17 namespace llvm {
18 namespace sys {
19
20   /// This class encapsulates the notion of a memory block which has an address
21   /// and a size. It is used by the Memory class (a friend) as the result of
22   /// various memory allocation operations.
23   /// @see Memory
24   /// @brief Memory block abstraction.
25   class MemoryBlock {
26   public:
27     void* base() const { return Address; }
28     unsigned size() const { return Size; }
29   private:
30     void * Address;   ///< Address of first byte of memory area
31     unsigned Size;    ///< Size, in bytes of the memory area
32     friend class Memory;
33   };
34
35   /// This class provides various memory handling functions that manipulate
36   /// MemoryBlock instances.
37   /// @since 1.4
38   /// @brief An abstraction for memory operations.
39   class Memory {
40     /// @name Functions
41     /// @{
42     public:
43       /// This method allocates a block of Read/Write/Execute memory that is
44       /// suitable for executing dynamically generated code (e.g. JIT). An
45       /// attempt to allocate \p NumBytes bytes of virtual memory is made.
46       /// \p NearBlock may point to an existing allocation in which case
47       /// an attempt is made to allocate more memory near the existing block.
48       /// @throws std::string if an error occurred.
49       /// @brief Allocate Read/Write/Execute memory.
50       static MemoryBlock AllocateRWX(unsigned NumBytes, const MemoryBlock* NearBlock);
51
52       /// This method releases a block of Read/Write/Execute memory that was
53       /// allocated with the AllocateRWX method. It should not be used to
54       /// release any memory block allocated any other way.
55       /// @throws std::string if an error occurred.
56       /// @brief Release Read/Write/Execute memory.
57       static void ReleaseRWX(MemoryBlock& block);
58
59     /// @}
60   };
61 }
62 }
63
64
65 #endif