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