diff options
Diffstat (limited to 'clang/lib/Frontend/CompilerInstance.cpp')
-rw-r--r-- | clang/lib/Frontend/CompilerInstance.cpp | 63 |
1 files changed, 31 insertions, 32 deletions
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index 3e67cf1..d6f3aec 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -159,17 +159,11 @@ bool CompilerInstance::createTarget() { return true; } -llvm::vfs::FileSystem &CompilerInstance::getVirtualFileSystem() const { - return getFileManager().getVirtualFileSystem(); -} - -llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> -CompilerInstance::getVirtualFileSystemPtr() const { - return getFileManager().getVirtualFileSystemPtr(); -} - -void CompilerInstance::setFileManager( - llvm::IntrusiveRefCntPtr<FileManager> Value) { +void CompilerInstance::setFileManager(IntrusiveRefCntPtr<FileManager> Value) { + if (!hasVirtualFileSystem()) + setVirtualFileSystem(Value->getVirtualFileSystemPtr()); + assert(Value == nullptr || + getVirtualFileSystemPtr() == Value->getVirtualFileSystemPtr()); FileMgr = std::move(Value); } @@ -282,6 +276,20 @@ static void collectVFSEntries(CompilerInstance &CI, MDC->addFile(E.VPath, E.RPath); } +void CompilerInstance::createVirtualFileSystem( + IntrusiveRefCntPtr<llvm::vfs::FileSystem> BaseFS, DiagnosticConsumer *DC) { + DiagnosticOptions DiagOpts; + DiagnosticsEngine Diags(DiagnosticIDs::create(), DiagOpts, DC, + /*ShouldOwnClient=*/false); + + VFS = createVFSFromCompilerInvocation(getInvocation(), Diags, + std::move(BaseFS)); + // FIXME: Should this go into createVFSFromCompilerInvocation? + if (getFrontendOpts().ShowStats) + VFS = + llvm::makeIntrusiveRefCnt<llvm::vfs::TracingFileSystem>(std::move(VFS)); +} + // Diagnostics static void SetUpDiagnosticLog(DiagnosticOptions &DiagOpts, const CodeGenOptions *CodeGenOpts, @@ -333,11 +341,10 @@ static void SetupSerializedDiagnostics(DiagnosticOptions &DiagOpts, } } -void CompilerInstance::createDiagnostics(llvm::vfs::FileSystem &VFS, - DiagnosticConsumer *Client, +void CompilerInstance::createDiagnostics(DiagnosticConsumer *Client, bool ShouldOwnClient) { - Diagnostics = createDiagnostics(VFS, getDiagnosticOpts(), Client, - ShouldOwnClient, &getCodeGenOpts()); + Diagnostics = createDiagnostics(getVirtualFileSystem(), getDiagnosticOpts(), + Client, ShouldOwnClient, &getCodeGenOpts()); } IntrusiveRefCntPtr<DiagnosticsEngine> CompilerInstance::createDiagnostics( @@ -375,18 +382,9 @@ IntrusiveRefCntPtr<DiagnosticsEngine> CompilerInstance::createDiagnostics( // File Manager -FileManager *CompilerInstance::createFileManager( - IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS) { - if (!VFS) - VFS = FileMgr ? FileMgr->getVirtualFileSystemPtr() - : createVFSFromCompilerInvocation(getInvocation(), - getDiagnostics()); - assert(VFS && "FileManager has no VFS?"); - if (getFrontendOpts().ShowStats) - VFS = - llvm::makeIntrusiveRefCnt<llvm::vfs::TracingFileSystem>(std::move(VFS)); - FileMgr = llvm::makeIntrusiveRefCnt<FileManager>(getFileSystemOpts(), - std::move(VFS)); +FileManager *CompilerInstance::createFileManager() { + assert(VFS && "CompilerInstance needs a VFS for creating FileManager"); + FileMgr = llvm::makeIntrusiveRefCnt<FileManager>(getFileSystemOpts(), VFS); return FileMgr.get(); } @@ -1167,20 +1165,21 @@ std::unique_ptr<CompilerInstance> CompilerInstance::cloneForModuleCompileImpl( auto &Inv = Instance.getInvocation(); if (ThreadSafeConfig) { - Instance.createFileManager(ThreadSafeConfig->getVFS()); + Instance.setVirtualFileSystem(ThreadSafeConfig->getVFS()); + Instance.createFileManager(); } else if (FrontendOpts.ModulesShareFileManager) { + Instance.setVirtualFileSystem(getVirtualFileSystemPtr()); Instance.setFileManager(getFileManagerPtr()); } else { - Instance.createFileManager(getVirtualFileSystemPtr()); + Instance.setVirtualFileSystem(getVirtualFileSystemPtr()); + Instance.createFileManager(); } if (ThreadSafeConfig) { - Instance.createDiagnostics(Instance.getVirtualFileSystem(), - &ThreadSafeConfig->getDiagConsumer(), + Instance.createDiagnostics(&ThreadSafeConfig->getDiagConsumer(), /*ShouldOwnClient=*/false); } else { Instance.createDiagnostics( - Instance.getVirtualFileSystem(), new ForwardingDiagnosticConsumer(getDiagnosticClient()), /*ShouldOwnClient=*/true); } |