1 //===-- CompilerInvocation.h - Compiler Invocation Helper Data --*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_CLANG_FRONTEND_COMPILERINVOCATION_H_
11 #define LLVM_CLANG_FRONTEND_COMPILERINVOCATION_H_
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"
32 template<typename T> class SmallVectorImpl;
39 /// CompilerInvocation - Helper class for holding the data necessary to invoke
42 /// This class is designed to represent an abstract "invocation" of the
43 /// compiler, including data such as the include paths, the code generation
44 /// options, the warning flags, and so on.
45 class CompilerInvocation : public llvm::RefCountedBase<CompilerInvocation> {
46 /// Options controlling the static analyzer.
47 AnalyzerOptions AnalyzerOpts;
49 /// Options controlling IRgen and the backend.
50 CodeGenOptions CodeGenOpts;
52 /// Options controlling dependency output.
53 DependencyOutputOptions DependencyOutputOpts;
55 /// Options controlling the diagnostic engine.
56 DiagnosticOptions DiagnosticOpts;
58 /// Options controlling file system operations.
59 FileSystemOptions FileSystemOpts;
61 /// Options controlling the frontend itself.
62 FrontendOptions FrontendOpts;
64 /// Options controlling the #include directive.
65 HeaderSearchOptions HeaderSearchOpts;
67 /// Options controlling the language variant.
70 /// Options controlling the preprocessor (aside from #include handling).
71 PreprocessorOptions PreprocessorOpts;
73 /// Options controlling preprocessed output.
74 PreprocessorOutputOptions PreprocessorOutputOpts;
76 /// Options controlling the target.
77 TargetOptions TargetOpts;
80 CompilerInvocation() {}
82 /// @name Utility Methods
85 /// CreateFromArgs - Create a compiler invocation from a list of input
88 /// \param Res [out] - The resulting invocation.
89 /// \param ArgBegin - The first element in the argument vector.
90 /// \param ArgEnd - The last element in the argument vector.
91 /// \param Diags - The diagnostic engine to use for errors.
92 static void CreateFromArgs(CompilerInvocation &Res,
93 const char* const *ArgBegin,
94 const char* const *ArgEnd,
97 /// GetBuiltinIncludePath - Get the directory where the compiler headers
98 /// reside, relative to the compiler binary (found by the passed in
101 /// \param Argv0 - The program path (from argv[0]), for finding the builtin
103 /// \param MainAddr - The address of main (or some other function in the main
104 /// executable), for finding the builtin compiler path.
105 static std::string GetResourcesPath(const char *Argv0, void *MainAddr);
107 /// toArgs - Convert the CompilerInvocation to a list of strings suitable for
108 /// passing to CreateFromArgs.
109 void toArgs(std::vector<std::string> &Res);
111 /// setLangDefaults - Set language defaults for the given input language and
112 /// language standard in this CompilerInvocation.
114 /// \param IK - The input language.
115 /// \param LangStd - The input language standard.
116 void setLangDefaults(InputKind IK,
117 LangStandard::Kind LangStd = LangStandard::lang_unspecified) {
118 setLangDefaults(LangOpts, IK, LangStd);
121 /// setLangDefaults - Set language defaults for the given input language and
122 /// language standard in the given LangOptions object.
124 /// \param LangOpts - The LangOptions object to set up.
125 /// \param IK - The input language.
126 /// \param LangStd - The input language standard.
127 static void setLangDefaults(LangOptions &Opts, InputKind IK,
128 LangStandard::Kind LangStd = LangStandard::lang_unspecified);
131 /// @name Option Subgroups
134 AnalyzerOptions &getAnalyzerOpts() { return AnalyzerOpts; }
135 const AnalyzerOptions &getAnalyzerOpts() const {
139 CodeGenOptions &getCodeGenOpts() { return CodeGenOpts; }
140 const CodeGenOptions &getCodeGenOpts() const {
144 DependencyOutputOptions &getDependencyOutputOpts() {
145 return DependencyOutputOpts;
147 const DependencyOutputOptions &getDependencyOutputOpts() const {
148 return DependencyOutputOpts;
151 DiagnosticOptions &getDiagnosticOpts() { return DiagnosticOpts; }
152 const DiagnosticOptions &getDiagnosticOpts() const { return DiagnosticOpts; }
154 FileSystemOptions &getFileSystemOpts() { return FileSystemOpts; }
155 const FileSystemOptions &getFileSystemOpts() const {
156 return FileSystemOpts;
159 HeaderSearchOptions &getHeaderSearchOpts() { return HeaderSearchOpts; }
160 const HeaderSearchOptions &getHeaderSearchOpts() const {
161 return HeaderSearchOpts;
164 FrontendOptions &getFrontendOpts() { return FrontendOpts; }
165 const FrontendOptions &getFrontendOpts() const {
169 LangOptions &getLangOpts() { return LangOpts; }
170 const LangOptions &getLangOpts() const { return LangOpts; }
172 PreprocessorOptions &getPreprocessorOpts() { return PreprocessorOpts; }
173 const PreprocessorOptions &getPreprocessorOpts() const {
174 return PreprocessorOpts;
177 PreprocessorOutputOptions &getPreprocessorOutputOpts() {
178 return PreprocessorOutputOpts;
180 const PreprocessorOutputOptions &getPreprocessorOutputOpts() const {
181 return PreprocessorOutputOpts;
184 TargetOptions &getTargetOpts() { return TargetOpts; }
185 const TargetOptions &getTargetOpts() const {
192 } // end namespace clang