]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/include/clang/Frontend/CompilerInvocation.h
Merge llvm, clang, lld, lldb, compiler-rt and libc++ r304149, and update
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / clang / include / clang / Frontend / CompilerInvocation.h
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/DiagnosticOptions.h"
14 #include "clang/Basic/FileSystemOptions.h"
15 #include "clang/Basic/LangOptions.h"
16 #include "clang/Frontend/CodeGenOptions.h"
17 #include "clang/Frontend/DependencyOutputOptions.h"
18 #include "clang/Frontend/FrontendOptions.h"
19 #include "clang/Frontend/LangStandard.h"
20 #include "clang/Frontend/MigratorOptions.h"
21 #include "clang/Frontend/PreprocessorOutputOptions.h"
22 #include "clang/StaticAnalyzer/Core/AnalyzerOptions.h"
23 #include "llvm/ADT/IntrusiveRefCntPtr.h"
24 #include <string>
25
26 namespace llvm {
27 class Triple;
28
29 namespace opt {
30 class ArgList;
31 }
32 }
33
34 namespace clang {
35 class PreprocessorOptions;
36 class HeaderSearchOptions;
37 class TargetOptions;
38 class LangOptions;
39 class CompilerInvocation;
40 class DiagnosticsEngine;
41
42 /// \brief Fill out Opts based on the options given in Args.
43 ///
44 /// Args must have been created from the OptTable returned by
45 /// createCC1OptTable().
46 ///
47 /// When errors are encountered, return false and, if Diags is non-null,
48 /// report the error(s).
49 bool ParseDiagnosticArgs(DiagnosticOptions &Opts, llvm::opt::ArgList &Args,
50                          DiagnosticsEngine *Diags = nullptr,
51                          bool DefaultDiagColor = true,
52                          bool DefaultShowOpt = true);
53
54 class CompilerInvocationBase {
55   void operator=(const CompilerInvocationBase &) = delete;
56
57 public:
58   /// Options controlling the language variant.
59   std::shared_ptr<LangOptions> LangOpts;
60
61   /// Options controlling the target.
62   std::shared_ptr<TargetOptions> TargetOpts;
63
64   /// Options controlling the diagnostic engine.
65   IntrusiveRefCntPtr<DiagnosticOptions> DiagnosticOpts;
66
67   /// Options controlling the \#include directive.
68   std::shared_ptr<HeaderSearchOptions> HeaderSearchOpts;
69
70   /// Options controlling the preprocessor (aside from \#include handling).
71   std::shared_ptr<PreprocessorOptions> PreprocessorOpts;
72
73   CompilerInvocationBase();
74   ~CompilerInvocationBase();
75
76   CompilerInvocationBase(const CompilerInvocationBase &X);
77
78   LangOptions *getLangOpts() { return LangOpts.get(); }
79   const LangOptions *getLangOpts() const { return LangOpts.get(); }
80
81   TargetOptions &getTargetOpts() { return *TargetOpts.get(); }
82   const TargetOptions &getTargetOpts() const {
83     return *TargetOpts.get();
84   }
85
86   DiagnosticOptions &getDiagnosticOpts() const { return *DiagnosticOpts; }
87
88   HeaderSearchOptions &getHeaderSearchOpts() { return *HeaderSearchOpts; }
89   const HeaderSearchOptions &getHeaderSearchOpts() const {
90     return *HeaderSearchOpts;
91   }
92   std::shared_ptr<HeaderSearchOptions> getHeaderSearchOptsPtr() const {
93     return HeaderSearchOpts;
94   }
95
96   std::shared_ptr<PreprocessorOptions> getPreprocessorOptsPtr() {
97     return PreprocessorOpts;
98   }
99   PreprocessorOptions &getPreprocessorOpts() { return *PreprocessorOpts; }
100   const PreprocessorOptions &getPreprocessorOpts() const {
101     return *PreprocessorOpts;
102   }
103 };
104   
105 /// \brief Helper class for holding the data necessary to invoke the compiler.
106 ///
107 /// This class is designed to represent an abstract "invocation" of the
108 /// compiler, including data such as the include paths, the code generation
109 /// options, the warning flags, and so on.
110 class CompilerInvocation : public CompilerInvocationBase {
111   /// Options controlling the static analyzer.
112   AnalyzerOptionsRef AnalyzerOpts;
113
114   MigratorOptions MigratorOpts;
115   
116   /// Options controlling IRgen and the backend.
117   CodeGenOptions CodeGenOpts;
118
119   /// Options controlling dependency output.
120   DependencyOutputOptions DependencyOutputOpts;
121
122   /// Options controlling file system operations.
123   FileSystemOptions FileSystemOpts;
124
125   /// Options controlling the frontend itself.
126   FrontendOptions FrontendOpts;
127
128   /// Options controlling preprocessed output.
129   PreprocessorOutputOptions PreprocessorOutputOpts;
130
131 public:
132   CompilerInvocation() : AnalyzerOpts(new AnalyzerOptions()) {}
133
134   /// @name Utility Methods
135   /// @{
136
137   /// \brief Create a compiler invocation from a list of input options.
138   /// \returns true on success.
139   ///
140   /// \param [out] Res - The resulting invocation.
141   /// \param ArgBegin - The first element in the argument vector.
142   /// \param ArgEnd - The last element in the argument vector.
143   /// \param Diags - The diagnostic engine to use for errors.
144   static bool CreateFromArgs(CompilerInvocation &Res,
145                              const char* const *ArgBegin,
146                              const char* const *ArgEnd,
147                              DiagnosticsEngine &Diags);
148
149   /// \brief Get the directory where the compiler headers
150   /// reside, relative to the compiler binary (found by the passed in
151   /// arguments).
152   ///
153   /// \param Argv0 - The program path (from argv[0]), for finding the builtin
154   /// compiler path.
155   /// \param MainAddr - The address of main (or some other function in the main
156   /// executable), for finding the builtin compiler path.
157   static std::string GetResourcesPath(const char *Argv0, void *MainAddr);
158
159   /// \brief Set language defaults for the given input language and
160   /// language standard in the given LangOptions object.
161   ///
162   /// \param Opts - The LangOptions object to set up.
163   /// \param IK - The input language.
164   /// \param T - The target triple.
165   /// \param PPOpts - The PreprocessorOptions affected.
166   /// \param LangStd - The input language standard.
167   static void setLangDefaults(LangOptions &Opts, InputKind IK,
168                    const llvm::Triple &T, PreprocessorOptions &PPOpts,
169                    LangStandard::Kind LangStd = LangStandard::lang_unspecified);
170   
171   /// \brief Retrieve a module hash string that is suitable for uniquely 
172   /// identifying the conditions under which the module was built.
173   std::string getModuleHash() const;
174   
175   /// @}
176   /// @name Option Subgroups
177   /// @{
178
179   AnalyzerOptionsRef getAnalyzerOpts() const {
180     return AnalyzerOpts;
181   }
182
183   MigratorOptions &getMigratorOpts() { return MigratorOpts; }
184   const MigratorOptions &getMigratorOpts() const {
185     return MigratorOpts;
186   }
187   
188   CodeGenOptions &getCodeGenOpts() { return CodeGenOpts; }
189   const CodeGenOptions &getCodeGenOpts() const {
190     return CodeGenOpts;
191   }
192
193   DependencyOutputOptions &getDependencyOutputOpts() {
194     return DependencyOutputOpts;
195   }
196   const DependencyOutputOptions &getDependencyOutputOpts() const {
197     return DependencyOutputOpts;
198   }
199
200   FileSystemOptions &getFileSystemOpts() { return FileSystemOpts; }
201   const FileSystemOptions &getFileSystemOpts() const {
202     return FileSystemOpts;
203   }
204
205   FrontendOptions &getFrontendOpts() { return FrontendOpts; }
206   const FrontendOptions &getFrontendOpts() const {
207     return FrontendOpts;
208   }
209
210   PreprocessorOutputOptions &getPreprocessorOutputOpts() {
211     return PreprocessorOutputOpts;
212   }
213   const PreprocessorOutputOptions &getPreprocessorOutputOpts() const {
214     return PreprocessorOutputOpts;
215   }
216
217   /// @}
218 };
219
220 namespace vfs {
221   class FileSystem;
222 }
223
224 IntrusiveRefCntPtr<vfs::FileSystem>
225 createVFSFromCompilerInvocation(const CompilerInvocation &CI,
226                                 DiagnosticsEngine &Diags);
227
228 IntrusiveRefCntPtr<vfs::FileSystem>
229 createVFSFromCompilerInvocation(const CompilerInvocation &CI,
230                                 DiagnosticsEngine &Diags,
231                                 IntrusiveRefCntPtr<vfs::FileSystem> BaseFS);
232
233 } // end namespace clang
234
235 #endif