2003-09-18 16:16:32 +00:00
|
|
|
//===-- llvm/ModuleProvider.h - Interface for module providers --*- C++ -*-===//
|
2005-04-21 20:19:05 +00:00
|
|
|
//
|
2003-10-20 20:19:47 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 19:59:42 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 20:19:05 +00:00
|
|
|
//
|
2003-10-20 20:19:47 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2003-09-18 16:16:32 +00:00
|
|
|
//
|
2003-09-30 17:53:30 +00:00
|
|
|
// This file provides an abstract interface for loading a module from some
|
|
|
|
// place. This interface allows incremental or random access loading of
|
|
|
|
// functions from the file. This is useful for applications like JIT compilers
|
|
|
|
// or interprocedural optimizers that do not need the entire program in memory
|
|
|
|
// at the same time.
|
2003-09-18 16:16:32 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef MODULEPROVIDER_H
|
|
|
|
#define MODULEPROVIDER_H
|
|
|
|
|
2006-07-06 21:35:01 +00:00
|
|
|
#include <string>
|
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
namespace llvm {
|
|
|
|
|
2003-09-18 16:16:32 +00:00
|
|
|
class Function;
|
|
|
|
class Module;
|
|
|
|
|
2003-10-04 20:14:59 +00:00
|
|
|
class ModuleProvider {
|
2003-09-18 16:16:32 +00:00
|
|
|
protected:
|
2003-09-22 23:35:23 +00:00
|
|
|
Module *TheModule;
|
2003-10-04 20:14:59 +00:00
|
|
|
ModuleProvider();
|
2003-09-18 16:16:32 +00:00
|
|
|
|
|
|
|
public:
|
2003-10-04 20:14:59 +00:00
|
|
|
virtual ~ModuleProvider();
|
2003-09-18 16:16:32 +00:00
|
|
|
|
2003-09-22 23:35:23 +00:00
|
|
|
/// getModule - returns the module this provider is encapsulating.
|
2003-09-18 16:16:32 +00:00
|
|
|
///
|
2003-09-22 23:35:23 +00:00
|
|
|
Module* getModule() { return TheModule; }
|
2003-09-18 16:16:32 +00:00
|
|
|
|
2006-07-06 21:35:01 +00:00
|
|
|
/// materializeFunction - make sure the given function is fully read. If the
|
|
|
|
/// module is corrupt, this returns true and fills in the optional string
|
|
|
|
/// with information about the problem. If successful, this returns false.
|
2003-09-18 16:16:32 +00:00
|
|
|
///
|
2006-07-06 21:35:01 +00:00
|
|
|
virtual bool materializeFunction(Function *F, std::string *ErrInfo = 0) = 0;
|
2003-09-18 16:16:32 +00:00
|
|
|
|
2007-03-29 18:30:26 +00:00
|
|
|
/// dematerializeFunction - If the given function is read in, and if the
|
|
|
|
/// module provider supports it, release the memory for the function, and set
|
|
|
|
/// it up to be materialized lazily. If the provider doesn't support this
|
|
|
|
/// capability, this method is a noop.
|
|
|
|
///
|
2008-05-19 20:15:12 +00:00
|
|
|
virtual void dematerializeFunction(Function *) {}
|
2007-03-29 18:30:26 +00:00
|
|
|
|
2003-09-18 16:16:32 +00:00
|
|
|
/// materializeModule - make sure the entire Module has been completely read.
|
2006-07-06 21:35:01 +00:00
|
|
|
/// On error, return null and fill in the error string if specified.
|
2003-09-18 16:16:32 +00:00
|
|
|
///
|
2006-07-06 21:35:01 +00:00
|
|
|
virtual Module* materializeModule(std::string *ErrInfo = 0) = 0;
|
2003-09-18 16:16:32 +00:00
|
|
|
|
|
|
|
/// releaseModule - no longer delete the Module* when provider is destroyed.
|
2006-07-06 21:35:01 +00:00
|
|
|
/// On error, return null and fill in the error string if specified.
|
2003-09-18 16:16:32 +00:00
|
|
|
///
|
2006-07-06 21:35:01 +00:00
|
|
|
virtual Module* releaseModule(std::string *ErrInfo = 0) {
|
2003-09-22 23:35:23 +00:00
|
|
|
// Since we're losing control of this Module, we must hand it back complete
|
2006-07-07 00:01:01 +00:00
|
|
|
if (!materializeModule(ErrInfo))
|
2006-07-06 21:35:01 +00:00
|
|
|
return 0;
|
2005-04-21 20:19:05 +00:00
|
|
|
Module *tempM = TheModule;
|
|
|
|
TheModule = 0;
|
|
|
|
return tempM;
|
2003-09-22 23:35:23 +00:00
|
|
|
}
|
2003-09-18 16:16:32 +00:00
|
|
|
};
|
|
|
|
|
2003-12-30 02:44:04 +00:00
|
|
|
|
|
|
|
/// ExistingModuleProvider - Allow conversion from a fully materialized Module
|
|
|
|
/// into a ModuleProvider, allowing code that expects a ModuleProvider to work
|
|
|
|
/// if we just have a Module. Note that the ModuleProvider takes ownership of
|
|
|
|
/// the Module specified.
|
|
|
|
struct ExistingModuleProvider : public ModuleProvider {
|
2008-03-25 22:06:05 +00:00
|
|
|
explicit ExistingModuleProvider(Module *M) {
|
2003-12-30 02:44:04 +00:00
|
|
|
TheModule = M;
|
|
|
|
}
|
2008-05-19 20:15:12 +00:00
|
|
|
bool materializeFunction(Function *, std::string * = 0) {
|
2006-07-06 21:35:01 +00:00
|
|
|
return false;
|
|
|
|
}
|
2008-05-19 20:15:12 +00:00
|
|
|
Module* materializeModule(std::string * = 0) { return TheModule; }
|
2003-12-30 02:44:04 +00:00
|
|
|
};
|
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
} // End llvm namespace
|
|
|
|
|
2003-09-18 16:16:32 +00:00
|
|
|
#endif
|