LLVM API Documentation

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 #include <string>
00022 
00023 namespace llvm {
00024 
00025 class Function;
00026 class Module;
00027 
00028 class ModuleProvider {
00029 protected:
00030   Module *TheModule;
00031   ModuleProvider();
00032 
00033 public:
00034   virtual ~ModuleProvider();
00035 
00036   /// getModule - returns the module this provider is encapsulating.
00037   ///
00038   Module* getModule() { return TheModule; }
00039 
00040   /// materializeFunction - make sure the given function is fully read.  If the
00041   /// module is corrupt, this returns true and fills in the optional string
00042   /// with information about the problem.  If successful, this returns false.
00043   ///
00044   virtual bool materializeFunction(Function *F, std::string *ErrInfo = 0) = 0;
00045 
00046   /// materializeModule - make sure the entire Module has been completely read.
00047   /// On error, return null and fill in the error string if specified.
00048   ///
00049   virtual Module* materializeModule(std::string *ErrInfo = 0) = 0;
00050 
00051   /// releaseModule - no longer delete the Module* when provider is destroyed.
00052   /// On error, return null and fill in the error string if specified.
00053   ///
00054   virtual Module* releaseModule(std::string *ErrInfo = 0) {
00055     // Since we're losing control of this Module, we must hand it back complete
00056     if (!materializeModule(ErrInfo))
00057       return 0;
00058     Module *tempM = TheModule;
00059     TheModule = 0;
00060     return tempM;
00061   }
00062 };
00063 
00064 
00065 /// ExistingModuleProvider - Allow conversion from a fully materialized Module
00066 /// into a ModuleProvider, allowing code that expects a ModuleProvider to work
00067 /// if we just have a Module.  Note that the ModuleProvider takes ownership of
00068 /// the Module specified.
00069 struct ExistingModuleProvider : public ModuleProvider {
00070   ExistingModuleProvider(Module *M) {
00071     TheModule = M;
00072   }
00073   bool materializeFunction(Function *F, std::string *ErrInfo = 0) {
00074     return false;
00075   }
00076   Module* materializeModule(std::string *ErrInfo = 0) { return TheModule; }
00077 };
00078 
00079 } // End llvm namespace
00080 
00081 #endif