Skip to content

Commit

Permalink
Add executor explicit init patch
Browse files Browse the repository at this point in the history
  • Loading branch information
weliveindetail committed Mar 10, 2024
1 parent 023cab5 commit fee6829
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
24 changes: 20 additions & 4 deletions clang/lib/Interpreter/Interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,24 @@ IncrementalCompilerBuilder::CreateCudaHost() {
}

Interpreter::Interpreter(std::unique_ptr<CompilerInstance> CI,
llvm::Error &Err) {
llvm::ErrorAsOutParameter EAO(&Err);
llvm::Error &ErrOut) {
llvm::ErrorAsOutParameter EAO(&ErrOut);
auto LLVMCtx = std::make_unique<llvm::LLVMContext>();
TSCtx = std::make_unique<llvm::orc::ThreadSafeContext>(std::move(LLVMCtx));
IncrParser = std::make_unique<IncrementalParser>(*this, std::move(CI),
*TSCtx->getContext(), Err);
IncrParser = std::make_unique<IncrementalParser>(
*this, std::move(CI), *TSCtx->getContext(), ErrOut);
if (llvm::Error Err = CreateExecutor()) {
ErrOut = joinErrors(std::move(ErrOut), std::move(Err));
return;
}

// Process the PTUs that came from initialization. For example -include will
// give us a header that's processed at initialization of the preprocessor.
for (PartialTranslationUnit &PTU : IncrParser->getPTUs())
if (llvm::Error Err = Execute(PTU)) {
ErrOut = joinErrors(std::move(ErrOut), std::move(Err));
return;
}
}

Interpreter::~Interpreter() {
Expand Down Expand Up @@ -386,6 +398,10 @@ llvm::Error Interpreter::CreateExecutor() {
return llvm::make_error<llvm::StringError>("Operation failed. "
"Execution engine exists",
std::error_code());
if (!IncrParser->getCodeGen())
return llvm::make_error<llvm::StringError>("Operation failed. "
"No code generator available",
std::error_code());
llvm::Error Err = llvm::Error::success();
auto Executor = std::make_unique<IncrementalExecutor>(*TSCtx, Err, TI);
if (!Err)
Expand Down
4 changes: 2 additions & 2 deletions clang/test/Interpreter/execute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

// RUN: cat %s | clang-repl | FileCheck %s
// RUN: cat %s | clang-repl -Xcc -O2 | FileCheck %s
// RUN: clang-repl -Xcc -include -Xcc %s | FileCheck %s
// RUN: clang-repl -Xcc -fsyntax-only -Xcc -include -Xcc %s
extern "C" int printf(const char *, ...);
int i = 42;
auto r1 = printf("i = %d\n", i);
Expand All @@ -19,5 +21,3 @@ auto r2 = printf("S[f=%f, m=0x%llx]\n", s.f, reinterpret_cast<unsigned long long

inline int foo() { return 42; }
int r3 = foo();

%quit
5 changes: 2 additions & 3 deletions clang/unittests/Interpreter/InterpreterExtensionsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ class TestCreateResetExecutor : public Interpreter {
llvm::Error &Err)
: Interpreter(std::move(CI), Err) {}

llvm::Error testCreateExecutor() {
return Interpreter::CreateExecutor();
}
llvm::Error testCreateExecutor() { return Interpreter::CreateExecutor(); }

void resetExecutor() { Interpreter::ResetExecutor(); }
};
Expand All @@ -45,6 +43,7 @@ TEST(InterpreterExtensionsTest, ExecutorCreateReset) {
llvm::Error ErrOut = llvm::Error::success();
TestCreateResetExecutor Interp(cantFail(CB.CreateCpp()), ErrOut);
cantFail(std::move(ErrOut));
Interp.resetExecutor();
cantFail(Interp.testCreateExecutor());
Interp.resetExecutor();
cantFail(Interp.testCreateExecutor());
Expand Down

0 comments on commit fee6829

Please sign in to comment.