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
|
|
|
|
//
|
2007-12-29 20:59:42 +01:00
|
|
|
// This file 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
|
|
|
|
|
2006-07-06 23:35:01 +02:00
|
|
|
#include <string>
|
|
|
|
|
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
|
|
|
|
2006-07-06 23:35:01 +02: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 18:16:32 +02:00
|
|
|
///
|
2006-07-06 23:35:01 +02:00
|
|
|
virtual bool materializeFunction(Function *F, std::string *ErrInfo = 0) = 0;
|
2003-09-18 18:16:32 +02:00
|
|
|
|
2007-03-29 20:30:26 +02: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 22:15:12 +02:00
|
|
|
virtual void dematerializeFunction(Function *) {}
|
2007-03-29 20:30:26 +02:00
|
|
|
|
2003-09-18 18:16:32 +02:00
|
|
|
/// materializeModule - make sure the entire Module has been completely read.
|
2006-07-06 23:35:01 +02:00
|
|
|
/// On error, return null and fill in the error string if specified.
|
2003-09-18 18:16:32 +02:00
|
|
|
///
|
2006-07-06 23:35:01 +02:00
|
|
|
virtual Module* materializeModule(std::string *ErrInfo = 0) = 0;
|
2003-09-18 18:16:32 +02:00
|
|
|
|
|
|
|
/// releaseModule - no longer delete the Module* when provider is destroyed.
|
2006-07-06 23:35:01 +02:00
|
|
|
/// On error, return null and fill in the error string if specified.
|
2003-09-18 18:16:32 +02:00
|
|
|
///
|
2006-07-06 23:35:01 +02:00
|
|
|
virtual Module* releaseModule(std::string *ErrInfo = 0) {
|
2003-09-23 01:35:23 +02:00
|
|
|
// Since we're losing control of this Module, we must hand it back complete
|
2006-07-07 02:01:01 +02:00
|
|
|
if (!materializeModule(ErrInfo))
|
2006-07-06 23:35:01 +02:00
|
|
|
return 0;
|
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 {
|
2008-03-25 23:06:05 +01:00
|
|
|
explicit ExistingModuleProvider(Module *M) {
|
2003-12-30 03:44:04 +01:00
|
|
|
TheModule = M;
|
|
|
|
}
|
2008-05-19 22:15:12 +02:00
|
|
|
bool materializeFunction(Function *, std::string * = 0) {
|
2006-07-06 23:35:01 +02:00
|
|
|
return false;
|
|
|
|
}
|
2008-05-19 22:15:12 +02:00
|
|
|
Module* materializeModule(std::string * = 0) { 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
|