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 #include "llvm/ADT/Triple.h" 17 #include "llvm/Support/Compiler.h" 18 19 namespace clang { 20 class ObjCRuntime; 21 22 namespace driver { 23 class Driver; 24 25 namespace toolchains { 26 class Darwin; 27 } 28 29 namespace tools { 30 31 /// \brief Clang compiler tool. 32 class LLVM_LIBRARY_VISIBILITY Clang : public Tool { 33 public: 34 static const char *getBaseInputName(const ArgList &Args, 35 const InputInfoList &Inputs); 36 static const char *getBaseInputStem(const ArgList &Args, 37 const InputInfoList &Inputs); 38 static const char *getDependencyFileName(const ArgList &Args, 39 const InputInfoList &Inputs); 40 41 private: 42 void AddPreprocessingOptions(Compilation &C, 43 const JobAction &JA, 44 const Driver &D, 45 const ArgList &Args, 46 ArgStringList &CmdArgs, 47 const InputInfo &Output, 48 const InputInfoList &Inputs) const; 49 50 void AddARMTargetArgs(const ArgList &Args, ArgStringList &CmdArgs, 51 bool KernelOrKext) const; 52 void AddMIPSTargetArgs(const ArgList &Args, ArgStringList &CmdArgs) const; 53 void AddPPCTargetArgs(const ArgList &Args, ArgStringList &CmdArgs) const; 54 void AddSparcTargetArgs(const ArgList &Args, ArgStringList &CmdArgs) const; 55 void AddX86TargetArgs(const ArgList &Args, ArgStringList &CmdArgs) const; 56 void AddHexagonTargetArgs (const ArgList &Args, ArgStringList &CmdArgs) const; 57 58 enum RewriteKind { RK_None, RK_Fragile, RK_NonFragile }; 59 60 ObjCRuntime AddObjCRuntimeArgs(const ArgList &args, ArgStringList &cmdArgs, 61 RewriteKind rewrite) const; 62 63 public: 64 Clang(const ToolChain &TC) : Tool("clang", "clang frontend", TC) {} 65 66 virtual bool hasGoodDiagnostics() const { return true; } 67 virtual bool hasIntegratedAssembler() const { return true; } 68 virtual bool hasIntegratedCPP() const { return true; } 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 /// \brief Clang integrated assembler tool. 78 class LLVM_LIBRARY_VISIBILITY ClangAs : public Tool { 79 void AddARMTargetArgs(const ArgList &Args, ArgStringList &CmdArgs) const; 80 void AddX86TargetArgs(const ArgList &Args, ArgStringList &CmdArgs) const; 81 public: 82 ClangAs(const ToolChain &TC) : Tool("clang::as", 83 "clang integrated assembler", TC) {} 84 85 virtual bool hasGoodDiagnostics() const { return true; } 86 virtual bool hasIntegratedAssembler() const { return false; } 87 virtual bool hasIntegratedCPP() const { return false; } 88 89 virtual void ConstructJob(Compilation &C, const JobAction &JA, 90 const InputInfo &Output, 91 const InputInfoList &Inputs, 92 const ArgList &TCArgs, 93 const char *LinkingOutput) const; 94 }; 95 96 /// gcc - Generic GCC tool implementations. 97 namespace gcc { 98 class LLVM_LIBRARY_VISIBILITY Common : public Tool { 99 public: 100 Common(const char *Name, const char *ShortName, 101 const ToolChain &TC) : Tool(Name, ShortName, TC) {} 102 103 virtual void ConstructJob(Compilation &C, const JobAction &JA, 104 const InputInfo &Output, 105 const InputInfoList &Inputs, 106 const ArgList &TCArgs, 107 const char *LinkingOutput) const; 108 109 /// RenderExtraToolArgs - Render any arguments necessary to force 110 /// the particular tool mode. 111 virtual void RenderExtraToolArgs(const JobAction &JA, 112 ArgStringList &CmdArgs) const = 0; 113 }; 114 115 116 class LLVM_LIBRARY_VISIBILITY Preprocess : public Common { 117 public: 118 Preprocess(const ToolChain &TC) : Common("gcc::Preprocess", 119 "gcc preprocessor", TC) {} 120 121 virtual bool hasGoodDiagnostics() const { return true; } 122 virtual bool hasIntegratedCPP() const { return false; } 123 124 virtual void RenderExtraToolArgs(const JobAction &JA, 125 ArgStringList &CmdArgs) const; 126 }; 127 128 class LLVM_LIBRARY_VISIBILITY Precompile : public Common { 129 public: 130 Precompile(const ToolChain &TC) : Common("gcc::Precompile", 131 "gcc precompile", TC) {} 132 133 virtual bool hasGoodDiagnostics() const { return true; } 134 virtual bool hasIntegratedCPP() const { return true; } 135 136 virtual void RenderExtraToolArgs(const JobAction &JA, 137 ArgStringList &CmdArgs) const; 138 }; 139 140 class LLVM_LIBRARY_VISIBILITY Compile : public Common { 141 public: 142 Compile(const ToolChain &TC) : Common("gcc::Compile", 143 "gcc frontend", TC) {} 144 145 virtual bool hasGoodDiagnostics() const { return true; } 146 virtual bool hasIntegratedCPP() const { return true; } 147 148 virtual void RenderExtraToolArgs(const JobAction &JA, 149 ArgStringList &CmdArgs) const; 150 }; 151 152 class LLVM_LIBRARY_VISIBILITY Assemble : public Common { 153 public: 154 Assemble(const ToolChain &TC) : Common("gcc::Assemble", 155 "assembler (via gcc)", TC) {} 156 157 virtual bool hasIntegratedCPP() const { return false; } 158 159 virtual void RenderExtraToolArgs(const JobAction &JA, 160 ArgStringList &CmdArgs) const; 161 }; 162 163 class LLVM_LIBRARY_VISIBILITY Link : public Common { 164 public: 165 Link(const ToolChain &TC) : Common("gcc::Link", 166 "linker (via gcc)", TC) {} 167 168 virtual bool hasIntegratedCPP() const { return false; } 169 virtual bool isLinkJob() const { return true; } 170 171 virtual void RenderExtraToolArgs(const JobAction &JA, 172 ArgStringList &CmdArgs) const; 173 }; 174 } // end namespace gcc 175 176 namespace hexagon { 177 // For Hexagon, we do not need to instantiate tools for PreProcess, PreCompile and Compile. 178 // We simply use "clang -cc1" for those actions. 179 class LLVM_LIBRARY_VISIBILITY Assemble : public Tool { 180 public: 181 Assemble(const ToolChain &TC) : Tool("hexagon::Assemble", 182 "hexagon-as", TC) {} 183 184 virtual bool hasIntegratedCPP() const { return false; } 185 186 virtual void RenderExtraToolArgs(const JobAction &JA, 187 ArgStringList &CmdArgs) const; 188 virtual void ConstructJob(Compilation &C, const JobAction &JA, 189 const InputInfo &Output, 190 const InputInfoList &Inputs, 191 const ArgList &TCArgs, 192 const char *LinkingOutput) const; 193 }; 194 195 class LLVM_LIBRARY_VISIBILITY Link : public Tool { 196 public: 197 Link(const ToolChain &TC) : Tool("hexagon::Link", 198 "hexagon-ld", TC) {} 199 200 virtual bool hasIntegratedCPP() const { return false; } 201 virtual bool isLinkJob() const { return true; } 202 203 virtual void RenderExtraToolArgs(const JobAction &JA, 204 ArgStringList &CmdArgs) const; 205 virtual void ConstructJob(Compilation &C, const JobAction &JA, 206 const InputInfo &Output, 207 const InputInfoList &Inputs, 208 const ArgList &TCArgs, 209 const char *LinkingOutput) const; 210 }; 211 } // end namespace hexagon. 212 213 214 namespace darwin { 215 llvm::Triple::ArchType getArchTypeForDarwinArchName(StringRef Str); 216 217 class LLVM_LIBRARY_VISIBILITY DarwinTool : public Tool { 218 virtual void anchor(); 219 protected: 220 void AddDarwinArch(const ArgList &Args, ArgStringList &CmdArgs) const; 221 222 const toolchains::Darwin &getDarwinToolChain() const { 223 return reinterpret_cast<const toolchains::Darwin&>(getToolChain()); 224 } 225 226 public: 227 DarwinTool(const char *Name, const char *ShortName, 228 const ToolChain &TC) : Tool(Name, ShortName, TC) {} 229 }; 230 231 class LLVM_LIBRARY_VISIBILITY Assemble : public DarwinTool { 232 public: 233 Assemble(const ToolChain &TC) : DarwinTool("darwin::Assemble", 234 "assembler", TC) {} 235 236 virtual bool hasIntegratedCPP() const { return false; } 237 238 virtual void ConstructJob(Compilation &C, const JobAction &JA, 239 const InputInfo &Output, 240 const InputInfoList &Inputs, 241 const ArgList &TCArgs, 242 const char *LinkingOutput) const; 243 }; 244 245 class LLVM_LIBRARY_VISIBILITY Link : public DarwinTool { 246 bool NeedsTempPath(const InputInfoList &Inputs) const; 247 void AddLinkArgs(Compilation &C, const ArgList &Args, 248 ArgStringList &CmdArgs, const InputInfoList &Inputs) const; 249 250 public: 251 Link(const ToolChain &TC) : DarwinTool("darwin::Link", "linker", TC) {} 252 253 virtual bool hasIntegratedCPP() const { return false; } 254 virtual bool isLinkJob() const { return true; } 255 256 virtual void ConstructJob(Compilation &C, const JobAction &JA, 257 const InputInfo &Output, 258 const InputInfoList &Inputs, 259 const ArgList &TCArgs, 260 const char *LinkingOutput) const; 261 }; 262 263 class LLVM_LIBRARY_VISIBILITY Lipo : public DarwinTool { 264 public: 265 Lipo(const ToolChain &TC) : DarwinTool("darwin::Lipo", "lipo", 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 class LLVM_LIBRARY_VISIBILITY Dsymutil : public DarwinTool { 277 public: 278 Dsymutil(const ToolChain &TC) : DarwinTool("darwin::Dsymutil", 279 "dsymutil", TC) {} 280 281 virtual bool hasIntegratedCPP() const { return false; } 282 virtual bool isDsymutilJob() const { return true; } 283 284 virtual void ConstructJob(Compilation &C, const JobAction &JA, 285 const InputInfo &Output, 286 const InputInfoList &Inputs, 287 const ArgList &TCArgs, 288 const char *LinkingOutput) const; 289 }; 290 291 class LLVM_LIBRARY_VISIBILITY VerifyDebug : public DarwinTool { 292 public: 293 VerifyDebug(const ToolChain &TC) : DarwinTool("darwin::VerifyDebug", 294 "dwarfdump", 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 305 } 306 307 /// openbsd -- Directly call GNU Binutils assembler and linker 308 namespace openbsd { 309 class LLVM_LIBRARY_VISIBILITY Assemble : public Tool { 310 public: 311 Assemble(const ToolChain &TC) : Tool("openbsd::Assemble", "assembler", 312 TC) {} 313 314 virtual bool hasIntegratedCPP() const { return false; } 315 316 virtual void ConstructJob(Compilation &C, const JobAction &JA, 317 const InputInfo &Output, 318 const InputInfoList &Inputs, 319 const ArgList &TCArgs, 320 const char *LinkingOutput) const; 321 }; 322 class LLVM_LIBRARY_VISIBILITY Link : public Tool { 323 public: 324 Link(const ToolChain &TC) : Tool("openbsd::Link", "linker", TC) {} 325 326 virtual bool hasIntegratedCPP() const { return false; } 327 virtual bool isLinkJob() const { return true; } 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 } // end namespace openbsd 336 337 /// bitrig -- Directly call GNU Binutils assembler and linker 338 namespace bitrig { 339 class LLVM_LIBRARY_VISIBILITY Assemble : public Tool { 340 public: 341 Assemble(const ToolChain &TC) : Tool("bitrig::Assemble", "assembler", 342 TC) {} 343 344 virtual bool hasIntegratedCPP() const { return false; } 345 346 virtual void ConstructJob(Compilation &C, const JobAction &JA, 347 const InputInfo &Output, 348 const InputInfoList &Inputs, 349 const ArgList &TCArgs, 350 const char *LinkingOutput) const; 351 }; 352 class LLVM_LIBRARY_VISIBILITY Link : public Tool { 353 public: 354 Link(const ToolChain &TC) : Tool("bitrig::Link", "linker", TC) {} 355 356 virtual bool hasIntegratedCPP() const { return false; } 357 virtual bool isLinkJob() const { return true; } 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 bitrig 366 367 /// freebsd -- Directly call GNU Binutils assembler and linker 368 namespace 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 virtual bool isLinkJob() const { return true; } 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 } // end namespace freebsd 396 397 /// netbsd -- Directly call GNU Binutils assembler and linker 398 namespace netbsd { 399 class LLVM_LIBRARY_VISIBILITY Assemble : public Tool { 400 401 public: 402 Assemble(const ToolChain &TC) 403 : Tool("netbsd::Assemble", "assembler", TC) {} 404 405 virtual bool hasIntegratedCPP() const { return false; } 406 407 virtual void ConstructJob(Compilation &C, const JobAction &JA, 408 const InputInfo &Output, 409 const InputInfoList &Inputs, 410 const ArgList &TCArgs, 411 const char *LinkingOutput) const; 412 }; 413 class LLVM_LIBRARY_VISIBILITY Link : public Tool { 414 415 public: 416 Link(const ToolChain &TC) 417 : Tool("netbsd::Link", "linker", TC) {} 418 419 virtual bool hasIntegratedCPP() const { return false; } 420 virtual bool isLinkJob() const { return true; } 421 422 virtual void ConstructJob(Compilation &C, const JobAction &JA, 423 const InputInfo &Output, 424 const InputInfoList &Inputs, 425 const ArgList &TCArgs, 426 const char *LinkingOutput) const; 427 }; 428 } // end namespace netbsd 429 430 /// linux -- Directly call GNU Binutils assembler and linker 431 namespace linuxtools { 432 class LLVM_LIBRARY_VISIBILITY Assemble : public Tool { 433 public: 434 Assemble(const ToolChain &TC) : Tool("linux::Assemble", "assembler", 435 TC) {} 436 437 virtual bool hasIntegratedCPP() const { return false; } 438 439 virtual void ConstructJob(Compilation &C, const JobAction &JA, 440 const InputInfo &Output, 441 const InputInfoList &Inputs, 442 const ArgList &TCArgs, 443 const char *LinkingOutput) const; 444 }; 445 class LLVM_LIBRARY_VISIBILITY Link : public Tool { 446 public: 447 Link(const ToolChain &TC) : Tool("linux::Link", "linker", TC) {} 448 449 virtual bool hasIntegratedCPP() const { return false; } 450 virtual bool isLinkJob() const { return true; } 451 452 virtual void ConstructJob(Compilation &C, const JobAction &JA, 453 const InputInfo &Output, 454 const InputInfoList &Inputs, 455 const ArgList &TCArgs, 456 const char *LinkingOutput) const; 457 }; 458 } 459 /// minix -- Directly call GNU Binutils assembler and linker 460 namespace minix { 461 class LLVM_LIBRARY_VISIBILITY Assemble : public Tool { 462 public: 463 Assemble(const ToolChain &TC) : Tool("minix::Assemble", "assembler", 464 TC) {} 465 466 virtual bool hasIntegratedCPP() const { return false; } 467 468 virtual void ConstructJob(Compilation &C, const JobAction &JA, 469 const InputInfo &Output, 470 const InputInfoList &Inputs, 471 const ArgList &TCArgs, 472 const char *LinkingOutput) const; 473 }; 474 class LLVM_LIBRARY_VISIBILITY Link : public Tool { 475 public: 476 Link(const ToolChain &TC) : Tool("minix::Link", "linker", TC) {} 477 478 virtual bool hasIntegratedCPP() const { return false; } 479 virtual bool isLinkJob() const { return true; } 480 481 virtual void ConstructJob(Compilation &C, const JobAction &JA, 482 const InputInfo &Output, 483 const InputInfoList &Inputs, 484 const ArgList &TCArgs, 485 const char *LinkingOutput) const; 486 }; 487 } // end namespace minix 488 489 /// solaris -- Directly call Solaris assembler and linker 490 namespace solaris { 491 class LLVM_LIBRARY_VISIBILITY Assemble : public Tool { 492 public: 493 Assemble(const ToolChain &TC) : Tool("solaris::Assemble", "assembler", 494 TC) {} 495 496 virtual bool hasIntegratedCPP() const { return false; } 497 498 virtual void ConstructJob(Compilation &C, const JobAction &JA, 499 const InputInfo &Output, 500 const InputInfoList &Inputs, 501 const ArgList &TCArgs, 502 const char *LinkingOutput) const; 503 }; 504 class LLVM_LIBRARY_VISIBILITY Link : public Tool { 505 public: 506 Link(const ToolChain &TC) : Tool("solaris::Link", "linker", TC) {} 507 508 virtual bool hasIntegratedCPP() const { return false; } 509 virtual bool isLinkJob() const { return true; } 510 511 virtual void ConstructJob(Compilation &C, const JobAction &JA, 512 const InputInfo &Output, 513 const InputInfoList &Inputs, 514 const ArgList &TCArgs, 515 const char *LinkingOutput) const; 516 }; 517 } // end namespace solaris 518 519 /// auroraux -- Directly call GNU Binutils assembler and linker 520 namespace auroraux { 521 class LLVM_LIBRARY_VISIBILITY Assemble : public Tool { 522 public: 523 Assemble(const ToolChain &TC) : Tool("auroraux::Assemble", "assembler", 524 TC) {} 525 526 virtual bool hasIntegratedCPP() const { return false; } 527 528 virtual void ConstructJob(Compilation &C, const JobAction &JA, 529 const InputInfo &Output, 530 const InputInfoList &Inputs, 531 const ArgList &TCArgs, 532 const char *LinkingOutput) const; 533 }; 534 class LLVM_LIBRARY_VISIBILITY Link : public Tool { 535 public: 536 Link(const ToolChain &TC) : Tool("auroraux::Link", "linker", TC) {} 537 538 virtual bool hasIntegratedCPP() const { return false; } 539 virtual bool isLinkJob() const { return true; } 540 541 virtual void ConstructJob(Compilation &C, const JobAction &JA, 542 const InputInfo &Output, 543 const InputInfoList &Inputs, 544 const ArgList &TCArgs, 545 const char *LinkingOutput) const; 546 }; 547 } // end namespace auroraux 548 549 /// dragonfly -- Directly call GNU Binutils assembler and linker 550 namespace dragonfly { 551 class LLVM_LIBRARY_VISIBILITY Assemble : public Tool { 552 public: 553 Assemble(const ToolChain &TC) : Tool("dragonfly::Assemble", "assembler", 554 TC) {} 555 556 virtual bool hasIntegratedCPP() const { return false; } 557 558 virtual void ConstructJob(Compilation &C, const JobAction &JA, 559 const InputInfo &Output, 560 const InputInfoList &Inputs, 561 const ArgList &TCArgs, 562 const char *LinkingOutput) const; 563 }; 564 class LLVM_LIBRARY_VISIBILITY Link : public Tool { 565 public: 566 Link(const ToolChain &TC) : Tool("dragonfly::Link", "linker", TC) {} 567 568 virtual bool hasIntegratedCPP() const { return false; } 569 virtual bool isLinkJob() const { return true; } 570 571 virtual void ConstructJob(Compilation &C, const JobAction &JA, 572 const InputInfo &Output, 573 const InputInfoList &Inputs, 574 const ArgList &TCArgs, 575 const char *LinkingOutput) const; 576 }; 577 } // end namespace dragonfly 578 579 /// Visual studio tools. 580 namespace visualstudio { 581 class LLVM_LIBRARY_VISIBILITY Link : public Tool { 582 public: 583 Link(const ToolChain &TC) : Tool("visualstudio::Link", "linker", TC) {} 584 585 virtual bool hasIntegratedCPP() const { return false; } 586 virtual bool isLinkJob() const { return true; } 587 588 virtual void ConstructJob(Compilation &C, const JobAction &JA, 589 const InputInfo &Output, 590 const InputInfoList &Inputs, 591 const ArgList &TCArgs, 592 const char *LinkingOutput) const; 593 }; 594 } // end namespace visualstudio 595 596 } // end namespace toolchains 597 } // end namespace driver 598 } // end namespace clang 599 600 #endif // CLANG_LIB_DRIVER_TOOLS_H_ 601