13 #ifndef LLVM_CLANG_FRONTEND_PRECOMPILED_PREAMBLE_H 14 #define LLVM_CLANG_FRONTEND_PRECOMPILED_PREAMBLE_H 18 #include "llvm/ADT/IntrusiveRefCntPtr.h" 19 #include "llvm/Support/AlignOf.h" 20 #include "llvm/Support/MD5.h" 23 #include <system_error> 24 #include <type_traits> 34 class CompilerInstance;
35 class CompilerInvocation;
37 class PCHContainerOperations;
41 llvm::MemoryBuffer *Buffer,
44 class PreambleCallbacks;
51 struct PreambleFileHash;
78 static llvm::ErrorOr<PrecompiledPreamble>
83 std::shared_ptr<PCHContainerOperations> PCHContainerOps,
101 llvm::vfs::FileSystem *VFS)
const;
113 llvm::MemoryBuffer *MainFileBuffer)
const;
120 llvm::MemoryBuffer *MainFileBuffer)
const;
124 bool PreambleEndsAtStartOfLine,
125 llvm::StringMap<PreambleFileHash> FilesInPreamble);
135 static llvm::ErrorOr<TempPCHFile> CreateNewPreamblePCHFile();
138 static llvm::ErrorOr<TempPCHFile> createInSystemTempDir(
const Twine &Prefix,
143 static llvm::ErrorOr<TempPCHFile> createFromCustomPath(
const Twine &Path);
146 TempPCHFile(std::string FilePath);
149 TempPCHFile(TempPCHFile &&Other);
150 TempPCHFile &operator=(TempPCHFile &&Other);
152 TempPCHFile(
const TempPCHFile &) =
delete;
156 llvm::StringRef getFilePath()
const;
159 void RemoveFileIfPresent();
165 class InMemoryPreamble {
172 enum class Kind { Empty, InMemory, TempFile };
174 PCHStorage() =
default;
175 PCHStorage(TempPCHFile File);
176 PCHStorage(InMemoryPreamble Memory);
178 PCHStorage(
const PCHStorage &) =
delete;
179 PCHStorage &operator=(
const PCHStorage &) =
delete;
181 PCHStorage(PCHStorage &&Other);
182 PCHStorage &operator=(PCHStorage &&Other);
188 TempPCHFile &asFile();
189 const TempPCHFile &asFile()
const;
191 InMemoryPreamble &asMemory();
192 const InMemoryPreamble &asMemory()
const;
199 Kind StorageKind = Kind::Empty;
200 llvm::AlignedCharArrayUnion<TempPCHFile, InMemoryPreamble> Storage = {};
204 struct PreambleFileHash {
215 llvm::MD5::MD5Result MD5 = {};
217 static PreambleFileHash createForFile(off_t Size, time_t ModTime);
218 static PreambleFileHash
219 createForMemoryBuffer(
const llvm::MemoryBuffer *Buffer);
221 friend bool operator==(
const PreambleFileHash &LHS,
222 const PreambleFileHash &RHS) {
223 return LHS.Size == RHS.Size && LHS.ModTime == RHS.ModTime &&
226 friend bool operator!=(
const PreambleFileHash &LHS,
227 const PreambleFileHash &RHS) {
228 return !(LHS == RHS);
236 llvm::MemoryBuffer *MainFileBuffer)
const;
242 setupPreambleStorage(
const PCHStorage &Storage,
253 llvm::StringMap<PreambleFileHash> FilesInPreamble;
257 std::vector<char> PreambleBytes;
259 bool PreambleEndsAtStartOfLine;
278 virtual void AfterPCHEmitted(
ASTWriter &Writer);
285 virtual std::unique_ptr<PPCallbacks> createPPCallbacks();
300 const char *
name()
const noexcept
override;
301 std::string message(
int condition)
const override;
Describes the bounds (start, size) of the preamble and a flag required by PreprocessorOptions::Precom...
bool operator==(CanQual< T > x, CanQual< U > y)
Specialize PointerLikeTypeTraits to allow LazyGenerationalUpdatePtr to be placed into a PointerUnion...
PreprocessorOptions - This class is used for passing the various options used in preprocessor initial...
__SIZE_TYPE__ size_t
The unsigned integer type of the result of the sizeof operator.
std::error_code make_error_code(BuildPreambleError Error)
Concrete class used by the front-end to report problems and issues.
A set of callbacks to gather useful information while building a preamble.
Defines the clang::Preprocessor interface.
PreambleBounds ComputePreambleBounds(const LangOptions &LangOpts, llvm::MemoryBuffer *Buffer, unsigned MaxLines)
Runs lexer to compute suggested preamble bounds.
CompilerInstance - Helper class for managing a single instance of the Clang compiler.
Dataflow Directional Tag Classes.
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.
bool operator!=(CanQual< T > x, CanQual< U > y)
Writes an AST file containing the contents of a translation unit.
static Decl::Kind getKind(const Decl *D)