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