clang 22.0.0git
CreateInvocationFromArgs.h
Go to the documentation of this file.
1//===--- CreateInvocationFromArgs.h - CompilerInvocation from Args --------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// Utility for creating a CompilerInvocation from command-line arguments, for
10// tools to use in preparation to parse a file.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_DRIVER_CREATEINVOCATIONFROMARGS_H
15#define LLVM_CLANG_DRIVER_CREATEINVOCATIONFROMARGS_H
16
18#include "clang/Basic/LLVM.h"
19#include "llvm/Support/VirtualFileSystem.h"
20#include <memory>
21#include <string>
22#include <vector>
23
24namespace clang {
25
28
29/// Optional inputs to createInvocation.
31 /// Receives diagnostics encountered while parsing command-line flags.
32 /// If not provided, these are printed to stderr.
34 /// Used e.g. to probe for system headers locations.
35 /// If not provided, the real filesystem is used.
36 /// FIXME: the driver does perform some non-virtualized IO.
38 /// Whether to attempt to produce a non-null (possibly incorrect) invocation
39 /// if any errors were encountered.
40 /// By default, always return null on errors.
41 bool RecoverOnError = false;
42 /// Allow the driver to probe the filesystem for PCH files.
43 /// This is used to replace -include with -include-pch in the cc1 args.
44 /// FIXME: ProbePrecompiled=true is a poor, historical default.
45 /// It misbehaves if the PCH file is from GCC, has the wrong version, etc.
46 bool ProbePrecompiled = false;
47 /// If set, the target is populated with the cc1 args produced by the driver.
48 /// This may be populated even if createInvocation returns nullptr.
49 std::vector<std::string> *CC1Args = nullptr;
50};
51
52/// Interpret clang arguments in preparation to parse a file.
53///
54/// This simulates a number of steps Clang takes when its driver is invoked:
55/// - choosing actions (e.g compile + link) to run
56/// - probing the system for settings like standard library locations
57/// - spawning a cc1 subprocess to compile code, with more explicit arguments
58/// - in the cc1 process, assembling those arguments into a CompilerInvocation
59/// which is used to configure the parser
60///
61/// This simulation is lossy, e.g. in some situations one driver run would
62/// result in multiple parses. (Multi-arch, CUDA, ...).
63/// This function tries to select a reasonable invocation that tools should use.
64///
65/// Args[0] should be the driver name, such as "clang" or "/usr/bin/g++".
66/// Absolute path is preferred - this affects searching for system headers.
67///
68/// May return nullptr if an invocation could not be determined.
69/// See CreateInvocationOptions::RecoverOnError to try harder!
70std::unique_ptr<CompilerInvocation>
72 CreateInvocationOptions Opts = {});
73
74} // namespace clang
75
76#endif // LLVM_CLANG_DRIVER_CREATEINVOCATIONFROMARGS_H
Defines the Diagnostic-related interfaces.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Helper class for holding the data necessary to invoke the compiler.
Concrete class used by the front-end to report problems and issues.
Definition Diagnostic.h:232
The JSON file list parser is used to communicate input to InstallAPI.
std::unique_ptr< CompilerInvocation > createInvocation(ArrayRef< const char * > Args, CreateInvocationOptions Opts={})
Interpret clang arguments in preparation to parse a file.
Optional inputs to createInvocation.
IntrusiveRefCntPtr< DiagnosticsEngine > Diags
Receives diagnostics encountered while parsing command-line flags.
bool ProbePrecompiled
Allow the driver to probe the filesystem for PCH files.
bool RecoverOnError
Whether to attempt to produce a non-null (possibly incorrect) invocation if any errors were encounter...
IntrusiveRefCntPtr< llvm::vfs::FileSystem > VFS
Used e.g.
std::vector< std::string > * CC1Args
If set, the target is populated with the cc1 args produced by the driver.