Add a pointer to the owning LLVMContext to Module. This requires threading LLVMConte...
authorOwen Anderson <resistor@mac.com>
Wed, 1 Jul 2009 16:58:40 +0000 (16:58 +0000)
committerOwen Anderson <resistor@mac.com>
Wed, 1 Jul 2009 16:58:40 +0000 (16:58 +0000)
of the bitcode reader and ASM parser APIs, as well as supporting it in all of the tools.

Patches for Clang and LLVM-GCC to follow.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@74614 91177308-0d34-0410-b5e6-96231b3b80d8

60 files changed:
examples/BrainF/BrainF.cpp
examples/BrainF/BrainF.h
examples/BrainF/BrainFDriver.cpp
examples/Fibonacci/fibonacci.cpp
examples/HowToUseJIT/HowToUseJIT.cpp
examples/Kaleidoscope/toy.cpp
examples/ModuleMaker/ModuleMaker.cpp
examples/ParallelJIT/ParallelJIT.cpp
include/llvm-c/BitReader.h
include/llvm-c/Core.h
include/llvm/Assembly/Parser.h
include/llvm/Bitcode/Archive.h
include/llvm/Bitcode/ReaderWriter.h
include/llvm/Debugger/Debugger.h
include/llvm/LinkAllVMCore.h
include/llvm/Linker.h
include/llvm/Module.h
include/llvm/Transforms/Utils/Cloning.h
lib/Archive/Archive.cpp
lib/Archive/ArchiveInternals.h
lib/Archive/ArchiveReader.cpp
lib/Archive/ArchiveWriter.cpp
lib/AsmParser/Parser.cpp
lib/Bitcode/Reader/BitReader.cpp
lib/Bitcode/Reader/BitcodeReader.cpp
lib/Bitcode/Reader/BitcodeReader.h
lib/Debugger/Debugger.cpp
lib/Linker/LinkArchives.cpp
lib/Linker/LinkItems.cpp
lib/Linker/Linker.cpp
lib/Transforms/Utils/CloneModule.cpp
lib/VMCore/Core.cpp
lib/VMCore/Module.cpp
tools/bugpoint/BugDriver.cpp
tools/bugpoint/BugDriver.h
tools/bugpoint/CrashDebugger.cpp
tools/bugpoint/Miscompilation.cpp
tools/bugpoint/OptimizerDriver.cpp
tools/bugpoint/bugpoint.cpp
tools/llc/llc.cpp
tools/lli/lli.cpp
tools/llvm-ar/llvm-ar.cpp
tools/llvm-as/llvm-as.cpp
tools/llvm-db/CLIDebugger.cpp
tools/llvm-db/CLIDebugger.h
tools/llvm-db/Commands.cpp
tools/llvm-db/llvm-db.cpp
tools/llvm-dis/llvm-dis.cpp
tools/llvm-extract/llvm-extract.cpp
tools/llvm-ld/llvm-ld.cpp
tools/llvm-link/llvm-link.cpp
tools/llvm-nm/llvm-nm.cpp
tools/llvm-prof/llvm-prof.cpp
tools/llvm-ranlib/llvm-ranlib.cpp
tools/lto/LTOCodeGenerator.cpp
tools/lto/LTOCodeGenerator.h
tools/lto/LTOModule.cpp
tools/lto/LTOModule.h
tools/lto/lto.cpp
tools/opt/opt.cpp

index 32a14c4d5328bd4260009aa349fc11e75edc32ae..0caff13e81ec25e077db10cb7605ea94e2184eb6 100644 (file)
@@ -36,19 +36,20 @@ const char *BrainF::headreg = "head";
 const char *BrainF::label   = "brainf";
 const char *BrainF::testreg = "test";
 
