1f4a2713aSLionel Sambuc //===-- CompilerInvocation.h - Compiler Invocation Helper Data --*- C++ -*-===// 2f4a2713aSLionel Sambuc // 3f4a2713aSLionel Sambuc // The LLVM Compiler Infrastructure 4f4a2713aSLionel Sambuc // 5f4a2713aSLionel Sambuc // This file is distributed under the University of Illinois Open Source 6f4a2713aSLionel Sambuc // License. See LICENSE.TXT for details. 7f4a2713aSLionel Sambuc // 8f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===// 9f4a2713aSLionel Sambuc 10f4a2713aSLionel Sambuc #ifndef LLVM_CLANG_FRONTEND_COMPILERINVOCATION_H_ 11f4a2713aSLionel Sambuc #define LLVM_CLANG_FRONTEND_COMPILERINVOCATION_H_ 12f4a2713aSLionel Sambuc 13f4a2713aSLionel Sambuc #include "clang/Basic/DiagnosticOptions.h" 14f4a2713aSLionel Sambuc #include "clang/Basic/FileSystemOptions.h" 15f4a2713aSLionel Sambuc #include "clang/Basic/LangOptions.h" 16f4a2713aSLionel Sambuc #include "clang/Basic/TargetOptions.h" 17f4a2713aSLionel Sambuc #include "clang/Frontend/CodeGenOptions.h" 18f4a2713aSLionel Sambuc #include "clang/Frontend/DependencyOutputOptions.h" 19f4a2713aSLionel Sambuc #include "clang/Frontend/FrontendOptions.h" 20f4a2713aSLionel Sambuc #include "clang/Frontend/LangStandard.h" 21f4a2713aSLionel Sambuc #include "clang/Frontend/MigratorOptions.h" 22f4a2713aSLionel Sambuc #include "clang/Frontend/PreprocessorOutputOptions.h" 23f4a2713aSLionel Sambuc #include "clang/Lex/HeaderSearchOptions.h" 24f4a2713aSLionel Sambuc #include "clang/Lex/PreprocessorOptions.h" 25f4a2713aSLionel Sambuc #include "clang/StaticAnalyzer/Core/AnalyzerOptions.h" 26f4a2713aSLionel Sambuc #include "llvm/ADT/IntrusiveRefCntPtr.h" 27f4a2713aSLionel Sambuc #include "llvm/ADT/StringMap.h" 28f4a2713aSLionel Sambuc #include "llvm/ADT/StringRef.h" 29f4a2713aSLionel Sambuc #include <string> 30f4a2713aSLionel Sambuc #include <vector> 31f4a2713aSLionel Sambuc 32f4a2713aSLionel Sambuc namespace llvm { 33f4a2713aSLionel Sambuc namespace opt { 34f4a2713aSLionel Sambuc class ArgList; 35f4a2713aSLionel Sambuc } 36f4a2713aSLionel Sambuc } 37f4a2713aSLionel Sambuc 38f4a2713aSLionel Sambuc namespace clang { 39f4a2713aSLionel Sambuc class CompilerInvocation; 40f4a2713aSLionel Sambuc class DiagnosticsEngine; 41f4a2713aSLionel Sambuc 42f4a2713aSLionel Sambuc /// \brief Fill out Opts based on the options given in Args. 43f4a2713aSLionel Sambuc /// 44f4a2713aSLionel Sambuc /// Args must have been created from the OptTable returned by 45f4a2713aSLionel Sambuc /// createCC1OptTable(). 46f4a2713aSLionel Sambuc /// 47f4a2713aSLionel Sambuc /// When errors are encountered, return false and, if Diags is non-null, 48f4a2713aSLionel Sambuc /// report the error(s). 49f4a2713aSLionel Sambuc bool ParseDiagnosticArgs(DiagnosticOptions &Opts, llvm::opt::ArgList &Args, 50*0a6a1f1dSLionel Sambuc DiagnosticsEngine *Diags = nullptr); 51f4a2713aSLionel Sambuc 52f4a2713aSLionel Sambuc class CompilerInvocationBase : public RefCountedBase<CompilerInvocation> { 53*0a6a1f1dSLionel Sambuc void operator=(const CompilerInvocationBase &) LLVM_DELETED_FUNCTION; 54*0a6a1f1dSLionel Sambuc 55*0a6a1f1dSLionel Sambuc public: 56f4a2713aSLionel Sambuc /// Options controlling the language variant. 57*0a6a1f1dSLionel Sambuc std::shared_ptr<LangOptions> LangOpts; 58f4a2713aSLionel Sambuc 59f4a2713aSLionel Sambuc /// Options controlling the target. 60*0a6a1f1dSLionel Sambuc std::shared_ptr<TargetOptions> TargetOpts; 61f4a2713aSLionel Sambuc 62f4a2713aSLionel Sambuc /// Options controlling the diagnostic engine. 63f4a2713aSLionel Sambuc IntrusiveRefCntPtr<DiagnosticOptions> DiagnosticOpts; 64f4a2713aSLionel Sambuc 65f4a2713aSLionel Sambuc /// Options controlling the \#include directive. 66f4a2713aSLionel Sambuc IntrusiveRefCntPtr<HeaderSearchOptions> HeaderSearchOpts; 67f4a2713aSLionel Sambuc 68f4a2713aSLionel Sambuc /// Options controlling the preprocessor (aside from \#include handling). 69f4a2713aSLionel Sambuc IntrusiveRefCntPtr<PreprocessorOptions> PreprocessorOpts; 70f4a2713aSLionel Sambuc 71f4a2713aSLionel Sambuc CompilerInvocationBase(); 72*0a6a1f1dSLionel Sambuc ~CompilerInvocationBase(); 73f4a2713aSLionel Sambuc 74f4a2713aSLionel Sambuc CompilerInvocationBase(const CompilerInvocationBase &X); 75f4a2713aSLionel Sambuc getLangOpts()76*0a6a1f1dSLionel Sambuc LangOptions *getLangOpts() { return LangOpts.get(); } getLangOpts()77*0a6a1f1dSLionel Sambuc const LangOptions *getLangOpts() const { return LangOpts.get(); } 78f4a2713aSLionel Sambuc getTargetOpts()79*0a6a1f1dSLionel Sambuc TargetOptions &getTargetOpts() { return *TargetOpts.get(); } getTargetOpts()80f4a2713aSLionel Sambuc const TargetOptions &getTargetOpts() const { 81*0a6a1f1dSLionel Sambuc return *TargetOpts.get(); 82f4a2713aSLionel Sambuc } 83f4a2713aSLionel Sambuc getDiagnosticOpts()84f4a2713aSLionel Sambuc DiagnosticOptions &getDiagnosticOpts() const { return *DiagnosticOpts; } 85f4a2713aSLionel Sambuc getHeaderSearchOpts()86f4a2713aSLionel Sambuc HeaderSearchOptions &getHeaderSearchOpts() { return *HeaderSearchOpts; } getHeaderSearchOpts()87f4a2713aSLionel Sambuc const HeaderSearchOptions &getHeaderSearchOpts() const { 88f4a2713aSLionel Sambuc return *HeaderSearchOpts; 89f4a2713aSLionel Sambuc } 90f4a2713aSLionel Sambuc getPreprocessorOpts()91f4a2713aSLionel Sambuc PreprocessorOptions &getPreprocessorOpts() { return *PreprocessorOpts; } getPreprocessorOpts()92f4a2713aSLionel Sambuc const PreprocessorOptions &getPreprocessorOpts() const { 93f4a2713aSLionel Sambuc return *PreprocessorOpts; 94f4a2713aSLionel Sambuc } 95f4a2713aSLionel Sambuc }; 96f4a2713aSLionel Sambuc 97f4a2713aSLionel Sambuc /// \brief Helper class for holding the data necessary to invoke the compiler. 98f4a2713aSLionel Sambuc /// 99f4a2713aSLionel Sambuc /// This class is designed to represent an abstract "invocation" of the 100f4a2713aSLionel Sambuc /// compiler, including data such as the include paths, the code generation 101f4a2713aSLionel Sambuc /// options, the warning flags, and so on. 102f4a2713aSLionel Sambuc class CompilerInvocation : public CompilerInvocationBase { 103f4a2713aSLionel Sambuc /// Options controlling the static analyzer. 104f4a2713aSLionel Sambuc AnalyzerOptionsRef AnalyzerOpts; 105f4a2713aSLionel Sambuc 106f4a2713aSLionel Sambuc MigratorOptions MigratorOpts; 107f4a2713aSLionel Sambuc 108f4a2713aSLionel Sambuc /// Options controlling IRgen and the backend. 109f4a2713aSLionel Sambuc CodeGenOptions CodeGenOpts; 110f4a2713aSLionel Sambuc 111f4a2713aSLionel Sambuc /// Options controlling dependency output. 112f4a2713aSLionel Sambuc DependencyOutputOptions DependencyOutputOpts; 113f4a2713aSLionel Sambuc 114f4a2713aSLionel Sambuc /// Options controlling file system operations. 115f4a2713aSLionel Sambuc FileSystemOptions FileSystemOpts; 116f4a2713aSLionel Sambuc 117f4a2713aSLionel Sambuc /// Options controlling the frontend itself. 118f4a2713aSLionel Sambuc FrontendOptions FrontendOpts; 119f4a2713aSLionel Sambuc 120f4a2713aSLionel Sambuc /// Options controlling preprocessed output. 121f4a2713aSLionel Sambuc PreprocessorOutputOptions PreprocessorOutputOpts; 122f4a2713aSLionel Sambuc 123f4a2713aSLionel Sambuc public: CompilerInvocation()124f4a2713aSLionel Sambuc CompilerInvocation() : AnalyzerOpts(new AnalyzerOptions()) {} 125f4a2713aSLionel Sambuc 126f4a2713aSLionel Sambuc /// @name Utility Methods 127f4a2713aSLionel Sambuc /// @{ 128f4a2713aSLionel Sambuc 129f4a2713aSLionel Sambuc /// \brief Create a compiler invocation from a list of input options. 130f4a2713aSLionel Sambuc /// \returns true on success. 131f4a2713aSLionel Sambuc /// 132f4a2713aSLionel Sambuc /// \param [out] Res - The resulting invocation. 133f4a2713aSLionel Sambuc /// \param ArgBegin - The first element in the argument vector. 134f4a2713aSLionel Sambuc /// \param ArgEnd - The last element in the argument vector. 135f4a2713aSLionel Sambuc /// \param Diags - The diagnostic engine to use for errors. 136f4a2713aSLionel Sambuc static bool CreateFromArgs(CompilerInvocation &Res, 137f4a2713aSLionel Sambuc const char* const *ArgBegin, 138f4a2713aSLionel Sambuc const char* const *ArgEnd, 139f4a2713aSLionel Sambuc DiagnosticsEngine &Diags); 140f4a2713aSLionel Sambuc 141f4a2713aSLionel Sambuc /// \brief Get the directory where the compiler headers 142f4a2713aSLionel Sambuc /// reside, relative to the compiler binary (found by the passed in 143f4a2713aSLionel Sambuc /// arguments). 144f4a2713aSLionel Sambuc /// 145f4a2713aSLionel Sambuc /// \param Argv0 - The program path (from argv[0]), for finding the builtin 146f4a2713aSLionel Sambuc /// compiler path. 147f4a2713aSLionel Sambuc /// \param MainAddr - The address of main (or some other function in the main 148f4a2713aSLionel Sambuc /// executable), for finding the builtin compiler path. 149f4a2713aSLionel Sambuc static std::string GetResourcesPath(const char *Argv0, void *MainAddr); 150f4a2713aSLionel Sambuc 151f4a2713aSLionel Sambuc /// \brief Set language defaults for the given input language and 152f4a2713aSLionel Sambuc /// language standard in the given LangOptions object. 153f4a2713aSLionel Sambuc /// 154f4a2713aSLionel Sambuc /// \param Opts - The LangOptions object to set up. 155f4a2713aSLionel Sambuc /// \param IK - The input language. 156f4a2713aSLionel Sambuc /// \param LangStd - The input language standard. 157f4a2713aSLionel Sambuc static void setLangDefaults(LangOptions &Opts, InputKind IK, 158f4a2713aSLionel Sambuc LangStandard::Kind LangStd = LangStandard::lang_unspecified); 159f4a2713aSLionel Sambuc 160f4a2713aSLionel Sambuc /// \brief Retrieve a module hash string that is suitable for uniquely 161f4a2713aSLionel Sambuc /// identifying the conditions under which the module was built. 162f4a2713aSLionel Sambuc std::string getModuleHash() const; 163f4a2713aSLionel Sambuc 164f4a2713aSLionel Sambuc /// @} 165f4a2713aSLionel Sambuc /// @name Option Subgroups 166f4a2713aSLionel Sambuc /// @{ 167f4a2713aSLionel Sambuc getAnalyzerOpts()168f4a2713aSLionel Sambuc AnalyzerOptionsRef getAnalyzerOpts() const { 169f4a2713aSLionel Sambuc return AnalyzerOpts; 170f4a2713aSLionel Sambuc } 171f4a2713aSLionel Sambuc getMigratorOpts()172f4a2713aSLionel Sambuc MigratorOptions &getMigratorOpts() { return MigratorOpts; } getMigratorOpts()173f4a2713aSLionel Sambuc const MigratorOptions &getMigratorOpts() const { 174f4a2713aSLionel Sambuc return MigratorOpts; 175f4a2713aSLionel Sambuc } 176f4a2713aSLionel Sambuc getCodeGenOpts()177f4a2713aSLionel Sambuc CodeGenOptions &getCodeGenOpts() { return CodeGenOpts; } getCodeGenOpts()178f4a2713aSLionel Sambuc const CodeGenOptions &getCodeGenOpts() const { 179f4a2713aSLionel Sambuc return CodeGenOpts; 180f4a2713aSLionel Sambuc } 181f4a2713aSLionel Sambuc getDependencyOutputOpts()182f4a2713aSLionel Sambuc DependencyOutputOptions &getDependencyOutputOpts() { 183f4a2713aSLionel Sambuc return DependencyOutputOpts; 184f4a2713aSLionel Sambuc } getDependencyOutputOpts()185f4a2713aSLionel Sambuc const DependencyOutputOptions &getDependencyOutputOpts() const { 186f4a2713aSLionel Sambuc return DependencyOutputOpts; 187f4a2713aSLionel Sambuc } 188f4a2713aSLionel Sambuc getFileSystemOpts()189f4a2713aSLionel Sambuc FileSystemOptions &getFileSystemOpts() { return FileSystemOpts; } getFileSystemOpts()190f4a2713aSLionel Sambuc const FileSystemOptions &getFileSystemOpts() const { 191f4a2713aSLionel Sambuc return FileSystemOpts; 192f4a2713aSLionel Sambuc } 193f4a2713aSLionel Sambuc getFrontendOpts()194f4a2713aSLionel Sambuc FrontendOptions &getFrontendOpts() { return FrontendOpts; } getFrontendOpts()195f4a2713aSLionel Sambuc const FrontendOptions &getFrontendOpts() const { 196f4a2713aSLionel Sambuc return FrontendOpts; 197f4a2713aSLionel Sambuc } 198f4a2713aSLionel Sambuc getPreprocessorOutputOpts()199f4a2713aSLionel Sambuc PreprocessorOutputOptions &getPreprocessorOutputOpts() { 200f4a2713aSLionel Sambuc return PreprocessorOutputOpts; 201f4a2713aSLionel Sambuc } getPreprocessorOutputOpts()202f4a2713aSLionel Sambuc const PreprocessorOutputOptions &getPreprocessorOutputOpts() const { 203f4a2713aSLionel Sambuc return PreprocessorOutputOpts; 204f4a2713aSLionel Sambuc } 205f4a2713aSLionel Sambuc 206f4a2713aSLionel Sambuc /// @} 207f4a2713aSLionel Sambuc }; 208f4a2713aSLionel Sambuc 209*0a6a1f1dSLionel Sambuc namespace vfs { 210*0a6a1f1dSLionel Sambuc class FileSystem; 211*0a6a1f1dSLionel Sambuc } 212*0a6a1f1dSLionel Sambuc 213*0a6a1f1dSLionel Sambuc IntrusiveRefCntPtr<vfs::FileSystem> 214*0a6a1f1dSLionel Sambuc createVFSFromCompilerInvocation(const CompilerInvocation &CI, 215*0a6a1f1dSLionel Sambuc DiagnosticsEngine &Diags); 216*0a6a1f1dSLionel Sambuc 217f4a2713aSLionel Sambuc } // end namespace clang 218f4a2713aSLionel Sambuc 219f4a2713aSLionel Sambuc #endif 220