clang  3.9.0
Tool.h
Go to the documentation of this file.
1 //===--- Tool.h - Compilation Tools -----------------------------*- 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_DRIVER_TOOL_H
11 #define LLVM_CLANG_DRIVER_TOOL_H
12 
13 #include "clang/Basic/LLVM.h"
14 #include "llvm/Support/Program.h"
15 
16 namespace llvm {
17 namespace opt {
18  class ArgList;
19 }
20 }
21 
22 namespace clang {
23 namespace driver {
24 
25  class Compilation;
26  class InputInfo;
27  class Job;
28  class JobAction;
29  class ToolChain;
30 
32 
33 /// Tool - Information on a specific compilation tool.
34 class Tool {
35 public:
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 transfered to a file.
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
42  // tools.
44  // Input file names can live in a file, but flags can't. E.g.: ld64 (Mac
45  // OS X linker).
47  // Does not support response files: all arguments must be passed via
48  // command line.
50  };
51 
52 private:
53  /// The tool name (for debugging).
54  const char *Name;
55 
56  /// The human readable name for the tool, for use in diagnostics.
57  const char *ShortName;
58 
59  /// The tool chain this tool is a part of.
60  const ToolChain &TheToolChain;
61 
62  /// The level of support for response files seen in this tool
63  const ResponseFileSupport ResponseSupport;
64 
65  /// The encoding to use when writing response files for this tool on Windows
66  const llvm::sys::WindowsEncodingMethod ResponseEncoding;
67 
68  /// The flag used to pass a response file via command line to this tool
69  const char *const ResponseFlag;
70 
71 public:
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 = "@");
76 
77 public:
78  virtual ~Tool();
79 
80  const char *getName() const { return Name; }
81 
82  const char *getShortName() const { return ShortName; }
83 
84  const ToolChain &getToolChain() const { return TheToolChain; }
85 
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.
94  return ResponseSupport;
95  }
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.
99  ///
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.
104  ///
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;
110  }
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; }
114 
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; }
118 
119  /// ConstructJob - Construct jobs to perform the action \p JA,
120  /// writing to \p Output and with \p Inputs, and add the jobs to
121  /// \p C.
122  ///
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 };
133 
134 } // end namespace driver
135 } // end namespace clang
136 
137 #endif
virtual void ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &TCArgs, const char *LinkingOutput) const =0
ConstructJob - Construct jobs to perform the action JA, writing to Output and with Inputs...
virtual bool hasGoodDiagnostics() const
Does this tool have "good" standardized diagnostics, or should the driver add an additional "command ...
Definition: Tool.h:117
virtual ~Tool()
Definition: Tool.cpp:22
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
InputInfo - Wrapper for information about an input source.
Definition: InputInfo.h:23
const ToolChain & getToolChain() const
Definition: Tool.h:84
virtual bool isDsymutilJob() const
Definition: Tool.h:90
virtual bool isLinkJob() const
Definition: Tool.h:89
virtual bool hasIntegratedAssembler() const
Definition: Tool.h:86
virtual bool canEmitIR() const
Definition: Tool.h:87
const char * getResponseFileFlag() const
Returns which prefix to use when passing the name of a response file as a parameter to this tool...
Definition: Tool.h:113
virtual bool hasIntegratedCPP() const =0
const char * getShortName() const
Definition: Tool.h:82
Tool(const char *Name, const char *ShortName, const ToolChain &TC, ResponseFileSupport ResponseSupport=RF_None, llvm::sys::WindowsEncodingMethod ResponseEncoding=llvm::sys::WEM_UTF8, const char *ResponseFlag="@")
Definition: Tool.cpp:14
ResponseFileSupport getResponseFilesSupport() const
Returns the level of support for response files of this tool, whether it accepts arguments to be pass...
Definition: Tool.h:93
const char * getName() const
Definition: Tool.h:80
SmallVector< InputInfo, 4 > InputInfoList
Definition: Tool.h:29
llvm::sys::WindowsEncodingMethod getResponseFileEncoding() const
Returns which encoding the response file should use.
Definition: Tool.h:108
Tool - Information on a specific compilation tool.
Definition: Tool.h:34
Compilation - A set of tasks to perform for a single driver invocation.
Definition: Compilation.h:35
ToolChain - Access to tools for a single platform.
Definition: ToolChain.h:48