Lines Matching +full:main +full:- +full:storage

1 //===--- PrecompiledPreamble.cpp - Build precompiled preambles --*- C++ -*-===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
11 //===----------------------------------------------------------------------===//
28 #include "llvm/Config/llvm-config.h"
49 #warning "Unknown platform. Defaulting to UNIX-style paths for in-memory PCHs" in getInMemoryPreamblePath()
59 // so we create an in-memory VFS with just that and overlay it on top. in createVFSOverlayForPreamblePCH()
62 PCHFS->addFile(PCHFilename, 0, std::move(PCHBuffer)); in createVFSOverlayForPreamblePCH()
65 Overlay->pushOverlay(PCHFS); in createVFSOverlayForPreamblePCH()
74 // spuriously added by '-isystem' (e.g. to suppress warnings from those
106 // (We have some false negatives if PP recovered e.g. <foo> -> "foo") in InclusionDirective()
128 if (IncludingFile->getDir()) in InclusionDirective()
129 NotFoundRelativeTo(IncludingFile->getDir()); in InclusionDirective()
198 // so it's not intended to be used outside preamble-handling.
201 // A main method used to construct TempPCHFile.
204 // crash-recovery testing, which is the only case where the preamble files in create()
212 // that we would never get a race condition in a multi-threaded setting in create()
221 llvm::sys::path::append(TempPath, "preamble-%%%%%%.pch"); in create()
223 // Use the same owner-only file permissions as fs::createTemporaryFile(). in create()
243 TemporaryFiles::getInstance().addFile(this->FilePath); in TempPCHFile()
263 *FileOS << Buffer->Data; in setEmittedPreamblePCH()
268 this->HasEmittedPreamblePCH = true; in setEmittedPreamblePCH()
288 std::unique_ptr<llvm::raw_pwrite_stream> FileOS; // null if in-memory
364 S->File = std::move(File); in file()
369 S->Memory = std::move(Buf); in inMemory()
383 return File->getFilePath(); in filePath()
387 return StringRef(Memory->Data.data(), Memory->Data.size()); in memoryContents()
390 // Shrink in-memory buffers to fit.
391 // This incurs a copy, but preambles tend to be long-lived.
396 Memory->Data = decltype(Memory->Data)(Memory->Data); in shrink()
423 FrontendOptions &FrontendOpts = PreambleInvocation->getFrontendOpts(); in Build()
425 PreambleInvocation->getPreprocessorOpts(); in Build()
428 std::unique_ptr<PCHStorage> Storage; in Build() local
430 Storage = PCHStorage::inMemory(Buffer); in Build()
438 Storage = PCHStorage::file(std::move(PreamblePCHFile)); in Build()
443 std::vector<char> PreambleBytes(MainFileBuffer->getBufferStart(), in Build()
444 MainFileBuffer->getBufferStart() + in Build()
451 StoreInMemory ? getInMemoryPreamblePath() : Storage->filePath()); in Build()
465 Clang->setInvocation(std::move(PreambleInvocation)); in Build()
466 Clang->setDiagnostics(&Diagnostics); in Build()
469 if (!Clang->createTarget()) in Build()
472 if (Clang->getFrontendOpts().Inputs.size() != 1 || in Build()
473 Clang->getFrontendOpts().Inputs[0].getKind().getFormat() != in Build()
475 Clang->getFrontendOpts().Inputs[0].getKind().getLanguage() == in Build()
482 ProcessWarningOptions(Diagnostics, Clang->getDiagnosticOpts()); in Build()
485 createVFSFromCompilerInvocation(Clang->getInvocation(), Diagnostics, VFS); in Build()
488 Clang->setFileManager(new FileManager(Clang->getFileSystemOpts(), VFS)); in Build()
491 Clang->setSourceManager( in Build()
492 new SourceManager(Diagnostics, Clang->getFileManager())); in Build()
495 Clang->addDependencyCollector(PreambleDepCollector); in Build()
497 Clang->getLangOpts().CompilingPCH = true; in Build()
499 // Remap the main source file to the preamble buffer. in Build()
502 MainFileBuffer->getBuffer().slice(0, Bounds.Size), MainFilePath); in Build()
515 /*WritePCHFile=*/Storage->getKind() == PCHStorage::Kind::TempFile, in Build()
517 if (!Act->BeginSourceFile(*Clang.get(), Clang->getFrontendOpts().Inputs[0])) in Build()
520 // Performed after BeginSourceFile to ensure Clang->Preprocessor can be in Build()
527 Clang->getPreprocessor().addPPCallbacks(std::move(DelegatedPPCallbacks)); in Build()
529 Clang->getPreprocessor().addCommentHandler(CommentHandler); in Build()
531 Clang->getPreprocessor().addPPCallbacks( in Build()
533 MissingFiles, Clang->getPreprocessor().getHeaderSearchInfo(), in Build()
534 Clang->getSourceManager())); in Build()
536 if (llvm::Error Err = Act->Execute()) in Build()
542 Act->EndSourceFile(); in Build()
544 if (!Act->hasEmittedPreamblePCH()) in Build()
546 Act.reset(); // Frees the PCH buffer, unless Storage keeps it in memory. in Build()
552 SourceManager &SourceMgr = Clang->getSourceManager(); in Build()
553 for (auto &Filename : PreambleDepCollector->getDependencies()) { in Build()
554 auto MaybeFile = Clang->getFileManager().getOptionalFileRef(Filename); in Build()
571 // Shrinking the storage requires extra temporary memory. in Build()
575 Storage->shrink(); in Build()
577 std::move(Storage), std::move(PreambleBytes), PreambleEndsAtStartOfLine, in Build()
586 switch (Storage->getKind()) { in getSize()
588 return Storage->memoryContents().size(); in getSize()
591 if (llvm::sys::fs::file_size(Storage->filePath(), Result)) in getSize()
599 llvm_unreachable("Unhandled storage kind"); in getSize()
613 PreambleInvocation->getPreprocessorOpts(); in CanReuse()
617 // the main-file buffer within the precompiled preamble to fit the in CanReuse()
618 // new main file. in CanReuse()
624 // The preamble has not changed. We may be able to re-use the precompiled in CanReuse()
652 PreambleFileHash::createForMemoryBuffer(RB.second->getMemBufferRef()); in CanReuse()
670 if (OverridenFileBuffer->second != F.second) in CanReuse()
685 // This file was remapped; check whether the newly-mapped file in CanReuse()
687 if (Overridden->second != F.second) in CanReuse()
704 // consider the preamble out-of-date. in CanReuse()
706 if (Status->isRegularFile()) in CanReuse()
728 std::unique_ptr<PCHStorage> Storage, std::vector<char> PreambleBytes, in PrecompiledPreamble() argument
732 : Storage(std::move(Storage)), FilesInPreamble(std::move(FilesInPreamble)), in PrecompiledPreamble()
736 assert(this->Storage != nullptr); in PrecompiledPreamble()
771 // Remap main file to point to MainFileBuffer. in configurePreamble()
786 setupPreambleStorage(*Storage, PreprocessorOpts, VFS); in configurePreamble()
790 const PCHStorage &Storage, PreprocessorOptions &PreprocessorOpts, in setupPreambleStorage() argument
792 if (Storage.getKind() == PCHStorage::Kind::TempFile) { in setupPreambleStorage()
793 llvm::StringRef PCHPath = Storage.filePath(); in setupPreambleStorage()
799 if (VFS == RealFS || VFS->exists(PCHPath)) in setupPreambleStorage()
801 auto Buf = RealFS->getBufferForFile(PCHPath); in setupPreambleStorage()
809 // We have a slight inconsistency here -- we're using the VFS to in setupPreambleStorage()
813 assert(Storage.getKind() == PCHStorage::Kind::InMemory); in setupPreambleStorage()
814 // For in-memory preamble, we have to provide a VFS overlay that makes it in setupPreambleStorage()
820 Storage.memoryContents(), PCHPath, /*RequiresNullTerminator=*/false); in setupPreambleStorage()
841 return "build-preamble.error"; in name()