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"
33 class DiagnosticsEngine;
35 /// CompilerInvocation - Helper class for holding the data necessary to invoke
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.
41 class CompilerInvocation : public llvm::RefCountedBase<CompilerInvocation> {
42 /// Options controlling the static analyzer.
43 AnalyzerOptions AnalyzerOpts;
45 /// Options controlling IRgen and the backend.
46 CodeGenOptions CodeGenOpts;
48 /// Options controlling dependency output.
49 DependencyOutputOptions DependencyOutputOpts;
51 /// Options controlling the diagnostic engine.
52 DiagnosticOptions DiagnosticOpts;
54 /// Options controlling file system operations.
55 FileSystemOptions FileSystemOpts;
57 /// Options controlling the frontend itself.
58 FrontendOptions FrontendOpts;
60 /// Options controlling the #include directive.
61 HeaderSearchOptions HeaderSearchOpts;
63 /// Options controlling the language variant.
66 /// Options controlling the preprocessor (aside from #include handling).
67 PreprocessorOptions PreprocessorOpts;
69 /// Options controlling preprocessed output.
70 PreprocessorOutputOptions PreprocessorOutputOpts;
72 /// Options controlling the target.
73 TargetOptions TargetOpts;
76 CompilerInvocation() {}
78 /// @name Utility Methods
81 /// CreateFromArgs - Create a compiler invocation from a list of input
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);
93 /// GetBuiltinIncludePath - Get the directory where the compiler headers
94 /// reside, relative to the compiler binary (found by the passed in
97 /// \param Argv0 - The program path (from argv[0]), for finding the builtin
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);
103 /// toArgs - Convert the CompilerInvocation to a list of strings suitable for
104 /// passing to CreateFromArgs.
105 void toArgs(std::vector<std::string> &Res);
107 /// setLangDefaults - Set language defaults for the given input language and
108 /// language standard in this CompilerInvocation.
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);
117 /// setLangDefaults - Set language defaults for the given input language and
118 /// language standard in the given LangOptions object.
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);
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;
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