diff options
55 files changed, 107 insertions, 98 deletions
diff --git a/examples/BrainF/BrainF.cpp b/examples/BrainF/BrainF.cpp index 0caff13e81..fa6d6675e7 100644 --- a/examples/BrainF/BrainF.cpp +++ b/examples/BrainF/BrainF.cpp @@ -37,7 +37,7 @@ const char *BrainF::label = "brainf"; const char *BrainF::testreg = "test"; Module *BrainF::parse(std::istream *in1, int mem, CompileFlags cf, - LLVMContext* Context) { + const LLVMContext& Context) { in = in1; memtotal = mem; comflag = cf; @@ -48,7 +48,7 @@ Module *BrainF::parse(std::istream *in1, int mem, CompileFlags cf, return module; } -void BrainF::header(LLVMContext* C) { +void BrainF::header(const LLVMContext& C) { module = new Module("BrainF", C); //Function prototypes diff --git a/examples/BrainF/BrainF.h b/examples/BrainF/BrainF.h index d0fb1b1de0..d21d3bb891 100644 --- a/examples/BrainF/BrainF.h +++ b/examples/BrainF/BrainF.h @@ -39,7 +39,8 @@ 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, LLVMContext* C); + Module *parse(std::istream *in1, int mem, CompileFlags cf, + const LLVMContext& C); protected: /// The different symbols in the BrainF language @@ -65,7 +66,7 @@ class BrainF { static const char *testreg; /// Put the brainf function preamble and other fixed pieces of code - void header(LLVMContext* C); + void header(const LLVMContext& C); /// The main loop for parsing. It calls itself recursively /// to handle the depth of nesting of "[]". diff --git a/examples/BrainF/BrainFDriver.cpp b/examples/BrainF/BrainFDriver.cpp index 0868d73506..4eaa4940e7 100644 --- a/examples/BrainF/BrainFDriver.cpp +++ b/examples/BrainF/BrainFDriver.cpp @@ -126,7 +126,7 @@ int main(int argc, char **argv) { //Read the BrainF program BrainF bf; - Module *mod = bf.parse(in, 65536, cf, &Context); //64 KiB + Module *mod = bf.parse(in, 65536, cf, Context); //64 KiB if (in != &std::cin) {delete in;} addMainFunction(mod); diff --git a/examples/Fibonacci/fibonacci.cpp b/examples/Fibonacci/fibonacci.cpp index 58c0dcdaf5..c3431fc352 100644 --- a/examples/Fibonacci/fibonacci.cpp +++ b/examples/Fibonacci/fibonacci.cpp @@ -94,7 +94,7 @@ int main(int argc, char **argv) { LLVMContext Context; // Create some module to put our function into it. - Module *M = new Module("test", &Context); + Module *M = new Module("test", Context); // We are about to create the "fib" function: Function *FibF = CreateFibFunction(M); diff --git a/examples/HowToUseJIT/HowToUseJIT.cpp b/examples/HowToUseJIT/HowToUseJIT.cpp index f11c3e256e..6734547916 100644 --- a/examples/HowToUseJIT/HowToUseJIT.cpp +++ b/examples/HowToUseJIT/HowToUseJIT.cpp @@ -55,7 +55,7 @@ int main() { LLVMContext Context; // Create some module to put our function into it. - Module *M = new Module("test", &Context); + 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". diff --git a/examples/Kaleidoscope/toy.cpp b/examples/Kaleidoscope/toy.cpp index 9ca6035156..612cfa547c 100644 --- a/examples/Kaleidoscope/toy.cpp +++ b/examples/Kaleidoscope/toy.cpp @@ -1099,7 +1099,7 @@ int main() { getNextToken(); // Make the module, which holds all the code. - TheModule = new Module("my cool jit", &Context); + TheModule = new Module("my cool jit", Context); // Create the JIT. TheExecutionEngine = ExecutionEngine::create(TheModule); diff --git a/examples/ModuleMaker/ModuleMaker.cpp b/examples/ModuleMaker/ModuleMaker.cpp index 322835e04f..59a86d031d 100644 --- a/examples/ModuleMaker/ModuleMaker.cpp +++ b/examples/ModuleMaker/ModuleMaker.cpp @@ -27,7 +27,7 @@ int main() { // Create the "module" or "program" or "translation unit" to hold the // function - Module *M = new Module("test", &Context); + Module *M = new Module("test", Context); // Create the main function: first create the type 'int ()' FunctionType *FT = FunctionType::get(Type::Int32Ty, /*not vararg*/false); diff --git a/examples/ParallelJIT/ParallelJIT.cpp b/examples/ParallelJIT/ParallelJIT.cpp index 858cd52de6..eadd0f58e5 100644 --- a/examples/ParallelJIT/ParallelJIT.cpp +++ b/examples/ParallelJIT/ParallelJIT.cpp @@ -236,7 +236,7 @@ int main() { LLVMContext Context; // Create some module to put our function into it. - Module *M = new Module("test", &Context); + Module *M = new Module("test", Context); Function* add1F = createAdd1( M ); Function* fibF = CreateFibFunction( M ); diff --git a/include/llvm-c/lto.h b/include/llvm-c/lto.h index 5d92fc5af0..d9a2e5ce68 100644 --- a/include/llvm-c/lto.h +++ b/include/llvm-c/lto.h @@ -58,6 +58,7 @@ typedef struct LTOModule* lto_module_t; /** opaque reference to a code generator */ typedef struct LTOCodeGenerator* lto_code_gen_t; +typedef struct LTOContext* lto_context_t; #ifdef __cplusplus extern "C" { @@ -76,7 +77,6 @@ lto_get_version(void); extern const char* lto_get_error_message(void); - /** * Checks if a file is a loadable object file. */ diff --git a/include/llvm/Assembly/Parser.h b/include/llvm/Assembly/Parser.h index 2a5bac7a70..616750ae3e 100644 --- a/include/llvm/Assembly/Parser.h +++ b/include/llvm/Assembly/Parser.h @@ -32,7 +32,7 @@ class LLVMContext; Module *ParseAssemblyFile( const std::string &Filename, ///< The name of the file to parse ParseError &Error, ///< If not null, an object to return errors in. - LLVMContext* Context ///< Context in which to allocate globals info. + const LLVMContext& Context ///< Context in which to allocate globals info. ); /// The function is a secondary interface to the LLVM Assembly Parser. It parses @@ -45,7 +45,7 @@ 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. - LLVMContext* Context + const LLVMContext& Context ); //===------------------------------------------------------------------------=== diff --git a/include/llvm/Bitcode/Archive.h b/include/llvm/Bitcode/Archive.h index c188df8824..85b918ed32 100644 --- a/include/llvm/Bitcode/Archive.h +++ b/include/llvm/Bitcode/Archive.h @@ -280,7 +280,7 @@ class Archive { /// @brief Create an empty Archive. static Archive* CreateEmpty( const sys::Path& Filename,///< Name of the archive to (eventually) create. - LLVMContext* C ///< Context to use for global information + const LLVMContext& C ///< Context to use for global information ); /// Open an existing archive and load its contents in preparation for @@ -291,7 +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 + const LLVMContext& C, ///< The context to use for global information std::string* ErrorMessage ///< An optional error string ); @@ -313,7 +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 + const LLVMContext& C, ///< The context to use for global info std::string* ErrorMessage=0 ///< An optional error string ); @@ -453,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, LLVMContext* C); + explicit Archive(const sys::Path& filename, const LLVMContext& C); /// @param data The symbol table data to be parsed /// @param len The length of the symbol table data @@ -534,7 +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. + const LLVMContext& Context; ///< This holds global data. /// @} /// @name Hidden /// @{ diff --git a/include/llvm/Bitcode/ReaderWriter.h b/include/llvm/Bitcode/ReaderWriter.h index a7811876ff..3cde47bf77 100644 --- a/include/llvm/Bitcode/ReaderWriter.h +++ b/include/llvm/Bitcode/ReaderWriter.h @@ -32,13 +32,13 @@ 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, + const 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, LLVMContext* Context, + Module *ParseBitcodeFile(MemoryBuffer *Buffer, const LLVMContext& Context, std::string *ErrMsg = 0); /// WriteBitcodeToFile - Write the specified module to the specified output diff --git a/include/llvm/Debugger/Debugger.h b/include/llvm/Debugger/Debugger.h index ed04ed533a..d003539e7e 100644 --- a/include/llvm/Debugger/Debugger.h +++ b/include/llvm/Debugger/Debugger.h @@ -96,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, LLVMContext* Context); + void loadProgram(const std::string &Path, const 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 diff --git a/include/llvm/LLVMContext.h b/include/llvm/LLVMContext.h index 1d95502bcd..f0c2200c7a 100644 --- a/include/llvm/LLVMContext.h +++ b/include/llvm/LLVMContext.h @@ -198,7 +198,7 @@ public: }; /// FOR BACKWARDS COMPATIBILITY - Returns a global context. -LLVMContext* getGlobalContext(); +extern const LLVMContext& getGlobalContext(); } diff --git a/include/llvm/LinkAllVMCore.h b/include/llvm/LinkAllVMCore.h index 3c4b9c447b..e5a51971f1 100644 --- a/include/llvm/LinkAllVMCore.h +++ b/include/llvm/LinkAllVMCore.h @@ -16,6 +16,7 @@ #ifndef LLVM_LINKALLVMCORE_H #define LLVM_LINKALLVMCORE_H +#include "llvm/LLVMContext.h" #include "llvm/Module.h" #include "llvm/Instructions.h" #include "llvm/IntrinsicInst.h" @@ -44,7 +45,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("", 0); + llvm::Module* M = new llvm::Module("", llvm::getGlobalContext()); (void)new llvm::UnreachableInst(); (void) llvm::createVerifierPass(); (void) new llvm::Mangler(*M,""); diff --git a/include/llvm/Linker.h b/include/llvm/Linker.h index 8389dc770e..2ab0ed4705 100644 --- a/include/llvm/Linker.h +++ b/include/llvm/Linker.h @@ -67,7 +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 + const LLVMContext& C, ///< Context for global info unsigned Flags = 0 ///< ControlFlags (one or more |'d together) ); @@ -285,7 +285,7 @@ class Linker { /// @name Data /// @{ private: - LLVMContext* Context; ///< The context for global information + const 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. diff --git a/include/llvm/Module.h b/include/llvm/Module.h index 8370ffb872..8efa8e0e0e 100644 --- a/include/llvm/Module.h +++ b/include/llvm/Module.h @@ -110,7 +110,7 @@ public: /// @name Member Variables /// @{ private: - LLVMContext* Context; ///< The LLVMContext from which types and + const 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 @@ -131,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, LLVMContext* C); + explicit Module(const std::string &ModuleID, const LLVMContext& C); /// The module destructor. This will dropAllReferences. ~Module(); @@ -162,7 +162,7 @@ public: /// Get the global data context. /// @returns LLVMContext - a container for LLVM's global information - LLVMContext* getContext() const { return Context; } + const LLVMContext& getContext() const { return Context; } /// Get any module-scope inline assembly blocks. /// @returns a string containing the module-scope inline assembly blocks. diff --git a/lib/Archive/Archive.cpp b/lib/Archive/Archive.cpp index e6903b607f..1a8b25ace2 100644 --- a/lib/Archive/Archive.cpp +++ b/lib/Archive/Archive.cpp @@ -138,7 +138,7 @@ 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, LLVMContext* C) +Archive::Archive(const sys::Path& filename, const LLVMContext& C) : archPath(filename), members(), mapfile(0), base(0), symTab(), strtab(), symTabSize(0), firstFileOffset(0), modules(), foreignST(0), Context(C) { } @@ -208,7 +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, + const LLVMContext& Context, std::vector<std::string>& symbols, std::string* ErrMsg) { std::auto_ptr<MemoryBuffer> Buffer( @@ -240,7 +240,7 @@ bool llvm::GetBitcodeSymbols(const sys::Path& fName, ModuleProvider* llvm::GetBitcodeSymbols(const unsigned char *BufPtr, unsigned Length, const std::string& ModuleID, - LLVMContext* Context, + const LLVMContext& Context, std::vector<std::string>& symbols, std::string* ErrMsg) { // Get the module provider diff --git a/lib/Archive/ArchiveInternals.h b/lib/Archive/ArchiveInternals.h index cdd8e35ca0..15f01b3690 100644 --- a/lib/Archive/ArchiveInternals.h +++ b/lib/Archive/ArchiveInternals.h @@ -73,13 +73,13 @@ namespace llvm { // Get just the externally visible defined symbols from the bitcode bool GetBitcodeSymbols(const sys::Path& fName, - LLVMContext* Context, + const LLVMContext& Context, std::vector<std::string>& symbols, std::string* ErrMsg); ModuleProvider* GetBitcodeSymbols(const unsigned char*Buffer,unsigned Length, const std::string& ModuleID, - LLVMContext* Context, + const LLVMContext& Context, std::vector<std::string>& symbols, std::string* ErrMsg); } diff --git a/lib/Archive/ArchiveReader.cpp b/lib/Archive/ArchiveReader.cpp index 4e3e28166c..2393554ede 100644 --- a/lib/Archive/ArchiveReader.cpp +++ b/lib/Archive/ArchiveReader.cpp @@ -327,7 +327,7 @@ Archive::loadArchive(std::string* error) { // Open and completely load the archive file. Archive* -Archive::OpenAndLoad(const sys::Path& file, LLVMContext* C, +Archive::OpenAndLoad(const sys::Path& file, const LLVMContext& C, std::string* ErrorMessage) { std::auto_ptr<Archive> result ( new Archive(file, C)); if (result->mapToMemory(ErrorMessage)) @@ -441,7 +441,8 @@ Archive::loadSymbolTable(std::string* ErrorMsg) { } // Open the archive and load just the symbol tables -Archive* Archive::OpenAndLoadSymbols(const sys::Path& file, LLVMContext* C, +Archive* Archive::OpenAndLoadSymbols(const sys::Path& file, + const LLVMContext& C, std::string* ErrorMessage) { std::auto_ptr<Archive> result ( new Archive(file, C) ); if (result->mapToMemory(ErrorMessage)) diff --git a/lib/Archive/ArchiveWriter.cpp b/lib/Archive/ArchiveWriter.cpp index 641e3324d6..e84035404b 100644 --- a/lib/Archive/ArchiveWriter.cpp +++ b/lib/Archive/ArchiveWriter.cpp @@ -64,7 +64,7 @@ static inline unsigned numVbrBytes(unsigned num) { } // Create an empty archive. -Archive* Archive::CreateEmpty(const sys::Path& FilePath, LLVMContext* C) { +Archive* Archive::CreateEmpty(const sys::Path& FilePath, const LLVMContext& C) { Archive* result = new Archive(FilePath, C); return result; } diff --git a/lib/AsmParser/Parser.cpp b/lib/AsmParser/Parser.cpp index 7759c70d73..daf23fe748 100644 --- a/lib/AsmParser/Parser.cpp +++ b/lib/AsmParser/Parser.cpp @@ -21,7 +21,7 @@ using namespace llvm; Module *llvm::ParseAssemblyFile(const std::string &Filename, ParseError &Err, - LLVMContext* Context) { + const LLVMContext& Context) { Err.setFilename(Filename); std::string ErrorStr; @@ -39,7 +39,7 @@ Module *llvm::ParseAssemblyFile(const std::string &Filename, ParseError &Err, } Module *llvm::ParseAssemblyString(const char *AsmString, Module *M, - ParseError &Err, LLVMContext* Context) { + ParseError &Err, const LLVMContext& Context) { Err.setFilename("<string>"); OwningPtr<MemoryBuffer> diff --git a/lib/Bitcode/Reader/BitReader.cpp b/lib/Bitcode/Reader/BitReader.cpp index 2baf71bb54..273975a59b 100644 --- a/lib/Bitcode/Reader/BitReader.cpp +++ b/lib/Bitcode/Reader/BitReader.cpp @@ -22,7 +22,7 @@ int LLVMParseBitcode(LLVMMemoryBufferRef MemBuf, LLVMContextRef ContextRef, LLVMModuleRef *OutModule, char **OutMessage) { std::string Message; - *OutModule = wrap(ParseBitcodeFile(unwrap(MemBuf), unwrap(ContextRef), + *OutModule = wrap(ParseBitcodeFile(unwrap(MemBuf), *unwrap(ContextRef), &Message)); if (!*OutModule) { if (OutMessage) @@ -42,7 +42,7 @@ int LLVMGetBitcodeModuleProvider(LLVMMemoryBufferRef MemBuf, char **OutMessage) { std::string Message; - *OutMP = wrap(getBitcodeModuleProvider(unwrap(MemBuf), unwrap(ContextRef), + *OutMP = wrap(getBitcodeModuleProvider(unwrap(MemBuf), *unwrap(ContextRef), &Message)); if (!*OutMP) { if (OutMessage) diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp index 7cf0324299..ce33de04f7 100644 --- a/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/lib/Bitcode/Reader/BitcodeReader.cpp @@ -2090,7 +2090,7 @@ Module *BitcodeReader::releaseModule(std::string *ErrInfo) { /// getBitcodeModuleProvider - lazy function-at-a-time loading from a file. /// ModuleProvider *llvm::getBitcodeModuleProvider(MemoryBuffer *Buffer, - LLVMContext* Context, + const LLVMContext& Context, |