Added ImmutableMap constructor that accepts a const TreeTy*.
[oota-llvm.git] / include / llvm / ModuleProvider.h
1 //===-- llvm/ModuleProvider.h - Interface for module providers --*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
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
14 // at the same time.
15 //
16 //===----------------------------------------------------------------------===//
17
18 #ifndef MODULEPROVIDER_H
19 #define MODULEPROVIDER_H
20
21 #include <string>
22
23 namespace llvm {
24
25 class Function;
26 class Module;
27
28 class ModuleProvider {
29 protected:
30   Module *TheModule;
31   ModuleProvider();
32
33 public:
34   virtual ~ModuleProvider();
35
36   /// getModule - returns the module this provider is encapsulating.
37   ///
38   Module* getModule() { return TheModule; }
39
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.
43   ///
44   virtual bool materializeFunction(Function *F, std::string *ErrInfo = 0) = 0;
45
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.
50   ///
51   virtual void dematerializeFunction(Function *) {}
52   
53   /// materializeModule - make sure the entire Module has been completely read.
54   /// On error, return null and fill in the error string if specified.
55   ///
56   virtual Module* materializeModule(std::string *ErrInfo = 0) = 0;
57
58   /// releaseModule - no longer delete the Module* when provider is destroyed.
59   /// On error, return null and fill in the error string if specified.
60   ///
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))
64       return 0;
65     Module *tempM = TheModule;
66     TheModule = 0;
67     return tempM;
68   }
69 };
70
71
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   explicit ExistingModuleProvider(Module *M) {
78     TheModule = M;
79   }
80   bool materializeFunction(Function *, std::string * = 0) {
81     return false;
82   }
83   Module* materializeModule(std::string * = 0) { return TheModule; }
84 };
85
86 } // End llvm namespace
87
88 #endif