blob: f7480ea9745fca3543367feabc2a851332d26bbc [file] [log] [blame]
Daniel Dunbar47ac7d22009-03-18 06:00:36 +00001//===--- Tools.cpp - Tools Implementations ------------------------------*-===//
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#include "Tools.h"
11
Daniel Dunbar871adcf2009-03-18 07:06:02 +000012#include "clang/Driver/Arg.h"
Daniel Dunbarb488c1d2009-03-18 08:07:30 +000013#include "clang/Driver/ArgList.h"
Daniel Dunbar871adcf2009-03-18 07:06:02 +000014#include "clang/Driver/Compilation.h"
15#include "clang/Driver/Job.h"
Daniel Dunbarb488c1d2009-03-18 08:07:30 +000016#include "clang/Driver/HostInfo.h"
17#include "clang/Driver/Option.h"
18#include "clang/Driver/ToolChain.h"
Daniel Dunbar871adcf2009-03-18 07:06:02 +000019#include "clang/Driver/Util.h"
20
21#include "llvm/ADT/SmallVector.h"
22
23#include "InputInfo.h"
24
Daniel Dunbar47ac7d22009-03-18 06:00:36 +000025using namespace clang::driver;
26using namespace clang::driver::tools;
27
28void Clang::ConstructJob(Compilation &C, const JobAction &JA,
Daniel Dunbar871adcf2009-03-18 07:06:02 +000029 Job &Dest,
30 const InputInfo &Output,
Daniel Dunbar62cf6012009-03-18 06:07:59 +000031 const InputInfoList &Inputs,
Daniel Dunbar47ac7d22009-03-18 06:00:36 +000032 const ArgList &TCArgs,
33 const char *LinkingOutput) const {
Daniel Dunbarb488c1d2009-03-18 08:07:30 +000034 ArgStringList CmdArgs;
35
36 for (InputInfoList::const_iterator
37 it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
38 const InputInfo &II = *it;
39 if (II.isPipe())
40 CmdArgs.push_back("-");
41 else
42 CmdArgs.push_back(II.getInputFilename());
43 }
44
45 if (Output.isPipe()) {
46 CmdArgs.push_back("-o");
47 CmdArgs.push_back("-");
48 } else if (const char *N = Output.getInputFilename()) {
49 CmdArgs.push_back("-o");
50 CmdArgs.push_back(N);
51 }
52
53 Dest.addCommand(new Command("clang", CmdArgs));
Daniel Dunbar47ac7d22009-03-18 06:00:36 +000054}
55
Daniel Dunbarb488c1d2009-03-18 08:07:30 +000056void gcc::Common::ConstructJob(Compilation &C, const JobAction &JA,
57 Job &Dest,
58 const InputInfo &Output,
59 const InputInfoList &Inputs,
60 const ArgList &TCArgs,
61 const char *LinkingOutput) const {
62 ArgStringList CmdArgs;
Daniel Dunbar47ac7d22009-03-18 06:00:36 +000063
Daniel Dunbarb488c1d2009-03-18 08:07:30 +000064 for (ArgList::const_iterator
65 it = TCArgs.begin(), ie = TCArgs.end(); it != ie; ++it) {
66 Arg *A = *it;
67 if (A->getOption().hasForwardToGCC())
68 A->render(TCArgs, CmdArgs);
69 }
70
71 RenderExtraToolArgs(CmdArgs);
72
73 // If using a driver driver, force the arch.
74 if (getToolChain().getHost().useDriverDriver()) {
75 CmdArgs.push_back("-arch");
76 CmdArgs.push_back(getToolChain().getArchName().c_str());
77 }
78
79 if (Output.isPipe()) {
80 CmdArgs.push_back("-o");
81 CmdArgs.push_back("-");
82 } else if (const char *N = Output.getInputFilename()) {
83 CmdArgs.push_back("-o");
84 CmdArgs.push_back(N);
85 } else
86 CmdArgs.push_back("-fsyntax-only");
87
88
89 // Only pass -x if gcc will understand it; otherwise hope gcc
90 // understands the suffix correctly. The main use case this would go
91 // wrong in is for linker inputs if they happened to have an odd
92 // suffix; really the only way to get this to happen is a command
93 // like '-x foobar a.c' which will treat a.c like a linker input.
94 //
95 // FIXME: For the linker case specifically, can we safely convert
96 // inputs into '-Wl,' options?
97 for (InputInfoList::const_iterator
98 it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
99 const InputInfo &II = *it;
100 if (types::canTypeBeUserSpecified(II.getType())) {
101 CmdArgs.push_back("-x");
102 CmdArgs.push_back(types::getTypeName(II.getType()));
103 }
104
105 if (II.isPipe())
106 CmdArgs.push_back("-");
107 else
108 // FIXME: Linker inputs
109 CmdArgs.push_back(II.getInputFilename());
110 }
111
112 Dest.addCommand(new Command("gcc", CmdArgs));
Daniel Dunbar47ac7d22009-03-18 06:00:36 +0000113}
114
Daniel Dunbarb488c1d2009-03-18 08:07:30 +0000115void gcc::Preprocess::RenderExtraToolArgs(ArgStringList &CmdArgs) const {
116 CmdArgs.push_back("-E");
Daniel Dunbar47ac7d22009-03-18 06:00:36 +0000117}
118
Daniel Dunbarb488c1d2009-03-18 08:07:30 +0000119void gcc::Precompile::RenderExtraToolArgs(ArgStringList &CmdArgs) const {
120 // The type is good enough.
Daniel Dunbar47ac7d22009-03-18 06:00:36 +0000121}
122
Daniel Dunbarb488c1d2009-03-18 08:07:30 +0000123void gcc::Compile::RenderExtraToolArgs(ArgStringList &CmdArgs) const {
124 CmdArgs.push_back("-S");
Daniel Dunbar47ac7d22009-03-18 06:00:36 +0000125}
126
Daniel Dunbarb488c1d2009-03-18 08:07:30 +0000127void gcc::Assemble::RenderExtraToolArgs(ArgStringList &CmdArgs) const {
128 CmdArgs.push_back("-c");
Daniel Dunbar47ac7d22009-03-18 06:00:36 +0000129}
Daniel Dunbarb488c1d2009-03-18 08:07:30 +0000130
131void gcc::Link::RenderExtraToolArgs(ArgStringList &CmdArgs) const {
132 // The types are (hopefully) good enough.
133}
134