12ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar//===--- Tool.h - Compilation Tools -----------------------------*- C++ -*-===//
22ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar//
32ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar//                     The LLVM Compiler Infrastructure
42ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar//
52ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar// This file is distributed under the University of Illinois Open Source
62ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar// License. See LICENSE.TXT for details.
72ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar//
82ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar//===----------------------------------------------------------------------===//
92ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar
10176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines#ifndef LLVM_CLANG_DRIVER_TOOL_H
11176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines#define LLVM_CLANG_DRIVER_TOOL_H
122ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar
13686775deca8b8685eb90801495880e3abdd844c2Chris Lattner#include "clang/Basic/LLVM.h"
14176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines#include "llvm/Support/Program.h"
1547ac7d27c44bd64a7d0fc03d4babc196cf2b8230Daniel Dunbar
16b1e25a1bc03292dc538d336573e0be1490223171Reid Klecknernamespace llvm {
17b1e25a1bc03292dc538d336573e0be1490223171Reid Klecknernamespace opt {
18b1e25a1bc03292dc538d336573e0be1490223171Reid Kleckner  class ArgList;
19b1e25a1bc03292dc538d336573e0be1490223171Reid Kleckner}
20b1e25a1bc03292dc538d336573e0be1490223171Reid Kleckner}
21b1e25a1bc03292dc538d336573e0be1490223171Reid Kleckner
222ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbarnamespace clang {
232ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbarnamespace driver {
24b1e25a1bc03292dc538d336573e0be1490223171Reid Kleckner
2547ac7d27c44bd64a7d0fc03d4babc196cf2b8230Daniel Dunbar  class Compilation;
2647ac7d27c44bd64a7d0fc03d4babc196cf2b8230Daniel Dunbar  class InputInfo;
27871adcf4e41285e3f4c3b62eaa1b2e05b60b92daDaniel Dunbar  class Job;
2847ac7d27c44bd64a7d0fc03d4babc196cf2b8230Daniel Dunbar  class JobAction;
29670b7f4fe6720e91520ec5a993b33c00058ed77aDaniel Dunbar  class ToolChain;
301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
31686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  typedef SmallVector<InputInfo, 4> InputInfoList;
3247ac7d27c44bd64a7d0fc03d4babc196cf2b8230Daniel Dunbar
332ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar/// Tool - Information on a specific compilation tool.
342ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbarclass Tool {
35176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hinespublic:
36176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  // Documents the level of support for response files in this tool.
37176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  // Response files are necessary if the command line gets too large,
38176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  // requiring the arguments to be transfered to a file.
39176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  enum ResponseFileSupport {
40176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines    // Provides full support for response files, which means we can transfer
41176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines    // all tool input arguments to a file. E.g.: clang, gcc, binutils and MSVC
42176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines    // tools.
43176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines    RF_Full,
44176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines    // Input file names can live in a file, but flags can't. E.g.: ld64 (Mac
45176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines    // OS X linker).
46176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines    RF_FileList,
47176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines    // Does not support response files: all arguments must be passed via
48176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines    // command line.
49176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines    RF_None
50176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  };
51176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines
52176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hinesprivate:
5331b1e5437e7435879fc044afb77ff27096008e72Daniel Dunbar  /// The tool name (for debugging).
5431b1e5437e7435879fc044afb77ff27096008e72Daniel Dunbar  const char *Name;
5531b1e5437e7435879fc044afb77ff27096008e72Daniel Dunbar
563038204fd8f6ff22082dd18e4b12ed252b75a5e4Daniel Dunbar  /// The human readable name for the tool, for use in diagnostics.
573038204fd8f6ff22082dd18e4b12ed252b75a5e4Daniel Dunbar  const char *ShortName;
583038204fd8f6ff22082dd18e4b12ed252b75a5e4Daniel Dunbar
5931b1e5437e7435879fc044afb77ff27096008e72Daniel Dunbar  /// The tool chain this tool is a part of.
60670b7f4fe6720e91520ec5a993b33c00058ed77aDaniel Dunbar  const ToolChain &TheToolChain;
61670b7f4fe6720e91520ec5a993b33c00058ed77aDaniel Dunbar
62176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  /// The level of support for response files seen in this tool
63176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  const ResponseFileSupport ResponseSupport;
64176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines
65176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  /// The encoding to use when writing response files for this tool on Windows
66176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  const llvm::sys::WindowsEncodingMethod ResponseEncoding;
67176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines
68176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  /// The flag used to pass a response file via command line to this tool
69176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  const char *const ResponseFlag;
70176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines
71670b7f4fe6720e91520ec5a993b33c00058ed77aDaniel Dunbarpublic:
72176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  Tool(const char *Name, const char *ShortName, const ToolChain &TC,
73176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines       ResponseFileSupport ResponseSupport = RF_None,
74176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines       llvm::sys::WindowsEncodingMethod ResponseEncoding = llvm::sys::WEM_UTF8,
75176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines       const char *ResponseFlag = "@");
762ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar
772ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbarpublic:
782ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar  virtual ~Tool();
792ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar
8031b1e5437e7435879fc044afb77ff27096008e72Daniel Dunbar  const char *getName() const { return Name; }
8131b1e5437e7435879fc044afb77ff27096008e72Daniel Dunbar
823038204fd8f6ff22082dd18e4b12ed252b75a5e4Daniel Dunbar  const char *getShortName() const { return ShortName; }
833038204fd8f6ff22082dd18e4b12ed252b75a5e4Daniel Dunbar
84670b7f4fe6720e91520ec5a993b33c00058ed77aDaniel Dunbar  const ToolChain &getToolChain() const { return TheToolChain; }
85670b7f4fe6720e91520ec5a993b33c00058ed77aDaniel Dunbar
868767cbc475ed96397b6f08617814eeb9cab121bdDaniel Dunbar  virtual bool hasIntegratedAssembler() const { return false; }
870e2c34f92f00628d48968dfea096d36381f494cbStephen Hines  virtual bool canEmitIR() const { return false; }
882ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar  virtual bool hasIntegratedCPP() const = 0;
898ba9a6244c56b19bc2a24de5d0c32ff37d50177bChad Rosier  virtual bool isLinkJob() const { return false; }
9075dbc717c21a662b7836ed34cc4e7da7b8fa33c0Chad Rosier  virtual bool isDsymutilJob() const { return false; }
91176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  /// \brief Returns the level of support for response files of this tool,
92176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  /// whether it accepts arguments to be passed via a file on disk.
93176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  ResponseFileSupport getResponseFilesSupport() const {
94176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines    return ResponseSupport;
95176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  }
96176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  /// \brief Returns which encoding the response file should use. This is only
97176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  /// relevant on Windows platforms where there are different encodings being
98176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  /// accepted for different tools. On UNIX, UTF8 is universal.
99176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  ///
100176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  /// Windows use cases: - GCC and Binutils on mingw only accept ANSI response
101176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  /// files encoded with the system current code page.
102176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  /// - MSVC's CL.exe and LINK.exe accept UTF16 on Windows.
103176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  /// - Clang accepts both UTF8 and UTF16.
104176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  ///
105176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  /// FIXME: When GNU tools learn how to parse UTF16 on Windows, we should
106176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  /// always use UTF16 for Windows, which is the Windows official encoding for
107176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  /// international characters.
108176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  llvm::sys::WindowsEncodingMethod getResponseFileEncoding() const {
109176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines    return ResponseEncoding;
110176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  }
111176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  /// \brief Returns which prefix to use when passing the name of a response
112176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  /// file as a parameter to this tool.
113176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  const char *getResponseFileFlag() const { return ResponseFlag; }
11447ac7d27c44bd64a7d0fc03d4babc196cf2b8230Daniel Dunbar
11560a53f24b160724de0e8dd0e142009981540fd26Daniel Dunbar  /// \brief Does this tool have "good" standardized diagnostics, or should the
11660a53f24b160724de0e8dd0e142009981540fd26Daniel Dunbar  /// driver add an additional "command failed" diagnostic on failures.
11760a53f24b160724de0e8dd0e142009981540fd26Daniel Dunbar  virtual bool hasGoodDiagnostics() const { return false; }
11860a53f24b160724de0e8dd0e142009981540fd26Daniel Dunbar
1191824d54df85a462ada812dadda18130f951d40f3Dmitri Gribenko  /// ConstructJob - Construct jobs to perform the action \p JA,
120c8ba0a0acd30f0b56d08a3a0947f68ac01a40730Hans Wennborg  /// writing to \p Output and with \p Inputs, and add the jobs to
121c8ba0a0acd30f0b56d08a3a0947f68ac01a40730Hans Wennborg  /// \p C.
12247ac7d27c44bd64a7d0fc03d4babc196cf2b8230Daniel Dunbar  ///
12347ac7d27c44bd64a7d0fc03d4babc196cf2b8230Daniel Dunbar  /// \param TCArgs - The argument list for this toolchain, with any
12447ac7d27c44bd64a7d0fc03d4babc196cf2b8230Daniel Dunbar  /// tool chain specific translations applied.
12547ac7d27c44bd64a7d0fc03d4babc196cf2b8230Daniel Dunbar  /// \param LinkingOutput - If this output will eventually feed the
12647ac7d27c44bd64a7d0fc03d4babc196cf2b8230Daniel Dunbar  /// linker, then this is the final output name of the linked image.
12747ac7d27c44bd64a7d0fc03d4babc196cf2b8230Daniel Dunbar  virtual void ConstructJob(Compilation &C, const JobAction &JA,
1281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                            const InputInfo &Output,
1291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                            const InputInfoList &Inputs,
130dd0b3c4c72464af92e2c27dd5a67e29f91ba7b28Reid Kleckner                            const llvm::opt::ArgList &TCArgs,
13147ac7d27c44bd64a7d0fc03d4babc196cf2b8230Daniel Dunbar                            const char *LinkingOutput) const = 0;
1322ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar};
1332ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar
1342ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar} // end namespace driver
1352ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar} // end namespace clang
1362ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar
1372ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar#endif
138