[llvm-commits] [PATCH] Add an LLVMContext member to Module

Chris Lattner clattner at apple.com
Tue Jun 30 22:27:55 PDT 2009


On Jun 30, 2009, at 3:40 PM, Owen Anderson wrote:

> Here's the first of many patches related to pushing LLVMContext  
> through the existing APIs.  This adds an LLVMContext member to each  
> Module, which involves threading LLVMContext through large parts of  
> the bitcode reader, the ASM parser, and all of the tools.

Looks good to me.  Some minor nits:

+  /// Get the global data context.
+  /// @returns LLVMContext - a container for LLVM's global information
+  LLVMContext* getContext() const { return Context; }

Should this return a non-const context given a const module?



@@ -30,7 +31,8 @@
  /// @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.
  );

Is Context allowed to be null?  If not, these APIs (and the module  
ctor etc) should take the context by-reference, instead of by-pointer.




  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
  );

The module should already have a context, no need for it here.

+++ include/llvm-c/BitReader.h	(working copy)
@@ -29,13 +29,14 @@
  /* 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);


We really don't want to change the C APIs.  This will break bindings  
and cause other problems.  Please retain these entry-points (calling  
through here will default to using the "global" context).  If someone  
wants to enhance the C apis to support multiple contexts, they can add  
new C api entrypoints in the future.

Otherwise, looks great, please commit with these changes.  Thanks Owen,

-Chris



More information about the llvm-commits mailing list