1 //===--- Tools.h - Tool Implementations -------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef CLANG_LIB_DRIVER_TOOLS_H_
11 #define CLANG_LIB_DRIVER_TOOLS_H_
13 #include "clang/Driver/Tool.h"
14 #include "clang/Driver/Types.h"
15 #include "clang/Driver/Util.h"
17 #include "llvm/ADT/Triple.h"
18 #include "llvm/Support/Compiler.h"
24 namespace toolchains {
30 /// \brief Clang compiler tool.
31 class LLVM_LIBRARY_VISIBILITY Clang : public Tool {
32 void AddPreprocessingOptions(const Driver &D,
34 ArgStringList &CmdArgs,
35 const InputInfo &Output,
36 const InputInfoList &Inputs) const;
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;
45 Clang(const ToolChain &TC) : Tool("clang", "clang frontend", TC) {}
47 virtual bool hasGoodDiagnostics() const { return true; }
48 virtual bool hasIntegratedAssembler() const { return true; }
49 virtual bool hasIntegratedCPP() const { return true; }
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;
58 /// \brief Clang integrated assembler tool.
59 class LLVM_LIBRARY_VISIBILITY ClangAs : public Tool {
61 ClangAs(const ToolChain &TC) : Tool("clang::as",
62 "clang integrated assembler", TC) {}
64 virtual bool hasGoodDiagnostics() const { return true; }
65 virtual bool hasIntegratedAssembler() const { return false; }
66 virtual bool hasIntegratedCPP() const { return false; }
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;
75 /// gcc - Generic GCC tool implementations.
77 class LLVM_LIBRARY_VISIBILITY Common : public Tool {
79 Common(const char *Name, const char *ShortName,
80 const ToolChain &TC) : Tool(Name, ShortName, TC) {}
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;
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;
95 class LLVM_LIBRARY_VISIBILITY Preprocess : public Common {
97 Preprocess(const ToolChain &TC) : Common("gcc::Preprocess",
98 "gcc preprocessor", TC) {}
100 virtual bool hasGoodDiagnostics() const { return true; }
101 virtual bool hasIntegratedCPP() const { return false; }
103 virtual void RenderExtraToolArgs(const JobAction &JA,
104 ArgStringList &CmdArgs) const;
107 class LLVM_LIBRARY_VISIBILITY Precompile : public Common {
109 Precompile(const ToolChain &TC) : Common("gcc::Precompile",
110 "gcc precompile", TC) {}
112 virtual bool hasGoodDiagnostics() const { return true; }
113 virtual bool hasIntegratedCPP() const { return true; }
115 virtual void RenderExtraToolArgs(const JobAction &JA,
116 ArgStringList &CmdArgs) const;
119 class LLVM_LIBRARY_VISIBILITY Compile : public Common {
121 Compile(const ToolChain &TC) : Common("gcc::Compile",
122 "gcc frontend", TC) {}
124 virtual bool hasGoodDiagnostics() const { return true; }
125 virtual bool hasIntegratedCPP() const { return true; }
127 virtual void RenderExtraToolArgs(const JobAction &JA,
128 ArgStringList &CmdArgs) const;
131 class LLVM_LIBRARY_VISIBILITY Assemble : public Common {
133 Assemble(const ToolChain &TC) : Common("gcc::Assemble",
134 "assembler (via gcc)", TC) {}
136 virtual bool hasIntegratedCPP() const { return false; }
138 virtual void RenderExtraToolArgs(const JobAction &JA,
139 ArgStringList &CmdArgs) const;
142 class LLVM_LIBRARY_VISIBILITY Link : public Common {
144 Link(const ToolChain &TC) : Common("gcc::Link",
145 "linker (via gcc)", TC) {}
147 virtual bool hasIntegratedCPP() const { return false; }
149 virtual void RenderExtraToolArgs(const JobAction &JA,
150 ArgStringList &CmdArgs) const;
152 } // end namespace gcc
155 class LLVM_LIBRARY_VISIBILITY DarwinTool : public Tool {
157 void AddDarwinArch(const ArgList &Args, ArgStringList &CmdArgs) const;
159 const toolchains::Darwin &getDarwinToolChain() const {
160 return reinterpret_cast<const toolchains::Darwin&>(getToolChain());
164 DarwinTool(const char *Name, const char *ShortName,
165 const ToolChain &TC) : Tool(Name, ShortName, TC) {}
168 class LLVM_LIBRARY_VISIBILITY CC1 : public DarwinTool {
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);
178 const char *getCC1Name(types::ID Type) const;
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;
194 CC1(const char *Name, const char *ShortName,
195 const ToolChain &TC) : DarwinTool(Name, ShortName, TC) {}
197 virtual bool hasGoodDiagnostics() const { return true; }
198 virtual bool hasIntegratedCPP() const { return true; }
201 class LLVM_LIBRARY_VISIBILITY Preprocess : public CC1 {
203 Preprocess(const ToolChain &TC) : CC1("darwin::Preprocess",
204 "gcc preprocessor", TC) {}
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;
213 class LLVM_LIBRARY_VISIBILITY Compile : public CC1 {
215 Compile(const ToolChain &TC) : CC1("darwin::Compile", "gcc frontend", TC) {}
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;
224 class LLVM_LIBRARY_VISIBILITY Assemble : public DarwinTool {
226 Assemble(const ToolChain &TC) : DarwinTool("darwin::Assemble",
229 virtual bool hasIntegratedCPP() const { return false; }
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;
238 class LLVM_LIBRARY_VISIBILITY Link : public DarwinTool {
239 void AddLinkArgs(Compilation &C, const ArgList &Args,
240 ArgStringList &CmdArgs) const;
243 Link(const ToolChain &TC) : DarwinTool("darwin::Link", "linker", TC) {}
245 virtual bool hasIntegratedCPP() const { return false; }
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;
254 class LLVM_LIBRARY_VISIBILITY Lipo : public DarwinTool {
256 Lipo(const ToolChain &TC) : DarwinTool("darwin::Lipo", "lipo", TC) {}
258 virtual bool hasIntegratedCPP() const { return false; }
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;
267 class LLVM_LIBRARY_VISIBILITY Dsymutil : public DarwinTool {
269 Dsymutil(const ToolChain &TC) : DarwinTool("darwin::Dsymutil",
272 virtual bool hasIntegratedCPP() const { return false; }
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;
281 class LLVM_LIBRARY_VISIBILITY VerifyDebug : public DarwinTool {
283 VerifyDebug(const ToolChain &TC) : DarwinTool("darwin::VerifyDebug",
286 virtual bool hasIntegratedCPP() const { return false; }
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;
297 /// openbsd -- Directly call GNU Binutils assembler and linker
299 class LLVM_LIBRARY_VISIBILITY Assemble : public Tool {
301 Assemble(const ToolChain &TC) : Tool("openbsd::Assemble", "assembler",
304 virtual bool hasIntegratedCPP() const { return false; }
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;
312 class LLVM_LIBRARY_VISIBILITY Link : public Tool {
314 Link(const ToolChain &TC) : Tool("openbsd::Link", "linker", TC) {}
316 virtual bool hasIntegratedCPP() const { return false; }
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;
324 } // end namespace openbsd
326 /// freebsd -- Directly call GNU Binutils assembler and linker
328 class LLVM_LIBRARY_VISIBILITY Assemble : public Tool {
330 Assemble(const ToolChain &TC) : Tool("freebsd::Assemble", "assembler",
333 virtual bool hasIntegratedCPP() const { return false; }
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;
341 class LLVM_LIBRARY_VISIBILITY Link : public Tool {
343 Link(const ToolChain &TC) : Tool("freebsd::Link", "linker", TC) {}
345 virtual bool hasIntegratedCPP() const { return false; }
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;
353 } // end namespace freebsd
355 /// netbsd -- Directly call GNU Binutils assembler and linker
357 class LLVM_LIBRARY_VISIBILITY Assemble : public Tool {
359 const llvm::Triple ToolTriple;
362 Assemble(const ToolChain &TC, const llvm::Triple &ToolTriple)
363 : Tool("netbsd::Assemble", "assembler", TC), ToolTriple(ToolTriple) {}
365 virtual bool hasIntegratedCPP() const { return false; }
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;
373 class LLVM_LIBRARY_VISIBILITY Link : public Tool {
375 const llvm::Triple ToolTriple;
378 Link(const ToolChain &TC, const llvm::Triple &ToolTriple)
379 : Tool("netbsd::Link", "linker", TC), ToolTriple(ToolTriple) {}
381 virtual bool hasIntegratedCPP() const { return false; }
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;
389 } // end namespace netbsd
391 /// linux -- Directly call GNU Binutils assembler and linker
392 namespace linuxtools {
393 class LLVM_LIBRARY_VISIBILITY Assemble : public Tool {
395 Assemble(const ToolChain &TC) : Tool("linux::Assemble", "assembler",
398 virtual bool hasIntegratedCPP() const { return false; }
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;
406 class LLVM_LIBRARY_VISIBILITY Link : public Tool {
408 Link(const ToolChain &TC) : Tool("linux::Link", "linker", TC) {}
410 virtual bool hasIntegratedCPP() const { return false; }
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;
419 /// minix -- Directly call GNU Binutils assembler and linker
421 class LLVM_LIBRARY_VISIBILITY Assemble : public Tool {
423 Assemble(const ToolChain &TC) : Tool("minix::Assemble", "assembler",
426 virtual bool hasIntegratedCPP() const { return false; }
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;
434 class LLVM_LIBRARY_VISIBILITY Link : public Tool {
436 Link(const ToolChain &TC) : Tool("minix::Link", "linker", TC) {}
438 virtual bool hasIntegratedCPP() const { return false; }
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;
446 } // end namespace minix
448 /// auroraux -- Directly call GNU Binutils assembler and linker
450 class LLVM_LIBRARY_VISIBILITY Assemble : public Tool {
452 Assemble(const ToolChain &TC) : Tool("auroraux::Assemble", "assembler",
455 virtual bool hasIntegratedCPP() const { return false; }
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;
463 class LLVM_LIBRARY_VISIBILITY Link : public Tool {
465 Link(const ToolChain &TC) : Tool("auroraux::Link", "linker", TC) {}
467 virtual bool hasIntegratedCPP() const { return false; }
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;
475 } // end namespace auroraux
477 /// dragonfly -- Directly call GNU Binutils assembler and linker
478 namespace dragonfly {
479 class LLVM_LIBRARY_VISIBILITY Assemble : public Tool {
481 Assemble(const ToolChain &TC) : Tool("dragonfly::Assemble", "assembler",
484 virtual bool hasIntegratedCPP() const { return false; }
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;
492 class LLVM_LIBRARY_VISIBILITY Link : public Tool {
494 Link(const ToolChain &TC) : Tool("dragonfly::Link", "linker", TC) {}
496 virtual bool hasIntegratedCPP() const { return false; }
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;
504 } // end namespace dragonfly
506 /// Visual studio tools.
507 namespace visualstudio {
508 class LLVM_LIBRARY_VISIBILITY Link : public Tool {
510 Link(const ToolChain &TC) : Tool("visualstudio::Link", "linker", TC) {}
512 virtual bool hasIntegratedCPP() const { return false; }
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;
520 } // end namespace visualstudio
522 } // end namespace toolchains
523 } // end namespace driver
524 } // end namespace clang
526 #endif // CLANG_LIB_DRIVER_TOOLS_H_