1 //===--- Tool.h - Compilation Tools -----------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_CLANG_DRIVER_TOOL_H
10 #define LLVM_CLANG_DRIVER_TOOL_H
12 #include "clang/Basic/LLVM.h"
13 #include "llvm/Support/Program.h"
30 typedef SmallVector<InputInfo, 4> InputInfoList;
32 /// Tool - Information on a specific compilation tool.
35 // Documents the level of support for response files in this tool.
36 // Response files are necessary if the command line gets too large,
37 // requiring the arguments to be transferred to a file.
38 enum ResponseFileSupport {
39 // Provides full support for response files, which means we can transfer
40 // all tool input arguments to a file. E.g.: clang, gcc, binutils and MSVC
43 // Input file names can live in a file, but flags can't. E.g.: ld64 (Mac
46 // Does not support response files: all arguments must be passed via
52 /// The tool name (for debugging).
55 /// The human readable name for the tool, for use in diagnostics.
56 const char *ShortName;
58 /// The tool chain this tool is a part of.
59 const ToolChain &TheToolChain;
61 /// The level of support for response files seen in this tool
62 const ResponseFileSupport ResponseSupport;
64 /// The encoding to use when writing response files for this tool on Windows
65 const llvm::sys::WindowsEncodingMethod ResponseEncoding;
67 /// The flag used to pass a response file via command line to this tool
68 const char *const ResponseFlag;
71 Tool(const char *Name, const char *ShortName, const ToolChain &TC,
72 ResponseFileSupport ResponseSupport = RF_None,
73 llvm::sys::WindowsEncodingMethod ResponseEncoding = llvm::sys::WEM_UTF8,
74 const char *ResponseFlag = "@");
79 const char *getName() const { return Name; }
81 const char *getShortName() const { return ShortName; }
83 const ToolChain &getToolChain() const { return TheToolChain; }
85 virtual bool hasIntegratedAssembler() const { return false; }
86 virtual bool canEmitIR() const { return false; }
87 virtual bool hasIntegratedCPP() const = 0;
88 virtual bool isLinkJob() const { return false; }
89 virtual bool isDsymutilJob() const { return false; }
90 /// Returns the level of support for response files of this tool,
91 /// whether it accepts arguments to be passed via a file on disk.
92 ResponseFileSupport getResponseFilesSupport() const {
93 return ResponseSupport;
95 /// Returns which encoding the response file should use. This is only
96 /// relevant on Windows platforms where there are different encodings being
97 /// accepted for different tools. On UNIX, UTF8 is universal.
99 /// Windows use cases: - GCC and Binutils on mingw only accept ANSI response
100 /// files encoded with the system current code page.
101 /// - MSVC's CL.exe and LINK.exe accept UTF16 on Windows.
102 /// - Clang accepts both UTF8 and UTF16.
104 /// FIXME: When GNU tools learn how to parse UTF16 on Windows, we should
105 /// always use UTF16 for Windows, which is the Windows official encoding for
106 /// international characters.
107 llvm::sys::WindowsEncodingMethod getResponseFileEncoding() const {
108 return ResponseEncoding;
110 /// Returns which prefix to use when passing the name of a response
111 /// file as a parameter to this tool.
112 const char *getResponseFileFlag() const { return ResponseFlag; }
114 /// Does this tool have "good" standardized diagnostics, or should the
115 /// driver add an additional "command failed" diagnostic on failures.
116 virtual bool hasGoodDiagnostics() const { return false; }
118 /// ConstructJob - Construct jobs to perform the action \p JA,
119 /// writing to \p Output and with \p Inputs, and add the jobs to
122 /// \param TCArgs - The argument list for this toolchain, with any
123 /// tool chain specific translations applied.
124 /// \param LinkingOutput - If this output will eventually feed the
125 /// linker, then this is the final output name of the linked image.
126 virtual void ConstructJob(Compilation &C, const JobAction &JA,
127 const InputInfo &Output,
128 const InputInfoList &Inputs,
129 const llvm::opt::ArgList &TCArgs,
130 const char *LinkingOutput) const = 0;
131 /// Construct jobs to perform the action \p JA, writing to the \p Outputs and
132 /// with \p Inputs, and add the jobs to \p C. The default implementation
133 /// assumes a single output and is expected to be overloaded for the tools
134 /// that support multiple inputs.
136 /// \param TCArgs The argument list for this toolchain, with any
137 /// tool chain specific translations applied.
138 /// \param LinkingOutput If this output will eventually feed the
139 /// linker, then this is the final output name of the linked image.
140 virtual void ConstructJobMultipleOutputs(Compilation &C, const JobAction &JA,
141 const InputInfoList &Outputs,
142 const InputInfoList &Inputs,
143 const llvm::opt::ArgList &TCArgs,
144 const char *LinkingOutput) const;
147 } // end namespace driver
148 } // end namespace clang