22
22
#include " llvm/ADT/StringMap.h"
23
23
#include " llvm/ADT/StringRef.h"
24
24
#include " llvm/ADT/StringSet.h"
25
- #include " llvm/Option/OptSpecifier.h"
26
25
#include " llvm/Support/FileCollector.h"
27
26
#include " llvm/Support/VirtualFileSystem.h"
28
27
#include < cstdint>
@@ -190,18 +189,47 @@ IntrusiveRefCntPtr<ExternalSemaSource>
190
189
createChainedIncludesSource (CompilerInstance &CI,
191
190
IntrusiveRefCntPtr<ExternalSemaSource> &Reader);
192
191
193
- // / createInvocationFromCommandLine - Construct a compiler invocation object for
194
- // / a command line argument vector.
192
+ // / Optional inputs to createInvocation.
193
+ struct CreateInvocationOptions {
194
+ // / Receives diagnostics encountered while parsing command-line flags.
195
+ // / If not provided, these are printed to stderr.
196
+ IntrusiveRefCntPtr<DiagnosticsEngine> Diags = nullptr ;
197
+ // / Used e.g. to probe for system headers locations.
198
+ // / If not provided, the real filesystem is used.
199
+ // / FIXME: the driver does perform some non-virtualized IO.
200
+ IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS = nullptr ;
201
+ // / Whether to attempt to produce a non-null (possibly incorrect) invocation
202
+ // / if any errors were encountered.
203
+ // / By default, always return null on errors.
204
+ bool RecoverOnError = false ;
205
+ // / If set, the target is populated with the cc1 args produced by the driver.
206
+ // / This may be populated even if createInvocation returns nullptr.
207
+ std::vector<std::string> *CC1Args = nullptr ;
208
+ };
209
+
210
+ // / Interpret clang arguments in preparation to parse a file.
211
+ // /
212
+ // / This simulates a number of steps Clang takes when its driver is invoked:
213
+ // / - choosing actions (e.g compile + link) to run
214
+ // / - probing the system for settings like standard library locations
215
+ // / - spawning a cc1 subprocess to compile code, with more explicit arguments
216
+ // / - in the cc1 process, assembling those arguments into a CompilerInvocation
217
+ // / which is used to configure the parser
195
218
// /
196
- // / \param ShouldRecoverOnErrors - whether we should attempt to return a
197
- // / non-null (and possibly incorrect) CompilerInvocation if any errors were
198
- // / encountered. When this flag is false, always return null on errors .
219
+ // / This simulation is lossy, e.g. in some situations one driver run would
220
+ // / result in multiple parses. (Multi-arch, CUDA, ...).
221
+ // / This function tries to select a reasonable invocation that tools should use .
199
222
// /
200
- // / \param CC1Args - if non-null, will be populated with the args to cc1
201
- // / expanded from \p Args. May be set even if nullptr is returned .
223
+ // / Args[0] should be the driver name, such as "clang" or "/usr/bin/g++".
224
+ // / Absolute path is preferred - this affects searching for system headers .
202
225
// /
203
- // / \return A CompilerInvocation, or nullptr if none was built for the given
204
- // / argument vector.
226
+ // / May return nullptr if an invocation could not be determined.
227
+ // / See CreateInvocationOptions::ShouldRecoverOnErrors to try harder!
228
+ std::unique_ptr<CompilerInvocation>
229
+ createInvocation (ArrayRef<const char *> Args,
230
+ CreateInvocationOptions Opts = {});
231
+
232
+ // / Deprecated version of createInvocation with individual optional args.
205
233
std::unique_ptr<CompilerInvocation> createInvocationFromCommandLine (
206
234
ArrayRef<const char *> Args,
207
235
IntrusiveRefCntPtr<DiagnosticsEngine> Diags =
@@ -210,8 +238,6 @@ std::unique_ptr<CompilerInvocation> createInvocationFromCommandLine(
210
238
bool ShouldRecoverOnErrors = false,
211
239
std::vector<std::string> *CC1Args = nullptr);
212
240
213
- // Frontend timing utils
214
-
215
241
} // namespace clang
216
242
217
243
#endif // LLVM_CLANG_FRONTEND_UTILS_H
0 commit comments