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