14 #ifndef LLVM_CLANG_FRONTEND_PRECOMPILED_PREAMBLE_H
15 #define LLVM_CLANG_FRONTEND_PRECOMPILED_PREAMBLE_H
19 #include "llvm/ADT/IntrusiveRefCntPtr.h"
20 #include "llvm/Support/MD5.h"
22 #include <system_error>
23 #include <type_traits>
34 class CompilerInstance;
35 class CompilerInvocation;
37 class PCHContainerOperations;
43 : Size(Size), PreambleEndsAtStartOfLine(PreambleEndsAtStartOfLine) {}
56 llvm::MemoryBuffer *
Buffer,
66 struct PreambleFileHash;
90 static llvm::ErrorOr<PrecompiledPreamble>
94 std::shared_ptr<PCHContainerOperations> PCHContainerOps,
112 llvm::MemoryBuffer *MainFileBuffer)
const;
116 bool PreambleEndsAtStartOfLine,
117 llvm::StringMap<PreambleFileHash> FilesInPreamble);
127 static llvm::ErrorOr<TempPCHFile> CreateNewPreamblePCHFile();
130 static llvm::ErrorOr<TempPCHFile> createInSystemTempDir(
const Twine &Prefix,
135 static llvm::ErrorOr<TempPCHFile> createFromCustomPath(
const Twine &Path);
141 TempPCHFile(TempPCHFile &&Other);
142 TempPCHFile &
operator=(TempPCHFile &&Other);
144 TempPCHFile(
const TempPCHFile &) =
delete;
148 llvm::StringRef getFilePath()
const;
151 void RemoveFileIfPresent();
158 struct PreambleFileHash {
169 llvm::MD5::MD5Result MD5 = {};
171 static PreambleFileHash createForFile(off_t Size, time_t ModTime);
172 static PreambleFileHash
173 createForMemoryBuffer(
const llvm::MemoryBuffer *
Buffer);
175 friend bool operator==(
const PreambleFileHash &LHS,
176 const PreambleFileHash &RHS) {
177 return LHS.Size == RHS.Size && LHS.ModTime == RHS.ModTime &&
180 friend bool operator!=(
const PreambleFileHash &LHS,
181 const PreambleFileHash &RHS) {
182 return !(LHS == RHS);
193 llvm::StringMap<PreambleFileHash> FilesInPreamble;
197 std::vector<char> PreambleBytes;
199 bool PreambleEndsAtStartOfLine;
236 const char *
name()
const noexcept
override;
237 std::string
message(
int condition)
const override;
A size of the preamble and a flag required by PreprocessorOptions::PrecompiledPreambleBytes.
bool operator==(CanQual< T > x, CanQual< U > y)
std::unique_ptr< llvm::MemoryBuffer > Buffer
The virtual file system interface.
Token - This structure provides full information about a lexed token.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
std::error_code make_error_code(BuildPreambleError Error)
Concrete class used by the front-end to report problems and issues.
virtual ~PreambleCallbacks()=default
bool PreambleEndsAtStartOfLine
Whether the preamble ends at the start of a new line.
A set of callbacks to gather useful information while building a preamble.
PreambleBounds getBounds() const
PreambleBounds used to build the preamble.
Defines the clang::Preprocessor interface.
virtual void HandleMacroDefined(const Token &MacroNameTok, const MacroDirective *MD)
Called for each macro defined in the Preamble.
PreambleBounds ComputePreambleBounds(const LangOptions &LangOpts, llvm::MemoryBuffer *Buffer, unsigned MaxLines)
Runs lexer to compute suggested preamble bounds.
bool CanReuse(const CompilerInvocation &Invocation, const llvm::MemoryBuffer *MainFileBuffer, PreambleBounds Bounds, vfs::FileSystem *VFS) const
Check whether PrecompiledPreamble can be reused for the new contents(MainFileBuffer) of the main file...
Encapsulates changes to the "macros namespace" (the location where the macro name became active...
CompilerInstance - Helper class for managing a single instance of the Clang compiler.
PreambleBounds(unsigned Size, bool PreambleEndsAtStartOfLine)
virtual void AfterPCHEmitted(ASTWriter &Writer)
Called after PCH has been emitted.
PrecompiledPreamble(PrecompiledPreamble &&)=default
std::string message(int condition) const override
const char * name() const noexceptoverride
A class holding a PCH and all information to check whether it is valid to reuse the PCH for the subse...
Helper class for holding the data necessary to invoke the compiler.
virtual void AfterExecute(CompilerInstance &CI)
Called after FrontendAction::Execute(), but before FrontendAction::EndSourceFile().
void AddImplicitPreamble(CompilerInvocation &CI, llvm::MemoryBuffer *MainFileBuffer) const
Changes options inside CI to use PCH from this preamble.
unsigned Size
Size of the preamble in bytes.
bool operator!=(CanQual< T > x, CanQual< U > y)
Writes an AST file containing the contents of a translation unit.
static llvm::ErrorOr< PrecompiledPreamble > Build(const CompilerInvocation &Invocation, const llvm::MemoryBuffer *MainFileBuffer, PreambleBounds Bounds, DiagnosticsEngine &Diagnostics, IntrusiveRefCntPtr< vfs::FileSystem > VFS, std::shared_ptr< PCHContainerOperations > PCHContainerOps, PreambleCallbacks &Callbacks)
Try to build PrecompiledPreamble for Invocation.
virtual void HandleTopLevelDecl(DeclGroupRef DG)
Called for each TopLevelDecl.
PrecompiledPreamble & operator=(PrecompiledPreamble &&)=default