Tools.h revision ba30bbe4e36a30a274da809a11a42f9cdc168e92
1//===--- Tools.h - Tool Implementations -------------------------*- 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 CLANG_LIB_DRIVER_TOOLS_H_ 11#define CLANG_LIB_DRIVER_TOOLS_H_ 12 13#include "clang/Driver/Tool.h" 14#include "clang/Driver/Types.h" 15#include "clang/Driver/Util.h" 16 17#include "llvm/Support/Compiler.h" 18 19namespace clang { 20namespace driver { 21 class Driver; 22 23namespace toolchains { 24 class Darwin; 25} 26 27namespace tools { 28 29 /// \brief Clang compiler tool. 30 class LLVM_LIBRARY_VISIBILITY Clang : public Tool { 31 void AddPreprocessingOptions(const Driver &D, 32 const ArgList &Args, 33 ArgStringList &CmdArgs, 34 const InputInfo &Output, 35 const InputInfoList &Inputs) const; 36 37 void AddARMTargetArgs(const ArgList &Args, ArgStringList &CmdArgs) const; 38 void AddMIPSTargetArgs(const ArgList &Args, ArgStringList &CmdArgs) const; 39 void AddX86TargetArgs(const ArgList &Args, ArgStringList &CmdArgs) const; 40 41 public: 42 Clang(const ToolChain &TC) : Tool("clang", "clang frontend", TC) {} 43 44 virtual bool hasGoodDiagnostics() const { return true; } 45 virtual bool hasIntegratedAssembler() const { return true; } 46 virtual bool hasIntegratedCPP() const { return true; } 47 48 virtual void ConstructJob(Compilation &C, const JobAction &JA, 49 const InputInfo &Output, 50 const InputInfoList &Inputs, 51 const ArgList &TCArgs, 52 const char *LinkingOutput) const; 53 }; 54 55 /// \brief Clang integrated assembler tool. 56 class LLVM_LIBRARY_VISIBILITY ClangAs : public Tool { 57 public: 58 ClangAs(const ToolChain &TC) : Tool("clang::as", 59 "clang integrated assembler", TC) {} 60 61 virtual bool hasGoodDiagnostics() const { return true; } 62 virtual bool hasIntegratedAssembler() const { return false; } 63 virtual bool hasIntegratedCPP() const { return false; } 64 65 virtual void ConstructJob(Compilation &C, const JobAction &JA, 66 const InputInfo &Output, 67 const InputInfoList &Inputs, 68 const ArgList &TCArgs, 69 const char *LinkingOutput) const; 70 }; 71 72 /// gcc - Generic GCC tool implementations. 73namespace gcc { 74 class LLVM_LIBRARY_VISIBILITY Common : public Tool { 75 public: 76 Common(const char *Name, const char *ShortName, 77 const ToolChain &TC) : Tool(Name, ShortName, TC) {} 78 79 virtual void ConstructJob(Compilation &C, const JobAction &JA, 80 const InputInfo &Output, 81 const InputInfoList &Inputs, 82 const ArgList &TCArgs, 83 const char *LinkingOutput) const; 84 85 /// RenderExtraToolArgs - Render any arguments necessary to force 86 /// the particular tool mode. 87 virtual void RenderExtraToolArgs(const JobAction &JA, 88 ArgStringList &CmdArgs) const = 0; 89 }; 90 91 92 class LLVM_LIBRARY_VISIBILITY Preprocess : public Common { 93 public: 94 Preprocess(const ToolChain &TC) : Common("gcc::Preprocess", 95 "gcc preprocessor", TC) {} 96 97 virtual bool hasGoodDiagnostics() const { return true; } 98 virtual bool hasIntegratedCPP() const { return false; } 99 100 virtual void RenderExtraToolArgs(const JobAction &JA, 101 ArgStringList &CmdArgs) const; 102 }; 103 104 class LLVM_LIBRARY_VISIBILITY Precompile : public Common { 105 public: 106 Precompile(const ToolChain &TC) : Common("gcc::Precompile", 107 "gcc precompile", TC) {} 108 109 virtual bool hasGoodDiagnostics() const { return true; } 110 virtual bool hasIntegratedCPP() const { return true; } 111 112 virtual void RenderExtraToolArgs(const JobAction &JA, 113 ArgStringList &CmdArgs) const; 114 }; 115 116 class LLVM_LIBRARY_VISIBILITY Compile : public Common { 117 public: 118 Compile(const ToolChain &TC) : Common("gcc::Compile", 119 "gcc frontend", TC) {} 120 121 virtual bool hasGoodDiagnostics() const { return true; } 122 virtual bool hasIntegratedCPP() const { return true; } 123 124 virtual void RenderExtraToolArgs(const JobAction &JA, 125 ArgStringList &CmdArgs) const; 126 }; 127 128 class LLVM_LIBRARY_VISIBILITY Assemble : public Common { 129 public: 130 Assemble(const ToolChain &TC) : Common("gcc::Assemble", 131 "assembler (via gcc)", TC) {} 132 133 virtual bool hasIntegratedCPP() const { return false; } 134 135 virtual void RenderExtraToolArgs(const JobAction &JA, 136 ArgStringList &CmdArgs) const; 137 }; 138 139 class LLVM_LIBRARY_VISIBILITY Link : public Common { 140 public: 141 Link(const ToolChain &TC) : Common("gcc::Link", 142 "linker (via gcc)", TC) {} 143 144 virtual bool hasIntegratedCPP() const { return false; } 145 146 virtual void RenderExtraToolArgs(const JobAction &JA, 147 ArgStringList &CmdArgs) const; 148 }; 149} // end namespace gcc 150 151namespace darwin { 152 class LLVM_LIBRARY_VISIBILITY DarwinTool : public Tool { 153 protected: 154 void AddDarwinArch(const ArgList &Args, ArgStringList &CmdArgs) const; 155 156 const toolchains::Darwin &getDarwinToolChain() const { 157 return reinterpret_cast<const toolchains::Darwin&>(getToolChain()); 158 } 159 160 public: 161 DarwinTool(const char *Name, const char *ShortName, 162 const ToolChain &TC) : Tool(Name, ShortName, TC) {} 163 }; 164 165 class LLVM_LIBRARY_VISIBILITY CC1 : public DarwinTool { 166 public: 167 static const char *getBaseInputName(const ArgList &Args, 168 const InputInfoList &Input); 169 static const char *getBaseInputStem(const ArgList &Args, 170 const InputInfoList &Input); 171 static const char *getDependencyFileName(const ArgList &Args, 172 const InputInfoList &Inputs); 173 174 protected: 175 const char *getCC1Name(types::ID Type) const; 176 177 void AddCC1Args(const ArgList &Args, ArgStringList &CmdArgs) const; 178 void AddCC1OptionsArgs(const ArgList &Args, ArgStringList &CmdArgs, 179 const InputInfoList &Inputs, 180 const ArgStringList &OutputArgs) const; 181 void AddCPPOptionsArgs(const ArgList &Args, ArgStringList &CmdArgs, 182 const InputInfoList &Inputs, 183 const ArgStringList &OutputArgs) const; 184 void AddCPPUniqueOptionsArgs(const ArgList &Args, 185 ArgStringList &CmdArgs, 186 const InputInfoList &Inputs) const; 187 void AddCPPArgs(const ArgList &Args, ArgStringList &CmdArgs) const; 188 189 public: 190 CC1(const char *Name, const char *ShortName, 191 const ToolChain &TC) : DarwinTool(Name, ShortName, TC) {} 192 193 virtual bool hasGoodDiagnostics() const { return true; } 194 virtual bool hasIntegratedCPP() const { return true; } 195 }; 196 197 class LLVM_LIBRARY_VISIBILITY Preprocess : public CC1 { 198 public: 199 Preprocess(const ToolChain &TC) : CC1("darwin::Preprocess", 200 "gcc preprocessor", TC) {} 201 202 virtual void ConstructJob(Compilation &C, const JobAction &JA, 203 const InputInfo &Output, 204 const InputInfoList &Inputs, 205 const ArgList &TCArgs, 206 const char *LinkingOutput) const; 207 }; 208 209 class LLVM_LIBRARY_VISIBILITY Compile : public CC1 { 210 public: 211 Compile(const ToolChain &TC) : CC1("darwin::Compile", "gcc frontend", TC) {} 212 213 virtual void ConstructJob(Compilation &C, const JobAction &JA, 214 const InputInfo &Output, 215 const InputInfoList &Inputs, 216 const ArgList &TCArgs, 217 const char *LinkingOutput) const; 218 }; 219 220 class LLVM_LIBRARY_VISIBILITY Assemble : public DarwinTool { 221 public: 222 Assemble(const ToolChain &TC) : DarwinTool("darwin::Assemble", 223 "assembler", TC) {} 224 225 virtual bool hasIntegratedCPP() const { return false; } 226 227 virtual void ConstructJob(Compilation &C, const JobAction &JA, 228 const InputInfo &Output, 229 const InputInfoList &Inputs, 230 const ArgList &TCArgs, 231 const char *LinkingOutput) const; 232 }; 233 234 class LLVM_LIBRARY_VISIBILITY Link : public DarwinTool { 235 void AddLinkArgs(const ArgList &Args, ArgStringList &CmdArgs) const; 236 237 public: 238 Link(const ToolChain &TC) : DarwinTool("darwin::Link", "linker", TC) {} 239 240 virtual bool hasIntegratedCPP() const { return false; } 241 242 virtual void ConstructJob(Compilation &C, const JobAction &JA, 243 const InputInfo &Output, 244 const InputInfoList &Inputs, 245 const ArgList &TCArgs, 246 const char *LinkingOutput) const; 247 }; 248 249 class LLVM_LIBRARY_VISIBILITY Lipo : public DarwinTool { 250 public: 251 Lipo(const ToolChain &TC) : DarwinTool("darwin::Lipo", "lipo", TC) {} 252 253 virtual bool hasIntegratedCPP() const { return false; } 254 255 virtual void ConstructJob(Compilation &C, const JobAction &JA, 256 const InputInfo &Output, 257 const InputInfoList &Inputs, 258 const ArgList &TCArgs, 259 const char *LinkingOutput) const; 260 }; 261 262 class LLVM_LIBRARY_VISIBILITY Dsymutil : public DarwinTool { 263 public: 264 Dsymutil(const ToolChain &TC) : DarwinTool("darwin::Dsymutil", 265 "dsymutil", TC) {} 266 267 virtual bool hasIntegratedCPP() const { return false; } 268 269 virtual void ConstructJob(Compilation &C, const JobAction &JA, 270 const InputInfo &Output, 271 const InputInfoList &Inputs, 272 const ArgList &TCArgs, 273 const char *LinkingOutput) const; 274 }; 275} 276 277 /// openbsd -- Directly call GNU Binutils assembler and linker 278namespace openbsd { 279 class LLVM_LIBRARY_VISIBILITY Assemble : public Tool { 280 public: 281 Assemble(const ToolChain &TC) : Tool("openbsd::Assemble", "assembler", 282 TC) {} 283 284 virtual bool hasIntegratedCPP() const { return false; } 285 286 virtual void ConstructJob(Compilation &C, const JobAction &JA, 287 const InputInfo &Output, 288 const InputInfoList &Inputs, 289 const ArgList &TCArgs, 290 const char *LinkingOutput) const; 291 }; 292 class LLVM_LIBRARY_VISIBILITY Link : public Tool { 293 public: 294 Link(const ToolChain &TC) : Tool("openbsd::Link", "linker", TC) {} 295 296 virtual bool hasIntegratedCPP() const { return false; } 297 298 virtual void ConstructJob(Compilation &C, const JobAction &JA, 299 const InputInfo &Output, 300 const InputInfoList &Inputs, 301 const ArgList &TCArgs, 302 const char *LinkingOutput) const; 303 }; 304} // end namespace openbsd 305 306 /// freebsd -- Directly call GNU Binutils assembler and linker 307namespace freebsd { 308 class LLVM_LIBRARY_VISIBILITY Assemble : public Tool { 309 public: 310 Assemble(const ToolChain &TC) : Tool("freebsd::Assemble", "assembler", 311 TC) {} 312 313 virtual bool hasIntegratedCPP() const { return false; } 314 315 virtual void ConstructJob(Compilation &C, const JobAction &JA, 316 const InputInfo &Output, 317 const InputInfoList &Inputs, 318 const ArgList &TCArgs, 319 const char *LinkingOutput) const; 320 }; 321 class LLVM_LIBRARY_VISIBILITY Link : public Tool { 322 public: 323 Link(const ToolChain &TC) : Tool("freebsd::Link", "linker", TC) {} 324 325 virtual bool hasIntegratedCPP() const { return false; } 326 327 virtual void ConstructJob(Compilation &C, const JobAction &JA, 328 const InputInfo &Output, 329 const InputInfoList &Inputs, 330 const ArgList &TCArgs, 331 const char *LinkingOutput) const; 332 }; 333} // end namespace freebsd 334 335 /// linux -- Directly call GNU Binutils assembler and linker 336namespace linuxtools { 337 class LLVM_LIBRARY_VISIBILITY Assemble : public Tool { 338 public: 339 Assemble(const ToolChain &TC) : Tool("linux::Assemble", "assembler", 340 TC) {} 341 342 virtual bool hasIntegratedCPP() const { return false; } 343 344 virtual void ConstructJob(Compilation &C, const JobAction &JA, 345 const InputInfo &Output, 346 const InputInfoList &Inputs, 347 const ArgList &TCArgs, 348 const char *LinkingOutput) const; 349 }; 350} 351 /// minix -- Directly call GNU Binutils assembler and linker 352namespace minix { 353 class LLVM_LIBRARY_VISIBILITY Assemble : public Tool { 354 public: 355 Assemble(const ToolChain &TC) : Tool("minix::Assemble", "assembler", 356 TC) {} 357 358 virtual bool hasIntegratedCPP() const { return false; } 359 360 virtual void ConstructJob(Compilation &C, const JobAction &JA, 361 const InputInfo &Output, 362 const InputInfoList &Inputs, 363 const ArgList &TCArgs, 364 const char *LinkingOutput) const; 365 }; 366 class LLVM_LIBRARY_VISIBILITY Link : public Tool { 367 public: 368 Link(const ToolChain &TC) : Tool("minix::Link", "linker", TC) {} 369 370 virtual bool hasIntegratedCPP() const { return false; } 371 372 virtual void ConstructJob(Compilation &C, const JobAction &JA, 373 const InputInfo &Output, 374 const InputInfoList &Inputs, 375 const ArgList &TCArgs, 376 const char *LinkingOutput) const; 377 }; 378} // end namespace minix 379 380 /// auroraux -- Directly call GNU Binutils assembler and linker 381namespace auroraux { 382 class LLVM_LIBRARY_VISIBILITY Assemble : public Tool { 383 public: 384 Assemble(const ToolChain &TC) : Tool("auroraux::Assemble", "assembler", 385 TC) {} 386 387 virtual bool hasIntegratedCPP() const { return false; } 388 389 virtual void ConstructJob(Compilation &C, const JobAction &JA, 390 const InputInfo &Output, 391 const InputInfoList &Inputs, 392 const ArgList &TCArgs, 393 const char *LinkingOutput) const; 394 }; 395 class LLVM_LIBRARY_VISIBILITY Link : public Tool { 396 public: 397 Link(const ToolChain &TC) : Tool("auroraux::Link", "linker", TC) {} 398 399 virtual bool hasIntegratedCPP() const { return false; } 400 401 virtual void ConstructJob(Compilation &C, const JobAction &JA, 402 const InputInfo &Output, 403 const InputInfoList &Inputs, 404 const ArgList &TCArgs, 405 const char *LinkingOutput) const; 406 }; 407} // end namespace auroraux 408 409 /// dragonfly -- Directly call GNU Binutils assembler and linker 410namespace dragonfly { 411 class LLVM_LIBRARY_VISIBILITY Assemble : public Tool { 412 public: 413 Assemble(const ToolChain &TC) : Tool("dragonfly::Assemble", "assembler", 414 TC) {} 415 416 virtual bool hasIntegratedCPP() const { return false; } 417 418 virtual void ConstructJob(Compilation &C, const JobAction &JA, 419 const InputInfo &Output, 420 const InputInfoList &Inputs, 421 const ArgList &TCArgs, 422 const char *LinkingOutput) const; 423 }; 424 class LLVM_LIBRARY_VISIBILITY Link : public Tool { 425 public: 426 Link(const ToolChain &TC) : Tool("dragonfly::Link", "linker", TC) {} 427 428 virtual bool hasIntegratedCPP() const { return false; } 429 430 virtual void ConstructJob(Compilation &C, const JobAction &JA, 431 const InputInfo &Output, 432 const InputInfoList &Inputs, 433 const ArgList &TCArgs, 434 const char *LinkingOutput) const; 435 }; 436} // end namespace dragonfly 437 438} // end namespace toolchains 439} // end namespace driver 440} // end namespace clang 441 442#endif // CLANG_LIB_DRIVER_TOOLS_H_ 443