Tools.h revision 1bd91374498ac78e72545f08f4daa6491f9c9d14
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/ADT/Triple.h" 18#include "llvm/Support/Compiler.h" 19 20namespace clang { 21namespace driver { 22 class Driver; 23 24namespace toolchains { 25 class Darwin; 26} 27 28namespace tools { 29 30 /// \brief Clang compiler tool. 31 class LLVM_LIBRARY_VISIBILITY Clang : public Tool { 32 void AddPreprocessingOptions(Compilation &C, 33 const Driver &D, 34 const ArgList &Args, 35 ArgStringList &CmdArgs, 36 const InputInfo &Output, 37 const InputInfoList &Inputs) const; 38 39 void AddARMTargetArgs(const ArgList &Args, ArgStringList &CmdArgs, 40 bool KernelOrKext) const; 41 void AddMIPSTargetArgs(const ArgList &Args, ArgStringList &CmdArgs) const; 42 void AddSparcTargetArgs(const ArgList &Args, ArgStringList &CmdArgs) const; 43 void AddX86TargetArgs(const ArgList &Args, ArgStringList &CmdArgs) const; 44 void AddHexagonTargetArgs (const ArgList &Args, ArgStringList &CmdArgs) const; 45 46 public: 47 Clang(const ToolChain &TC) : Tool("clang", "clang frontend", TC) {} 48 49 virtual bool hasGoodDiagnostics() const { return true; } 50 virtual bool hasIntegratedAssembler() const { return true; } 51 virtual bool hasIntegratedCPP() const { return true; } 52 53 virtual void ConstructJob(Compilation &C, const JobAction &JA, 54 const InputInfo &Output, 55 const InputInfoList &Inputs, 56 const ArgList &TCArgs, 57 const char *LinkingOutput) const; 58 }; 59 60 /// \brief Clang integrated assembler tool. 61 class LLVM_LIBRARY_VISIBILITY ClangAs : public Tool { 62 public: 63 ClangAs(const ToolChain &TC) : Tool("clang::as", 64 "clang integrated assembler", TC) {} 65 66 virtual bool hasGoodDiagnostics() const { return true; } 67 virtual bool hasIntegratedAssembler() const { return false; } 68 virtual bool hasIntegratedCPP() const { return false; } 69 70 virtual void ConstructJob(Compilation &C, const JobAction &JA, 71 const InputInfo &Output, 72 const InputInfoList &Inputs, 73 const ArgList &TCArgs, 74 const char *LinkingOutput) const; 75 }; 76 77 /// gcc - Generic GCC tool implementations. 78namespace gcc { 79 class LLVM_LIBRARY_VISIBILITY Common : public Tool { 80 public: 81 Common(const char *Name, const char *ShortName, 82 const ToolChain &TC) : Tool(Name, ShortName, TC) {} 83 84 virtual void ConstructJob(Compilation &C, const JobAction &JA, 85 const InputInfo &Output, 86 const InputInfoList &Inputs, 87 const ArgList &TCArgs, 88 const char *LinkingOutput) const; 89 90 /// RenderExtraToolArgs - Render any arguments necessary to force 91 /// the particular tool mode. 92 virtual void RenderExtraToolArgs(const JobAction &JA, 93 ArgStringList &CmdArgs) const = 0; 94 }; 95 96 97 class LLVM_LIBRARY_VISIBILITY Preprocess : public Common { 98 public: 99 Preprocess(const ToolChain &TC) : Common("gcc::Preprocess", 100 "gcc preprocessor", TC) {} 101 102 virtual bool hasGoodDiagnostics() const { return true; } 103 virtual bool hasIntegratedCPP() const { return false; } 104 105 virtual void RenderExtraToolArgs(const JobAction &JA, 106 ArgStringList &CmdArgs) const; 107 }; 108 109 class LLVM_LIBRARY_VISIBILITY Precompile : public Common { 110 public: 111 Precompile(const ToolChain &TC) : Common("gcc::Precompile", 112 "gcc precompile", TC) {} 113 114 virtual bool hasGoodDiagnostics() const { return true; } 115 virtual bool hasIntegratedCPP() const { return true; } 116 117 virtual void RenderExtraToolArgs(const JobAction &JA, 118 ArgStringList &CmdArgs) const; 119 }; 120 121 class LLVM_LIBRARY_VISIBILITY Compile : public Common { 122 public: 123 Compile(const ToolChain &TC) : Common("gcc::Compile", 124 "gcc frontend", TC) {} 125 126 virtual bool hasGoodDiagnostics() const { return true; } 127 virtual bool hasIntegratedCPP() const { return true; } 128 129 virtual void RenderExtraToolArgs(const JobAction &JA, 130 ArgStringList &CmdArgs) const; 131 }; 132 133 class LLVM_LIBRARY_VISIBILITY Assemble : public Common { 134 public: 135 Assemble(const ToolChain &TC) : Common("gcc::Assemble", 136 "assembler (via gcc)", TC) {} 137 138 virtual bool hasIntegratedCPP() const { return false; } 139 140 virtual void RenderExtraToolArgs(const JobAction &JA, 141 ArgStringList &CmdArgs) const; 142 }; 143 144 class LLVM_LIBRARY_VISIBILITY Link : public Common { 145 public: 146 Link(const ToolChain &TC) : Common("gcc::Link", 147 "linker (via gcc)", TC) {} 148 149 virtual bool hasIntegratedCPP() const { return false; } 150 151 virtual void RenderExtraToolArgs(const JobAction &JA, 152 ArgStringList &CmdArgs) const; 153 }; 154} // end namespace gcc 155 156namespace hexagon { 157 // For Hexagon, we do not need to instantiate tools for PreProcess, PreCompile and Compile. 158 // We simply use "clang -cc1" for those actions. 159 class LLVM_LIBRARY_VISIBILITY Assemble : public Tool { 160 public: 161 Assemble(const ToolChain &TC) : Tool("hexagon::Assemble", 162 "hexagon-as", TC) {} 163 164 virtual bool hasIntegratedCPP() const { return false; } 165 166 virtual void RenderExtraToolArgs(const JobAction &JA, 167 ArgStringList &CmdArgs) const; 168 virtual void ConstructJob(Compilation &C, const JobAction &JA, 169 const InputInfo &Output, 170 const InputInfoList &Inputs, 171 const ArgList &TCArgs, 172 const char *LinkingOutput) const; 173 }; 174 175 class LLVM_LIBRARY_VISIBILITY Link : public Tool { 176 public: 177 Link(const ToolChain &TC) : Tool("hexagon::Link", 178 "hexagon-ld", TC) {} 179 180 virtual bool hasIntegratedCPP() const { return false; } 181 182 virtual void RenderExtraToolArgs(const JobAction &JA, 183 ArgStringList &CmdArgs) const; 184 virtual void ConstructJob(Compilation &C, const JobAction &JA, 185 const InputInfo &Output, 186 const InputInfoList &Inputs, 187 const ArgList &TCArgs, 188 const char *LinkingOutput) const; 189 }; 190} // end namespace hexagon. 191 192 193namespace darwin { 194 class LLVM_LIBRARY_VISIBILITY DarwinTool : public Tool { 195 virtual void anchor(); 196 protected: 197 void AddDarwinArch(const ArgList &Args, ArgStringList &CmdArgs) const; 198 199 const toolchains::Darwin &getDarwinToolChain() const { 200 return reinterpret_cast<const toolchains::Darwin&>(getToolChain()); 201 } 202 203 public: 204 DarwinTool(const char *Name, const char *ShortName, 205 const ToolChain &TC) : Tool(Name, ShortName, TC) {} 206 }; 207 208 class LLVM_LIBRARY_VISIBILITY CC1 : public DarwinTool { 209 virtual void anchor(); 210 public: 211 static const char *getBaseInputName(const ArgList &Args, 212 const InputInfoList &Input); 213 static const char *getBaseInputStem(const ArgList &Args, 214 const InputInfoList &Input); 215 static const char *getDependencyFileName(const ArgList &Args, 216 const InputInfoList &Inputs); 217 218 protected: 219 const char *getCC1Name(types::ID Type) const; 220 221 void AddCC1Args(const ArgList &Args, ArgStringList &CmdArgs) const; 222 void RemoveCC1UnsupportedArgs(ArgStringList &CmdArgs) const; 223 void AddCC1OptionsArgs(const ArgList &Args, ArgStringList &CmdArgs, 224 const InputInfoList &Inputs, 225 const ArgStringList &OutputArgs) const; 226 void AddCPPOptionsArgs(const ArgList &Args, ArgStringList &CmdArgs, 227 const InputInfoList &Inputs, 228 const ArgStringList &OutputArgs) const; 229 void AddCPPUniqueOptionsArgs(const ArgList &Args, 230 ArgStringList &CmdArgs, 231 const InputInfoList &Inputs) const; 232 void AddCPPArgs(const ArgList &Args, ArgStringList &CmdArgs) const; 233 234 public: 235 CC1(const char *Name, const char *ShortName, 236 const ToolChain &TC) : DarwinTool(Name, ShortName, TC) {} 237 238 virtual bool hasGoodDiagnostics() const { return true; } 239 virtual bool hasIntegratedCPP() const { return true; } 240 }; 241 242 class LLVM_LIBRARY_VISIBILITY Preprocess : public CC1 { 243 public: 244 Preprocess(const ToolChain &TC) : CC1("darwin::Preprocess", 245 "gcc preprocessor", TC) {} 246 247 virtual void ConstructJob(Compilation &C, const JobAction &JA, 248 const InputInfo &Output, 249 const InputInfoList &Inputs, 250 const ArgList &TCArgs, 251 const char *LinkingOutput) const; 252 }; 253 254 class LLVM_LIBRARY_VISIBILITY Compile : public CC1 { 255 public: 256 Compile(const ToolChain &TC) : CC1("darwin::Compile", "gcc frontend", TC) {} 257 258 virtual void ConstructJob(Compilation &C, const JobAction &JA, 259 const InputInfo &Output, 260 const InputInfoList &Inputs, 261 const ArgList &TCArgs, 262 const char *LinkingOutput) const; 263 }; 264 265 class LLVM_LIBRARY_VISIBILITY Assemble : public DarwinTool { 266 public: 267 Assemble(const ToolChain &TC) : DarwinTool("darwin::Assemble", 268 "assembler", TC) {} 269 270 virtual bool hasIntegratedCPP() const { return false; } 271 272 virtual void ConstructJob(Compilation &C, const JobAction &JA, 273 const InputInfo &Output, 274 const InputInfoList &Inputs, 275 const ArgList &TCArgs, 276 const char *LinkingOutput) const; 277 }; 278 279 class LLVM_LIBRARY_VISIBILITY Link : public DarwinTool { 280 void AddLinkArgs(Compilation &C, const ArgList &Args, 281 ArgStringList &CmdArgs) const; 282 283 public: 284 Link(const ToolChain &TC) : DarwinTool("darwin::Link", "linker", TC) {} 285 286 virtual bool hasIntegratedCPP() const { return false; } 287 288 virtual void ConstructJob(Compilation &C, const JobAction &JA, 289 const InputInfo &Output, 290 const InputInfoList &Inputs, 291 const ArgList &TCArgs, 292 const char *LinkingOutput) const; 293 }; 294 295 class LLVM_LIBRARY_VISIBILITY Lipo : public DarwinTool { 296 public: 297 Lipo(const ToolChain &TC) : DarwinTool("darwin::Lipo", "lipo", TC) {} 298 299 virtual bool hasIntegratedCPP() const { return false; } 300 301 virtual void ConstructJob(Compilation &C, const JobAction &JA, 302 const InputInfo &Output, 303 const InputInfoList &Inputs, 304 const ArgList &TCArgs, 305 const char *LinkingOutput) const; 306 }; 307 308 class LLVM_LIBRARY_VISIBILITY Dsymutil : public DarwinTool { 309 public: 310 Dsymutil(const ToolChain &TC) : DarwinTool("darwin::Dsymutil", 311 "dsymutil", 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 322 class LLVM_LIBRARY_VISIBILITY VerifyDebug : public DarwinTool { 323 public: 324 VerifyDebug(const ToolChain &TC) : DarwinTool("darwin::VerifyDebug", 325 "dwarfdump", TC) {} 326 327 virtual bool hasIntegratedCPP() const { return false; } 328 329 virtual void ConstructJob(Compilation &C, const JobAction &JA, 330 const InputInfo &Output, 331 const InputInfoList &Inputs, 332 const ArgList &TCArgs, 333 const char *LinkingOutput) const; 334 }; 335 336} 337 338 /// openbsd -- Directly call GNU Binutils assembler and linker 339namespace openbsd { 340 class LLVM_LIBRARY_VISIBILITY Assemble : public Tool { 341 public: 342 Assemble(const ToolChain &TC) : Tool("openbsd::Assemble", "assembler", 343 TC) {} 344 345 virtual bool hasIntegratedCPP() const { return false; } 346 347 virtual void ConstructJob(Compilation &C, const JobAction &JA, 348 const InputInfo &Output, 349 const InputInfoList &Inputs, 350 const ArgList &TCArgs, 351 const char *LinkingOutput) const; 352 }; 353 class LLVM_LIBRARY_VISIBILITY Link : public Tool { 354 public: 355 Link(const ToolChain &TC) : Tool("openbsd::Link", "linker", TC) {} 356 357 virtual bool hasIntegratedCPP() const { return false; } 358 359 virtual void ConstructJob(Compilation &C, const JobAction &JA, 360 const InputInfo &Output, 361 const InputInfoList &Inputs, 362 const ArgList &TCArgs, 363 const char *LinkingOutput) const; 364 }; 365} // end namespace openbsd 366 367 /// freebsd -- Directly call GNU Binutils assembler and linker 368namespace freebsd { 369 class LLVM_LIBRARY_VISIBILITY Assemble : public Tool { 370 public: 371 Assemble(const ToolChain &TC) : Tool("freebsd::Assemble", "assembler", 372 TC) {} 373 374 virtual bool hasIntegratedCPP() const { return false; } 375 376 virtual void ConstructJob(Compilation &C, const JobAction &JA, 377 const InputInfo &Output, 378 const InputInfoList &Inputs, 379 const ArgList &TCArgs, 380 const char *LinkingOutput) const; 381 }; 382 class LLVM_LIBRARY_VISIBILITY Link : public Tool { 383 public: 384 Link(const ToolChain &TC) : Tool("freebsd::Link", "linker", TC) {} 385 386 virtual bool hasIntegratedCPP() const { return false; } 387 388 virtual void ConstructJob(Compilation &C, const JobAction &JA, 389 const InputInfo &Output, 390 const InputInfoList &Inputs, 391 const ArgList &TCArgs, 392 const char *LinkingOutput) const; 393 }; 394} // end namespace freebsd 395 396 /// netbsd -- Directly call GNU Binutils assembler and linker 397namespace netbsd { 398 class LLVM_LIBRARY_VISIBILITY Assemble : public Tool { 399 400 public: 401 Assemble(const ToolChain &TC) 402 : Tool("netbsd::Assemble", "assembler", TC) {} 403 404 virtual bool hasIntegratedCPP() const { return false; } 405 406 virtual void ConstructJob(Compilation &C, const JobAction &JA, 407 const InputInfo &Output, 408 const InputInfoList &Inputs, 409 const ArgList &TCArgs, 410 const char *LinkingOutput) const; 411 }; 412 class LLVM_LIBRARY_VISIBILITY Link : public Tool { 413 414 public: 415 Link(const ToolChain &TC) 416 : Tool("netbsd::Link", "linker", TC) {} 417 418 virtual bool hasIntegratedCPP() const { return false; } 419 420 virtual void ConstructJob(Compilation &C, const JobAction &JA, 421 const InputInfo &Output, 422 const InputInfoList &Inputs, 423 const ArgList &TCArgs, 424 const char *LinkingOutput) const; 425 }; 426} // end namespace netbsd 427 428 /// linux -- Directly call GNU Binutils assembler and linker 429namespace linuxtools { 430 class LLVM_LIBRARY_VISIBILITY Assemble : public Tool { 431 public: 432 Assemble(const ToolChain &TC) : Tool("linux::Assemble", "assembler", 433 TC) {} 434 435 virtual bool hasIntegratedCPP() const { return false; } 436 437 virtual void ConstructJob(Compilation &C, const JobAction &JA, 438 const InputInfo &Output, 439 const InputInfoList &Inputs, 440 const ArgList &TCArgs, 441 const char *LinkingOutput) const; 442 }; 443 class LLVM_LIBRARY_VISIBILITY Link : public Tool { 444 public: 445 Link(const ToolChain &TC) : Tool("linux::Link", "linker", TC) {} 446 447 virtual bool hasIntegratedCPP() const { return false; } 448 449 virtual void ConstructJob(Compilation &C, const JobAction &JA, 450 const InputInfo &Output, 451 const InputInfoList &Inputs, 452 const ArgList &TCArgs, 453 const char *LinkingOutput) const; 454 }; 455} 456 /// minix -- Directly call GNU Binutils assembler and linker 457namespace minix { 458 class LLVM_LIBRARY_VISIBILITY Assemble : public Tool { 459 public: 460 Assemble(const ToolChain &TC) : Tool("minix::Assemble", "assembler", 461 TC) {} 462 463 virtual bool hasIntegratedCPP() const { return false; } 464 465 virtual void ConstructJob(Compilation &C, const JobAction &JA, 466 const InputInfo &Output, 467 const InputInfoList &Inputs, 468 const ArgList &TCArgs, 469 const char *LinkingOutput) const; 470 }; 471 class LLVM_LIBRARY_VISIBILITY Link : public Tool { 472 public: 473 Link(const ToolChain &TC) : Tool("minix::Link", "linker", TC) {} 474 475 virtual bool hasIntegratedCPP() const { return false; } 476 477 virtual void ConstructJob(Compilation &C, const JobAction &JA, 478 const InputInfo &Output, 479 const InputInfoList &Inputs, 480 const ArgList &TCArgs, 481 const char *LinkingOutput) const; 482 }; 483} // end namespace minix 484 485 /// auroraux -- Directly call GNU Binutils assembler and linker 486namespace auroraux { 487 class LLVM_LIBRARY_VISIBILITY Assemble : public Tool { 488 public: 489 Assemble(const ToolChain &TC) : Tool("auroraux::Assemble", "assembler", 490 TC) {} 491 492 virtual bool hasIntegratedCPP() const { return false; } 493 494 virtual void ConstructJob(Compilation &C, const JobAction &JA, 495 const InputInfo &Output, 496 const InputInfoList &Inputs, 497 const ArgList &TCArgs, 498 const char *LinkingOutput) const; 499 }; 500 class LLVM_LIBRARY_VISIBILITY Link : public Tool { 501 public: 502 Link(const ToolChain &TC) : Tool("auroraux::Link", "linker", TC) {} 503 504 virtual bool hasIntegratedCPP() const { return false; } 505 506 virtual void ConstructJob(Compilation &C, const JobAction &JA, 507 const InputInfo &Output, 508 const InputInfoList &Inputs, 509 const ArgList &TCArgs, 510 const char *LinkingOutput) const; 511 }; 512} // end namespace auroraux 513 514 /// dragonfly -- Directly call GNU Binutils assembler and linker 515namespace dragonfly { 516 class LLVM_LIBRARY_VISIBILITY Assemble : public Tool { 517 public: 518 Assemble(const ToolChain &TC) : Tool("dragonfly::Assemble", "assembler", 519 TC) {} 520 521 virtual bool hasIntegratedCPP() const { return false; } 522 523 virtual void ConstructJob(Compilation &C, const JobAction &JA, 524 const InputInfo &Output, 525 const InputInfoList &Inputs, 526 const ArgList &TCArgs, 527 const char *LinkingOutput) const; 528 }; 529 class LLVM_LIBRARY_VISIBILITY Link : public Tool { 530 public: 531 Link(const ToolChain &TC) : Tool("dragonfly::Link", "linker", TC) {} 532 533 virtual bool hasIntegratedCPP() const { return false; } 534 535 virtual void ConstructJob(Compilation &C, const JobAction &JA, 536 const InputInfo &Output, 537 const InputInfoList &Inputs, 538 const ArgList &TCArgs, 539 const char *LinkingOutput) const; 540 }; 541} // end namespace dragonfly 542 543 /// Visual studio tools. 544namespace visualstudio { 545 class LLVM_LIBRARY_VISIBILITY Link : public Tool { 546 public: 547 Link(const ToolChain &TC) : Tool("visualstudio::Link", "linker", TC) {} 548 549 virtual bool hasIntegratedCPP() const { return false; } 550 551 virtual void ConstructJob(Compilation &C, const JobAction &JA, 552 const InputInfo &Output, 553 const InputInfoList &Inputs, 554 const ArgList &TCArgs, 555 const char *LinkingOutput) const; 556 }; 557} // end namespace visualstudio 558 559} // end namespace toolchains 560} // end namespace driver 561} // end namespace clang 562 563#endif // CLANG_LIB_DRIVER_TOOLS_H_ 564