13#ifndef LLVM_CLANG_FRONTEND_PRECOMPILEDPREAMBLE_H
14#define LLVM_CLANG_FRONTEND_PRECOMPILEDPREAMBLE_H
18#include "llvm/ADT/IntrusiveRefCntPtr.h"
19#include "llvm/ADT/StringRef.h"
20#include "llvm/Support/MD5.h"
21#include "llvm/Support/VirtualFileSystemFwd.h"
24#include <system_error>
41 const llvm::MemoryBufferRef &Buffer,
51 struct PreambleFileHash;
82 static llvm::ErrorOr<PrecompiledPreamble>
87 std::shared_ptr<PCHContainerOperations> PCHContainerOps,
88 bool StoreInMemory, StringRef StoragePath,
105 return {PreambleBytes.data(), PreambleBytes.size()};
111 const llvm::MemoryBufferRef &MainFileBuffer,
124 llvm::MemoryBuffer *MainFileBuffer)
const;
131 llvm::MemoryBuffer *MainFileBuffer)
const;
135 std::vector<char> PreambleBytes,
136 bool PreambleEndsAtStartOfLine,
137 llvm::StringMap<PreambleFileHash> FilesInPreamble,
138 llvm::StringSet<> MissingFiles);
141 struct PreambleFileHash {
152 llvm::MD5::MD5Result MD5 = {};
154 static PreambleFileHash createForFile(off_t Size, time_t ModTime);
155 static PreambleFileHash
156 createForMemoryBuffer(
const llvm::MemoryBufferRef &Buffer);
158 friend bool operator==(
const PreambleFileHash &LHS,
159 const PreambleFileHash &RHS) {
160 return LHS.Size == RHS.Size && LHS.ModTime == RHS.ModTime &&
163 friend bool operator!=(
const PreambleFileHash &LHS,
164 const PreambleFileHash &RHS) {
165 return !(LHS == RHS);
171 void configurePreamble(PreambleBounds Bounds, CompilerInvocation &CI,
172 IntrusiveRefCntPtr<llvm::vfs::FileSystem> &VFS,
173 llvm::MemoryBuffer *MainFileBuffer)
const;
179 setupPreambleStorage(
const PCHStorage &Storage,
180 PreprocessorOptions &PreprocessorOpts,
181 IntrusiveRefCntPtr<llvm::vfs::FileSystem> &VFS);
184 std::unique_ptr<PCHStorage> Storage;
190 llvm::StringMap<PreambleFileHash> FilesInPreamble;
199 llvm::StringSet<> MissingFiles;
203 std::vector<char> PreambleBytes;
205 bool PreambleEndsAtStartOfLine;
250 const char *
name()
const noexcept override;
258struct std::is_error_code_enum<
clang::BuildPreambleError> : std::true_type {};
*collection of selector each with an associated kind and an ordered *collection of selectors A selector has a an optional score condition
Defines the clang::Preprocessor interface.
Writes an AST file containing the contents of a translation unit.
std::string message(int condition) const override
const char * name() const noexcept override
CompilerInstance - Helper class for managing a single instance of the Clang compiler.
Helper class for holding the data necessary to invoke the compiler.
Decl - This represents one declaration (or definition), e.g.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
A registry of PCHContainerWriter and -Reader objects for different formats.
A set of callbacks to gather useful information while building a preamble.
virtual void AfterPCHEmitted(ASTWriter &Writer)
Called after PCH has been emitted.
virtual void BeforeExecute(CompilerInstance &CI)
Called before FrontendAction::Execute.
virtual CommentHandler * getCommentHandler()
The returned CommentHandler will be added to the preprocessor if not null.
virtual ~PreambleCallbacks()=default
virtual void HandleTopLevelDecl(DeclGroupRef DG)
Called for each TopLevelDecl.
virtual std::unique_ptr< PPCallbacks > createPPCallbacks()
Creates wrapper class for PPCallbacks so we can also process information about includes that are insi...
virtual void AfterExecute(CompilerInstance &CI)
Called after FrontendAction::Execute(), but before FrontendAction::EndSourceFile().
virtual bool shouldSkipFunctionBody(Decl *D)
Determines which function bodies are parsed, by default skips everything.
void OverridePreamble(CompilerInvocation &CI, IntrusiveRefCntPtr< llvm::vfs::FileSystem > &VFS, llvm::MemoryBuffer *MainFileBuffer) const
Configure CI to use this preamble.
static llvm::ErrorOr< PrecompiledPreamble > Build(const CompilerInvocation &Invocation, const llvm::MemoryBuffer *MainFileBuffer, PreambleBounds Bounds, IntrusiveRefCntPtr< DiagnosticsEngine > Diagnostics, IntrusiveRefCntPtr< llvm::vfs::FileSystem > VFS, std::shared_ptr< PCHContainerOperations > PCHContainerOps, bool StoreInMemory, StringRef StoragePath, PreambleCallbacks &Callbacks)
Try to build PrecompiledPreamble for Invocation.
llvm::StringRef getContents() const
Returned string is not null-terminated.
PrecompiledPreamble & operator=(PrecompiledPreamble &&)
bool CanReuse(const CompilerInvocation &Invocation, const llvm::MemoryBufferRef &MainFileBuffer, PreambleBounds Bounds, llvm::vfs::FileSystem &VFS) const
Check whether PrecompiledPreamble can be reused for the new contents(MainFileBuffer) of the main file...
void AddImplicitPreamble(CompilerInvocation &CI, IntrusiveRefCntPtr< llvm::vfs::FileSystem > &VFS, llvm::MemoryBuffer *MainFileBuffer) const
Changes options inside CI to use PCH from this preamble.
std::size_t getSize() const
Returns the size, in bytes, that preamble takes on disk or in memory.
PreambleBounds getBounds() const
PreambleBounds used to build the preamble.
PrecompiledPreamble(PrecompiledPreamble &&)
Top level wrappers for InstallAPI frontend operations.
std::error_code make_error_code(BuildPreambleError Error)
PreambleBounds ComputePreambleBounds(const LangOptions &LangOpts, const llvm::MemoryBufferRef &Buffer, unsigned MaxLines)
Runs lexer to compute suggested preamble bounds.
@ CouldntCreateTargetInfo
Diagnostic wrappers for TextAPI types for error reporting.
Describes the bounds (start, size) of the preamble and a flag required by PreprocessorOptions::Precom...