clang 22.0.0git
IncrementalAction.h
Go to the documentation of this file.
1//===--- IncrementalAction.h - Incremental Frontend Action -*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_CLANG_INTERPRETER_INCREMENTALACTION_H
10#define LLVM_CLANG_INTERPRETER_INCREMENTALACTION_H
11
14
15namespace llvm {
16class Module;
17}
18
19namespace clang {
20
21class Interpreter;
22class CodeGenerator;
23
24/// A custom action enabling the incremental processing functionality.
25///
26/// The usual \p FrontendAction expects one call to ExecuteAction and once it
27/// sees a call to \p EndSourceFile it deletes some of the important objects
28/// such as \p Preprocessor and \p Sema assuming no further input will come.
29///
30/// \p IncrementalAction ensures it keep its underlying action's objects alive
31/// as long as the \p IncrementalParser needs them.
32///
34private:
35 bool IsTerminating = false;
36 Interpreter &Interp;
37 [[maybe_unused]] CompilerInstance &CI;
38 std::unique_ptr<ASTConsumer> Consumer;
39
40 /// When CodeGen is created the first llvm::Module gets cached in many places
41 /// and we must keep it alive.
42 std::unique_ptr<llvm::Module> CachedInCodeGenModule;
43
44public:
45 IncrementalAction(CompilerInstance &Instance, llvm::LLVMContext &LLVMCtx,
46 llvm::Error &Err, Interpreter &I,
47 std::unique_ptr<ASTConsumer> Consumer = nullptr);
48
49 FrontendAction *getWrapped() const { return WrappedAction.get(); }
50
54
55 std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
56 StringRef InFile) override;
57
58 void ExecuteAction() override;
59
60 // Do not terminate after processing the input. This allows us to keep various
61 // clang objects alive and to incrementally grow the current TU.
62 void EndSourceFile() override;
63
64 void FinalizeAction();
65
66 /// Cache the current CodeGen module to preserve internal references.
67 void CacheCodeGenModule();
68
69 /// Access the cached CodeGen module.
70 llvm::Module *getCachedCodeGenModule() const;
71
72 /// Access the current code generator.
74
75 /// Generate an LLVM module for the most recent parsed input.
76 std::unique_ptr<llvm::Module> GenModule();
77};
78
80 Interpreter &Interp;
81
82public:
83 InProcessPrintingASTConsumer(std::unique_ptr<ASTConsumer> C, Interpreter &I);
84
85 bool HandleTopLevelDecl(DeclGroupRef DGR) override;
86};
87
88} // end namespace clang
89
90#endif // LLVM_CLANG_INTERPRETER_INCREMENTALACTION_H
The primary public interface to the Clang code generator.
CompilerInstance - Helper class for managing a single instance of the Clang compiler.
Abstract base class for actions which can be performed by the frontend.
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.
TranslationUnitKind getTranslationUnitKind() override
For AST-based actions, the kind of translation unit we're handling.
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.
Definition Interpreter.h:91
MultiplexConsumer(std::vector< std::unique_ptr< ASTConsumer > > C)
WrapperFrontendAction(std::unique_ptr< FrontendAction > WrappedAction)
Construct a WrapperFrontendAction from an existing action, taking ownership of it.
std::unique_ptr< FrontendAction > WrappedAction
The JSON file list parser is used to communicate input to InstallAPI.
@ Module
Module linkage, which indicates that the entity can be referred to from other translation units withi...
Definition Linkage.h:54
TranslationUnitKind
Describes the kind of translation unit being processed.
@ TU_Incremental
The translation unit is a is a complete translation unit that we might incrementally extend later.
Diagnostic wrappers for TextAPI types for error reporting.
Definition Dominators.h:30