-Module *BrainF::parse(std::istream *in1, int mem, CompileFlags cf) {
+Module *BrainF::parse(std::istream *in1, int mem, CompileFlags cf,
+                      LLVMContext* Context) {
   in       = in1;
   memtotal = mem;
   comflag  = cf;
 
-  header();
+  header(Context);
   readloop(0, 0, 0);
   delete builder;
   return module;
 }
 
-void BrainF::header() {
-  module = new Module("BrainF");
+void BrainF::header(LLVMContext* C) {
+  module = new Module("BrainF", C);
 
   //Function prototypes
 
index 06c00ae4df247bbced806d2efb9ceddd7bc981c9..d0fb1b1de0ef38f1e339bcdc4fc9db9feb5f9835 100644 (file)
@@ -15,6 +15,7 @@
 #ifndef BRAINF_H
 #define BRAINF_H
 
+#include "llvm/LLVMContext.h"
 #include "llvm/Module.h"
 #include "llvm/Support/IRBuilder.h"
 
@@ -38,7 +39,7 @@ class BrainF {
     /// containing the resulting code.
     /// On error, it calls abort.
     /// The caller must delete the returned module.
-    Module *parse(std::istream *in1, int mem, CompileFlags cf);
+    Module *parse(std::istream *in1, int mem, CompileFlags cf, LLVMContext* C);
 
   protected:
     /// The different symbols in the BrainF language
@@ -64,7 +65,7 @@ class BrainF {
     static const char *testreg;
 
     /// Put the brainf function preamble and other fixed pieces of code
-    void header();
+    void header(LLVMContext* C);
 
     /// The main loop for parsing.  It calls itself recursively
     /// to handle the depth of nesting of "[]".
index 06e77d2e2a3ec2a6338490d0ecc6d3d4fe08eab6..0868d735066364c665b6eb9d0eec21eda6478b62 100644 (file)
@@ -86,6 +86,8 @@ void addMainFunction(Module *mod) {
 int main(int argc, char **argv) {
   cl::ParseCommandLineOptions(argc, argv, " BrainF compiler\n");
 
+  LLVMContext Context;
+
   if (InputFilename == "") {
     std::cerr<<"Error: You must specify the filename of the program to "
     "be compiled.  Use --help to see the options.\n";
@@ -124,7 +126,7 @@ int main(int argc, char **argv) {
 
   //Read the BrainF program
   BrainF bf;
-  Module *mod = bf.parse(in, 65536, cf); //64 KiB
+  Module *mod = bf.parse(in, 65536, cf, &Context); //64 KiB
   if (in != &std::cin) {delete in;}
   addMainFunction(mod);
 
index 09f2203c68ffdde1341eb8265352054b88ab5ba6..58c0dcdaf5cae229f23c0901456fe5a27827751a 100644 (file)
@@ -23,6 +23,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "llvm/LLVMContext.h"
 #include "llvm/Module.h"
 #include "llvm/DerivedTypes.h"
 #include "llvm/Constants.h"
@@ -90,8 +91,10 @@ static Function *CreateFibFunction(Module *M) {
 int main(int argc, char **argv) {
   int n = argc > 1 ? atol(argv[1]) : 24;
 
+  LLVMContext Context;
+  
   // Create some module to put our function into it.
-  Module *M = new Module("test");
+  Module *M = new Module("test", &Context);
 
   // We are about to create the "fib" function:
   Function *FibF = CreateFibFunction(M);
index a9f10009e1eca9057d4e588525d4abc3815e856f..f11c3e256e6f23ee8faf05db3271e9ddfc9c0168 100644 (file)
@@ -34,6 +34,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "llvm/LLVMContext.h"
 #include "llvm/Module.h"
 #include "llvm/Constants.h"
 #include "llvm/DerivedTypes.h"
@@ -50,9 +51,11 @@ using namespace llvm;
 int main() {
   
   InitializeNativeTarget();
+
+  LLVMContext Context;
   
   // Create some module to put our function into it.
-  Module *M = new Module("test");
+  Module *M = new Module("test", &Context);
 
   // Create the add1 function entry and insert this entry into module M.  The
   // function will have a return type of "int" and take an argument of "int".
index c75014a69ba40ff632fc1c811a62224e0ec7d723..9ca6035156cda8b63142feb9d719fdd3a083d2fc 100644 (file)
@@ -1,5 +1,6 @@
 #include "llvm/DerivedTypes.h"
 #include "llvm/ExecutionEngine/ExecutionEngine.h"
+#include "llvm/LLVMContext.h"
 #include "llvm/Module.h"
 #include "llvm/ModuleProvider.h"
 #include "llvm/PassManager.h"
@@ -1083,6 +1084,7 @@ double printd(double X) {
 
 int main() {
   InitializeNativeTarget();
+  LLVMContext Context;
   
   // Install standard binary operators.
   // 1 is lowest precedence.
@@ -1097,7 +1099,7 @@ int main() {
   getNextToken();
 
   // Make the module, which holds all the code.
-  TheModule = new Module("my cool jit");
+  TheModule = new Module("my cool jit", &Context);
   
   // Create the JIT.
   TheExecutionEngine = ExecutionEngine::create(TheModule);
index e2584e7ff34dd57198960502f2108aca3e19b7e9..322835e04f20a7a0ec24b9cd2614231d5a7c6dcf 100644 (file)
@@ -13,6 +13,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "llvm/LLVMContext.h"
 #include "llvm/Module.h"
 #include "llvm/DerivedTypes.h"
 #include "llvm/Constants.h"
 using namespace llvm;
 
 int main() {
+  LLVMContext Context;
+
   // Create the "module" or "program" or "translation unit" to hold the
   // function
-  Module *M = new Module("test");
+  Module *M = new Module("test", &Context);
 
   // Create the main function: first create the type 'int ()'
   FunctionType *FT = FunctionType::get(Type::Int32Ty, /*not vararg*/false);
index a6d7dcf7b556c0d8fde244f03e0c1e3aec857c4e..858cd52de6aea6ea915c298d7fa214b02b1a3695 100644 (file)
@@ -18,6 +18,7 @@
 // same time). This test had assertion errors until I got the locking right.
 
 #include <pthread.h>
+#include "llvm/LLVMContext.h"
 #include "llvm/Module.h"
 #include "llvm/Constants.h"
 #include "llvm/DerivedTypes.h"
@@ -232,9 +233,10 @@ void* callFunc( void* param )
 
 int main() {
   InitializeNativeTarget();
+  LLVMContext Context;
 
   // Create some module to put our function into it.
-  Module *M = new Module("test");
+  Module *M = new Module("test", &Context);
 
   Function* add1F = createAdd1( M );
   Function* fibF = CreateFibFunction( M );
index e30b431d887289a7bf487ae297ef27dbb7516f8b..4284d7d2372012f814c336f409f4f81df1a9878a 100644 (file)
@@ -29,13 +29,14 @@ extern "C" {
 /* Builds a module from the bitcode in the specified memory buffer, returning a
    reference to the module via the OutModule parameter. Returns 0 on success.
    Optionally returns a human-readable error message via OutMessage. */ 
-int LLVMParseBitcode(LLVMMemoryBufferRef MemBuf,
+int LLVMParseBitcode(LLVMMemoryBufferRef MemBuf, LLVMContextRef ContextRef,
                      LLVMModuleRef *OutModule, char **OutMessage);
 
 /* Reads a module from the specified path, returning via the OutMP parameter
    a module provider which performs lazy deserialization. Returns 0 on success.
    Optionally returns a human-readable error message via OutMessage. */ 
 int LLVMGetBitcodeModuleProvider(LLVMMemoryBufferRef MemBuf,
+                                 LLVMContextRef ContextRef,
                                  LLVMModuleProviderRef *OutMP,
                                  char **OutMessage);
 
index d2d88454d711ee2d11f2750044970ddddda5726e..7019b4cc660e1d02d672931ec2fe0ab55e011223 100644 (file)
@@ -46,6 +46,11 @@ extern "C" {
 
 /* Opaque types. */
 
+/**
+ * The top-level container for all LLVM global data.  See the LLVMContext class.
+ */
+typedef struct LLVMCtxt *LLVMContextRef;
+
 /**
  * The top-level container for all other LLVM Intermediate Representation (IR)
  * objects. See the llvm::Module class.
@@ -188,6 +193,10 @@ void LLVMDisposeMessage(char *Message);
 
 /*===-- Modules -----------------------------------------------------------===*/
 
+/* Create and destroy contexts. */
+LLVMContextRef LLVMContextCreate();
+void LLVMContextDispose(LLVMContextRef C);
+
 /* Create and destroy modules. */ 
 /** See llvm::Module::Module. */
 LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
@@ -815,6 +824,7 @@ namespace llvm {
   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(PATypeHolder,       LLVMTypeHandleRef    )
   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ModuleProvider,     LLVMModuleProviderRef)
   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer,       LLVMMemoryBufferRef  )
+  DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLVMContext,        LLVMContextRef       )
   DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase,    LLVMPassManagerRef   )
   
   #undef DEFINE_STDCXX_CONVERSION_FUNCTIONS
index e4a38e41b67aeb6c1917161d55595c70f5039057..2a5bac7a704cca322b7c180e8bbe4291d4af9e06 100644 (file)
@@ -21,6 +21,7 @@ namespace llvm {
 class Module;
 class ParseError;
 class raw_ostream;
+class LLVMContext;
 
 /// This function is the main interface to the LLVM Assembly Parser. It parses
 /// an ASCII file that (presumably) contains LLVM Assembly code. It returns a
@@ -30,7 +31,8 @@ class raw_ostream;
 /// @brief Parse LLVM Assembly from a file
 Module *ParseAssemblyFile(
   const std::string &Filename, ///< The name of the file to parse
-  ParseError &Error            ///< If not null, an object to return errors in.
+  ParseError &Error,           ///< If not null, an object to return errors in.
+  LLVMContext* Context         ///< Context in which to allocate globals info.
 );
 
 /// The function is a secondary interface to the LLVM Assembly Parser. It parses
@@ -42,7 +44,8 @@ Module *ParseAssemblyFile(
 Module *ParseAssemblyString(
   const char *AsmString, ///< The string containing assembly
   Module *M,             ///< A module to add the assembly too.
-  ParseError &Error      ///< If not null, an object to return errors in.
+  ParseError &Error,     ///< If not null, an object to return errors in.
+  LLVMContext* Context
 );
 
 //===------------------------------------------------------------------------===
index a3631ace545f96cf439f6eb1f8257d4c5363daf8..c188df882419e4ecad84dfc44630f98d0db1560e 100644 (file)
@@ -32,6 +32,7 @@ class ModuleProvider;      // From VMCore
 class Module;              // From VMCore
 class Archive;             // Declared below
 class ArchiveMemberHeader; // Internal implementation class
+class LLVMContext;         // Global data
 
 /// This class is the main class manipulated by users of the Archive class. It
 /// holds information about one member of the Archive. It is also the element
@@ -278,7 +279,8 @@ class Archive {
     /// @returns An Archive* that represents the new archive file.
     /// @brief Create an empty Archive.
     static Archive* CreateEmpty(
-      const sys::Path& Filename ///< Name of the archive to (eventually) create.
+      const sys::Path& Filename,///< Name of the archive to (eventually) create.
+      LLVMContext* C            ///< Context to use for global information
     );
 
     /// Open an existing archive and load its contents in preparation for
@@ -289,6 +291,7 @@ class Archive {
     /// @brief Open and load an archive file
     static Archive* OpenAndLoad(
       const sys::Path& filePath,  ///< The file path to open and load
+      LLVMContext* C,             ///< The context to use for global information
       std::string* ErrorMessage   ///< An optional error string
     );
 
@@ -310,6 +313,7 @@ class Archive {
     /// @brief Open an existing archive and load its symbols.
     static Archive* OpenAndLoadSymbols(
       const sys::Path& Filename,   ///< Name of the archive file to open
+      LLVMContext* C,              ///< The context to use for global info
       std::string* ErrorMessage=0  ///< An optional error string
     );
 
@@ -449,7 +453,7 @@ class Archive {
   protected:
     /// @brief Construct an Archive for \p filename and optionally  map it
     /// into memory.
-    explicit Archive(const sys::Path& filename);
+    explicit Archive(const sys::Path& filename, LLVMContext* C);
 
     /// @param data The symbol table data to be parsed
     /// @param len  The length of the symbol table data
@@ -530,6 +534,7 @@ class Archive {
     unsigned firstFileOffset; ///< Offset to first normal file.
     ModuleMap modules;        ///< The modules loaded via symbol lookup.
     ArchiveMember* foreignST; ///< This holds the foreign symbol table.
+    LLVMContext* Context;     ///< This holds global data.
   /// @}
   /// @name Hidden
   /// @{
index abdd5d3d8b1945e4f7071ccbfe0029ddefb50022..a7811876ff687679c1a317756202c5da742a1b65 100644 (file)
@@ -23,6 +23,7 @@ namespace llvm {
   class MemoryBuffer;
   class ModulePass;
   class BitstreamWriter;
+  class LLVMContext;
   class raw_ostream;
   
   /// getBitcodeModuleProvider - Read the header of the specified bitcode buffer
@@ -31,12 +32,14 @@ namespace llvm {
   /// error, this returns null, *does not* take ownership of Buffer, and fills
   /// in *ErrMsg with an error description if ErrMsg is non-null.
   ModuleProvider *getBitcodeModuleProvider(MemoryBuffer *Buffer,
+                                           LLVMContext* Context,
                                            std::string *ErrMsg = 0);
 
   /// ParseBitcodeFile - Read the specified bitcode file, returning the module.
   /// If an error occurs, this returns null and fills in *ErrMsg if it is
   /// non-null.  This method *never* takes ownership of Buffer.
-  Module *ParseBitcodeFile(MemoryBuffer *Buffer, std::string *ErrMsg = 0);
+  Module *ParseBitcodeFile(MemoryBuffer *Buffer, LLVMContext* Context,
+                           std::string *ErrMsg = 0);
 
   /// WriteBitcodeToFile - Write the specified module to the specified output
   /// stream.
index 5b0b97addf4ab059ec59078bbad7079c8d1415ed..ed04ed533adba87517976869bfb0944276c6fcd2 100644 (file)
@@ -20,6 +20,7 @@
 namespace llvm {
   class Module;
   class InferiorProcess;
+  class LLVMContext;
 
   /// Debugger class - This class implements the LLVM source-level debugger.
   /// This allows clients to handle the user IO processing without having to
@@ -95,7 +96,7 @@ namespace llvm {
     /// the PATH for the specified program, loading it when found.  If the
     /// specified program cannot be found, an exception is thrown to indicate
     /// the error.
-    void loadProgram(const std::string &Path);
+    void loadProgram(const std::string &Path, LLVMContext* Context);
 
     /// unloadProgram - If a program is running, kill it, then unload all traces
     /// of the current program.  If no program is loaded, this method silently
index 4c428a00631c2927f6b3466ee2d42cce5e142944..3c4b9c447b9d23f578c95a627be1d731f21e82b8 100644 (file)
@@ -44,7 +44,7 @@ namespace {
       // to know that getenv() never returns -1, this will do the job.
       if (std::getenv("bar") != (char*) -1)
         return;
-      llvm::Module* M = new llvm::Module("");
+      llvm::Module* M = new llvm::Module("", 0);
       (void)new llvm::UnreachableInst();
       (void)    llvm::createVerifierPass(); 
       (void) new llvm::Mangler(*M,"");
index 884e872602bdd8f8aeafa5a0551e50842f4d14c9..8389dc770efcbab2cb97a09857dc0a6b94159726 100644 (file)
@@ -21,6 +21,7 @@
 namespace llvm {
 
 class Module;
+class LLVMContext;
 
 /// This class provides the core functionality of linking in LLVM. It retains a
 /// Module object which is the composite of the modules and libraries linked
@@ -66,6 +67,7 @@ class Linker {
     Linker(
         const std::string& progname, ///< name of tool running linker
         const std::string& modulename, ///< name of linker's end-result module
+        LLVMContext* C, ///< Context for global info
         unsigned Flags = 0  ///< ControlFlags (one or more |'d together)
     );
 
@@ -283,6 +285,7 @@ class Linker {
   /// @name Data
   /// @{
   private:
+    LLVMContext* Context; ///< The context for global information
     Module* Composite; ///< The composite module linked together
     std::vector<sys::Path> LibPaths; ///< The library search paths
     unsigned Flags;    ///< Flags to control optional behavior.
index 9c8607a188a1360f8329591d5b74dc7f594b89eb..8370ffb872cdb6ff05ee064b37e1a13a47e96009 100644 (file)
@@ -25,6 +25,7 @@ namespace llvm {
 
 class GlobalValueRefMap;   // Used by ConstantVals.cpp
 class FunctionType;
+class LLVMContext;
 
 template<> struct ilist_traits<Function>
   : public SymbolTableListTraits<Function, Module> {
@@ -109,6 +110,8 @@ public:
 /// @name Member Variables
 /// @{
 private:
+  LLVMContext* Context;          ///< The LLVMContext from which types and
+                                 ///< constants are allocated.
   GlobalListType GlobalList;     ///< The Global Variables in the module
   FunctionListType FunctionList; ///< The Functions in the module
   AliasListType AliasList;       ///< The Aliases in the module
@@ -128,7 +131,7 @@ private:
 public:
   /// The Module constructor. Note that there is no default constructor. You
   /// must provide a name for the module upon construction.
-  explicit Module(const std::string &ModuleID);
+  explicit Module(const std::string &ModuleID, LLVMContext* C);
   /// The module destructor. This will dropAllReferences.
   ~Module();
 
@@ -157,6 +160,10 @@ public:
   /// @returns PointerSize - an enumeration for the size of the target's pointer
   PointerSize getPointerSize() const;
 
+  /// Get the global data context.
+  /// @returns LLVMContext - a container for LLVM's global information
+  LLVMContext* getContext() const { return Context; }
+
   /// Get any module-scope inline assembly blocks.
   /// @returns a string containing the module-scope inline assembly blocks.
   const std::string &getModuleInlineAsm() const { return GlobalScopeAsm; }
index 1e2bbaa295b37139c90b6910928650cb281249aa..840d9708cbaf51fb1bdeed71407726302b98a788 100644 (file)
@@ -37,6 +37,7 @@ class Trace;
 class CallGraph;
 class TargetData;
 class LoopInfo;
+class LLVMContext;
 template<class N> class LoopBase;
 typedef LoopBase<BasicBlock> Loop;
 
index c6c89d27dbb0ab78592953e2542de3da5ca077eb..e6903b607fb858bc34b5a813db117c81581566b3 100644 (file)
@@ -138,9 +138,9 @@ bool ArchiveMember::replaceWith(const sys::Path& newFile, std::string* ErrMsg) {
 // Archive constructor - this is the only constructor that gets used for the
 // Archive class. Everything else (default,copy) is deprecated. This just
 // initializes and maps the file into memory, if requested.
-Archive::Archive(const sys::Path& filename)
+Archive::Archive(const sys::Path& filename, LLVMContext* C)
   : archPath(filename), members(), mapfile(0), base(0), symTab(), strtab(),
-    symTabSize(0), firstFileOffset(0), modules(), foreignST(0) {
+    symTabSize(0), firstFileOffset(0), modules(), foreignST(0), Context(C) {
 }
 
 bool
@@ -208,6 +208,7 @@ static void getSymbols(Module*M, std::vector<std::string>& symbols) {
 
 // Get just the externally visible defined symbols from the bitcode
 bool llvm::GetBitcodeSymbols(const sys::Path& fName,
+                             LLVMContext* Context,
                              std::vector<std::string>& symbols,
                              std::string* ErrMsg) {
   std::auto_ptr<MemoryBuffer> Buffer(
@@ -217,7 +218,7 @@ bool llvm::GetBitcodeSymbols(const sys::Path& fName,
     return true;
   }
   
-  ModuleProvider *MP = getBitcodeModuleProvider(Buffer.get(), ErrMsg);
+  ModuleProvider *MP = getBitcodeModuleProvider(Buffer.get(), Context, ErrMsg);
   if (!MP)
     return true;
   
@@ -239,13 +240,14 @@ bool llvm::GetBitcodeSymbols(const sys::Path& fName,
 ModuleProvider*
 llvm::GetBitcodeSymbols(const unsigned char *BufPtr, unsigned Length,
                         const std::string& ModuleID,
+                        LLVMContext* Context,
                         std::vector<std::string>& symbols,
                         std::string* ErrMsg) {
   // Get the module provider
   MemoryBuffer *Buffer =MemoryBuffer::getNewMemBuffer(Length, ModuleID.c_str());
   memcpy((char*)Buffer->getBufferStart(), BufPtr, Length);
   
-  ModuleProvider *MP = getBitcodeModuleProvider(Buffer, ErrMsg);
+  ModuleProvider *MP = getBitcodeModuleProvider(Buffer, Context, ErrMsg);
   if (!MP)
     return 0;
   
index 7ba30244a2138084fcdeb360810ec6d9bd7f3aa3..cdd8e35ca0dc05b6efb16c6eacde940273713bb8 100644 (file)
@@ -31,6 +31,8 @@
 
 namespace llvm {
 
+  class LLVMContext;
+
   /// The ArchiveMemberHeader structure is used internally for bitcode
   /// archives.
   /// The header precedes each file member in the archive. This structure is
@@ -71,11 +73,13 @@ namespace llvm {
   
   // Get just the externally visible defined symbols from the bitcode
   bool GetBitcodeSymbols(const sys::Path& fName,
+                          LLVMContext* Context,
                           std::vector<std::string>& symbols,
                           std::string* ErrMsg);
   
   ModuleProvider* GetBitcodeSymbols(const unsigned char*Buffer,unsigned Length,
                                     const std::string& ModuleID,
+                                    LLVMContext* Context,
                                     std::vector<std::string>& symbols,
                                     std::string* ErrMsg);
 }
index b07e884b654796f0e01c72104eabaf917193d15d..4e3e28166ca549fa10c0545803af11979b4b1fa1 100644 (file)
@@ -327,9 +327,9 @@ Archive::loadArchive(std::string* error) {
 
 // Open and completely load the archive file.
 Archive*
-Archive::OpenAndLoad(const sys::Path& file, std::string* ErrorMessage) 
-{
-  std::auto_ptr<Archive> result ( new Archive(file));
+Archive::OpenAndLoad(const sys::Path& file, LLVMContext* C, 
+                     std::string* ErrorMessage) {
+  std::auto_ptr<Archive> result ( new Archive(file, C));
   if (result->mapToMemory(ErrorMessage))
     return 0;
   if (!result->loadArchive(ErrorMessage))
@@ -339,7 +339,8 @@ Archive::OpenAndLoad(const sys::Path& file, std::string* ErrorMessage)
 
 // Get all the bitcode modules from the archive
 bool
-Archive::getAllModules(std::vector<Module*>& Modules, std::string* ErrMessage) {
+Archive::getAllModules(std::vector<Module*>& Modules,
+                       std::string* ErrMessage) {
 
   for (iterator I=begin(), E=end(); I != E; ++I) {
     if (I->isBitcode()) {
@@ -349,7 +350,7 @@ Archive::getAllModules(std::vector<Module*>& Modules, std::string* ErrMessage) {
         MemoryBuffer::getNewMemBuffer(I->getSize(), FullMemberName.c_str());
       memcpy((char*)Buffer->getBufferStart(), I->getData(), I->getSize());
       
-      Module *M = ParseBitcodeFile(Buffer, ErrMessage);
+      Module *M = ParseBitcodeFile(Buffer, Context, ErrMessage);
       delete Buffer;
       if (!M)
         return true;
@@ -440,9 +441,9 @@ Archive::loadSymbolTable(std::string* ErrorMsg) {
 }
 
 // Open the archive and load just the symbol tables
-Archive*
-Archive::OpenAndLoadSymbols(const sys::Path& file, std::string* ErrorMessage) {
-  std::auto_ptr<Archive> result ( new Archive(file) );
+Archive* Archive::OpenAndLoadSymbols(const sys::Path& file, LLVMContext* C,
+                                     std::string* ErrorMessage) {
+  std::auto_ptr<Archive> result ( new Archive(file, C) );
   if (result->mapToMemory(ErrorMessage))
     return 0;
   if (!result->loadSymbolTable(ErrorMessage))
@@ -488,7 +489,7 @@ Archive::findModuleDefiningSymbol(const std::string& symbol,
                                                       FullMemberName.c_str());
   memcpy((char*)Buffer->getBufferStart(), mbr->getData(), mbr->getSize());
   
-  ModuleProvider *mp = getBitcodeModuleProvider(Buffer, ErrMsg);
+  ModuleProvider *mp = getBitcodeModuleProvider(Buffer, Context, ErrMsg);
   if (!mp)
     return 0;
 
@@ -536,7 +537,7 @@ Archive::findModulesDefiningSymbols(std::set<std::string>& symbols,
           mbr->getPath().toString() + ")";
         ModuleProvider* MP = 
           GetBitcodeSymbols((const unsigned char*)At, mbr->getSize(),
-                            FullMemberName, symbols, error);
+                            FullMemberName, Context, symbols, error);
 
         if (MP) {
           // Insert the module's symbols into the symbol table
@@ -615,7 +616,7 @@ bool Archive::isBitcodeArchive() {
     MemoryBuffer *Buffer =
       MemoryBuffer::getNewMemBuffer(I->getSize(), FullMemberName.c_str());
     memcpy((char*)Buffer->getBufferStart(), I->getData(), I->getSize());
-    Module *M = ParseBitcodeFile(Buffer);
+    Module *M = ParseBitcodeFile(Buffer, Context);
     delete Buffer;
     if (!M)
       return false;  // Couldn't parse bitcode, not a bitcode archive.
index cebb087745794012c5605e98616076f52b612e34..641e3324d63dd25525089e08de8e404d6a6ba9b7 100644 (file)
@@ -64,9 +64,8 @@ static inline unsigned numVbrBytes(unsigned num) {
 }
 
 // Create an empty archive.
-Archive*
-Archive::CreateEmpty(const sys::Path& FilePath ) {
-  Archive* result = new Archive(FilePath);
+Archive* Archive::CreateEmpty(const sys::Path& FilePath, LLVMContext* C) {
+  Archive* result = new Archive(FilePath, C);
   return result;
 }
 
@@ -229,7 +228,7 @@ Archive::writeMember(
       + ")";
     ModuleProvider* MP = 
       GetBitcodeSymbols((const unsigned char*)data,fSize,
-                        FullMemberName, symbols, ErrMsg);
+                        FullMemberName, Context, symbols, ErrMsg);
 
     // If the bitcode parsed successfully
     if ( MP ) {
index 759e00e3217a6989fe5a9e5195a8190e052cc5a3..7759c70d73da9ab0c6cf265539cc267a77914bcf 100644 (file)
@@ -20,7 +20,8 @@
 #include <cstring>
 using namespace llvm;
 
-Module *llvm::ParseAssemblyFile(const std::string &Filename, ParseError &Err) {
+Module *llvm::ParseAssemblyFile(const std::string &Filename, ParseError &Err,
+                                LLVMContext* Context) {
   Err.setFilename(Filename);
 
   std::string ErrorStr;
@@ -31,14 +32,14 @@ Module *llvm::ParseAssemblyFile(const std::string &Filename, ParseError &Err) {
     return 0;
   }
 
-  OwningPtr<Module> M(new Module(Filename));
+  OwningPtr<Module> M(new Module(Filename, Context));
   if (LLParser(F.get(), Err, M.get()).Run())
     return 0;
   return M.take();
 }
 
 Module *llvm::ParseAssemblyString(const char *AsmString, Module *M,
-                                  ParseError &Err) {
+                                  ParseError &Err, LLVMContext* Context) {
   Err.setFilename("<string>");
 
   OwningPtr<MemoryBuffer>
@@ -50,7 +51,7 @@ Module *llvm::ParseAssemblyString(const char *AsmString, Module *M,
     return LLParser(F.get(), Err, M).Run() ? 0 : M;
 
   // Otherwise create a new module.
-  OwningPtr<Module> M2(new Module("<string>"));
+  OwningPtr<Module> M2(new Module("<string>", Context));
   if (LLParser(F.get(), Err, M2.get()).Run())
     return 0;
   return M2.take();
index 52851cd142daca54f31329aed45cd37ae8326eed..2baf71bb541bab488872f8ab736ec92d3ef3b266 100644 (file)
@@ -18,11 +18,12 @@ using namespace llvm;
 /* Builds a module from the bitcode in the specified memory buffer, returning a
    reference to the module via the OutModule parameter. Returns 0 on success.
    Optionally returns a human-readable error message via OutMessage. */ 
-int LLVMParseBitcode(LLVMMemoryBufferRef MemBuf,
+int LLVMParseBitcode(LLVMMemoryBufferRef MemBuf, LLVMContextRef ContextRef,
                      LLVMModuleRef *OutModule, char **OutMessage) {
   std::string Message;
   
-  *OutModule = wrap(ParseBitcodeFile(unwrap(MemBuf), &Message));
+  *OutModule = wrap(ParseBitcodeFile(unwrap(MemBuf), unwrap(ContextRef),  
+                                     &Message));
   if (!*OutModule) {
     if (OutMessage)
       *OutMessage = strdup(Message.c_str());
@@ -36,11 +37,13 @@ int LLVMParseBitcode(LLVMMemoryBufferRef MemBuf,
    a module provider which performs lazy deserialization. Returns 0 on success.
    Optionally returns a human-readable error message via OutMessage. */ 
 int LLVMGetBitcodeModuleProvider(LLVMMemoryBufferRef MemBuf,
+                                 LLVMContextRef ContextRef,
                                  LLVMModuleProviderRef *OutMP,
                                  char **OutMessage) {
   std::string Message;
   
-  *OutMP = wrap(getBitcodeModuleProvider(unwrap(MemBuf), &Message));
+  *OutMP = wrap(getBitcodeModuleProvider(unwrap(MemBuf), unwrap(ContextRef), 
+                                         &Message));
   if (!*OutMP) {
     if (OutMessage)
       *OutMessage = strdup(Message.c_str());
index 6b9606c5d14b2e038b9c1213b58ecd6158ecb7ff..7cf03242990195b188daff8be41c1ba12e551fbc 100644 (file)
@@ -1087,7 +1087,7 @@ bool BitcodeReader::ParseModule(const std::string &ModuleID) {
     return Error("Malformed block record");
 
   // Otherwise, create the module.
-  TheModule = new Module(ModuleID);
+  TheModule = new Module(ModuleID, Context);
   
   SmallVector<uint64_t, 64> Record;
   std::vector<std::string> SectionTable;
@@ -2090,8 +2090,9 @@ Module *BitcodeReader::releaseModule(std::string *ErrInfo) {
 /// getBitcodeModuleProvider - lazy function-at-a-time loading from a file.
 ///
 ModuleProvider *llvm::getBitcodeModuleProvider(MemoryBuffer *Buffer,
+                                               LLVMContext* Context,
                                                std::string *ErrMsg) {
-  BitcodeReader *R = new BitcodeReader(Buffer);
+  BitcodeReader *R = new BitcodeReader(Buffer, Context);
   if (R->ParseBitcode()) {
     if (ErrMsg)
       *ErrMsg = R->getErrorString();
@@ -2106,9 +2107,11 @@ ModuleProvider *llvm::getBitcodeModuleProvider(MemoryBuffer *Buffer,
 
 /// ParseBitcodeFile - Read the specified bitcode file, returning the module.
 /// If an error occurs, return null and fill in *ErrMsg if non-null.
-Module *llvm::ParseBitcodeFile(MemoryBuffer *Buffer, std::string *ErrMsg){
+Module *llvm::ParseBitcodeFile(MemoryBuffer *Buffer, LLVMContext* Context, 
+                               std::string *ErrMsg){
   BitcodeReader *R;
-  R = static_cast<BitcodeReader*>(getBitcodeModuleProvider(Buffer, ErrMsg));
+  R = static_cast<BitcodeReader*>(getBitcodeModuleProvider(Buffer, Context, 
+                                                           ErrMsg));
   if (!R) return 0;
   
   // Read in the entire module.
index 0dc470b24a239a06d3b773ace9e3b6ce1e0ee047..498a34ae01bf19c92a1ebda920ede321e0998894 100644 (file)
@@ -26,6 +26,7 @@
 
 namespace llvm {
   class MemoryBuffer;
+  class LLVMContext;
   
 //===----------------------------------------------------------------------===//
 //                          BitcodeReaderValueList Class
@@ -85,6 +86,7 @@ public:
 };
 
 class BitcodeReader : public ModuleProvider {
+  LLVMContext* Context;
   MemoryBuffer *Buffer;
   BitstreamReader StreamFile;
   BitstreamCursor Stream;
@@ -123,8 +125,8 @@ class BitcodeReader : public ModuleProvider {
   /// stream) and what linkage the original function had.
   DenseMap<Function*, std::pair<uint64_t, unsigned> > DeferredFunctionInfo;
 public:
-  explicit BitcodeReader(MemoryBuffer *buffer)
-      : Buffer(buffer), ErrorString(0) {
+  explicit BitcodeReader(MemoryBuffer *buffer, LLVMContext* C)
+      : Context(C), Buffer(buffer), ErrorString(0) {
     HasReversedFunctionsWithBodies = false;
   }
   ~BitcodeReader() {
index b12d90ac9db025b843385937f1f67514eb6ef6c7..dbfbbed1dc5491ad3d623eec830b33044ccdb52d 100644 (file)
@@ -46,11 +46,11 @@ std::string Debugger::getProgramPath() const {
 }
 
 static Module *
-getMaterializedModuleProvider(const std::string &Filename) {
+getMaterializedModuleProvider(const std::string &Filename, LLVMContext* C) {
   std::auto_ptr<MemoryBuffer> Buffer;
   Buffer.reset(MemoryBuffer::getFileOrSTDIN(Filename.c_str()));
   if (Buffer.get())
-    return ParseBitcodeFile(Buffer.get());
+    return ParseBitcodeFile(Buffer.get(), C);
   return 0;
 }
 
@@ -58,9 +58,9 @@ getMaterializedModuleProvider(const std::string &Filename) {
 /// the PATH for the specified program, loading it when found.  If the
 /// specified program cannot be found, an exception is thrown to indicate the
 /// error.
-void Debugger::loadProgram(const std::string &Filename) {
-  if ((Program = getMaterializedModuleProvider(Filename)) ||
-      (Program = getMaterializedModuleProvider(Filename+".bc")))
+void Debugger::loadProgram(const std::string &Filename, LLVMContext* C) {
+  if ((Program = getMaterializedModuleProvider(Filename, C)) ||
+      (Program = getMaterializedModuleProvider(Filename+".bc", C)))
     return;   // Successfully loaded the program.
 
   // Search the program path for the file...
@@ -69,9 +69,9 @@ void Debugger::loadProgram(const std::string &Filename) {
 
     std::string Directory = getToken(Path, ":");
     while (!Directory.empty()) {
-      if ((Program = getMaterializedModuleProvider(Directory +"/"+ Filename)) ||
-          (Program = getMaterializedModuleProvider(Directory +"/"+ Filename
-                                                                      + ".bc")))
+      if ((Program = getMaterializedModuleProvider(Directory +"/"+ Filename, C))
+       || (Program = getMaterializedModuleProvider(Directory +"/"+ Filename
+                                                                   + ".bc", C)))
         return;   // Successfully loaded the program.
 
       Directory = getToken(Path, ":");
index 551cc8c390d86594de9813ec264ef9b488b5a5b7..faf01af127e9414c8b1789e507d495d56b3bb575 100644 (file)
@@ -115,7 +115,7 @@ Linker::LinkInArchive(const sys::Path &Filename, bool &is_native) {
 
   std::string ErrMsg;
   std::auto_ptr<Archive> AutoArch (
-    Archive::OpenAndLoadSymbols(Filename,&ErrMsg));
+    Archive::OpenAndLoadSymbols(Filename, Context, &ErrMsg));
 
   Archive* arch = AutoArch.get();
 
index 7c888aa498a3f1658b3e7f3a964698b4f03145c1..dc0f7c17bf42dbe6150ad4be8cc384b8ae55cd1a 100644 (file)
@@ -160,7 +160,7 @@ bool Linker::LinkInFile(const sys::Path &File, bool &is_native) {
   if (File.toString() == "-") {
     std::auto_ptr<Module> M;
     if (MemoryBuffer *Buffer = MemoryBuffer::getSTDIN()) {
-      M.reset(ParseBitcodeFile(Buffer, &Error));
+      M.reset(ParseBitcodeFile(Buffer, Context, &Error));
       delete Buffer;
       if (M.get())
         if (!LinkInModule(M.get(), &Error))
index d6737721d25fb74a5330e386737496a5cb8d3348..d0d69d072c1700bf5a4d81580593297342d9a3ee 100644 (file)
 using namespace llvm;
 
 Linker::Linker(const std::string& progname, const std::string& modname,
-               unsigned flags)
-  : Composite(0)
-  , LibPaths()
-  , Flags(flags)
-  , Error()
-  , ProgramName(progname)
-{
-  Composite = new Module(modname);
-}
-
-Linker::Linker(const std::string& progname, Module* aModule, unsigned flags)
-  : Composite(aModule)
-  , LibPaths()
-  , Flags(flags)
-  , Error()
-  , ProgramName(progname)
-{
-}
+               LLVMContext* C, unsigned flags): 
+  Context(C),
+  Composite(new Module(modname, C)),
+  LibPaths(),
+  Flags(flags),
+  Error(),
+  ProgramName(progname) { }
+
+Linker::Linker(const std::string& progname, Module* aModule, unsigned flags) : 
+  Context(aModule->getContext()),
+  Composite(aModule),
+  LibPaths(),
+  Flags(flags),
+  Error(),
+  ProgramName(progname) { }
 
 Linker::~Linker() {
   delete Composite;
@@ -106,7 +103,7 @@ Linker::LoadObject(const sys::Path &FN) {
   const std::string &FNS = FN.toString();
   std::auto_ptr<MemoryBuffer> Buffer(MemoryBuffer::getFileOrSTDIN(FNS.c_str()));
   if (Buffer.get())
-    Result = ParseBitcodeFile(Buffer.get(), &ParseErrorMessage);
+    Result = ParseBitcodeFile(Buffer.get(), Context, &ParseErrorMessage);
   else
     ParseErrorMessage = "Error reading file '" + FNS + "'";
     
index 337fa8a44bbe968ebc2f74dacef333adf50e28be..82f5b93a9544d51af2c6166221469fd43a8782dd 100644 (file)
@@ -35,7 +35,7 @@ Module *llvm::CloneModule(const Module *M) {
 Module *llvm::CloneModule(const Module *M,
                           DenseMap<const Value*, Value*> &ValueMap) {
   // First off, we need to create the new module...
-  Module *New = new Module(M->getModuleIdentifier());
+  Module *New = new Module(M->getModuleIdentifier(), M->getContext());
   New->setDataLayout(M->getDataLayout());
   New->setTargetTriple(M->getTargetTriple());
   New->setModuleInlineAsm(M->getModuleInlineAsm());
index f85dbe76119e0e9b1c224d250e4d5c53f18dc267..1c0a8f7af2593da522c70ac816f8643136ce0bf7 100644 (file)
@@ -18,6 +18,7 @@
 #include "llvm/DerivedTypes.h"
 #include "llvm/GlobalVariable.h"
 #include "llvm/GlobalAlias.h"
+#include "llvm/LLVMContext.h"
 #include "llvm/TypeSymbolTable.h"
 #include "llvm/ModuleProvider.h"
 #include "llvm/InlineAsm.h"
@@ -38,10 +39,21 @@ void LLVMDisposeMessage(char *Message) {
 }
 
 
+/*===-- Operations on contexts --------------------------------------------===*/
+
+LLVMContextRef LLVMContextCreate() {
+  return wrap(new LLVMContext());
+}
+
+void LLVMContextDispose(LLVMContextRef C) {
+  delete unwrap(C);
+}
+
+
 /*===-- Operations on modules ---------------------------------------------===*/
 
-LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID) {
-  return wrap(new Module(ModuleID));
+LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID, LLVMContextRef C) {
+  return wrap(new Module(ModuleID, unwrap(C)));
 }
 
 void LLVMDisposeModule(LLVMModuleRef M) {
index a598005e2a8946336fcd13efb190a10231d67dd8..96a25a5d0d25349b43db5965fd0af720a6690dc7 100644 (file)
@@ -15,6 +15,7 @@
 #include "llvm/InstrTypes.h"
 #include "llvm/Constants.h"
 #include "llvm/DerivedTypes.h"
+#include "llvm/LLVMContext.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/LeakDetector.h"
@@ -54,8 +55,8 @@ template class SymbolTableListTraits<GlobalAlias, Module>;
 // Primitive Module methods.
 //
 
-Module::Module(const std::string &MID)
-  : ModuleID(MID), DataLayout("") {
+Module::Module(const std::string &MID, LLVMContext* C)
+  : Context(C), ModuleID(MID), DataLayout("")  {
   ValSymTab = new ValueSymbolTable();
   TypeSymTab = new TypeSymbolTable();
 }
index d050b59ed770350531c4411f05dad79010667e4b..340522a4437b034aaf444462fcdd8515c35d9c3b 100644 (file)
@@ -64,24 +64,24 @@ std::string llvm::getPassesString(const std::vector<const PassInfo*> &Passes) {
 }
 
 BugDriver::BugDriver(const char *toolname, bool as_child, bool find_bugs,
-                     unsigned timeout, unsigned memlimit)
-  : ToolName(toolname), ReferenceOutputFile(OutputFile),
+                     unsigned timeout, unsigned memlimit, LLVMContext* ctxt)
+  : Context(ctxt), ToolName(toolname), ReferenceOutputFile(OutputFile),
     Program(0), Interpreter(0), SafeInterpreter(0), gcc(0),
-    run_as_child(as_child),
-    run_find_bugs(find_bugs), Timeout(timeout), MemoryLimit(memlimit) {}
+    run_as_child(as_child), run_find_bugs(find_bugs), Timeout(timeout), 
+    MemoryLimit(memlimit)  {}
 
 
 /// ParseInputFile - Given a bitcode or assembly input filename, parse and
 /// return it, or return null if not possible.
 ///
-Module *llvm::ParseInputFile(const std::string &Filename) {
+Module *llvm::ParseInputFile(const std::string &Filename, LLVMContext* Ctxt) {
   std::auto_ptr<MemoryBuffer> Buffer(MemoryBuffer::getFileOrSTDIN(Filename));
   Module *Result = 0;
   if (Buffer.get())
-    Result = ParseBitcodeFile(Buffer.get());
+    Result = ParseBitcodeFile(Buffer.get(), Ctxt);
   
   ParseError Err;
-  if (!Result && !(Result = ParseAssemblyFile(Filename, Err))) {
+  if (!Result && !(Result = ParseAssemblyFile(Filename, Err, Ctxt))) {
     Err.PrintError("bugpoint", errs()); 
     Result = 0;
   }
@@ -100,14 +100,14 @@ bool BugDriver::addSources(const std::vector<std::string> &Filenames) {
 
   try {
     // Load the first input file.
-    Program = ParseInputFile(Filenames[0]);
+    Program = ParseInputFile(Filenames[0], Context);
     if (Program == 0) return true;
     
     if (!run_as_child)
       std::cout << "Read input file      : '" << Filenames[0] << "'\n";
 
     for (unsigned i = 1, e = Filenames.size(); i != e; ++i) {
-      std::auto_ptr<Module> M(ParseInputFile(Filenames[i]));
+      std::auto_ptr<Module> M(ParseInputFile(Filenames[i], Context));
       if (M.get() == 0) return true;
 
       if (!run_as_child)
index 96e9fb98017556872e12ef56a4b3807c7343e6aa..4c81cc2a2b6db2b95f37f54a322d650aca3fc382 100644 (file)
@@ -30,6 +30,7 @@ class Function;
 class BasicBlock;
 class AbstractInterpreter;
 class Instruction;
+class LLVMContext;
 
 class DebugCrashes;
 
@@ -42,6 +43,7 @@ extern bool DisableSimplifyCFG;
 extern bool BugpointIsInterrupted;
 
 class BugDriver {
+  LLVMContext* Context;
   const std::string ToolName;  // Name of bugpoint
   std::string ReferenceOutputFile; // Name of `good' output file
   Module *Program;             // The raw program, linked together
@@ -60,10 +62,12 @@ class BugDriver {
 
 public:
   BugDriver(const char *toolname, bool as_child, bool find_bugs,
-            unsigned timeout, unsigned memlimit);
+            unsigned timeout, unsigned memlimit, LLVMContext* ctxt);
 
   const std::string &getToolName() const { return ToolName; }
 
+  LLVMContext* getContext() { return Context; }
+
   // Set up methods... these methods are used to copy information about the
   // command line arguments into instance variables of BugDriver.
   //
@@ -290,7 +294,7 @@ private:
 /// ParseInputFile - Given a bitcode or assembly input filename, parse and
 /// return it, or return null if not possible.
 ///
-Module *ParseInputFile(const std::string &InputFilename);
+Module *ParseInputFile(const std::string &InputFilename, LLVMContext* ctxt);
 
 
 /// getPassesString - Turn a list of passes into a string which indicates the
index 7daf57c91589f824fc374d83da681ff4abbb979f..9697b341f3a20f664e4ed5686e63d3b271e6a2b9 100644 (file)
@@ -73,7 +73,7 @@ ReducePassList::doTest(std::vector<const PassInfo*> &Prefix,
     PrefixOutput.set(PfxOutput);
     OrigProgram = BD.Program;
 
-    BD.Program = ParseInputFile(PrefixOutput.toString());
+    BD.Program = ParseInputFile(PrefixOutput.toString(), BD.getContext());
     if (BD.Program == 0) {
       std::cerr << BD.getToolName() << ": Error reading bitcode file '"
                 << PrefixOutput << "'!\n";
index 7e8ff78a9cf2404cb367886436899e23d233e874..b3260e13606f60609820b45eb2853c6f727b1109 100644 (file)
@@ -112,7 +112,7 @@ ReduceMiscompilingPasses::doTest(std::vector<const PassInfo*> &Prefix,
   // Ok, so now we know that the prefix passes work, try running the suffix
   // passes on the result of the prefix passes.
   //
-  Module *PrefixOutput = ParseInputFile(BitcodeResult);
+  Module *PrefixOutput = ParseInputFile(BitcodeResult, BD.getContext());
   if (PrefixOutput == 0) {
     std::cerr << BD.getToolName() << ": Error reading bitcode file '"
               << BitcodeResult << "'!\n";
index 3ded5e866b3e025baaea3eee40a49dcd3df6ff2d..741be24adefd044c64b14f646c3db50563f92d51 100644 (file)
@@ -255,7 +255,7 @@ Module *BugDriver::runPassesOn(Module *M,
   // Restore the current program.
   swapProgramIn(OldProgram);
 
-  Module *Ret = ParseInputFile(BitcodeResult);
+  Module *Ret = ParseInputFile(BitcodeResult, Context);
   if (Ret == 0) {
     cerr << getToolName() << ": Error reading bitcode file '"
          << BitcodeResult << "'!\n";
index 20f0e99a848881b40180c27afef40bb912d05ce5..57007e035c47d481616cc44dd75065a976ebcbc7 100644 (file)
@@ -16,6 +16,7 @@
 #include "BugDriver.h"
 #include "ToolRunner.h"
 #include "llvm/LinkAllPasses.h"
+#include "llvm/LLVMContext.h"
 #include "llvm/Support/PassNameParser.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/ManagedStatic.h"
@@ -73,8 +74,9 @@ int main(int argc, char **argv) {
                               "llvm.org/cmds/bugpoint.html"
                               " for more information.\n");
   sys::SetInterruptFunction(BugpointInterruptFunction);
-  
-  BugDriver D(argv[0], AsChild, FindBugs, TimeoutValue, MemoryLimit);
+
+  LLVMContext Context;
+  BugDriver D(argv[0], AsChild, FindBugs, TimeoutValue, MemoryLimit, &Context);
   if (D.addSources(InputFilenames)) return 1;
   D.addPasses(PassList.begin(), PassList.end());
 
index e71b37832363258f83eaffc0fe7dc7d2ff3cf0b4..d0d88c505f74bf7896eed753c969b94fe8e3b73f 100644 (file)
@@ -22,6 +22,7 @@
 #include "llvm/Target/TargetMachine.h"
 #include "llvm/Target/TargetMachineRegistry.h"
 #include "llvm/Transforms/Scalar.h"
+#include "llvm/LLVMContext.h"
 #include "llvm/Module.h"
 #include "llvm/ModuleProvider.h"
 #include "llvm/PassManager.h"
@@ -212,6 +213,7 @@ static raw_ostream *GetOutputStream(const char *ProgName) {
 int main(int argc, char **argv) {
   sys::PrintStackTraceOnErrorSignal();
   PrettyStackTraceProgram X(argc, argv);
+  LLVMContext Context;
   llvm_shutdown_obj Y;  // Call llvm_shutdown() on exit.
   cl::ParseCommandLineOptions(argc, argv, "llvm system compiler\n");
 
@@ -225,7 +227,7 @@ int main(int argc, char **argv) {
   std::auto_ptr<MemoryBuffer> Buffer(
                    MemoryBuffer::getFileOrSTDIN(InputFilename, &ErrorMessage));
   if (Buffer.get())
-    M.reset(ParseBitcodeFile(Buffer.get(), &ErrorMessage));
+    M.reset(ParseBitcodeFile(Buffer.get(), &Context, &ErrorMessage));
   if (M.get() == 0) {
     std::cerr << argv[0] << ": bitcode didn't read correctly.\n";
     std::cerr << "Reason: " << ErrorMessage << "\n";
index 25536746dad0a6efdf7dc11598d65f851d4f7084..10b86382a455a2803be7e7e9bbf6f0e5ce96caa0 100644 (file)
@@ -13,6 +13,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "llvm/LLVMContext.h"
 #include "llvm/Module.h"
 #include "llvm/ModuleProvider.h"
 #include "llvm/Type.h"
@@ -93,6 +94,7 @@ int main(int argc, char **argv, char * const *envp) {
   sys::PrintStackTraceOnErrorSignal();
   PrettyStackTraceProgram X(argc, argv);
   
+  LLVMContext Context;
   atexit(do_shutdown);  // Call llvm_shutdown() on exit.
   cl::ParseCommandLineOptions(argc, argv,
                               "llvm interpreter & dynamic compiler\n");
@@ -104,8 +106,8 @@ int main(int argc, char **argv, char * const *envp) {
   // Load the bitcode...
   std::string ErrorMsg;
   ModuleProvider *MP = NULL;
-  if (MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(InputFile,&ErrorMsg)) {
-    MP = getBitcodeModuleProvider(Buffer, &ErrorMsg);
+  if (MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(InputFile,&ErrorMsg)){
+    MP = getBitcodeModuleProvider(Buffer, &Context, &ErrorMsg);
     if (!MP) delete Buffer;
   }
   
index 5d81fc7cf3886d8bfdfb485f4e0e6c405994d812..960f8e371b8bab0d3a8007b697043a59713157ef 100644 (file)
@@ -12,6 +12,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "llvm/LLVMContext.h"
 #include "llvm/Module.h"
 #include "llvm/Bitcode/Archive.h"
 #include "llvm/Support/CommandLine.h"
@@ -690,6 +691,7 @@ int main(int argc, char **argv) {
   // Print a stack trace if we signal out.
   sys::PrintStackTraceOnErrorSignal();
   PrettyStackTraceProgram X(argc, argv);
+  LLVMContext Context;
   llvm_shutdown_obj Y;  // Call llvm_shutdown() on exit.
 
   // Have the command line options parsed and handle things
@@ -717,11 +719,11 @@ int main(int argc, char **argv) {
       // Produce a warning if we should and we're creating the archive
       if (!Create)
         std::cerr << argv[0] << ": creating " << ArchivePath.toString() << "\n";
-      TheArchive = Archive::CreateEmpty(ArchivePath);
+      TheArchive = Archive::CreateEmpty(ArchivePath, &Context);
       TheArchive->writeToDisk();
     } else {
       std::string Error;
-      TheArchive = Archive::OpenAndLoad(ArchivePath, &Error);
+      TheArchive = Archive::OpenAndLoad(ArchivePath, &Context, &Error);
       if (TheArchive == 0) {
         std::cerr << argv[0] << ": error loading '" << ArchivePath << "': "
                   << Error << "!\n";
index 79ece8f106f49708b256866ab6cfc73a7f2b12db..06798cbd28a33e23614d734eca84eff733b7fad2 100644 (file)
@@ -15,6 +15,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "llvm/LLVMContext.h"
 #include "llvm/Module.h"
 #include "llvm/Assembly/Parser.h"
 #include "llvm/Analysis/Verifier.h"
@@ -55,6 +56,7 @@ int main(int argc, char **argv) {
   // Print a stack trace if we signal out.
   sys::PrintStackTraceOnErrorSignal();
   PrettyStackTraceProgram X(argc, argv);
+  LLVMContext Context;
   llvm_shutdown_obj Y;  // Call llvm_shutdown() on exit.
   cl::ParseCommandLineOptions(argc, argv, "llvm .ll -> .bc assembler\n");
 
@@ -63,7 +65,7 @@ int main(int argc, char **argv) {
   try {
     // Parse the file now...
     ParseError Err;
-    std::auto_ptr<Module> M(ParseAssemblyFile(InputFilename, Err));
+    std::auto_ptr<Module> M(ParseAssemblyFile(InputFilename, Err, &Context));
     if (M.get() == 0) {
       Err.PrintError(argv[0], errs());
       return 1;
index 1d2a8387a9c76e209ebc92f2ac3bc17363cdae77..c7aedd1006e00f4b1bb286a0819505fcb4de19ba 100644 (file)
@@ -22,8 +22,9 @@ using namespace llvm;
 /// CLIDebugger constructor - This initializes the debugger to its default
 /// state, and initializes the command table.
 ///
-CLIDebugger::CLIDebugger()
-  : TheProgramInfo(0), TheRuntimeInfo(0), Prompt("(llvm-db) "), ListSize(10) {
+CLIDebugger::CLIDebugger(LLVMContext* ctxt)
+  : Context(ctxt), TheProgramInfo(0), TheRuntimeInfo(0),
+    Prompt("(llvm-db) "), ListSize(10) {
   // Initialize instance variables
   CurrentFile = 0;
   LineListedStart = 1;
index 56ea14dfbcfd88a0d1c6dbfda9bee37a35f25017..b1a31a4d91dcc900c6bd204ddae8451cafa42383 100644 (file)
@@ -24,10 +24,13 @@ namespace llvm {
   class SourceLanguage;
   class ProgramInfo;
   class RuntimeInfo;
+  class LLVMContext;
 
   /// CLIDebugger - This class implements the command line interface for the
   /// LLVM debugger.
   class CLIDebugger {
+    LLVMContext* Context;
+    
     /// Dbg - The low-level LLVM debugger object that we use to do our dirty
     /// work.
     Debugger Dbg;
@@ -79,7 +82,7 @@ namespace llvm {
     const SourceLanguage *CurrentLanguage;
 
   public:
-    CLIDebugger();
+    CLIDebugger(LLVMContext* ctxt);
 
     /// getDebugger - Return the current LLVM debugger implementation being
     /// used.
index ffebdd5d58f4bedfb0d2d304ed7625c9b6694d8f..4c916f42780536591e776545529869d837db1780 100644 (file)
@@ -64,7 +64,7 @@ void CLIDebugger::startProgramRunning() {
     TheProgramInfo = 0;
     CurrentFile = 0;
 
-    Dbg.loadProgram(Program.toString());
+    Dbg.loadProgram(Program.toString(), Context);
     TheProgramInfo = new ProgramInfo(Dbg.getProgram());
   }
 
@@ -244,7 +244,7 @@ void CLIDebugger::fileCommand(std::string &Options) {
     std::cout << "Unloaded program.\n";
   } else {
     std::cout << "Loading program... " << std::flush;
-    Dbg.loadProgram(Prog);
+    Dbg.loadProgram(Prog, Context);
     assert(Dbg.isProgramLoaded() &&
            "loadProgram succeeded, but not program loaded!");
     TheProgramInfo = new ProgramInfo(Dbg.getProgram());
index 04e616227b240c0dc5381c75bc0b0a3d765508bc..62ee325bfd4a932a86c6628b203cbd1e7946e34b 100644 (file)
@@ -13,6 +13,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "CLIDebugger.h"
+#include "llvm/LLVMContext.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/PrettyStackTrace.h"
@@ -54,6 +55,7 @@ int main(int argc, char **argv, char * const *envp) {
   sys::PrintStackTraceOnErrorSignal();
   PrettyStackTraceProgram X(argc, argv);
   
+  LLVMContext Context;
   llvm_shutdown_obj Y;  // Call llvm_shutdown() on exit.
   std::cout << "NOTE: llvm-db is known useless right now.\n";
   try {
@@ -68,7 +70,7 @@ int main(int argc, char **argv, char * const *envp) {
       InputArgs.push_back(InputFile);
 
     // Create the CLI debugger...
-    CLIDebugger D;
+    CLIDebugger D(&Context);
 
     // Initialize the debugger with the command line options we read...
     Debugger &Dbg = D.getDebugger();
index 471e5e2f5d2c8c8a2f64f5320f849db65172124c..3460f7e0fb7d3a010151e45212edd9999ed8ce36 100644 (file)
@@ -16,6 +16,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "llvm/LLVMContext.h"
 #include "llvm/Module.h"
 #include "llvm/PassManager.h"
 #include "llvm/Bitcode/ReaderWriter.h"
@@ -50,6 +51,7 @@ int main(int argc, char **argv) {
   sys::PrintStackTraceOnErrorSignal();
   PrettyStackTraceProgram X(argc, argv);
   
+  LLVMContext Context;
   llvm_shutdown_obj Y;  // Call llvm_shutdown() on exit.
   try {
     cl::ParseCommandLineOptions(argc, argv, "llvm .bc -> .ll disassembler\n");
@@ -61,7 +63,7 @@ int main(int argc, char **argv) {
    
     if (MemoryBuffer *Buffer
            = MemoryBuffer::getFileOrSTDIN(InputFilename, &ErrorMessage)) {
-      M.reset(ParseBitcodeFile(Buffer, &ErrorMessage));
+      M.reset(ParseBitcodeFile(Buffer, &Context, &ErrorMessage));
       delete Buffer;
     }
 
index 46840f2e223a8215f6afcc40a2cdc7cf9e319bd9..a9772116c9f4c092caed1fa40a77fc83575f1d6d 100644 (file)
@@ -12,6 +12,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "llvm/LLVMContext.h"
 #include "llvm/Module.h"
 #include "llvm/PassManager.h"
 #include "llvm/Bitcode/ReaderWriter.h"
@@ -60,7 +61,8 @@ int main(int argc, char **argv) {
   // Print a stack trace if we signal out.
   sys::PrintStackTraceOnErrorSignal();
   PrettyStackTraceProgram X(argc, argv);
-  
+
+  LLVMContext Context;
   llvm_shutdown_obj Y;  // Call llvm_shutdown() on exit.
   cl::ParseCommandLineOptions(argc, argv, "llvm extractor\n");
 
@@ -71,7 +73,7 @@ int main(int argc, char **argv) {
     cerr << argv[0] << ": Error reading file '" + InputFilename + "'\n";
     return 1;
   } else {
-    M.reset(ParseBitcodeFile(Buffer));
+    M.reset(ParseBitcodeFile(Buffer, &Context));
   }
   delete Buffer;
   
index fd2e0f7cac2501dc2b4c55cf88c6e2d8ce6621ea..435de0f4a36585181357dc7ba08d040cb6cad0a3 100644 (file)
@@ -22,6 +22,7 @@
 
 #include "llvm/LinkAllVMCore.h"
 #include "llvm/Linker.h"
+#include "llvm/LLVMContext.h"
 #include "llvm/System/Program.h"
 #include "llvm/Module.h"
 #include "llvm/PassManager.h"
@@ -505,7 +506,8 @@ int main(int argc, char **argv, char **envp) {
   // Print a stack trace if we signal out.
   sys::PrintStackTraceOnErrorSignal();
   PrettyStackTraceProgram X(argc, argv);
-  
+
+  LLVMContext Context;
   llvm_shutdown_obj Y;  // Call llvm_shutdown() on exit.
   try {
     // Initial global variable above for convenience printing of program name.
@@ -515,7 +517,7 @@ int main(int argc, char **argv, char **envp) {
     cl::ParseCommandLineOptions(argc, argv, "llvm linker\n");
 
     // Construct a Linker (now that Verbose is set)
-    Linker TheLinker(progname, OutputFilename, Verbose);
+    Linker TheLinker(progname, OutputFilename, &Context, Verbose);
 
     // Keep track of the native link items (versus the bitcode items)
     Linker::ItemList NativeLinkItems;
index 15850f4717e387f1bade550ee02f456842f3643d..ae5fa40ecba8491639cc96ca00cb8d4cfb666e0a 100644 (file)
@@ -13,6 +13,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/Linker.h"
+#include "llvm/LLVMContext.h"
 #include "llvm/Module.h"
 #include "llvm/Analysis/Verifier.h"
 #include "llvm/Bitcode/ReaderWriter.h"
@@ -47,7 +48,8 @@ DumpAsm("d", cl::desc("Print assembly as linked"), cl::Hidden);
 // LoadFile - Read the specified bitcode file in and return it.  This routine
 // searches the link path for the specified file to try to find it...
 //
-static inline std::auto_ptr<Module> LoadFile(const std::string &FN) {
+static inline std::auto_ptr<Module> LoadFile(const std::string &FN, 
+                                             LLVMContext* Context) {
   sys::Path Filename;
   if (!Filename.set(FN)) {
     cerr << "Invalid file name: '" << FN << "'\n";
@@ -62,7 +64,7 @@ static inline std::auto_ptr<Module> LoadFile(const std::string &FN) {
     const std::string &FNStr = Filename.toString();
     if (MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(FNStr,
                                                             &ErrorMessage)) {
-      Result = ParseBitcodeFile(Buffer, &ErrorMessage);
+      Result = ParseBitcodeFile(Buffer, Context, &ErrorMessage);
       delete Buffer;
     }
     if (Result) return std::auto_ptr<Module>(Result);   // Load successful!
@@ -84,13 +86,14 @@ int main(int argc, char **argv) {
   sys::PrintStackTraceOnErrorSignal();
   PrettyStackTraceProgram X(argc, argv);
   
+  LLVMContext Context;
   llvm_shutdown_obj Y;  // Call llvm_shutdown() on exit.
   cl::ParseCommandLineOptions(argc, argv, "llvm linker\n");
 
   unsigned BaseArg = 0;
   std::string ErrorMessage;
 
-  std::auto_ptr<Module> Composite(LoadFile(InputFilenames[BaseArg]));
+  std::auto_ptr<Module> Composite(LoadFile(InputFilenames[BaseArg], &Context));
   if (Composite.get() == 0) {
     cerr << argv[0] << ": error loading file '"
          << InputFilenames[BaseArg] << "'\n";
@@ -98,7 +101,7 @@ int main(int argc, char **argv) {
   }
 
   for (unsigned i = BaseArg+1; i < InputFilenames.size(); ++i) {
-    std::auto_ptr<Module> M(LoadFile(InputFilenames[i]));
+    std::auto_ptr<Module> M(LoadFile(InputFilenames[i], &Context));
     if (M.get() == 0) {
       cerr << argv[0] << ": error loading file '" <<InputFilenames[i]<< "'\n";
       return 1;
index 324e0f67035c7021686ae7425a6746d6b9e52802..3f19940660e93b0828f4760880ad6a1df8623654 100644 (file)
@@ -16,6 +16,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "llvm/LLVMContext.h"
 #include "llvm/Module.h"
 #include "llvm/Bitcode/ReaderWriter.h"
 #include "llvm/Bitcode/Archive.h"
@@ -132,6 +133,7 @@ static void DumpSymbolNamesFromModule(Module *M) {
 }
 
 static void DumpSymbolNamesFromFile(std::string &Filename) {
+  LLVMContext Context;
   std::string ErrorMessage;
   sys::Path aPath(Filename);
   // Note: Currently we do not support reading an archive from stdin.
@@ -140,7 +142,7 @@ static void DumpSymbolNamesFromFile(std::string &Filename) {
                    MemoryBuffer::getFileOrSTDIN(Filename, &ErrorMessage));
     Module *Result = 0;
     if (Buffer.get())
-      Result = ParseBitcodeFile(Buffer.get(), &ErrorMessage);
+      Result = ParseBitcodeFile(Buffer.get(), &Context, &ErrorMessage);
     
     if (Result)
       DumpSymbolNamesFromModule(Result);
@@ -151,7 +153,8 @@ static void DumpSymbolNamesFromFile(std::string &Filename) {
     
   } else if (aPath.isArchive()) {
     std::string ErrMsg;
-    Archive* archive = Archive::OpenAndLoad(sys::Path(Filename), &ErrorMessage);
+    Archive* archive = Archive::OpenAndLoad(sys::Path(Filename), &Context,
+                                            &ErrorMessage);
     if (!archive)
       std::cerr << ToolName << ": " << Filename << ": " << ErrorMessage << "\n";
     std::vector<Module *> Modules;
index 119dc1a1178c5d893b31c2d71fa4bc677512d901..104d879447e106d663395571b364c44e302b8d64 100644 (file)
@@ -14,6 +14,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/InstrTypes.h"
+#include "llvm/LLVMContext.h"
 #include "llvm/Module.h"
 #include "llvm/Assembly/AsmAnnotationWriter.h"
 #include "llvm/Analysis/ProfileInfoLoader.h"
@@ -115,7 +116,8 @@ int main(int argc, char **argv) {
   // Print a stack trace if we signal out.
   sys::PrintStackTraceOnErrorSignal();
   PrettyStackTraceProgram X(argc, argv);
-  
+
+  LLVMContext Context;
   llvm_shutdown_obj Y;  // Call llvm_shutdown() on exit.
   try {
     cl::ParseCommandLineOptions(argc, argv, "llvm profile dump decoder\n");
@@ -125,7 +127,7 @@ int main(int argc, char **argv) {
     Module *M = 0;
     if (MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(BitcodeFile,
                                                             &ErrorMessage)) {
-      M = ParseBitcodeFile(Buffer, &ErrorMessage);
+      M = ParseBitcodeFile(Buffer, &Context, &ErrorMessage);
       delete Buffer;
     }
     if (M == 0) {
index 72106104c0067f22f8b93ab5e6b0334db212aab6..7b1b413ecca852c91eed76a5cda54fe7555ca2e2 100644 (file)
@@ -11,6 +11,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "llvm/LLVMContext.h"
 #include "llvm/Module.h"
 #include "llvm/Bitcode/Archive.h"
 #include "llvm/Support/CommandLine.h"
@@ -46,7 +47,8 @@ int main(int argc, char **argv) {
   // Print a stack trace if we signal out.
   llvm::sys::PrintStackTraceOnErrorSignal();
   llvm::PrettyStackTraceProgram X(argc, argv);
-  
+
+  LLVMContext Context;
   llvm_shutdown_obj Y;  // Call llvm_shutdown() on exit.
 
   // Have the command line options parsed and handle things
@@ -73,7 +75,7 @@ int main(int argc, char **argv) {
 
     std::string err_msg;
     std::auto_ptr<Archive>
-      AutoArchive(Archive::OpenAndLoad(ArchivePath,&err_msg));
+      AutoArchive(Archive::OpenAndLoad(ArchivePath, &Context, &err_msg));
     Archive* TheArchive = AutoArchive.get();
     if (!TheArchive)
       throw err_msg;
index 52624ebe91001419ff0f8062f65be3e9ebb9d9f0..8ae196fe94270d0f1f2fea69978356c37fe4fe25 100644 (file)
@@ -70,7 +70,8 @@ const char* LTOCodeGenerator::getVersionString()
 
 
 LTOCodeGenerator::LTOCodeGenerator() 
-    : _linker("LinkTimeOptimizer", "ld-temp.o"), _target(NULL),
+    : _context(new LLVMContext()),
+      _linker("LinkTimeOptimizer", "ld-temp.o", _context), _target(NULL),
       _emitDwarfDebugInfo(false), _scopeRestrictionsDone(false),
       _codeModel(LTO_CODEGEN_PIC_MODEL_DYNAMIC),
       _nativeObjectFile(NULL), _gccPath(NULL), _assemblerPath(NULL)
index e02a7ab1159f1b6ed267e3970e49ed80db067f44..d412626fbf4a0f48a0fd3dbefc123b10609288d1 100644 (file)
@@ -16,6 +16,7 @@
 #define LTO_CODE_GENERATOR_H
 
 #include "llvm/Linker.h"
+#include "llvm/LLVMContext.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/SmallVector.h"
 
@@ -53,6 +54,7 @@ private:
     
     typedef llvm::StringMap<uint8_t> StringSet;
 
+    llvm::LLVMContext*          _context;
     llvm::Linker                _linker;
     llvm::TargetMachine*        _target;
     bool                        _emitDwarfDebugInfo;
index 939d0eacd1e30736a652df535c057fdcdffd94a5..64e79509017d96ec0d08caca7c455c8d776f3626 100644 (file)
@@ -15,6 +15,7 @@
 #include "LTOModule.h"
 
 #include "llvm/Constants.h"
+#include "llvm/LLVMContext.h"
 #include "llvm/Module.h"
 #include "llvm/ModuleProvider.h"
 #include "llvm/ADT/OwningPtr.h"
@@ -67,7 +68,8 @@ bool LTOModule::isBitcodeFileForTarget(const char* path,
 // takes ownership of buffer
 bool LTOModule::isTargetMatch(MemoryBuffer* buffer, const char* triplePrefix)
 {
-    OwningPtr<ModuleProvider> mp(getBitcodeModuleProvider(buffer));
+    OwningPtr<ModuleProvider> mp(getBitcodeModuleProvider(buffer,
+                                                          new LLVMContext()));
     // on success, mp owns buffer and both are deleted at end of this method
     if ( !mp ) {
         delete buffer;
@@ -84,12 +86,13 @@ LTOModule::LTOModule(Module* m, TargetMachine* t)
 {
 }
 
-LTOModule* LTOModule::makeLTOModule(const char* path, std::string& errMsg)
+LTOModule* LTOModule::makeLTOModule(const char* path, LLVMContext* Context,
+                                    std::string& errMsg)
 {
     OwningPtr<MemoryBuffer> buffer(MemoryBuffer::getFile(path, &errMsg));
     if ( !buffer )
         return NULL;
-    return makeLTOModule(buffer.get(), errMsg);
+    return makeLTOModule(buffer.get(), Context, errMsg);
 }
 
 /// makeBuffer - create a MemoryBuffer from a memory range.
@@ -109,12 +112,13 @@ MemoryBuffer* LTOModule::makeBuffer(const void* mem, size_t length)
 
 
 LTOModule* LTOModule::makeLTOModule(const void* mem, size_t length, 
+                                    LLVMContext* Context,
                                     std::string& errMsg)
 {
     OwningPtr<MemoryBuffer> buffer(makeBuffer(mem, length));
     if ( !buffer )
         return NULL;
-    return makeLTOModule(buffer.get(), errMsg);
+    return makeLTOModule(buffer.get(), Context, errMsg);
 }
 
 /// getFeatureString - Return a string listing the features associated with the
@@ -136,10 +140,11 @@ std::string getFeatureString(const char *TargetTriple) {
   return Features.getString();
 }
 
-LTOModule* LTOModule::makeLTOModule(MemoryBuffer* buffer, std::string& errMsg)
+LTOModule* LTOModule::makeLTOModule(MemoryBuffer* buffer, LLVMContext* Context,
+                                    std::string& errMsg)
 {
     // parse bitcode buffer
-    OwningPtr<Module> m(ParseBitcodeFile(buffer, &errMsg));
+    OwningPtr<Module> m(ParseBitcodeFile(buffer, Context, &errMsg));
     if ( !m )
         return NULL;
     // find machine architecture for this module
index 9de02a2a4e28cbeabf66138a3af0d2ff1873c037..bfdf6e7fd093489e296848130b05966f4bed74c2 100644 (file)
@@ -32,6 +32,7 @@ namespace llvm {
     class GlobalValue;
     class Value;
     class Function;
+    class LLVMContext;
 }
 
 
@@ -50,9 +51,12 @@ public:
     static bool              isBitcodeFileForTarget(const char* path, 
                                                     const char* triplePrefix);
 
-    static LTOModule*        makeLTOModule(const char* path, std::string& errMsg);
+    static LTOModule*        makeLTOModule(const char* path,
+                                          llvm::LLVMContext* Context,
+                                          std::string& errMsg);
     static LTOModule*        makeLTOModule(const void* mem, size_t length,
-                                                            std::string& errMsg);
+                                           llvm::LLVMContext* Context,
+                                           std::string& errMsg);
 
     const char*              getTargetTriple();
     uint32_t                 getSymbolCount();
@@ -83,10 +87,11 @@ private:
     bool                    objcClassNameFromExpression(llvm::Constant* c, 
                                                     std::string& name);
 
-    static bool             isTargetMatch(llvm::MemoryBuffer* memBuffer, 
+    static bool             isTargetMatch(llvm::MemoryBuffer* memBuffer,
                                                     const char* triplePrefix);
 
-    static LTOModule*       makeLTOModule(llvm::MemoryBuffer* buffer, 
+    static LTOModule*       makeLTOModule(llvm::MemoryBuffer* buffer,
+                                          llvm::LLVMContext* Context,
                                                         std::string& errMsg);
     static llvm::MemoryBuffer* makeBuffer(const void* mem, size_t length);
 
index a0f67b44f5f241fffe50ac142a27eadc08176bbb..c25f87c34045f6e2eafe9756cbf40f37a010a740 100644 (file)
@@ -13,6 +13,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm-c/lto.h"
+#include "llvm-c/Core.h"
 
 #include "LTOModule.h"
 #include "LTOCodeGenerator.h"
@@ -85,9 +86,10 @@ bool lto_module_is_object_file_in_memory_for_target(const void* mem,
 // loads an object file from disk  
 // returns NULL on error (check lto_get_error_message() for details)
 //
-lto_module_t lto_module_create(const char* path)
+lto_module_t lto_module_create(const char* path, LLVMContextRef Ctxt)
 {
-     return LTOModule::makeLTOModule(path, sLastErrorString);
+     return LTOModule::makeLTOModule(path, llvm::unwrap(Ctxt), 
+                                     sLastErrorString);
 }
 
 
@@ -95,9 +97,11 @@ lto_module_t lto_module_create(const char* path)
 // loads an object file from memory 
 // returns NULL on error (check lto_get_error_message() for details)
 //
-lto_module_t lto_module_create_from_memory(const void* mem, size_t length)
+lto_module_t lto_module_create_from_memory(const void* mem, size_t length,
+                                           LLVMContextRef Ctxt)
 {
-     return LTOModule::makeLTOModule(mem, length, sLastErrorString);
+     return LTOModule::makeLTOModule(mem, length, llvm::unwrap(Ctxt),
+                                     sLastErrorString);
 }
 
 
index 0c36e21fa58bd1726a45ca53a747b9f1e1ef8f39..b46960638d832f430c6a2d72deb66d228cb31971 100644 (file)
@@ -12,6 +12,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "llvm/LLVMContext.h"
 #include "llvm/Module.h"
 #include "llvm/ModuleProvider.h"
 #include "llvm/PassManager.h"
@@ -310,6 +311,7 @@ void AddStandardCompilePasses(PassManager &PM) {
 //
 int main(int argc, char **argv) {
   llvm_shutdown_obj X;  // Call llvm_shutdown() on exit.
+  LLVMContext Context;
   try {
     cl::ParseCommandLineOptions(argc, argv,
       "llvm .bc -> .bc modular optimizer and analysis printer\n");
@@ -325,7 +327,7 @@ int main(int argc, char **argv) {
     std::auto_ptr<Module> M;
     if (MemoryBuffer *Buffer
           = MemoryBuffer::getFileOrSTDIN(InputFilename, &ErrorMessage)) {
-      M.reset(ParseBitcodeFile(Buffer, &ErrorMessage));
+      M.reset(ParseBitcodeFile(Buffer, &Context, &ErrorMessage));
       delete Buffer;
     }