clang API Documentation
00001 //===--- Tool.h - Compilation Tools -----------------------------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 00010 #ifndef LLVM_CLANG_DRIVER_TOOL_H 00011 #define LLVM_CLANG_DRIVER_TOOL_H 00012 00013 #include "clang/Basic/LLVM.h" 00014 #include "llvm/Support/Program.h" 00015 00016 namespace llvm { 00017 namespace opt { 00018 class ArgList; 00019 } 00020 } 00021 00022 namespace clang { 00023 namespace driver { 00024 00025 class Compilation; 00026 class InputInfo; 00027 class Job; 00028 class JobAction; 00029 class ToolChain; 00030 00031 typedef SmallVector<InputInfo, 4> InputInfoList; 00032 00033 /// Tool - Information on a specific compilation tool. 00034 class Tool { 00035 public: 00036 // Documents the level of support for response files in this tool. 00037 // Response files are necessary if the command line gets too large, 00038 // requiring the arguments to be transfered to a file. 00039 enum ResponseFileSupport { 00040 // Provides full support for response files, which means we can transfer 00041 // all tool input arguments to a file. E.g.: clang, gcc, binutils and MSVC 00042 // tools. 00043 RF_Full, 00044 // Input file names can live in a file, but flags can't. E.g.: ld64 (Mac 00045 // OS X linker). 00046 RF_FileList, 00047 // Does not support response files: all arguments must be passed via 00048 // command line. 00049 RF_None 00050 }; 00051 00052 private: 00053 /// The tool name (for debugging). 00054 const char *Name; 00055 00056 /// The human readable name for the tool, for use in diagnostics. 00057 const char *ShortName; 00058 00059 /// The tool chain this tool is a part of. 00060 const ToolChain &TheToolChain; 00061 00062 /// The level of support for response files seen in this tool 00063 const ResponseFileSupport ResponseSupport; 00064 00065 /// The encoding to use when writing response files for this tool on Windows 00066 const llvm::sys::WindowsEncodingMethod ResponseEncoding; 00067 00068 /// The flag used to pass a response file via command line to this tool 00069 const char *const ResponseFlag; 00070 00071 public: 00072 Tool(const char *Name, const char *ShortName, const ToolChain &TC, 00073 ResponseFileSupport ResponseSupport = RF_None, 00074 llvm::sys::WindowsEncodingMethod ResponseEncoding = llvm::sys::WEM_UTF8, 00075 const char *ResponseFlag = "@"); 00076 00077 public: 00078 virtual ~Tool(); 00079 00080 const char *getName() const { return Name; } 00081 00082 const char *getShortName() const { return ShortName; } 00083 00084 const ToolChain &getToolChain() const { return TheToolChain; } 00085 00086 virtual bool hasIntegratedAssembler() const { return false; } 00087 virtual bool hasIntegratedCPP() const = 0; 00088 virtual bool isLinkJob() const { return false; } 00089 virtual bool isDsymutilJob() const { return false; } 00090 /// \brief Returns the level of support for response files of this tool, 00091 /// whether it accepts arguments to be passed via a file on disk. 00092 ResponseFileSupport getResponseFilesSupport() const { 00093 return ResponseSupport; 00094 } 00095 /// \brief Returns which encoding the response file should use. This is only 00096 /// relevant on Windows platforms where there are different encodings being 00097 /// accepted for different tools. On UNIX, UTF8 is universal. 00098 /// 00099 /// Windows use cases: - GCC and Binutils on mingw only accept ANSI response 00100 /// files encoded with the system current code page. 00101 /// - MSVC's CL.exe and LINK.exe accept UTF16 on Windows. 00102 /// - Clang accepts both UTF8 and UTF16. 00103 /// 00104 /// FIXME: When GNU tools learn how to parse UTF16 on Windows, we should 00105 /// always use UTF16 for Windows, which is the Windows official encoding for 00106 /// international characters. 00107 llvm::sys::WindowsEncodingMethod getResponseFileEncoding() const { 00108 return ResponseEncoding; 00109 } 00110 /// \brief Returns which prefix to use when passing the name of a response 00111 /// file as a parameter to this tool. 00112 const char *getResponseFileFlag() const { return ResponseFlag; } 00113 00114 /// \brief Does this tool have "good" standardized diagnostics, or should the 00115 /// driver add an additional "command failed" diagnostic on failures. 00116 virtual bool hasGoodDiagnostics() const { return false; } 00117 00118 /// ConstructJob - Construct jobs to perform the action \p JA, 00119 /// writing to \p Output and with \p Inputs, and add the jobs to 00120 /// \p C. 00121 /// 00122 /// \param TCArgs - The argument list for this toolchain, with any 00123 /// tool chain specific translations applied. 00124 /// \param LinkingOutput - If this output will eventually feed the 00125 /// linker, then this is the final output name of the linked image. 00126 virtual void ConstructJob(Compilation &C, const JobAction &JA, 00127 const InputInfo &Output, 00128 const InputInfoList &Inputs, 00129 const llvm::opt::ArgList &TCArgs, 00130 const char *LinkingOutput) const = 0; 00131 }; 00132 00133 } // end namespace driver 00134 } // end namespace clang 00135 00136 #endif