@@ -229,12 +229,30 @@ IncrementalCompilerBuilder::CreateCudaHost() {
229
229
}
230
230
231
231
Interpreter::Interpreter (std::unique_ptr<CompilerInstance> CI,
232
- llvm::Error &Err ) {
233
- llvm::ErrorAsOutParameter EAO (&Err );
232
+ llvm::Error &ErrOut ) {
233
+ llvm::ErrorAsOutParameter EAO (&ErrOut );
234
234
auto LLVMCtx = std::make_unique<llvm::LLVMContext>();
235
235
TSCtx = std::make_unique<llvm::orc::ThreadSafeContext>(std::move (LLVMCtx));
236
- IncrParser = std::make_unique<IncrementalParser>(*this , std::move (CI),
237
- *TSCtx->getContext (), Err);
236
+ IncrParser = std::make_unique<IncrementalParser>(
237
+ *this , std::move (CI), *TSCtx->getContext (), ErrOut);
238
+ if (ErrOut)
239
+ return ;
240
+
241
+ // Not all frontends support code-generation, e.g. ast-dump actions don't
242
+ if (IncrParser->getCodeGen ()) {
243
+ if (llvm::Error Err = CreateExecutor ()) {
244
+ ErrOut = joinErrors (std::move (ErrOut), std::move (Err));
245
+ return ;
246
+ }
247
+
248
+ // Process the PTUs that came from initialization. For example -include will
249
+ // give us a header that's processed at initialization of the preprocessor.
250
+ for (PartialTranslationUnit &PTU : IncrParser->getPTUs ())
251
+ if (llvm::Error Err = Execute (PTU)) {
252
+ ErrOut = joinErrors (std::move (ErrOut), std::move (Err));
253
+ return ;
254
+ }
255
+ }
238
256
}
239
257
240
258
Interpreter::~Interpreter () {
@@ -395,10 +413,16 @@ llvm::Error Interpreter::CreateExecutor() {
395
413
return llvm::make_error<llvm::StringError>(" Operation failed. "
396
414
" Execution engine exists" ,
397
415
std::error_code ());
416
+ if (!IncrParser->getCodeGen ())
417
+ return llvm::make_error<llvm::StringError>(" Operation failed. "
418
+ " No code generator available" ,
419
+ std::error_code ());
420
+
398
421
llvm::Expected<std::unique_ptr<llvm::orc::LLJITBuilder>> JB =
399
422
CreateJITBuilder (*getCompilerInstance ());
400
423
if (!JB)
401
424
return JB.takeError ();
425
+
402
426
llvm::Error Err = llvm::Error::success ();
403
427
auto Executor = std::make_unique<IncrementalExecutor>(*TSCtx, **JB, Err);
404
428
if (!Err)
0 commit comments