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