@@ -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 () {
@@ -375,6 +393,10 @@ Interpreter::Parse(llvm::StringRef Code) {
375
393
llvm::Error Interpreter::CreateExecutor () {
376
394
const clang::TargetInfo &TI =
377
395
getCompilerInstance ()->getASTContext ().getTargetInfo ();
396
+ if (!IncrParser->getCodeGen ())
397
+ return llvm::make_error<llvm::StringError>(" Operation failed. "
398
+ " No code generator available" ,
399
+ std::error_code ());
378
400
llvm::Error Err = llvm::Error::success ();
379
401
auto Executor = std::make_unique<IncrementalExecutor>(*TSCtx, Err, TI);
380
402
if (!Err)
0 commit comments