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