diff options
Diffstat (limited to 'include/clang/Frontend/Utils.h')
-rw-r--r-- | include/clang/Frontend/Utils.h | 73 |
1 files changed, 46 insertions, 27 deletions
diff --git a/include/clang/Frontend/Utils.h b/include/clang/Frontend/Utils.h index 8ccc31982dabd..67912a8dfcdde 100644 --- a/include/clang/Frontend/Utils.h +++ b/include/clang/Frontend/Utils.h @@ -1,4 +1,4 @@ -//===--- Utils.h - Misc utilities for the front-end -------------*- C++ -*-===// +//===- Utils.h - Misc utilities for the front-end ---------------*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -15,45 +15,49 @@ #define LLVM_CLANG_FRONTEND_UTILS_H #include "clang/Basic/Diagnostic.h" +#include "clang/Basic/LLVM.h" #include "clang/Basic/VirtualFileSystem.h" #include "llvm/ADT/IntrusiveRefCntPtr.h" +#include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringSet.h" #include "llvm/Option/OptSpecifier.h" +#include <cstdint> +#include <memory> +#include <string> +#include <system_error> #include <utility> +#include <vector> namespace llvm { -class raw_fd_ostream; + class Triple; namespace opt { + class ArgList; -} -} + +} // namespace opt + +} // namespace llvm namespace clang { -class ASTConsumer; + class ASTReader; class CompilerInstance; class CompilerInvocation; -class Decl; class DependencyOutputOptions; class DiagnosticsEngine; -class DiagnosticOptions; class ExternalSemaSource; -class FileManager; +class FrontendOptions; class HeaderSearch; class HeaderSearchOptions; -class IdentifierTable; class LangOptions; class PCHContainerReader; class Preprocessor; class PreprocessorOptions; class PreprocessorOutputOptions; -class SourceManager; -class Stmt; -class TargetInfo; -class FrontendOptions; /// Apply the header search options to get given HeaderSearch object. void ApplyHeaderSearchOptions(HeaderSearch &HS, @@ -68,7 +72,7 @@ void InitializePreprocessor(Preprocessor &PP, const PreprocessorOptions &PPOpts, const FrontendOptions &FEOpts); /// DoPrintPreprocessedInput - Implement -E mode. -void DoPrintPreprocessedInput(Preprocessor &PP, raw_ostream* OS, +void DoPrintPreprocessedInput(Preprocessor &PP, raw_ostream *OS, const PreprocessorOutputOptions &Opts); /// An interface for collecting the dependencies of a compilation. Users should @@ -78,9 +82,11 @@ void DoPrintPreprocessedInput(Preprocessor &PP, raw_ostream* OS, /// interface. class DependencyCollector { public: + virtual ~DependencyCollector(); + virtual void attachToPreprocessor(Preprocessor &PP); virtual void attachToASTReader(ASTReader &R); - llvm::ArrayRef<std::string> getDependencies() const { return Dependencies; } + ArrayRef<std::string> getDependencies() const { return Dependencies; } /// Called when a new file is seen. Return true if \p Filename should be added /// to the list of dependencies. @@ -88,17 +94,19 @@ public: /// The default implementation ignores <built-in> and system files. virtual bool sawDependency(StringRef Filename, bool FromModule, bool IsSystem, bool IsModuleFile, bool IsMissing); + /// Called when the end of the main file is reached. - virtual void finishedMainFile() { } + virtual void finishedMainFile() {} + /// Return true if system files should be passed to sawDependency(). virtual bool needSystemDependencies() { return false; } - virtual ~DependencyCollector(); -public: // implementation detail + // implementation detail /// Add a dependency \p Filename if it has not been seen before and /// sawDependency() returns true. void maybeAddDependency(StringRef Filename, bool FromModule, bool IsSystem, bool IsModuleFile, bool IsMissing); + private: llvm::StringSet<> Seen; std::vector<std::string> Dependencies; @@ -110,10 +118,13 @@ private: /// loaded. class DependencyFileGenerator { void *Impl; // Opaque implementation + DependencyFileGenerator(void *Impl); + public: static DependencyFileGenerator *CreateAndAttachToPreprocessor( Preprocessor &PP, const DependencyOutputOptions &Opts); + void AttachToASTReader(ASTReader &R); }; @@ -124,15 +135,20 @@ class ModuleDependencyCollector : public DependencyCollector { bool HasErrors = false; llvm::StringSet<> Seen; vfs::YAMLVFSWriter VFSWriter; - llvm::StringMap<std::string> SymLinkMap; bool getRealPath(StringRef SrcPath, SmallVectorImpl<char> &Result); - std::error_code copyToRoot(StringRef Src, StringRef Dst = ""); + std::error_code copyToRoot(StringRef Src, StringRef Dst = {}); + public: + ModuleDependencyCollector(std::string DestDir) + : DestDir(std::move(DestDir)) {} + ~ModuleDependencyCollector() override { writeFileMap(); } + StringRef getDest() { return DestDir; } bool insertSeen(StringRef Filename) { return Seen.insert(Filename).second; } - void addFile(StringRef Filename, StringRef FileDst = ""); + void addFile(StringRef Filename, StringRef FileDst = {}); + void addFileMapping(StringRef VPath, StringRef RPath) { VFSWriter.addFileMapping(VPath, RPath); } @@ -142,9 +158,6 @@ public: void writeFileMap(); bool hasErrors() { return HasErrors; } - ModuleDependencyCollector(std::string DestDir) - : DestDir(std::move(DestDir)) {} - ~ModuleDependencyCollector() { writeFileMap(); } }; /// AttachDependencyGraphGen - Create a dependency graph generator, and attach @@ -167,7 +180,7 @@ void AttachDependencyGraphGen(Preprocessor &PP, StringRef OutputFile, void AttachHeaderIncludeGen(Preprocessor &PP, const DependencyOutputOptions &DepOpts, bool ShowAllHeaders = false, - StringRef OutputPath = "", + StringRef OutputPath = {}, bool ShowDepth = true, bool MSStyle = false); /// Cache tokens for use with PCH. Note that this requires a seekable stream. @@ -221,6 +234,12 @@ template <typename T> void BuryPointer(std::unique_ptr<T> Ptr) { BuryPointer(Ptr.release()); } -} // end namespace clang +// Frontend timing utils + +/// If the user specifies the -ftime-report argument on an Clang command line +/// then the value of this boolean will be true, otherwise false. +extern bool FrontendTimesIsEnabled; + +} // namespace clang -#endif +#endif // LLVM_CLANG_FRONTEND_UTILS_H |