1 //===-- llvm/ModuleProvider.h - Interface for module providers --*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source 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
26 class ModuleProvider {
32 virtual ~ModuleProvider();
34 /// getModule - returns the module this provider is encapsulating.
36 Module* getModule() { return TheModule; }
38 /// materializeFunction - make sure the given function is fully read. Note
39 /// that this can throw an exception if the module is corrupt!
41 virtual void materializeFunction(Function *F) = 0;
43 /// materializeModule - make sure the entire Module has been completely read.
44 /// Note that this can throw an exception if the module is corrupt!
46 virtual Module* materializeModule() = 0;
48 /// releaseModule - no longer delete the Module* when provider is destroyed.
49 /// Note that this can throw an exception if the module is corrupt!
51 virtual Module* releaseModule() {
52 // Since we're losing control of this Module, we must hand it back complete
54 Module *tempM = TheModule;
61 /// ExistingModuleProvider - Allow conversion from a fully materialized Module
62 /// into a ModuleProvider, allowing code that expects a ModuleProvider to work
63 /// if we just have a Module. Note that the ModuleProvider takes ownership of
64 /// the Module specified.
65 struct ExistingModuleProvider : public ModuleProvider {
66 ExistingModuleProvider(Module *M) {
69 void materializeFunction(Function *F) {}
70 Module* materializeModule() { return TheModule; }
73 } // End llvm namespace