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/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"
34 class CompilerInvocation;
35 class DiagnosticsEngine;
41 /// CompilerInvocation - Fill out Opts based on the options given in Args.
42 /// Args must have been created from the OptTable returned by
43 /// createCC1OptTable(). When errors are encountered, return false and,
44 /// if Diags is non-null, report the error(s).
45 bool ParseDiagnosticArgs(DiagnosticOptions &Opts, driver::ArgList &Args,
46 DiagnosticsEngine *Diags = 0);
48 class CompilerInvocationBase : public RefCountedBase<CompilerInvocation> {
50 /// Options controlling the language variant.
51 IntrusiveRefCntPtr<LangOptions> LangOpts;
53 CompilerInvocationBase();
55 CompilerInvocationBase(const CompilerInvocationBase &X);
57 LangOptions *getLangOpts() { return LangOpts.getPtr(); }
58 const LangOptions *getLangOpts() const { return LangOpts.getPtr(); }
61 /// CompilerInvocation - Helper class for holding the data necessary to invoke
64 /// This class is designed to represent an abstract "invocation" of the
65 /// compiler, including data such as the include paths, the code generation
66 /// options, the warning flags, and so on.
67 class CompilerInvocation : public CompilerInvocationBase {
68 /// Options controlling the static analyzer.
69 AnalyzerOptions AnalyzerOpts;
71 MigratorOptions MigratorOpts;
73 /// Options controlling IRgen and the backend.
74 CodeGenOptions CodeGenOpts;
76 /// Options controlling dependency output.
77 DependencyOutputOptions DependencyOutputOpts;
79 /// Options controlling the diagnostic engine.
80 DiagnosticOptions DiagnosticOpts;
82 /// Options controlling file system operations.
83 FileSystemOptions FileSystemOpts;
85 /// Options controlling the frontend itself.
86 FrontendOptions FrontendOpts;
88 /// Options controlling the #include directive.
89 HeaderSearchOptions HeaderSearchOpts;
91 /// Options controlling the preprocessor (aside from #include handling).
92 PreprocessorOptions PreprocessorOpts;
94 /// Options controlling preprocessed output.
95 PreprocessorOutputOptions PreprocessorOutputOpts;
97 /// Options controlling the target.
98 TargetOptions TargetOpts;
101 CompilerInvocation() {}
103 /// @name Utility Methods
106 /// CreateFromArgs - Create a compiler invocation from a list of input
107 /// options. Returns true on success.
109 /// \param Res [out] - The resulting invocation.
110 /// \param ArgBegin - The first element in the argument vector.
111 /// \param ArgEnd - The last element in the argument vector.
112 /// \param Diags - The diagnostic engine to use for errors.
113 static bool CreateFromArgs(CompilerInvocation &Res,
114 const char* const *ArgBegin,
115 const char* const *ArgEnd,
116 DiagnosticsEngine &Diags);
118 /// GetBuiltinIncludePath - Get the directory where the compiler headers
119 /// reside, relative to the compiler binary (found by the passed in
122 /// \param Argv0 - The program path (from argv[0]), for finding the builtin
124 /// \param MainAddr - The address of main (or some other function in the main
125 /// executable), for finding the builtin compiler path.
126 static std::string GetResourcesPath(const char *Argv0, void *MainAddr);
128 /// toArgs - Convert the CompilerInvocation to a list of strings suitable for
129 /// passing to CreateFromArgs.
130 void toArgs(std::vector<std::string> &Res);
132 /// setLangDefaults - Set language defaults for the given input language and
133 /// language standard in this CompilerInvocation.
135 /// \param IK - The input language.
136 /// \param LangStd - The input language standard.
137 void setLangDefaults(InputKind IK,
138 LangStandard::Kind LangStd = LangStandard::lang_unspecified) {
139 setLangDefaults(*getLangOpts(), IK, LangStd);
142 /// setLangDefaults - Set language defaults for the given input language and
143 /// language standard in the given LangOptions object.
145 /// \param LangOpts - The LangOptions object to set up.
146 /// \param IK - The input language.
147 /// \param LangStd - The input language standard.
148 static void setLangDefaults(LangOptions &Opts, InputKind IK,
149 LangStandard::Kind LangStd = LangStandard::lang_unspecified);
151 /// \brief Retrieve a module hash string that is suitable for uniquely
152 /// identifying the conditions under which the module was built.
153 std::string getModuleHash() const;
156 /// @name Option Subgroups
159 AnalyzerOptions &getAnalyzerOpts() { return AnalyzerOpts; }
160 const AnalyzerOptions &getAnalyzerOpts() const {
164 MigratorOptions &getMigratorOpts() { return MigratorOpts; }
165 const MigratorOptions &getMigratorOpts() const {
169 CodeGenOptions &getCodeGenOpts() { return CodeGenOpts; }
170 const CodeGenOptions &getCodeGenOpts() const {
174 DependencyOutputOptions &getDependencyOutputOpts() {
175 return DependencyOutputOpts;
177 const DependencyOutputOptions &getDependencyOutputOpts() const {
178 return DependencyOutputOpts;
181 DiagnosticOptions &getDiagnosticOpts() { return DiagnosticOpts; }
182 const DiagnosticOptions &getDiagnosticOpts() const { return DiagnosticOpts; }
184 FileSystemOptions &getFileSystemOpts() { return FileSystemOpts; }
185 const FileSystemOptions &getFileSystemOpts() const {
186 return FileSystemOpts;
189 HeaderSearchOptions &getHeaderSearchOpts() { return HeaderSearchOpts; }
190 const HeaderSearchOptions &getHeaderSearchOpts() const {
191 return HeaderSearchOpts;
194 FrontendOptions &getFrontendOpts() { return FrontendOpts; }
195 const FrontendOptions &getFrontendOpts() const {
199 PreprocessorOptions &getPreprocessorOpts() { return PreprocessorOpts; }
200 const PreprocessorOptions &getPreprocessorOpts() const {
201 return PreprocessorOpts;
204 PreprocessorOutputOptions &getPreprocessorOutputOpts() {
205 return PreprocessorOutputOpts;
207 const PreprocessorOutputOptions &getPreprocessorOutputOpts() const {
208 return PreprocessorOutputOpts;
211 TargetOptions &getTargetOpts() { return TargetOpts; }
212 const TargetOptions &getTargetOpts() const {
219 } // end namespace clang