ObjectCache.h revision 251662
1//===-- ObjectCache.h - Class definition for the ObjectCache -----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_OBJECTCACHE_H 11#define LLVM_LIB_EXECUTIONENGINE_OBJECTCACHE_H 12 13#include "llvm/Support/MemoryBuffer.h" 14 15namespace llvm { 16 17class Module; 18 19/// This is the base ObjectCache type which can be provided to an 20/// ExecutionEngine for the purpose of avoiding compilation for Modules that 21/// have already been compiled and an object file is available. 22class ObjectCache { 23public: 24 ObjectCache() { } 25 26 virtual ~ObjectCache() { } 27 28 /// notifyObjectCompiled - Provides a pointer to compiled code for Module M. 29 virtual void notifyObjectCompiled(const Module *M, const MemoryBuffer *Obj) = 0; 30 31 /// getObjectCopy - Returns a pointer to a newly allocated MemoryBuffer that 32 /// contains the object which corresponds with Module M, or 0 if an object is 33 /// not available. The caller owns the MemoryBuffer returned by this function. 34 MemoryBuffer* getObjectCopy(const Module* M) { 35 const MemoryBuffer* Obj = getObject(M); 36 if (Obj) 37 return MemoryBuffer::getMemBufferCopy(Obj->getBuffer()); 38 else 39 return 0; 40 } 41 42protected: 43 /// getObject - Returns a pointer to a MemoryBuffer that contains an object 44 /// that corresponds with Module M, or 0 if an object is not available. 45 /// The pointer returned by this function is not suitable for loading because 46 /// the memory is read-only and owned by the ObjectCache. To retrieve an 47 /// owning pointer to a MemoryBuffer (which is suitable for calling 48 /// RuntimeDyld::loadObject() with) use getObjectCopy() instead. 49 virtual const MemoryBuffer* getObject(const Module* M) = 0; 50}; 51 52} 53 54#endif 55