• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===-- MCJITMemoryManager.h - Definition for the Memory Manager ---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_LIB_EXECUTIONENGINE_MCJITMEMORYMANAGER_H
11 #define LLVM_LIB_EXECUTIONENGINE_MCJITMEMORYMANAGER_H
12 
13 #include "llvm/Module.h"
14 #include "llvm/ExecutionEngine/JITMemoryManager.h"
15 #include "llvm/ExecutionEngine/RuntimeDyld.h"
16 #include <assert.h>
17 
18 namespace llvm {
19 
20 // The MCJIT memory manager is a layer between the standard JITMemoryManager
21 // and the RuntimeDyld interface that maps objects, by name, onto their
22 // matching LLVM IR counterparts in the module(s) being compiled.
23 class MCJITMemoryManager : public RTDyldMemoryManager {
24   virtual void anchor();
25   JITMemoryManager *JMM;
26 
27   // FIXME: Multiple modules.
28   Module *M;
29 public:
MCJITMemoryManager(JITMemoryManager * jmm,Module * m)30   MCJITMemoryManager(JITMemoryManager *jmm, Module *m) :
31     JMM(jmm?jmm:JITMemoryManager::CreateDefaultMemManager()), M(m) {}
32   // We own the JMM, so make sure to delete it.
~MCJITMemoryManager()33   ~MCJITMemoryManager() { delete JMM; }
34 
allocateDataSection(uintptr_t Size,unsigned Alignment,unsigned SectionID)35   uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment,
36                                unsigned SectionID) {
37     return JMM->allocateSpace(Size, Alignment);
38   }
39 
allocateCodeSection(uintptr_t Size,unsigned Alignment,unsigned SectionID)40   uint8_t *allocateCodeSection(uintptr_t Size, unsigned Alignment,
41                                unsigned SectionID) {
42     return JMM->allocateSpace(Size, Alignment);
43   }
44 
45   virtual void *getPointerToNamedFunction(const std::string &Name,
46                                           bool AbortOnFailure = true) {
47     return JMM->getPointerToNamedFunction(Name, AbortOnFailure);
48   }
49 
50 };
51 
52 } // End llvm namespace
53 
54 #endif
55