1 //===-- llvm/ModuleProvider.h - Interface for module providers --*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file provides an abstract interface for loading a module from some
11 // place. This interface allows incremental or random access loading of
12 // functions from the file. This is useful for applications like JIT compilers
13 // or interprocedural optimizers that do not need the entire program in memory
16 //===----------------------------------------------------------------------===//
18 #ifndef MODULEPROVIDER_H
19 #define MODULEPROVIDER_H
28 class ModuleProvider {
34 virtual ~ModuleProvider();
36 /// getModule - returns the module this provider is encapsulating.
38 Module* getModule() { return TheModule; }
40 /// materializeFunction - make sure the given function is fully read. If the
41 /// module is corrupt, this returns true and fills in the optional string
42 /// with information about the problem. If successful, this returns false.
44 virtual bool materializeFunction(Function *F, std::string *ErrInfo = 0) = 0;
46 /// dematerializeFunction - If the given function is read in, and if the
47 /// module provider supports it, release the memory for the function, and set
48 /// it up to be materialized lazily. If the provider doesn't support this
49 /// capability, this method is a noop.
51 virtual void dematerializeFunction(Function *F) {}
53 /// materializeModule - make sure the entire Module has been completely read.
54 /// On error, return null and fill in the error string if specified.
56 virtual Module* materializeModule(std::string *ErrInfo = 0) = 0;
58 /// releaseModule - no longer delete the Module* when provider is destroyed.
59 /// On error, return null and fill in the error string if specified.
61 virtual Module* releaseModule(std::string *ErrInfo = 0) {
62 // Since we're losing control of this Module, we must hand it back complete
63 if (!materializeModule(ErrInfo))
65 Module *tempM = TheModule;
72 /// ExistingModuleProvider - Allow conversion from a fully materialized Module
73 /// into a ModuleProvider, allowing code that expects a ModuleProvider to work
74 /// if we just have a Module. Note that the ModuleProvider takes ownership of
75 /// the Module specified.
76 struct ExistingModuleProvider : public ModuleProvider {
77 ExistingModuleProvider(Module *M) {
80 bool materializeFunction(Function *F, std::string *ErrInfo = 0) {
83 Module* materializeModule(std::string *ErrInfo = 0) { return TheModule; }
86 } // End llvm namespace