diff options
Diffstat (limited to 'lib/Frontend/CompilerInstance.cpp')
-rw-r--r-- | lib/Frontend/CompilerInstance.cpp | 174 |
1 files changed, 87 insertions, 87 deletions
diff --git a/lib/Frontend/CompilerInstance.cpp b/lib/Frontend/CompilerInstance.cpp index 408ebbee43..c413a42f44 100644 --- a/lib/Frontend/CompilerInstance.cpp +++ b/lib/Frontend/CompilerInstance.cpp @@ -79,7 +79,7 @@ void CompilerInstance::setFileManager(FileManager *Value) { FileMgr = Value; } -void CompilerInstance::setSourceManager(SourceManager *Value) { +void CompilerInstance::setSourceManager(SourceManager *Value) { SourceMgr = Value; } @@ -162,7 +162,7 @@ void CompilerInstance::createDiagnostics(int Argc, const char* const *Argv, &getCodeGenOpts()); } -llvm::IntrusiveRefCntPtr<DiagnosticsEngine> +llvm::IntrusiveRefCntPtr<DiagnosticsEngine> CompilerInstance::createDiagnostics(const DiagnosticOptions &Opts, int Argc, const char* const *Argv, DiagnosticConsumer *Client, @@ -184,13 +184,13 @@ CompilerInstance::createDiagnostics(const DiagnosticOptions &Opts, Diags->setClient(new TextDiagnosticPrinter(llvm::errs(), Opts)); // Chain in -verify checker, if requested. - if (Opts.VerifyDiagnostics) + if (Opts.VerifyDiagnostics) Diags->setClient(new VerifyDiagnosticConsumer(*Diags)); // Chain in -diagnostic-log-file dumper, if requested. if (!Opts.DiagnosticLogFile.empty()) SetUpDiagnosticLog(Opts, CodeGenOpts, *Diags); - + if (!Opts.DumpBuildInformation.empty()) SetUpBuildDumpLog(Opts, Argc, Argv, *Diags); @@ -216,18 +216,18 @@ void CompilerInstance::createSourceManager(FileManager &FileMgr) { void CompilerInstance::createPreprocessor() { const PreprocessorOptions &PPOpts = getPreprocessorOpts(); - + // Create a PTH manager if we are using some form of a token cache. PTHManager *PTHMgr = 0; if (!PPOpts.TokenCache.empty()) PTHMgr = PTHManager::Create(PPOpts.TokenCache, getDiagnostics()); - + // Create the Preprocessor. HeaderSearch *HeaderInfo = new HeaderSearch(getFileManager()); PP = new Preprocessor(getDiagnostics(), getLangOpts(), &getTarget(), getSourceManager(), *HeaderInfo, *this, PTHMgr, /*OwnsHeaderSearch=*/true); - + // Note that this is different then passing PTHMgr to Preprocessor's ctor. // That argument is used as the IdentifierInfoLookup argument to // IdentifierTable's ctor. @@ -235,30 +235,30 @@ void CompilerInstance::createPreprocessor() { PTHMgr->setPreprocessor(&*PP); PP->setPTHManager(PTHMgr); } - + if (PPOpts.DetailedRecord) PP->createPreprocessingRecord( PPOpts.DetailedRecordIncludesNestedMacroExpansions); - + InitializePreprocessor(*PP, PPOpts, getHeaderSearchOpts(), getFrontendOpts()); - + // Set up the module path, including the hash for the // module-creation options. llvm::SmallString<256> SpecificModuleCache( getHeaderSearchOpts().ModuleCachePath); if (!getHeaderSearchOpts().DisableModuleHash) - llvm::sys::path::append(SpecificModuleCache, + llvm::sys::path::append(SpecificModuleCache, getInvocation().getModuleHash()); PP->getHeaderSearchInfo().configureModules(SpecificModuleCache, getPreprocessorOpts().ModuleBuildPath.empty() - ? std::string() + ? std::string() : getPreprocessorOpts().ModuleBuildPath.back()); - + // Handle generating dependencies, if requested. const DependencyOutputOptions &DepOpts = getDependencyOutputOpts(); if (!DepOpts.OutputFile.empty()) AttachDependencyFileGen(*PP, DepOpts); - + // Handle generating header include information, if requested. if (DepOpts.ShowHeaderIncludes) AttachHeaderIncludeGen(*PP); @@ -290,7 +290,7 @@ void CompilerInstance::createPCHExternalASTSource(StringRef Path, llvm::OwningPtr<ExternalASTSource> Source; bool Preamble = getPreprocessorOpts().PrecompiledPreambleBytes.first != 0; Source.reset(createPCHExternalASTSource(Path, getHeaderSearchOpts().Sysroot, - DisablePCHValidation, + DisablePCHValidation, DisableStatCache, getPreprocessor(), getASTContext(), DeserializationListener, @@ -315,8 +315,8 @@ CompilerInstance::createPCHExternalASTSource(StringRef Path, Reader->setDeserializationListener( static_cast<ASTDeserializationListener *>(DeserializationListener)); - switch (Reader->ReadAST(Path, - Preamble ? serialization::MK_Preamble + switch (Reader->ReadAST(Path, + Preamble ? serialization::MK_Preamble : serialization::MK_PCH)) { case ASTReader::Success: // Set the predefines buffer as suggested by the PCH reader. Typically, the @@ -338,7 +338,7 @@ CompilerInstance::createPCHExternalASTSource(StringRef Path, // Code Completion -static bool EnableCodeCompletion(Preprocessor &PP, +static bool EnableCodeCompletion(Preprocessor &PP, const std::string &Filename, unsigned Line, unsigned Column) { @@ -398,7 +398,7 @@ CompilerInstance::createCodeCompletionConsumer(Preprocessor &PP, return 0; // Set up the creation routine for code-completion. - return new PrintingCodeCompleteConsumer(ShowMacros, ShowCodePatterns, + return new PrintingCodeCompleteConsumer(ShowMacros, ShowCodePatterns, ShowGlobals, OS); } @@ -440,7 +440,7 @@ void CompilerInstance::clearOutputFiles(bool EraseFiles) { } } else if (!it->Filename.empty() && EraseFiles) llvm::sys::Path(it->Filename).eraseFromDisk(); - + } OutputFiles.clear(); } @@ -619,7 +619,7 @@ bool CompilerInstance::ExecuteAction(FrontendAction &Act) { if (getFrontendOpts().ShowStats) llvm::EnableStatistics(); - + for (unsigned i = 0, e = getFrontendOpts().Inputs.size(); i != e; ++i) { const std::string &InFile = getFrontendOpts().Inputs[i].second; @@ -638,7 +638,7 @@ bool CompilerInstance::ExecuteAction(FrontendAction &Act) { // Get the total number of warnings/errors from the client. unsigned NumWarnings = getDiagnostics().getClient()->getNumWarnings(); unsigned NumErrors = getDiagnostics().getClient()->getNumErrors(); - + if (NumWarnings) OS << NumWarnings << " warning" << (NumWarnings == 1 ? "" : "s"); if (NumWarnings && NumErrors) @@ -687,7 +687,7 @@ namespace { /// \brief Class that manages the creation of a lock file to aid /// implicit coordination between different processes. /// - /// The implicit coordination works by creating a ".lock" file alongside + /// The implicit coordination works by creating a ".lock" file alongside /// the file that we're coordinating for, using the atomicity of the file /// system to ensure that only a single process can create that ".lock" file. /// When the lock file is removed, the owning process has finished the @@ -710,28 +710,28 @@ namespace { private: llvm::SmallString<128> LockFileName; llvm::SmallString<128> UniqueLockFileName; - + llvm::Optional<std::pair<std::string, int> > Owner; llvm::Optional<llvm::error_code> Error; - + LockFileManager(const LockFileManager &); LockFileManager &operator=(const LockFileManager &); - - static llvm::Optional<std::pair<std::string, int> > + + static llvm::Optional<std::pair<std::string, int> > readLockFile(StringRef LockFileName); - + static bool processStillExecuting(StringRef Hostname, int PID); - + public: - + LockFileManager(StringRef FileName); ~LockFileManager(); /// \brief Determine the state of the lock file. LockFileState getState() const; - + operator LockFileState() const { return getState(); } - + /// \brief For a shared lock, wait until the owner releases the lock. void waitForUnlock(); }; @@ -742,14 +742,14 @@ namespace { /// \param LockFileName The name of the lock file to read. /// /// \returns The process ID of the process that owns this lock file -llvm::Optional<std::pair<std::string, int> > +llvm::Optional<std::pair<std::string, int> > LockFileManager::readLockFile(StringRef LockFileName) { // Check whether the lock file exists. If not, clearly there's nothing // to read, so we just return. bool Exists = false; if (llvm::sys::fs::exists(LockFileName, Exists) || !Exists) return llvm::Optional<std::pair<std::string, int> >(); - + // Read the owning host and PID out of the lock file. If it appears that the // owning process is dead, the lock file is invalid. int PID = 0; @@ -770,42 +770,42 @@ bool LockFileManager::processStillExecuting(StringRef Hostname, int PID) { char MyHostname[256]; MyHostname[255] = 0; MyHostname[0] = 0; - gethostname(MyHostname, 255); + gethostname(MyHostname, 255); // Check whether the process is dead. If so, we're done. if (MyHostname == Hostname && getsid(PID) == -1 && errno == ESRCH) return false; #endif - + return true; } -LockFileManager::LockFileManager(StringRef FileName) +LockFileManager::LockFileManager(StringRef FileName) { LockFileName = FileName; LockFileName += ".lock"; - + // If the lock file already exists, don't bother to try to create our own // lock file; it won't work anyway. Just figure out who owns this lock file. if ((Owner = readLockFile(LockFileName))) return; - + // Create a lock file that is unique to this instance. UniqueLockFileName = LockFileName; UniqueLockFileName += "-%%%%%%%%"; int UniqueLockFileID; - if (llvm::error_code EC - = llvm::sys::fs::unique_file(UniqueLockFileName.str(), + if (llvm::error_code EC + = llvm::sys::fs::unique_file(UniqueLockFileName.str(), UniqueLockFileID, - UniqueLockFileName, + UniqueLockFileName, /*makeAbsolute=*/false)) { Error = EC; return; } - + // Write our process ID to our unique lock file. { llvm::raw_fd_ostream Out(UniqueLockFileID, /*shouldClose=*/true); - + #if LLVM_ON_UNIX // FIXME: move getpid() call into LLVM char hostname[256]; @@ -817,7 +817,7 @@ LockFileManager::LockFileManager(StringRef FileName) Out << "localhost 1"; #endif Out.close(); - + if (Out.has_error()) { // We failed to write out PID, so make up an excuse, remove the // unique lock file, and fail. @@ -827,16 +827,16 @@ LockFileManager::LockFileManager(StringRef FileName) return; } } - + // Create a hard link from the lock file name. If this succeeds, we're done. - llvm::error_code EC - = llvm::sys::fs::create_hard_link(UniqueLockFileName.str(), + llvm::error_code EC + = llvm::sys::fs::create_hard_link(UniqueLockFileName.str(), LockFileName.str()); if (EC == llvm::errc::success) return; - // Creating the hard link failed. - + // Creating the hard link failed. + #ifdef LLVM_ON_UNIX // The creation of the hard link may appear to fail, but if stat'ing the // unique file returns a link count of 2, then we can still declare success. @@ -847,12 +847,12 @@ LockFileManager::LockFileManager(StringRef FileName) #endif // Someone else managed to create the lock file first. Wipe out our unique - // lock file (it's useless now) and read the process ID from the lock file. + // lock file (it's useless now) and read the process ID from the lock file. bool Existed; llvm::sys::fs::remove(UniqueLockFileName.str(), Existed); if ((Owner = readLockFile(LockFileName))) return; - + // There is a lock file that nobody owns; try to clean it up and report // an error. llvm::sys::fs::remove(LockFileName.str(), Existed); @@ -865,14 +865,14 @@ LockFileManager::LockFileState LockFileManager::getState() const { if (Error) return LFS_Error; - + return LFS_Owned; } LockFileManager::~LockFileManager() { if (getState() != LFS_Owned) return; - + // Since we own the lock, remove the lock file and our own unique lock file. bool Existed; llvm::sys::fs::remove(LockFileName.str(), Existed); @@ -882,7 +882,7 @@ LockFileManager::~LockFileManager() { void LockFileManager::waitForUnlock() { if (getState() != LFS_Shared) return; - + #if LLVM_ON_WIN32 unsigned long Interval = 1; #else @@ -894,7 +894,7 @@ void LockFileManager::waitForUnlock() { const unsigned MaxSeconds = 3600; do { // Sleep for the designated interval, to allow the owning process time to - // finish up and + // finish up and // FIXME: Should we hook in to system APIs to get a notification when the // lock file is deleted? #if LLVM_ON_WIN32 @@ -909,7 +909,7 @@ void LockFileManager::waitForUnlock() { if (!processStillExecuting((*Owner).first, (*Owner).second)) return; - + // Exponentially increase the time we wait for the lock to be removed. #if LLVM_ON_WIN32 Interval *= 2; @@ -928,7 +928,7 @@ void LockFileManager::waitForUnlock() { Interval.tv_sec < MaxSeconds #endif ); - + // Give up. } @@ -943,31 +943,31 @@ static void compileModule(CompilerInstance &ImportingInstance, switch (Locked) { case LockFileManager::LFS_Error: return; - + case LockFileManager::LFS_Owned: // We're responsible for building the module ourselves. Do so below. break; - + case LockFileManager::LFS_Shared: // Someone else is responsible for building the module. Wait for them to // finish. Locked.waitForUnlock(); break; } - + // Construct a compiler invocation for creating this module. llvm::IntrusiveRefCntPtr<CompilerInvocation> Invocation (new CompilerInvocation(ImportingInstance.getInvocation())); - + // For any options that aren't intended to affect how a module is built, // reset them to their default values. Invocation->getLangOpts().resetNonModularOptions(); Invocation->getPreprocessorOpts().resetNonModularOptions(); - - // Note that this module is part of the module build path, so that we + + // Note that this module is part of the module build path, so that we // can detect cycles in the module graph. Invocation->getPreprocessorOpts().ModuleBuildPath.push_back(ModuleName); - + // Set up the inputs/outputs so that we build the module from its umbrella // header. FrontendOptions &FrontendOpts = Invocation->getFrontendOpts(); @@ -975,38 +975,38 @@ static void compileModule(CompilerInstance &ImportingInstance, FrontendOpts.DisableFree = false; FrontendOpts.Inputs.clear(); FrontendOpts.Inputs.push_back( - std::make_pair(getSourceInputKindFromOptions(Invocation->getLangOpts()), + std::make_pair(getSourceInputKindFromOptions(Invocation->getLangOpts()), UmbrellaHeader)); - + Invocation->getDiagnosticOpts().VerifyDiagnostics = 0; - - + + assert(ImportingInstance.getInvocation().getModuleHash() == Invocation->getModuleHash() && "Module hash mismatch!"); - + // Construct a compiler instance that will be used to actually create the // module. CompilerInstance Instance; Instance.setInvocation(&*Invocation); - Instance.createDiagnostics(/*argc=*/0, /*argv=*/0, + Instance.createDiagnostics(/*argc=*/0, /*argv=*/0, &ImportingInstance.getDiagnosticClient(), /*ShouldOwnClient=*/true, /*ShouldCloneClient=*/true); // Construct a module-generating action. GeneratePCHAction CreateModuleAction(true); - + // Execute the action to actually build the module in-place. Use a separate // thread so that we get a stack large enough. const unsigned ThreadStackSize = 8 << 20; llvm::CrashRecoveryContext CRC; CompileModuleData Data = { Instance, CreateModuleAction }; CRC.RunSafelyOnThread(&doCompileModule, &Data, ThreadStackSize); -} +} -ModuleKey CompilerInstance::loadModule(SourceLocation ImportLoc, +ModuleKey CompilerInstance::loadModule(SourceLocation ImportLoc, IdentifierInfo &ModuleName, - SourceLocation ModuleNameLoc) { + SourceLocation ModuleNameLoc) { // Determine what file we're searching from. SourceManager &SourceMgr = getSourceManager(); SourceLocation ExpandedImportLoc = SourceMgr.getExpansionLoc(ImportLoc); @@ -1022,17 +1022,17 @@ ModuleKey CompilerInstance::loadModule(SourceLocation ImportLoc, = PP->getHeaderSearchInfo().lookupModule(ModuleName.getName(), &ModuleFileName, &UmbrellaHeader); - + bool BuildingModule = false; if (!ModuleFile && !UmbrellaHeader.empty()) { // We didn't find the module, but there is an umbrella header that // can be used to create the module file. Create a separate compilation // module to do so. - + // Check whether there is a cycle in the module graph. SmallVectorImpl<std::string> &ModuleBuildPath = getPreprocessorOpts().ModuleBuildPath; - SmallVectorImpl<std::string>::iterator Pos + SmallVectorImpl<std::string>::iterator Pos = std::find(ModuleBuildPath.begin(), ModuleBuildPath.end(), ModuleName.getName()); if (Pos != ModuleBuildPath.end()) { @@ -1042,28 +1042,28 @@ ModuleKey CompilerInstance::loadModule(SourceLocation ImportLoc, CyclePath += " -> "; } CyclePath += ModuleName.getName(); - + getDiagnostics().Report(ModuleNameLoc, diag::err_module_cycle) << ModuleName.getName() << CyclePath; return 0; } - + getDiagnostics().Report(ModuleNameLoc, diag::warn_module_build) << ModuleName.getName(); BuildingModule = true; compileModule(*this, ModuleName.getName(), ModuleFileName, UmbrellaHeader); ModuleFile = PP->getHeaderSearchInfo().lookupModule(ModuleName.getName()); } - + if (!ModuleFile) { - getDiagnostics().Report(ModuleNameLoc, + getDiagnostics().Report(ModuleNameLoc, BuildingModule? diag::err_module_not_built : diag::err_module_not_found) << ModuleName.getName() << SourceRange(ImportLoc, ModuleNameLoc); return 0; } - + // If we don't already have an ASTReader, create one now. if (!ModuleManager) { if (!hasASTContext()) @@ -1073,7 +1073,7 @@ ModuleKey CompilerInstance::loadModule(SourceLocation ImportLoc, const PreprocessorOptions &PPOpts = getPreprocessorOpts(); ModuleManager = new ASTReader(getPreprocessor(), *Context, Sysroot.empty() ? "" : Sysroot.c_str(), - PPOpts.DisablePCHValidation, + PPOpts.DisablePCHValidation, PPOpts.DisableStatCache); if (hasASTConsumer()) { ModuleManager->setDeserializationListener( @@ -1089,7 +1089,7 @@ ModuleKey CompilerInstance::loadModule(SourceLocation ImportLoc, if (hasASTConsumer()) ModuleManager->StartTranslationUnit(&getASTConsumer()); } - + // Try to load the module we found. switch (ModuleManager->ReadAST(ModuleFile->getName(), serialization::MK_Module)) { @@ -1100,12 +1100,12 @@ ModuleKey CompilerInstance::loadModule(SourceLocation ImportLoc, // FIXME: The ASTReader will already have complained, but can we showhorn // that diagnostic information into a more useful form? return 0; - + case ASTReader::Failure: // Already complained. return 0; } - + // FIXME: The module file's FileEntry makes a poor key indeed! return (ModuleKey)ModuleFile; } |