clang 20.0.0git
|
A class holding a PCH and all information to check whether it is valid to reuse the PCH for the subsequent runs. More...
#include "clang/Frontend/PrecompiledPreamble.h"
Classes | |
class | PCHStorage |
Public Member Functions | |
PrecompiledPreamble (PrecompiledPreamble &&) | |
PrecompiledPreamble & | operator= (PrecompiledPreamble &&) |
~PrecompiledPreamble () | |
PreambleBounds | getBounds () const |
PreambleBounds used to build the preamble. | |
std::size_t | getSize () const |
Returns the size, in bytes, that preamble takes on disk or in memory. | |
llvm::StringRef | getContents () const |
Returned string is not null-terminated. | |
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. | |
void | OverridePreamble (CompilerInvocation &CI, IntrusiveRefCntPtr< llvm::vfs::FileSystem > &VFS, llvm::MemoryBuffer *MainFileBuffer) const |
Configure CI to use this preamble. | |
Static Public Member Functions | |
static llvm::ErrorOr< PrecompiledPreamble > | Build (const CompilerInvocation &Invocation, const llvm::MemoryBuffer *MainFileBuffer, PreambleBounds Bounds, DiagnosticsEngine &Diagnostics, IntrusiveRefCntPtr< llvm::vfs::FileSystem > VFS, std::shared_ptr< PCHContainerOperations > PCHContainerOps, bool StoreInMemory, StringRef StoragePath, PreambleCallbacks &Callbacks) |
Try to build PrecompiledPreamble for Invocation . | |
A class holding a PCH and all information to check whether it is valid to reuse the PCH for the subsequent runs.
Use BuildPreamble to create PCH and CanReusePreamble + AddImplicitPreamble to make use of it.
Definition at line 51 of file PrecompiledPreamble.h.
|
default |
|
default |
void PrecompiledPreamble::AddImplicitPreamble | ( | CompilerInvocation & | CI, |
IntrusiveRefCntPtr< llvm::vfs::FileSystem > & | VFS, | ||
llvm::MemoryBuffer * | MainFileBuffer | ||
) | const |
Changes options inside CI
to use PCH from this preamble.
Also remaps main file to MainFileBuffer
and updates VFS
to ensure the preamble is accessible. Requires that CanReuse() is true. For in-memory preambles, PrecompiledPreamble instance continues to own the MemoryBuffer with the Preamble after this method returns. The caller is responsible for making sure the PrecompiledPreamble instance outlives the compiler run and the AST that will be using the PCH.
Definition at line 713 of file PrecompiledPreamble.cpp.
|
static |
Try to build PrecompiledPreamble for Invocation
.
See BuildPreambleError for possible error codes.
Invocation | Original CompilerInvocation with options to compile the file. |
MainFileBuffer | Buffer with the contents of the main file. |
Bounds | Bounds of the preamble, result of calling ComputePreambleBounds. |
Diagnostics | Diagnostics engine to be used while building the preamble. |
VFS | An instance of vfs::FileSystem to be used for file accesses. |
PCHContainerOps | An instance of PCHContainerOperations. |
StoreInMemory | Store PCH in memory. If false, PCH will be stored in a temporary file. |
StoragePath | The path to a directory, in which to create a temporary file to store PCH in. If empty, the default system temporary directory is used. This parameter is ignored if StoreInMemory is true. |
Callbacks | A set of callbacks to be executed when building the preamble. |
Definition at line 413 of file PrecompiledPreamble.cpp.
References clang::PreprocessorOptions::addRemappedFile(), clang::PreambleCallbacks::AfterExecute(), clang::BadInputs, clang::PreambleCallbacks::BeforeExecute(), clang::BeginSourceFileFailed, clang::CouldntCreateTargetInfo, clang::CouldntCreateTempFile, clang::CouldntEmitPCH, clang::PreambleCallbacks::createPPCallbacks(), clang::createVFSFromCompilerInvocation(), clang::File, clang::PrecompiledPreamble::PCHStorage::file(), Filename, clang::frontend::GeneratePCH, clang::PreprocessorOptions::GeneratePreamble, clang::PreambleCallbacks::getCommentHandler(), clang::SourceManager::getFileEntryRefForID(), clang::SourceManager::getFileManager(), clang::SourceManager::getMainFileID(), clang::SourceManager::getMemoryBufferForFileOrFake(), clang::FileManager::getOptionalFileRef(), clang::PrecompiledPreamble::PCHStorage::inMemory(), clang::FrontendOptions::Inputs, clang::LLVM_IR, clang::FrontendOptions::OutputFile, clang::PreambleBounds::PreambleEndsAtStartOfLine, clang::PreprocessorOptions::PrecompiledPreambleBytes, clang::ProcessWarningOptions(), clang::FrontendOptions::ProgramAction, clang::DiagnosticsEngine::Reset(), clang::PreprocessorOptions::RetainRemappedFileBuffers, clang::PreambleBounds::Size, and clang::InputKind::Source.
bool PrecompiledPreamble::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.
Definition at line 602 of file PrecompiledPreamble.cpp.
References moveOnNoError(), clang::PreambleBounds::PreambleEndsAtStartOfLine, clang::PreprocessorOptions::RemappedFileBuffers, clang::PreprocessorOptions::RemappedFiles, and clang::PreambleBounds::Size.
PreambleBounds PrecompiledPreamble::getBounds | ( | ) | const |
PreambleBounds used to build the preamble.
Definition at line 581 of file PrecompiledPreamble.cpp.
|
inline |
Returned string is not null-terminated.
Definition at line 106 of file PrecompiledPreamble.h.
std::size_t PrecompiledPreamble::getSize | ( | ) | const |
Returns the size, in bytes, that preamble takes on disk or in memory.
For on-disk preambles returns 0 if filesystem operations fail. Intended to be used for logging and debugging purposes only.
Definition at line 585 of file PrecompiledPreamble.cpp.
References clang::Result.
|
default |
void PrecompiledPreamble::OverridePreamble | ( | CompilerInvocation & | CI, |
IntrusiveRefCntPtr< llvm::vfs::FileSystem > & | VFS, | ||
llvm::MemoryBuffer * | MainFileBuffer | ||
) | const |
Configure CI
to use this preamble.
Like AddImplicitPreamble, but doesn't assume CanReuse() is true. If this preamble does not match the file, it may parse differently.
Definition at line 720 of file PrecompiledPreamble.cpp.
References clang::ComputePreambleBounds(), and clang::CompilerInvocation::getLangOpts().