]> granicus.if.org Git - clang/commitdiff
CompilerInstance: Move LLVMContext member out of constructor.
authorDaniel Dunbar <daniel@zuster.org>
Tue, 16 Feb 2010 01:54:47 +0000 (01:54 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Tue, 16 Feb 2010 01:54:47 +0000 (01:54 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@96314 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Frontend/CompilerInstance.h
lib/Frontend/CompilerInstance.cpp
tools/driver/cc1_main.cpp

index 8f12b54be95e8029aca7b930133544ed4c701aad..1be4118e554214e864b267c836e3649a4874b4e4 100644 (file)
@@ -58,8 +58,7 @@ class TargetInfo;
 /// and a long form that takes explicit instances of any required objects.
 class CompilerInstance {
   /// The LLVM context used for this instance.
-  llvm::LLVMContext *LLVMContext;
-  bool OwnsLLVMContext;
+  llvm::OwningPtr<llvm::LLVMContext> LLVMContext;
 
   /// The options used in this compiler instance.
   llvm::OwningPtr<CompilerInvocation> Invocation;
@@ -97,11 +96,10 @@ class CompilerInstance {
   /// The list of active output files.
   std::list< std::pair<std::string, llvm::raw_ostream*> > OutputFiles;
 
+  void operator=(const CompilerInstance &);  // DO NOT IMPLEMENT
+  CompilerInstance(const CompilerInstance&); // DO NOT IMPLEMENT
 public:
-  /// Create a new compiler instance with the given LLVM context, optionally
-  /// taking ownership of it.
-  CompilerInstance(llvm::LLVMContext *_LLVMContext = 0,
-                   bool _OwnsLLVMContext = true);
+  CompilerInstance();
   ~CompilerInstance();
 
   /// @name High-Level Operations
@@ -150,12 +148,11 @@ public:
     return *LLVMContext;
   }
 
+  llvm::LLVMContext *takeLLVMContext() { return LLVMContext.take(); }
+
   /// setLLVMContext - Replace the current LLVM context and take ownership of
   /// \arg Value.
-  void setLLVMContext(llvm::LLVMContext *Value, bool TakeOwnership = true) {
-    LLVMContext = Value;
-    OwnsLLVMContext = TakeOwnership;
-  }
+  void setLLVMContext(llvm::LLVMContext *Value);
 
   /// }
   /// @name Compiler Invocation and Options
index a630486688e401e074ae71b06a4e29d4f8b65742..917cbd711ad358b471a48431541dadb70f4ad3f3 100644 (file)
 #include "llvm/System/Program.h"
 using namespace clang;
 
-CompilerInstance::CompilerInstance(llvm::LLVMContext *_LLVMContext,
-                                   bool _OwnsLLVMContext)
-  : LLVMContext(_LLVMContext),
-    OwnsLLVMContext(_OwnsLLVMContext),
-    Invocation(new CompilerInvocation) {
+CompilerInstance::CompilerInstance()
+  : Invocation(new CompilerInvocation()) {
 }
 
 CompilerInstance::~CompilerInstance() {
-  if (OwnsLLVMContext)
-    delete LLVMContext;
+}
+
+void CompilerInstance::setLLVMContext(llvm::LLVMContext *Value) {
+  LLVMContext.reset(Value);
 }
 
 void CompilerInstance::setInvocation(CompilerInvocation *Value) {
index 30d2a21c93abdf94fd7e9b4595aafa54ac8ca127..05fb6984d4168a43e6fc090954291c245309817d 100644 (file)
@@ -195,7 +195,9 @@ static int cc1_test(Diagnostic &Diags,
 
 int cc1_main(const char **ArgBegin, const char **ArgEnd,
              const char *Argv0, void *MainAddr) {
-  CompilerInstance Clang(new llvm::LLVMContext, true);
+  CompilerInstance Clang;
+
+  Clang.setLLVMContext(new llvm::LLVMContext);
 
   // Run clang -cc1 test.
   if (ArgBegin != ArgEnd && llvm::StringRef(ArgBegin[0]) == "-cc1test") {