blob: afb02fa49b5de504c52944b3fc5878530ba7c510 [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 Dunbar1d460332009-03-18 10:01:51 +000012#include "clang/Driver/Action.h"
Daniel Dunbar871adcf2009-03-18 07:06:02 +000013#include "clang/Driver/Arg.h"
Daniel Dunbarb488c1d2009-03-18 08:07:30 +000014#include "clang/Driver/ArgList.h"
Daniel Dunbar1d460332009-03-18 10:01:51 +000015#include "clang/Driver/Driver.h" // FIXME: Remove?
16#include "clang/Driver/DriverDiagnostic.h" // FIXME: Remove?
Daniel Dunbar871adcf2009-03-18 07:06:02 +000017#include "clang/Driver/Compilation.h"
18#include "clang/Driver/Job.h"
Daniel Dunbarb488c1d2009-03-18 08:07:30 +000019#include "clang/Driver/HostInfo.h"
20#include "clang/Driver/Option.h"
21#include "clang/Driver/ToolChain.h"
Daniel Dunbar871adcf2009-03-18 07:06:02 +000022#include "clang/Driver/Util.h"
23
24#include "llvm/ADT/SmallVector.h"
25
26#include "InputInfo.h"
27
Daniel Dunbar47ac7d22009-03-18 06:00:36 +000028using namespace clang::driver;
29using namespace clang::driver::tools;
30
31void Clang::ConstructJob(Compilation &C, const JobAction &JA,
Daniel Dunbar871adcf2009-03-18 07:06:02 +000032 Job &Dest,
33 const InputInfo &Output,
Daniel Dunbar62cf6012009-03-18 06:07:59 +000034 const InputInfoList &Inputs,
Daniel Dunbar1d460332009-03-18 10:01:51 +000035 const ArgList &Args,
Daniel Dunbar47ac7d22009-03-18 06:00:36 +000036 const char *LinkingOutput) const {
Daniel Dunbarb488c1d2009-03-18 08:07:30 +000037 ArgStringList CmdArgs;
38
Daniel Dunbar1d460332009-03-18 10:01:51 +000039 if (isa<AnalyzeJobAction>(JA)) {
40 assert(JA.getType() == types::TY_Plist && "Invalid output type.");
41 CmdArgs.push_back("-analyze");
42 } else if (isa<PreprocessJobAction>(JA)) {
43 CmdArgs.push_back("-E");
44 } else if (isa<PrecompileJobAction>(JA)) {
45 // No special option needed, driven by -x.
46 //
47 // FIXME: Don't drive this by -x, that is gross.
Daniel Dunbar1d460332009-03-18 10:01:51 +000048 } else {
49 assert(isa<CompileJobAction>(JA) && "Invalid action for clang tool.");
50
51 if (JA.getType() == types::TY_Nothing) {
52 CmdArgs.push_back("-fsyntax-only");
53 } else if (JA.getType() == types::TY_LLVMAsm) {
54 CmdArgs.push_back("-emit-llvm");
55 } else if (JA.getType() == types::TY_LLVMBC) {
56 CmdArgs.push_back("-emit-llvm-bc");
57 } else if (JA.getType() == types::TY_PP_Asm) {
58 CmdArgs.push_back("-S");
59 }
Daniel Dunbarb488c1d2009-03-18 08:07:30 +000060 }
61
Daniel Dunbar1d460332009-03-18 10:01:51 +000062 // The make clang go fast button.
63 CmdArgs.push_back("-disable-free");
64
65 if (isa<AnalyzeJobAction>(JA)) {
66 // Add default argument set.
67 //
68 // FIXME: Move into clang?
69 CmdArgs.push_back("-warn-dead-stores");
70 CmdArgs.push_back("-checker-cfref");
71 CmdArgs.push_back("-warn-objc-methodsigs");
72 // Do not enable the missing -dealloc check.
73 // '-warn-objc-missing-dealloc',
74 CmdArgs.push_back("-warn-objc-unused-ivars");
75
76 CmdArgs.push_back("-analyzer-output=plist");
77
78 // Add -Xanalyzer arguments when running as analyzer.
79 Args.AddAllArgValues(CmdArgs, options::OPT_Xanalyzer);
80 } else {
81 // Perform argument translation for LLVM backend. This
82 // takes some care in reconciling with llvm-gcc. The
83 // issue is that llvm-gcc translates these options based on
84 // the values in cc1, whereas we are processing based on
85 // the driver arguments.
86 //
87 // FIXME: This is currently broken for -f flags when -fno
88 // variants are present.
89
90 // This comes from the default translation the driver + cc1
91 // would do to enable flag_pic.
92 //
93 // FIXME: Centralize this code.
94 bool PICEnabled = (Args.hasArg(options::OPT_fPIC) ||
95 Args.hasArg(options::OPT_fpic) ||
96 Args.hasArg(options::OPT_fPIE) ||
97 Args.hasArg(options::OPT_fpie));
98 bool PICDisabled = (Args.hasArg(options::OPT_mkernel) ||
99 Args.hasArg(options::OPT_static));
100 const char *Model = getToolChain().GetForcedPicModel();
101 if (!Model) {
102 if (Args.hasArg(options::OPT_mdynamic_no_pic))
103 Model = "dynamic-no-pic";
104 else if (PICDisabled)
105 Model = "static";
106 else if (PICEnabled)
107 Model = "pic";
108 else
109 Model = getToolChain().GetDefaultRelocationModel();
110 }
111 CmdArgs.push_back("--relocation-model");
112 CmdArgs.push_back(Model);
113
114 if (Args.hasArg(options::OPT_ftime_report))
115 CmdArgs.push_back("--time-passes");
116 // FIXME: Set --enable-unsafe-fp-math.
117 if (!Args.hasArg(options::OPT_fomit_frame_pointer))
118 CmdArgs.push_back("--disable-fp-elim");
119 if (!Args.hasFlag(options::OPT_fzero_initialized_in_bss,
120 options::OPT_fno_zero_initialized_in_bss,
121 true))
122 CmdArgs.push_back("--nozero-initialized-in-bss");
Daniel Dunbarb3fd5002009-03-24 17:59:06 +0000123 if (Args.hasArg(options::OPT_dA) || Args.hasArg(options::OPT_fverbose_asm))
Daniel Dunbar1d460332009-03-18 10:01:51 +0000124 CmdArgs.push_back("--asm-verbose");
125 if (Args.hasArg(options::OPT_fdebug_pass_structure))
126 CmdArgs.push_back("--debug-pass=Structure");
127 if (Args.hasArg(options::OPT_fdebug_pass_arguments))
128 CmdArgs.push_back("--debug-pass=Arguments");
129 // FIXME: set --inline-threshhold=50 if (optimize_size || optimize
130 // < 3)
131 if (Args.hasFlag(options::OPT_funwind_tables,
132 options::OPT_fno_unwind_tables,
133 getToolChain().IsUnwindTablesDefault()))
134 CmdArgs.push_back("--unwind-tables=1");
135 else
136 CmdArgs.push_back("--unwind-tables=0");
137 if (!Args.hasFlag(options::OPT_mred_zone,
138 options::OPT_mno_red_zone,
139 true))
140 CmdArgs.push_back("--disable-red-zone");
141 if (Args.hasFlag(options::OPT_msoft_float,
142 options::OPT_mno_soft_float,
143 false))
144 CmdArgs.push_back("--soft-float");
145
146 // FIXME: Need target hooks.
147 if (memcmp(getToolChain().getPlatform().c_str(), "darwin", 6) == 0) {
148 if (getToolChain().getArchName() == "x86_64")
149 CmdArgs.push_back("--mcpu=core2");
150 else if (getToolChain().getArchName() == "i386")
151 CmdArgs.push_back("--mcpu=yonah");
152 }
153
154 // FIXME: Ignores ordering. Also, we need to find a realistic
155 // solution for this.
156 static const struct {
157 options::ID Pos, Neg;
158 const char *Name;
159 } FeatureOptions[] = {
160 { options::OPT_mmmx, options::OPT_mno_mmx, "mmx" },
161 { options::OPT_msse, options::OPT_mno_sse, "sse" },
162 { options::OPT_msse2, options::OPT_mno_sse2, "sse2" },
163 { options::OPT_msse3, options::OPT_mno_sse3, "sse3" },
164 { options::OPT_mssse3, options::OPT_mno_ssse3, "ssse3" },
165 { options::OPT_msse41, options::OPT_mno_sse41, "sse41" },
166 { options::OPT_msse42, options::OPT_mno_sse42, "sse42" },
167 { options::OPT_msse4a, options::OPT_mno_sse4a, "sse4a" },
168 { options::OPT_m3dnow, options::OPT_mno_3dnow, "3dnow" },
169 { options::OPT_m3dnowa, options::OPT_mno_3dnowa, "3dnowa" }
170 };
171 const unsigned NumFeatureOptions =
172 sizeof(FeatureOptions)/sizeof(FeatureOptions[0]);
173
174 // FIXME: Avoid std::string
175 std::string Attrs;
176 for (unsigned i=0; i < NumFeatureOptions; ++i) {
177 if (Args.hasArg(FeatureOptions[i].Pos)) {
Daniel Dunbar55b3b5f2009-03-19 17:36:04 +0000178 if (!Attrs.empty())
179 Attrs += ',';
Daniel Dunbar1d460332009-03-18 10:01:51 +0000180 Attrs += '+';
181 Attrs += FeatureOptions[i].Name;
182 } else if (Args.hasArg(FeatureOptions[i].Neg)) {
Daniel Dunbar55b3b5f2009-03-19 17:36:04 +0000183 if (!Attrs.empty())
184 Attrs += ',';
Daniel Dunbar1d460332009-03-18 10:01:51 +0000185 Attrs += '-';
186 Attrs += FeatureOptions[i].Name;
187 }
188 }
189 if (!Attrs.empty()) {
190 CmdArgs.push_back("--mattr");
191 CmdArgs.push_back(Args.MakeArgString(Attrs.c_str()));
192 }
193
194 if (Args.hasFlag(options::OPT_fmath_errno,
195 options::OPT_fno_math_errno,
196 getToolChain().IsMathErrnoDefault()))
197 CmdArgs.push_back("--fmath-errno=1");
198 else
199 CmdArgs.push_back("--fmath-errno=0");
200
201 if (Arg *A = Args.getLastArg(options::OPT_flimited_precision_EQ)) {
202 CmdArgs.push_back("--limit-float-precision");
203 CmdArgs.push_back(A->getValue(Args));
204 }
205
206 // FIXME: Add --stack-protector-buffer-size=<xxx> on
207 // -fstack-protect.
208
209 Args.AddLastArg(CmdArgs, options::OPT_MD);
Daniel Dunbar546654a2009-03-24 07:20:59 +0000210 Args.AddLastArg(CmdArgs, options::OPT_MMD);
Daniel Dunbar1d460332009-03-18 10:01:51 +0000211 Args.AddAllArgs(CmdArgs, options::OPT_MF);
212 Args.AddLastArg(CmdArgs, options::OPT_MP);
213 Args.AddAllArgs(CmdArgs, options::OPT_MT);
214
215 Arg *Unsupported = Args.getLastArg(options::OPT_M);
216 if (!Unsupported)
217 Unsupported = Args.getLastArg(options::OPT_MM);
218 if (!Unsupported)
219 Unsupported = Args.getLastArg(options::OPT_MG);
220 if (!Unsupported)
221 Unsupported = Args.getLastArg(options::OPT_MQ);
222 if (Unsupported) {
223 const Driver &D = getToolChain().getHost().getDriver();
224 D.Diag(clang::diag::err_drv_unsupported_opt)
225 << Unsupported->getOption().getName();
226 }
227 }
228
229 Args.AddAllArgs(CmdArgs, options::OPT_v);
230 Args.AddAllArgs(CmdArgs, options::OPT_D, options::OPT_U);
231 Args.AddAllArgs(CmdArgs, options::OPT_I_Group, options::OPT_F);
232 Args.AddLastArg(CmdArgs, options::OPT_P);
233 Args.AddAllArgs(CmdArgs, options::OPT_mmacosx_version_min_EQ);
234
235 // Special case debug options to only pass -g to clang. This is
236 // wrong.
237 if (Args.hasArg(options::OPT_g_Group))
238 CmdArgs.push_back("-g");
239
240 Args.AddLastArg(CmdArgs, options::OPT_nostdinc);
241
242 // FIXME: Clang isn't going to accept just anything here.
Daniel Dunbar049853d2009-03-20 19:38:56 +0000243 // FIXME: Use iterator.
Daniel Dunbar1d460332009-03-18 10:01:51 +0000244
Daniel Dunbar049853d2009-03-20 19:38:56 +0000245 // Add -i* options, and automatically translate to -include-pth for
246 // transparent PCH support. It's wonky, but we include looking for
247 // .gch so we can support seamless replacement into a build system
248 // already set up to be generating .gch files.
Daniel Dunbar1d460332009-03-18 10:01:51 +0000249 for (ArgList::const_iterator
250 it = Args.begin(), ie = Args.end(); it != ie; ++it) {
251 const Arg *A = *it;
Daniel Dunbar049853d2009-03-20 19:38:56 +0000252 if (!A->getOption().matches(options::OPT_i_Group))
253 continue;
254
Daniel Dunbar1d460332009-03-18 10:01:51 +0000255 if (A->getOption().matches(options::OPT_include)) {
Daniel Dunbar049853d2009-03-20 19:38:56 +0000256 bool FoundPTH = false;
Daniel Dunbar1d460332009-03-18 10:01:51 +0000257 llvm::sys::Path P(A->getValue(Args));
258 P.appendSuffix("pth");
259 if (P.exists()) {
Daniel Dunbar049853d2009-03-20 19:38:56 +0000260 FoundPTH = true;
Daniel Dunbar1d460332009-03-18 10:01:51 +0000261 } else {
262 P.eraseSuffix();
263 P.appendSuffix("gch");
Daniel Dunbar049853d2009-03-20 19:38:56 +0000264 if (P.exists())
265 FoundPTH = true;
266 }
267
268 if (FoundPTH) {
269 A->claim();
270 CmdArgs.push_back("-include-pth");
271 CmdArgs.push_back(Args.MakeArgString(P.c_str()));
272 continue;
Daniel Dunbar1d460332009-03-18 10:01:51 +0000273 }
274 }
Daniel Dunbar049853d2009-03-20 19:38:56 +0000275
276 // Not translated, render as usual.
277 A->claim();
278 A->render(Args, CmdArgs);
Daniel Dunbar1d460332009-03-18 10:01:51 +0000279 }
280
Daniel Dunbar337a6272009-03-24 20:17:30 +0000281 // Manually translate -O to -O1 and -O4 to -O3; let clang reject
282 // others.
283 if (Arg *A = Args.getLastArg(options::OPT_O_Group)) {
284 if (A->getOption().getId() == options::OPT_O4)
285 CmdArgs.push_back("-O3");
286 else if (A->getValue(Args)[0] == '\0')
Daniel Dunbar1d460332009-03-18 10:01:51 +0000287 CmdArgs.push_back("-O1");
288 else
Daniel Dunbar5697aa02009-03-18 23:39:35 +0000289 A->render(Args, CmdArgs);
Daniel Dunbar1d460332009-03-18 10:01:51 +0000290 }
291
Daniel Dunbarff7488d2009-03-20 00:52:38 +0000292 Args.AddAllArgs(CmdArgs, options::OPT_clang_W_Group,
293 options::OPT_pedantic_Group);
Daniel Dunbar1d460332009-03-18 10:01:51 +0000294 Args.AddLastArg(CmdArgs, options::OPT_w);
295 Args.AddAllArgs(CmdArgs, options::OPT_std_EQ, options::OPT_ansi,
296 options::OPT_trigraphs);
297
298 if (Arg *A = Args.getLastArg(options::OPT_ftemplate_depth_)) {
299 CmdArgs.push_back("-ftemplate-depth");
300 CmdArgs.push_back(A->getValue(Args));
301 }
302
303 Args.AddAllArgs(CmdArgs, options::OPT_clang_f_Group);
304
305 Args.AddLastArg(CmdArgs, options::OPT_dM);
306
307 Args.AddAllArgValues(CmdArgs, options::OPT_Xclang);
308
309 // FIXME: Always pass the full triple once we aren't concerned with
310 // ccc compat.
311 CmdArgs.push_back("-arch");
312 CmdArgs.push_back(getToolChain().getArchName().c_str());
313
Daniel Dunbarb488c1d2009-03-18 08:07:30 +0000314 if (Output.isPipe()) {
315 CmdArgs.push_back("-o");
316 CmdArgs.push_back("-");
Daniel Dunbar115a7922009-03-19 07:29:38 +0000317 } else if (Output.isFilename()) {
Daniel Dunbarb488c1d2009-03-18 08:07:30 +0000318 CmdArgs.push_back("-o");
Daniel Dunbar115a7922009-03-19 07:29:38 +0000319 CmdArgs.push_back(Output.getFilename());
320 } else {
321 assert(Output.isNothing() && "Invalid output.");
Daniel Dunbarb488c1d2009-03-18 08:07:30 +0000322 }
323
Daniel Dunbar1d460332009-03-18 10:01:51 +0000324 for (InputInfoList::const_iterator
325 it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
326 const InputInfo &II = *it;
327 CmdArgs.push_back("-x");
328 CmdArgs.push_back(types::getTypeName(II.getType()));
329 if (II.isPipe())
330 CmdArgs.push_back("-");
Daniel Dunbar115a7922009-03-19 07:29:38 +0000331 else if (II.isFilename())
332 CmdArgs.push_back(II.getFilename());
Daniel Dunbar1d460332009-03-18 10:01:51 +0000333 else
Daniel Dunbar115a7922009-03-19 07:29:38 +0000334 II.getInputArg().renderAsInput(Args, CmdArgs);
Daniel Dunbar1d460332009-03-18 10:01:51 +0000335 }
336
337 const char *Exec =
Daniel Dunbard7d5f022009-03-24 02:24:46 +0000338 Args.MakeArgString(getToolChain().GetProgramPath(C, "clang-cc").c_str());
Daniel Dunbar1d460332009-03-18 10:01:51 +0000339 Dest.addCommand(new Command(Exec, CmdArgs));
Daniel Dunbara880db02009-03-23 19:03:36 +0000340
341 // Claim some arguments which clang doesn't support, but we don't
342 // care to warn the user about.
343
344 // FIXME: Use iterator.
345 for (ArgList::const_iterator
346 it = Args.begin(), ie = Args.end(); it != ie; ++it) {
347 const Arg *A = *it;
348 if (A->getOption().matches(options::OPT_clang_ignored_W_Group) ||
349 A->getOption().matches(options::OPT_clang_ignored_f_Group))
350 A->claim();
351 }
Daniel Dunbar47ac7d22009-03-18 06:00:36 +0000352}
353
Daniel Dunbarb488c1d2009-03-18 08:07:30 +0000354void gcc::Common::ConstructJob(Compilation &C, const JobAction &JA,
355 Job &Dest,
356 const InputInfo &Output,
357 const InputInfoList &Inputs,
Daniel Dunbar1d460332009-03-18 10:01:51 +0000358 const ArgList &Args,
Daniel Dunbarb488c1d2009-03-18 08:07:30 +0000359 const char *LinkingOutput) const {
360 ArgStringList CmdArgs;
Daniel Dunbar47ac7d22009-03-18 06:00:36 +0000361
Daniel Dunbarb488c1d2009-03-18 08:07:30 +0000362 for (ArgList::const_iterator
Daniel Dunbar1d460332009-03-18 10:01:51 +0000363 it = Args.begin(), ie = Args.end(); it != ie; ++it) {
Daniel Dunbarb488c1d2009-03-18 08:07:30 +0000364 Arg *A = *it;
Daniel Dunbar75877192009-03-19 07:55:12 +0000365 if (A->getOption().hasForwardToGCC()) {
366 // It is unfortunate that we have to claim here, as this means
367 // we will basically never report anything interesting for
368 // platforms using a generic gcc.
369 A->claim();
Daniel Dunbar1d460332009-03-18 10:01:51 +0000370 A->render(Args, CmdArgs);
Daniel Dunbar75877192009-03-19 07:55:12 +0000371 }
Daniel Dunbarb488c1d2009-03-18 08:07:30 +0000372 }
373
374 RenderExtraToolArgs(CmdArgs);
375
376 // If using a driver driver, force the arch.
377 if (getToolChain().getHost().useDriverDriver()) {
378 CmdArgs.push_back("-arch");
379 CmdArgs.push_back(getToolChain().getArchName().c_str());
380 }
381
382 if (Output.isPipe()) {
383 CmdArgs.push_back("-o");
384 CmdArgs.push_back("-");
Daniel Dunbar115a7922009-03-19 07:29:38 +0000385 } else if (Output.isFilename()) {
Daniel Dunbarb488c1d2009-03-18 08:07:30 +0000386 CmdArgs.push_back("-o");
Daniel Dunbar115a7922009-03-19 07:29:38 +0000387 CmdArgs.push_back(Output.getFilename());
388 } else {
389 assert(Output.isNothing() && "Unexpected output");
Daniel Dunbarb488c1d2009-03-18 08:07:30 +0000390 CmdArgs.push_back("-fsyntax-only");
Daniel Dunbar115a7922009-03-19 07:29:38 +0000391 }
Daniel Dunbarb488c1d2009-03-18 08:07:30 +0000392
393
394 // Only pass -x if gcc will understand it; otherwise hope gcc
395 // understands the suffix correctly. The main use case this would go
396 // wrong in is for linker inputs if they happened to have an odd
397 // suffix; really the only way to get this to happen is a command
398 // like '-x foobar a.c' which will treat a.c like a linker input.
399 //
400 // FIXME: For the linker case specifically, can we safely convert
401 // inputs into '-Wl,' options?
402 for (InputInfoList::const_iterator
403 it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
404 const InputInfo &II = *it;
405 if (types::canTypeBeUserSpecified(II.getType())) {
406 CmdArgs.push_back("-x");
407 CmdArgs.push_back(types::getTypeName(II.getType()));
408 }
409
410 if (II.isPipe())
411 CmdArgs.push_back("-");
Daniel Dunbar115a7922009-03-19 07:29:38 +0000412 else if (II.isFilename())
413 CmdArgs.push_back(II.getFilename());
Daniel Dunbarb488c1d2009-03-18 08:07:30 +0000414 else
Daniel Dunbar115a7922009-03-19 07:29:38 +0000415 // Don't render as input, we need gcc to do the translations.
416 II.getInputArg().render(Args, CmdArgs);
Daniel Dunbarb488c1d2009-03-18 08:07:30 +0000417 }
418
Daniel Dunbar632f50e2009-03-18 21:34:08 +0000419 const char *Exec =
420 Args.MakeArgString(getToolChain().GetProgramPath(C, "gcc").c_str());
421 Dest.addCommand(new Command(Exec, CmdArgs));
Daniel Dunbar47ac7d22009-03-18 06:00:36 +0000422}
423
Daniel Dunbarb488c1d2009-03-18 08:07:30 +0000424void gcc::Preprocess::RenderExtraToolArgs(ArgStringList &CmdArgs) const {
425 CmdArgs.push_back("-E");
Daniel Dunbar47ac7d22009-03-18 06:00:36 +0000426}
427
Daniel Dunbarb488c1d2009-03-18 08:07:30 +0000428void gcc::Precompile::RenderExtraToolArgs(ArgStringList &CmdArgs) const {
429 // The type is good enough.
Daniel Dunbar47ac7d22009-03-18 06:00:36 +0000430}
431
Daniel Dunbarb488c1d2009-03-18 08:07:30 +0000432void gcc::Compile::RenderExtraToolArgs(ArgStringList &CmdArgs) const {
433 CmdArgs.push_back("-S");
Daniel Dunbar47ac7d22009-03-18 06:00:36 +0000434}
435
Daniel Dunbarb488c1d2009-03-18 08:07:30 +0000436void gcc::Assemble::RenderExtraToolArgs(ArgStringList &CmdArgs) const {
437 CmdArgs.push_back("-c");
Daniel Dunbar47ac7d22009-03-18 06:00:36 +0000438}
Daniel Dunbarb488c1d2009-03-18 08:07:30 +0000439
440void gcc::Link::RenderExtraToolArgs(ArgStringList &CmdArgs) const {
441 // The types are (hopefully) good enough.
442}
443
Daniel Dunbar8cac5f72009-03-20 16:06:39 +0000444void darwin::Assemble::ConstructJob(Compilation &C, const JobAction &JA,
445 Job &Dest, const InputInfo &Output,
446 const InputInfoList &Inputs,
447 const ArgList &Args,
448 const char *LinkingOutput) const {
449 ArgStringList CmdArgs;
450
451 assert(Inputs.size() == 1 && "Unexpected number of inputs.");
452 const InputInfo &Input = Inputs[0];
453
454 // Bit of a hack, this is only used for original inputs.
455 if (Input.isFilename() &&
456 strcmp(Input.getFilename(), Input.getBaseInput()) == 0 &&
457 Args.hasArg(options::OPT_g_Group))
458 CmdArgs.push_back("--gstabs");
459
460 // Derived from asm spec.
461 CmdArgs.push_back("-arch");
462 CmdArgs.push_back(getToolChain().getArchName().c_str());
463
464 CmdArgs.push_back("-force_cpusubtype_ALL");
465 if ((Args.hasArg(options::OPT_mkernel) ||
466 Args.hasArg(options::OPT_static) ||
467 Args.hasArg(options::OPT_fapple_kext)) &&
468 !Args.hasArg(options::OPT_dynamic))
469 CmdArgs.push_back("-static");
470
471 Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA,
472 options::OPT_Xassembler);
473
474 assert(Output.isFilename() && "Unexpected lipo output.");
475 CmdArgs.push_back("-o");
476 CmdArgs.push_back(Output.getFilename());
477
478 if (Input.isPipe()) {
479 CmdArgs.push_back("-");
480 } else {
481 assert(Input.isFilename() && "Invalid input.");
482 CmdArgs.push_back(Input.getFilename());
483 }
484
485 // asm_final spec is empty.
486
487 const char *Exec =
488 Args.MakeArgString(getToolChain().GetProgramPath(C, "as").c_str());
489 Dest.addCommand(new Command(Exec, CmdArgs));
490}
Daniel Dunbarff7488d2009-03-20 00:52:38 +0000491
492void darwin::Lipo::ConstructJob(Compilation &C, const JobAction &JA,
Daniel Dunbar8cac5f72009-03-20 16:06:39 +0000493 Job &Dest, const InputInfo &Output,
Daniel Dunbarff7488d2009-03-20 00:52:38 +0000494 const InputInfoList &Inputs,
495 const ArgList &Args,
496 const char *LinkingOutput) const {
497 ArgStringList CmdArgs;
498
499 CmdArgs.push_back("-create");
500 assert(Output.isFilename() && "Unexpected lipo output.");
Daniel Dunbara428df82009-03-24 00:24:37 +0000501
502 CmdArgs.push_back("-output");
Daniel Dunbarff7488d2009-03-20 00:52:38 +0000503 CmdArgs.push_back(Output.getFilename());
Daniel Dunbara428df82009-03-24 00:24:37 +0000504
Daniel Dunbarff7488d2009-03-20 00:52:38 +0000505 for (InputInfoList::const_iterator
506 it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
507 const InputInfo &II = *it;
508 assert(II.isFilename() && "Unexpected lipo input.");
509 CmdArgs.push_back(II.getFilename());
510 }
511 const char *Exec =
512 Args.MakeArgString(getToolChain().GetProgramPath(C, "lipo").c_str());
513 Dest.addCommand(new Command(Exec, CmdArgs));
514}