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