@@ -393,33 +393,29 @@ Interpreter::Interpreter(std::unique_ptr<CompilerInstance> CI,
393
393
return ;
394
394
CI->ExecuteAction (*Act);
395
395
396
- if (getCodeGen ())
397
- CachedInCodeGenModule = GenModule ();
396
+ ASTContext &C = CI->getASTContext ();
398
397
399
398
IncrParser = std::make_unique<IncrementalParser>(std::move (CI), ErrOut);
400
399
401
- // An initial PTU is needed as CUDA includes some headers automatically.
402
- auto PTU = Parse (" " );
403
- if (auto E = PTU.takeError ()) {
404
- ErrOut = joinErrors (std::move (ErrOut), std::move (E));
405
- return ;
406
- }
407
-
408
- if (getCodeGen ()) {
409
- PTU->TheModule = GenModule ();
410
- assert (PTU->TheModule && " Failed to create initial PTU" );
411
- }
412
-
413
400
if (ErrOut)
414
401
return ;
415
402
416
- // Not all frontends support code-generation, e.g. ast-dump actions don't
417
403
if (getCodeGen ()) {
404
+ CachedInCodeGenModule = GenModule ();
418
405
if (llvm::Error Err = CreateExecutor ()) {
419
406
ErrOut = joinErrors (std::move (ErrOut), std::move (Err));
420
407
return ;
421
408
}
409
+ }
410
+
411
+ // The initial PTU is filled by `-include` or by CUDA includes automatically.
412
+ RegisterPTU (C.getTranslationUnitDecl ());
413
+
414
+ // Prepare the IncrParser for input.
415
+ llvm::cantFail (Parse (" " ));
422
416
417
+ // Not all frontends support code-generation, e.g. ast-dump actions don't
418
+ if (getCodeGen ()) {
423
419
// Process the PTUs that came from initialization. For example -include will
424
420
// give us a header that's processed at initialization of the preprocessor.
425
421
for (PartialTranslationUnit &PTU : PTUs)
@@ -549,6 +545,17 @@ size_t Interpreter::getEffectivePTUSize() const {
549
545
return PTUs.size () - InitPTUSize;
550
546
}
551
547
548
+ PartialTranslationUnit &Interpreter::RegisterPTU (TranslationUnitDecl *TU) {
549
+ PTUs.emplace_back (PartialTranslationUnit ());
550
+ PartialTranslationUnit &LastPTU = PTUs.back ();
551
+ LastPTU.TUPart = TU;
552
+
553
+ if (std::unique_ptr<llvm::Module> M = GenModule ())
554
+ LastPTU.TheModule = std::move (M);
555
+
556
+ return LastPTU;
557
+ }
558
+
552
559
llvm::Expected<PartialTranslationUnit &>
553
560
Interpreter::Parse (llvm::StringRef Code) {
554
561
// If we have a device parser, parse it first. The generated code will be
@@ -568,14 +575,7 @@ Interpreter::Parse(llvm::StringRef Code) {
568
575
if (!TuOrErr)
569
576
return TuOrErr.takeError ();
570
577
571
- PTUs.emplace_back (PartialTranslationUnit ());
572
- PartialTranslationUnit &LastPTU = PTUs.back ();
573
- LastPTU.TUPart = *TuOrErr;
574
-
575
- if (std::unique_ptr<llvm::Module> M = GenModule ())
576
- LastPTU.TheModule = std::move (M);
577
-
578
- return LastPTU;
578
+ return RegisterPTU (*TuOrErr);
579
579
}
580
580
581
581
static llvm::Expected<llvm::orc::JITTargetMachineBuilder>
0 commit comments