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