2003-09-18 18:16:32 +02:00
|
|
|
//===-- llvm/ModuleProvider.h - Interface for module providers --*- C++ -*-===//
|
2005-04-21 22:19:05 +02:00
|
|
|
//
|
2003-10-20 22:19:47 +02: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.
|
2005-04-21 22:19:05 +02:00
|
|
|
//
|
2003-10-20 22:19:47 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
2003-09-18 18:16:32 +02:00
|
|
|
//
|
2003-09-30 19:53:30 +02: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 18:16:32 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef MODULEPROVIDER_H
|
|
|
|
#define MODULEPROVIDER_H
|
|
|
|
|
2003-11-11 23:41:34 +01:00
|
|
|
namespace llvm {
|
|
|
|
|
2003-09-18 18:16:32 +02:00
|
|
|
class Function;
|
|
|
|
class Module;
|
|
|
|
|
2003-10-04 22:14:59 +02:00
|
|
|
class ModuleProvider {
|
2003-09-18 18:16:32 +02:00
|
|
|
protected:
|
2003-09-23 01:35:23 +02:00
|
|
|
Module *TheModule;
|
2003-10-04 22:14:59 +02:00
|
|
|
ModuleProvider();
|
2003-09-18 18:16:32 +02:00
|
|
|
|
|
|
|
public:
|
2003-10-04 22:14:59 +02:00
|
|
|
virtual ~ModuleProvider();
|
2003-09-18 18:16:32 +02:00
|
|
|
|
2003-09-23 01:35:23 +02:00
|
|
|
/// getModule - returns the module this provider is encapsulating.
|
2003-09-18 18:16:32 +02:00
|
|
|
///
|
2003-09-23 01:35:23 +02:00
|
|
|
Module* getModule() { return TheModule; }
|
2003-09-18 18:16:32 +02:00
|
|
|
|
2004-02-01 01:32:48 +01: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 18:16:32 +02:00
|
|
|
///
|
|
|
|
virtual void materializeFunction(Function *F) = 0;
|
|
|
|
|
|
|
|
/// materializeModule - make sure the entire Module has been completely read.
|
2004-02-01 01:32:48 +01:00
|
|
|
/// Note that this can throw an exception if the module is corrupt!
|
2003-09-18 18:16:32 +02:00
|
|
|
///
|
2004-01-21 23:54:10 +01:00
|
|
|
virtual Module* materializeModule() = 0;
|
2003-09-18 18:16:32 +02:00
|
|
|
|
|
|
|
/// releaseModule - no longer delete the Module* when provider is destroyed.
|
2004-02-01 01:32:48 +01:00
|
|
|
/// Note that this can throw an exception if the module is corrupt!
|
2003-09-18 18:16:32 +02:00
|
|
|
///
|
2005-04-21 22:19:05 +02:00
|
|
|
virtual Module* releaseModule() {
|
2003-09-23 01:35:23 +02:00
|
|
|
// Since we're losing control of this Module, we must hand it back complete
|
|
|
|
materializeModule();
|
2005-04-21 22:19:05 +02:00
|
|
|
Module *tempM = TheModule;
|
|
|
|
TheModule = 0;
|
|
|
|
return tempM;
|
2003-09-23 01:35:23 +02:00
|
|
|
}
|
2003-09-18 18:16:32 +02:00
|
|
|
};
|
|
|
|
|
2003-12-30 03:44:04 +01: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 23:54:10 +01:00
|
|
|
Module* materializeModule() { return TheModule; }
|
2003-12-30 03:44:04 +01:00
|
|
|
};
|
|
|
|
|
2003-11-11 23:41:34 +01:00
|
|
|
} // End llvm namespace
|
|
|
|
|
2003-09-18 18:16:32 +02:00
|
|
|
#endif
|