2003-09-18 16:16:32 +00:00
|
|
|
//===-- llvm/ModuleProvider.h - Interface for module providers --*- C++ -*-===//
|
2003-10-20 20:19:47 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file was developed by the LLVM research group and is distributed under
|
|
|
|
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
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
|
|
|
|
|
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
|
|
|
|
2004-02-01 00:32:48 +00:00
|
|
|
/// materializeFunction - make sure the given function is fully read. Note
|
|
|
|
/// that this can throw an exception if the module is corrupt!
|
2003-09-18 16:16:32 +00:00
|
|
|
///
|
|
|
|
virtual void materializeFunction(Function *F) = 0;
|
|
|
|
|
|
|
|
/// materializeModule - make sure the entire Module has been completely read.
|
2004-02-01 00:32:48 +00:00
|
|
|
/// Note that this can throw an exception if the module is corrupt!
|
2003-09-18 16:16:32 +00:00
|
|
|
///
|
2004-01-21 22:54:10 +00:00
|
|
|
virtual Module* materializeModule() = 0;
|
2003-09-18 16:16:32 +00:00
|
|
|
|
|
|
|
/// releaseModule - no longer delete the Module* when provider is destroyed.
|
2004-02-01 00:32:48 +00:00
|
|
|
/// Note that this can throw an exception if the module is corrupt!
|
2003-09-18 16:16:32 +00:00
|
|
|
///
|
2003-09-22 23:35:23 +00:00
|
|
|
virtual Module* releaseModule() {
|
|
|
|
// Since we're losing control of this Module, we must hand it back complete
|
|
|
|
materializeModule();
|
|
|
|
Module *tempM = TheModule;
|
|
|
|
TheModule = 0;
|
|
|
|
return tempM;
|
|
|
|
}
|
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 {
|
|
|
|
ExistingModuleProvider(Module *M) {
|
|
|
|
TheModule = M;
|
|
|
|
}
|
|
|
|
void materializeFunction(Function *F) {}
|
2004-01-21 22:54:10 +00:00
|
|
|
Module* materializeModule() { 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
|