diff options
Diffstat (limited to 'clang/lib/Interpreter/Interpreter.cpp')
| -rw-r--r-- | clang/lib/Interpreter/Interpreter.cpp | 36 |
1 files changed, 32 insertions, 4 deletions
diff --git a/clang/lib/Interpreter/Interpreter.cpp b/clang/lib/Interpreter/Interpreter.cpp index b2e7727be39a..0191ad78581d 100644 --- a/clang/lib/Interpreter/Interpreter.cpp +++ b/clang/lib/Interpreter/Interpreter.cpp @@ -116,6 +116,9 @@ CreateCI(const llvm::opt::ArgStringList &Argv) { // times, reusing the same AST. Clang->getCodeGenOpts().ClearASTBeforeBackend = false; + Clang->getFrontendOpts().DisableFree = false; + Clang->getCodeGenOpts().DisableFree = false; + return std::move(Clang); } @@ -196,6 +199,12 @@ const CompilerInstance *Interpreter::getCompilerInstance() const { return IncrParser->getCI(); } +const llvm::orc::LLJIT *Interpreter::getExecutionEngine() const { + if (IncrExecutor) + return IncrExecutor->getExecutionEngine(); + return nullptr; +} + llvm::Expected<PartialTranslationUnit &> Interpreter::Parse(llvm::StringRef Code) { return IncrParser->Parse(Code); @@ -204,16 +213,16 @@ Interpreter::Parse(llvm::StringRef Code) { llvm::Error Interpreter::Execute(PartialTranslationUnit &T) { assert(T.TheModule); if (!IncrExecutor) { - const llvm::Triple &Triple = - getCompilerInstance()->getASTContext().getTargetInfo().getTriple(); + const clang::TargetInfo &TI = + getCompilerInstance()->getASTContext().getTargetInfo(); llvm::Error Err = llvm::Error::success(); - IncrExecutor = std::make_unique<IncrementalExecutor>(*TSCtx, Err, Triple); + IncrExecutor = std::make_unique<IncrementalExecutor>(*TSCtx, Err, TI); if (Err) return Err; } // FIXME: Add a callback to retain the llvm::Module once the JIT is done. - if (auto Err = IncrExecutor->addModule(std::move(T.TheModule))) + if (auto Err = IncrExecutor->addModule(T)) return Err; if (auto Err = IncrExecutor->runCtors()) @@ -251,3 +260,22 @@ Interpreter::getSymbolAddressFromLinkerName(llvm::StringRef Name) const { return IncrExecutor->getSymbolAddress(Name, IncrementalExecutor::LinkerName); } + +llvm::Error Interpreter::Undo(unsigned N) { + + std::list<PartialTranslationUnit> &PTUs = IncrParser->getPTUs(); + if (N > PTUs.size()) + return llvm::make_error<llvm::StringError>("Operation failed. " + "Too many undos", + std::error_code()); + for (unsigned I = 0; I < N; I++) { + if (IncrExecutor) { + if (llvm::Error Err = IncrExecutor->removeModule(PTUs.back())) + return Err; + } + + IncrParser->CleanUpPTU(PTUs.back()); + PTUs.pop_back(); + } + return llvm::Error::success(); +} |
