20#include "llvm/IR/Module.h"
21#include "llvm/Support/Error.h"
22#include "llvm/Support/ErrorHandling.h"
26 llvm::LLVMContext &LLVMCtx,
28 std::unique_ptr<ASTConsumer> Consumer)
30 llvm::ErrorAsOutParameter EAO(&Err);
31 std::unique_ptr<FrontendAction> Act;
32 switch (Instance.getFrontendOpts().ProgramAction) {
34 Err = llvm::createStringError(
35 std::errc::state_not_recoverable,
36 "Driver initialization failed. "
37 "Incremental mode for action %d is not supported",
38 Instance.getFrontendOpts().ProgramAction);
57 Interp(I), CI(Instance), Consumer(std::move(Consumer)) {}
59std::unique_ptr<ASTConsumer>
62 std::unique_ptr<ASTConsumer>
C =
66 std::vector<std::unique_ptr<ASTConsumer>> Cs;
67 Cs.push_back(std::move(Consumer));
68 Cs.push_back(std::move(
C));
69 return std::make_unique<MultiplexConsumer>(std::move(Cs));
72 return std::make_unique<InProcessPrintingASTConsumer>(std::move(
C), Interp);
86 assert(!IsTerminating &&
"Already finalized!");
97 return CachedInCodeGenModule.get();
101 static unsigned ID = 0;
110 assert(((!CachedInCodeGenModule ||
111 !CI.getPreprocessorOpts().Includes.empty() ||
112 !CI.getPreprocessorOpts().ImplicitPCHInclude.empty()) ||
113 (CachedInCodeGenModule->empty() &&
114 CachedInCodeGenModule->global_empty() &&
115 CachedInCodeGenModule->alias_empty() &&
116 CachedInCodeGenModule->ifunc_empty())) &&
117 "CodeGen wrote to a readonly module");
118 std::unique_ptr<llvm::Module> M(CG->ReleaseModule());
119 CG->StartModule(
"incr_module_" + std::to_string(ID++), M->getContext());
129 return static_cast<CodeGenAction *
>(WrappedAct)->getCodeGenerator();
146 if (
auto *TLSD = llvm::dyn_cast<TopLevelStmtDecl>(D))
147 if (TLSD && TLSD->isSemiMissing()) {
148 auto ExprOrErr = Interp.convertExprToValue(
cast<Expr>(TLSD->getStmt()));
149 if (llvm::Error E = ExprOrErr.takeError()) {
150 llvm::logAllUnhandledErrors(std::move(E), llvm::errs(),
151 "Value printing failed: ");
154 TLSD->setStmt(*ExprOrErr);
The primary public interface to the Clang code generator.
CompilerInstance - Helper class for managing a single instance of the Clang compiler.
DiagnosticsEngine & getDiagnostics() const
Get the current diagnostics engine.
Decl - This represents one declaration (or definition), e.g.
Concrete class used by the front-end to report problems and issues.
bool hasErrorOccurred() const
Abstract base class for actions which can be performed by the frontend.
const FrontendInputFile & getCurrentInput() const
virtual bool hasIRSupport() const
Does this action support use with IR files?
CompilerInstance & getCompilerInstance() const
InProcessPrintingASTConsumer(std::unique_ptr< ASTConsumer > C, Interpreter &I)
bool HandleTopLevelDecl(DeclGroupRef DGR) override
HandleTopLevelDecl - Handle the specified top-level declaration.
llvm::Module * getCachedCodeGenModule() const
Access the cached CodeGen module.
void ExecuteAction() override
Callback to run the program action, using the initialized compiler instance.
std::unique_ptr< ASTConsumer > CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override
Create the AST consumer object for this action, if supported.
CodeGenerator * getCodeGen() const
Access the current code generator.
void CacheCodeGenModule()
Cache the current CodeGen module to preserve internal references.
IncrementalAction(CompilerInstance &Instance, llvm::LLVMContext &LLVMCtx, llvm::Error &Err, Interpreter &I, std::unique_ptr< ASTConsumer > Consumer=nullptr)
FrontendAction * getWrapped() const
void EndSourceFile() override
Perform any per-file post processing, deallocate per-file objects, and run statistics and output file...
std::unique_ptr< llvm::Module > GenModule()
Generate an LLVM module for the most recent parsed input.
Provides top-level interfaces for incremental compilation and execution.
bool HandleTopLevelDecl(DeclGroupRef D) override
HandleTopLevelDecl - Handle the specified top-level declaration.
MultiplexConsumer(std::vector< std::unique_ptr< ASTConsumer > > C)
DeclContext * CurContext
CurContext - This is the current declaration context of parsing.
void ExecuteAction() override
Callback to run the program action, using the initialized compiler instance.
WrapperFrontendAction(std::unique_ptr< FrontendAction > WrappedAction)
Construct a WrapperFrontendAction from an existing action, taking ownership of it.
std::unique_ptr< ASTConsumer > CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override
Create the AST consumer object for this action, if supported.
void EndSourceFile() override
Perform any per-file post processing, deallocate per-file objects, and run statistics and output file...
@ PrintPreprocessedInput
-E mode.
@ ParseSyntaxOnly
Parse and perform semantic analysis.
@ EmitLLVM
Emit a .ll file.
@ PluginAction
Run a plugin action,.
@ ASTPrint
Parse ASTs and print them.
@ ASTDump
Parse ASTs and dump them.
@ EmitAssembly
Emit a .s file.
@ EmitLLVMOnly
Generate LLVM IR, but do not emit anything.
Top level wrappers for InstallAPI frontend operations.
std::unique_ptr< FrontendAction > CreateFrontendAction(CompilerInstance &CI)
Construct the FrontendAction of a compiler invocation based on the options specified for the compiler...
U cast(CodeGen::Address addr)