]> granicus.if.org Git - clang/commitdiff
D34444: Teach codegen to work in incremental processing mode.
authorVassil Vassilev <v.g.vassilev@gmail.com>
Sun, 27 Aug 2017 10:58:03 +0000 (10:58 +0000)
committerVassil Vassilev <v.g.vassilev@gmail.com>
Sun, 27 Aug 2017 10:58:03 +0000 (10:58 +0000)
When isIncrementalProcessingEnabled is on we might want to produce multiple
llvm::Modules. This patch allows the clients to start a new llvm::Module,
allowing CodeGen to continue working after a HandleEndOfTranslationUnit call.

This should give the necessary facilities to write a unittest for D34059.

As discussed in the review this is meant to give us a way to proceed forward
in our efforts to upstream our interpreter-related patches. The design of this
will likely change soon.

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

include/clang/CodeGen/ModuleBuilder.h
lib/CodeGen/ModuleBuilder.cpp

index 6f81ea9d6370b0e919d29c304944d5c7913407f5..e110f6fd30c1ead263e7794133298cfd29d4433a 100644 (file)
@@ -84,6 +84,10 @@ public:
   ///   code generator will schedule the entity for emission if a
   ///   definition has been registered with this code generator.
   llvm::Constant *GetAddrOfGlobal(GlobalDecl decl, bool isForDefinition);
+
+  /// Create a new \c llvm::Module after calling HandleTranslationUnit. This
+  /// enable codegen in interactive processing environments.
+  llvm::Module* StartModule(llvm::StringRef ModuleName, llvm::LLVMContext &C);
 };
 
 /// CreateLLVMCodeGen - Create a CodeGenerator instance.
index fc642850d60adeee8fa755283b43ca75b2b794a5..8aa9bfb421b4a75e07320828445c4fbd8db6cfcb 100644 (file)
@@ -119,6 +119,14 @@ namespace {
       return Builder->GetAddrOfGlobal(global, ForDefinition_t(isForDefinition));
     }
 
+    llvm::Module *StartModule(llvm::StringRef ModuleName,
+                              llvm::LLVMContext &C) {
+      assert(!M && "Replacing existing Module?");
+      M.reset(new llvm::Module(ModuleName, C));
+      Initialize(*Ctx);
+      return M.get();
+    }
+
     void Initialize(ASTContext &Context) override {
       Ctx = &Context;
 
@@ -317,6 +325,11 @@ llvm::Constant *CodeGenerator::GetAddrOfGlobal(GlobalDecl global,
            ->GetAddrOfGlobal(global, isForDefinition);
 }
 
+llvm::Module *CodeGenerator::StartModule(llvm::StringRef ModuleName,
+                                         llvm::LLVMContext &C) {
+  return static_cast<CodeGeneratorImpl*>(this)->StartModule(ModuleName, C);
+}
+
 CodeGenerator *clang::CreateLLVMCodeGen(
     DiagnosticsEngine &Diags, llvm::StringRef ModuleName,
     const HeaderSearchOptions &HeaderSearchOpts,