LLVM API Documentation

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

ModuleProvider.h

Go to the documentation of this file.
00001 //===-- llvm/ModuleProvider.h - Interface for module providers --*- C++ -*-===//
00002 // 
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file was developed by the LLVM research group and is distributed under
00006 // the University of Illinois Open Source License. See LICENSE.TXT for details.
00007 // 
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file provides an abstract interface for loading a module from some
00011 // place.  This interface allows incremental or random access loading of
00012 // functions from the file.  This is useful for applications like JIT compilers
00013 // or interprocedural optimizers that do not need the entire program in memory
00014 // at the same time.
00015 //
00016 //===----------------------------------------------------------------------===//
00017 
00018 #ifndef MODULEPROVIDER_H
00019 #define MODULEPROVIDER_H
00020 
00021 namespace llvm {
00022 
00023 class Function;
00024 class Module;
00025 
00026 class ModuleProvider {
00027 protected:
00028   Module *TheModule;
00029   ModuleProvider();
00030 
00031 public:
00032   virtual ~ModuleProvider();
00033 
00034   /// getModule - returns the module this provider is encapsulating.
00035   ///
00036   Module* getModule() { return TheModule; }
00037 
00038   /// materializeFunction - make sure the given function is fully read.  Note
00039   /// that this can throw an exception if the module is corrupt!
00040   ///
00041   virtual void materializeFunction(Function *F) = 0;
00042 
00043   /// materializeModule - make sure the entire Module has been completely read.
00044   /// Note that this can throw an exception if the module is corrupt!
00045   ///
00046   virtual Module* materializeModule() = 0;
00047 
00048   /// releaseModule - no longer delete the Module* when provider is destroyed.
00049   /// Note that this can throw an exception if the module is corrupt!
00050   ///
00051   virtual Module* releaseModule() { 
00052     // Since we're losing control of this Module, we must hand it back complete
00053     materializeModule();
00054     Module *tempM = TheModule; 
00055     TheModule = 0; 
00056     return tempM; 
00057   }
00058 };
00059 
00060 
00061 /// ExistingModuleProvider - Allow conversion from a fully materialized Module
00062 /// into a ModuleProvider, allowing code that expects a ModuleProvider to work
00063 /// if we just have a Module.  Note that the ModuleProvider takes ownership of
00064 /// the Module specified.
00065 struct ExistingModuleProvider : public ModuleProvider {
00066   ExistingModuleProvider(Module *M) {
00067     TheModule = M;
00068   }
00069   void materializeFunction(Function *F) {}
00070   Module* materializeModule() { return TheModule; }
00071 };
00072 
00073 } // End llvm namespace
00074 
00075 #endif