1414#include " IncrementalAction.h"
1515
1616#include " clang/AST/DeclContextInternals.h"
17- #include " clang/CodeGen/CodeGenAction.h"
18- #include " clang/CodeGen/ModuleBuilder.h"
1917#include " clang/Frontend/CompilerInstance.h"
20- #include " clang/Frontend/FrontendAction.h"
2118#include " clang/Interpreter/PartialTranslationUnit.h"
22- #include " clang/Lex/PreprocessorOptions.h"
2319#include " clang/Parse/Parser.h"
2420#include " clang/Sema/Sema.h"
2521#include " llvm/IR/Module.h"
@@ -37,10 +33,10 @@ namespace clang {
3733IncrementalParser::IncrementalParser (CompilerInstance &Instance,
3834 IncrementalAction *Act, llvm::Error &Err,
3935 std::list<PartialTranslationUnit> &PTUs)
40- : S(Instance.getSema()), CI(Instance), Act(Act), PTUs(PTUs) {
36+ : S(Instance.getSema()), Act(Act), PTUs(PTUs) {
4137 llvm::ErrorAsOutParameter EAO (&Err);
4238 Consumer = &S.getASTConsumer ();
43- P = std::make_unique< Parser> (S.getPreprocessor (), S, /* SkipBodies=*/ false );
39+ P. reset ( new Parser (S.getPreprocessor (), S, /* SkipBodies=*/ false ) );
4440 P->Initialize ();
4541}
4642
@@ -202,9 +198,9 @@ IncrementalParser::RegisterPTU(TranslationUnitDecl *TU,
202198 LastPTU.TUPart = TU;
203199
204200 if (!M)
205- M = GenModule ();
201+ M = Act-> GenModule ();
206202
207- assert ((!getCodeGen () || M) && " Must have a llvm::Module at this point" );
203+ assert ((!Act-> getCodeGen () || M) && " Must have a llvm::Module at this point" );
208204
209205 LastPTU.TheModule = std::move (M);
210206 LLVM_DEBUG (llvm::dbgs () << " compile-ptu " << PTUs.size () - 1
@@ -215,36 +211,4 @@ IncrementalParser::RegisterPTU(TranslationUnitDecl *TU,
215211 LLVM_DEBUG (llvm::dbgs () << " ]\n " );
216212 return LastPTU;
217213}
218-
219- std::unique_ptr<llvm::Module> IncrementalParser::GenModule () {
220- static unsigned ID = 0 ;
221- if (CodeGenerator *CG = getCodeGen ()) {
222- // Clang's CodeGen is designed to work with a single llvm::Module. In many
223- // cases for convenience various CodeGen parts have a reference to the
224- // llvm::Module (TheModule or Module) which does not change when a new
225- // module is pushed. However, the execution engine wants to take ownership
226- // of the module which does not map well to CodeGen's design. To work this
227- // around we created an empty module to make CodeGen happy. We should make
228- // sure it always stays empty.
229- assert (((!CachedInCodeGenModule ||
230- !CI.getPreprocessorOpts ().Includes .empty ()) ||
231- (CachedInCodeGenModule->empty () &&
232- CachedInCodeGenModule->global_empty () &&
233- CachedInCodeGenModule->alias_empty () &&
234- CachedInCodeGenModule->ifunc_empty ())) &&
235- " CodeGen wrote to a readonly module" );
236- std::unique_ptr<llvm::Module> M (CG->ReleaseModule ());
237- CG->StartModule (" incr_module_" + std::to_string (ID++), M->getContext ());
238- return M;
239- }
240- return nullptr ;
241- }
242-
243- CodeGenerator *IncrementalParser::getCodeGen () const {
244- FrontendAction *WrappedAct = Act->getWrapped ();
245- if (!WrappedAct->hasIRSupport ())
246- return nullptr ;
247- return static_cast <CodeGenAction *>(WrappedAct)->getCodeGenerator ();
248- }
249-
250214} // end namespace clang
0 commit comments