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 
31   typedef SmallVector<InputInfo, 4> InputInfoList;
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.
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
42     // tools.
43     RF_Full,
44     // Input file names can live in a file, but flags can't. E.g.: ld64 (Mac
45     // OS X linker).
46     RF_FileList,
47     // Does not support response files: all arguments must be passed via
48     // command line.
49     RF_None
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 
getName()80   const char *getName() const { return Name; }
81 
getShortName()82   const char *getShortName() const { return ShortName; }
83 
getToolChain()84   const ToolChain &getToolChain() const { return TheToolChain; }
85 
hasIntegratedAssembler()86   virtual bool hasIntegratedAssembler() const { return false; }
canEmitIR()87   virtual bool canEmitIR() const { return false; }
88   virtual bool hasIntegratedCPP() const = 0;
isLinkJob()89   virtual bool isLinkJob() const { return false; }
isDsymutilJob()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.
getResponseFilesSupport()93   ResponseFileSupport getResponseFilesSupport() const {
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.
getResponseFileEncoding()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.
getResponseFileFlag()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.
hasGoodDiagnostics()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
138