Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 1 | //===--- 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 Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 12 | #include "clang/Driver/Action.h" |
Daniel Dunbar | 871adcf | 2009-03-18 07:06:02 +0000 | [diff] [blame] | 13 | #include "clang/Driver/Arg.h" |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 14 | #include "clang/Driver/ArgList.h" |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 15 | #include "clang/Driver/Driver.h" // FIXME: Remove? |
| 16 | #include "clang/Driver/DriverDiagnostic.h" // FIXME: Remove? |
Daniel Dunbar | 871adcf | 2009-03-18 07:06:02 +0000 | [diff] [blame] | 17 | #include "clang/Driver/Compilation.h" |
| 18 | #include "clang/Driver/Job.h" |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 19 | #include "clang/Driver/HostInfo.h" |
| 20 | #include "clang/Driver/Option.h" |
| 21 | #include "clang/Driver/ToolChain.h" |
Daniel Dunbar | 871adcf | 2009-03-18 07:06:02 +0000 | [diff] [blame] | 22 | #include "clang/Driver/Util.h" |
| 23 | |
| 24 | #include "llvm/ADT/SmallVector.h" |
| 25 | |
| 26 | #include "InputInfo.h" |
| 27 | |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 28 | using namespace clang::driver; |
| 29 | using namespace clang::driver::tools; |
| 30 | |
| 31 | void Clang::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | 871adcf | 2009-03-18 07:06:02 +0000 | [diff] [blame] | 32 | Job &Dest, |
| 33 | const InputInfo &Output, |
Daniel Dunbar | 62cf601 | 2009-03-18 06:07:59 +0000 | [diff] [blame] | 34 | const InputInfoList &Inputs, |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 35 | const ArgList &Args, |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 36 | const char *LinkingOutput) const { |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 37 | ArgStringList CmdArgs; |
| 38 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 39 | 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. |
| 48 | |
| 49 | // FIXME: This is a total hack. Copy the input header file |
| 50 | // to the output, so that it can be -include'd by clang. |
| 51 | assert(Inputs.size() == 1 && "Cannot make PCH with multiple inputs."); |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame^] | 52 | assert(Output.isFilename() && "Unexpected output"); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 53 | assert(!Inputs[0].isPipe() && "Unexpected pipe"); |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame^] | 54 | assert(Inputs[0].isFilename() && "Unexpected input"); |
| 55 | const char *InputPath = Inputs[0].getFilename(); |
| 56 | llvm::sys::Path OutputPath(Output.getFilename()); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 57 | OutputPath.eraseComponent(); |
| 58 | if (OutputPath.empty()) |
| 59 | OutputPath = llvm::sys::Path(InputPath).getLast(); |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 60 | else |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 61 | OutputPath.appendComponent(llvm::sys::Path(InputPath).getLast()); |
| 62 | if (!OutputPath.exists()) { |
| 63 | ArgStringList CpArgs; |
| 64 | CpArgs.push_back(InputPath); |
| 65 | CpArgs.push_back(Args.MakeArgString(OutputPath.c_str())); |
Daniel Dunbar | ecc6362 | 2009-03-18 23:34:15 +0000 | [diff] [blame] | 66 | const char *Exec = |
| 67 | Args.MakeArgString(getToolChain().GetProgramPath(C, "cp").c_str()); |
| 68 | C.getJobs().addJob(new Command(Exec, CpArgs)); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 69 | } |
| 70 | } else { |
| 71 | assert(isa<CompileJobAction>(JA) && "Invalid action for clang tool."); |
| 72 | |
| 73 | if (JA.getType() == types::TY_Nothing) { |
| 74 | CmdArgs.push_back("-fsyntax-only"); |
| 75 | } else if (JA.getType() == types::TY_LLVMAsm) { |
| 76 | CmdArgs.push_back("-emit-llvm"); |
| 77 | } else if (JA.getType() == types::TY_LLVMBC) { |
| 78 | CmdArgs.push_back("-emit-llvm-bc"); |
| 79 | } else if (JA.getType() == types::TY_PP_Asm) { |
| 80 | CmdArgs.push_back("-S"); |
| 81 | } |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 82 | } |
| 83 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 84 | // The make clang go fast button. |
| 85 | CmdArgs.push_back("-disable-free"); |
| 86 | |
| 87 | if (isa<AnalyzeJobAction>(JA)) { |
| 88 | // Add default argument set. |
| 89 | // |
| 90 | // FIXME: Move into clang? |
| 91 | CmdArgs.push_back("-warn-dead-stores"); |
| 92 | CmdArgs.push_back("-checker-cfref"); |
| 93 | CmdArgs.push_back("-warn-objc-methodsigs"); |
| 94 | // Do not enable the missing -dealloc check. |
| 95 | // '-warn-objc-missing-dealloc', |
| 96 | CmdArgs.push_back("-warn-objc-unused-ivars"); |
| 97 | |
| 98 | CmdArgs.push_back("-analyzer-output=plist"); |
| 99 | |
| 100 | // Add -Xanalyzer arguments when running as analyzer. |
| 101 | Args.AddAllArgValues(CmdArgs, options::OPT_Xanalyzer); |
| 102 | } else { |
| 103 | // Perform argument translation for LLVM backend. This |
| 104 | // takes some care in reconciling with llvm-gcc. The |
| 105 | // issue is that llvm-gcc translates these options based on |
| 106 | // the values in cc1, whereas we are processing based on |
| 107 | // the driver arguments. |
| 108 | // |
| 109 | // FIXME: This is currently broken for -f flags when -fno |
| 110 | // variants are present. |
| 111 | |
| 112 | // This comes from the default translation the driver + cc1 |
| 113 | // would do to enable flag_pic. |
| 114 | // |
| 115 | // FIXME: Centralize this code. |
| 116 | bool PICEnabled = (Args.hasArg(options::OPT_fPIC) || |
| 117 | Args.hasArg(options::OPT_fpic) || |
| 118 | Args.hasArg(options::OPT_fPIE) || |
| 119 | Args.hasArg(options::OPT_fpie)); |
| 120 | bool PICDisabled = (Args.hasArg(options::OPT_mkernel) || |
| 121 | Args.hasArg(options::OPT_static)); |
| 122 | const char *Model = getToolChain().GetForcedPicModel(); |
| 123 | if (!Model) { |
| 124 | if (Args.hasArg(options::OPT_mdynamic_no_pic)) |
| 125 | Model = "dynamic-no-pic"; |
| 126 | else if (PICDisabled) |
| 127 | Model = "static"; |
| 128 | else if (PICEnabled) |
| 129 | Model = "pic"; |
| 130 | else |
| 131 | Model = getToolChain().GetDefaultRelocationModel(); |
| 132 | } |
| 133 | CmdArgs.push_back("--relocation-model"); |
| 134 | CmdArgs.push_back(Model); |
| 135 | |
| 136 | if (Args.hasArg(options::OPT_ftime_report)) |
| 137 | CmdArgs.push_back("--time-passes"); |
| 138 | // FIXME: Set --enable-unsafe-fp-math. |
| 139 | if (!Args.hasArg(options::OPT_fomit_frame_pointer)) |
| 140 | CmdArgs.push_back("--disable-fp-elim"); |
| 141 | if (!Args.hasFlag(options::OPT_fzero_initialized_in_bss, |
| 142 | options::OPT_fno_zero_initialized_in_bss, |
| 143 | true)) |
| 144 | CmdArgs.push_back("--nozero-initialized-in-bss"); |
| 145 | if (Args.hasArg(options::OPT_dA)) |
| 146 | CmdArgs.push_back("--asm-verbose"); |
| 147 | if (Args.hasArg(options::OPT_fdebug_pass_structure)) |
| 148 | CmdArgs.push_back("--debug-pass=Structure"); |
| 149 | if (Args.hasArg(options::OPT_fdebug_pass_arguments)) |
| 150 | CmdArgs.push_back("--debug-pass=Arguments"); |
| 151 | // FIXME: set --inline-threshhold=50 if (optimize_size || optimize |
| 152 | // < 3) |
| 153 | if (Args.hasFlag(options::OPT_funwind_tables, |
| 154 | options::OPT_fno_unwind_tables, |
| 155 | getToolChain().IsUnwindTablesDefault())) |
| 156 | CmdArgs.push_back("--unwind-tables=1"); |
| 157 | else |
| 158 | CmdArgs.push_back("--unwind-tables=0"); |
| 159 | if (!Args.hasFlag(options::OPT_mred_zone, |
| 160 | options::OPT_mno_red_zone, |
| 161 | true)) |
| 162 | CmdArgs.push_back("--disable-red-zone"); |
| 163 | if (Args.hasFlag(options::OPT_msoft_float, |
| 164 | options::OPT_mno_soft_float, |
| 165 | false)) |
| 166 | CmdArgs.push_back("--soft-float"); |
| 167 | |
| 168 | // FIXME: Need target hooks. |
| 169 | if (memcmp(getToolChain().getPlatform().c_str(), "darwin", 6) == 0) { |
| 170 | if (getToolChain().getArchName() == "x86_64") |
| 171 | CmdArgs.push_back("--mcpu=core2"); |
| 172 | else if (getToolChain().getArchName() == "i386") |
| 173 | CmdArgs.push_back("--mcpu=yonah"); |
| 174 | } |
| 175 | |
| 176 | // FIXME: Ignores ordering. Also, we need to find a realistic |
| 177 | // solution for this. |
| 178 | static const struct { |
| 179 | options::ID Pos, Neg; |
| 180 | const char *Name; |
| 181 | } FeatureOptions[] = { |
| 182 | { options::OPT_mmmx, options::OPT_mno_mmx, "mmx" }, |
| 183 | { options::OPT_msse, options::OPT_mno_sse, "sse" }, |
| 184 | { options::OPT_msse2, options::OPT_mno_sse2, "sse2" }, |
| 185 | { options::OPT_msse3, options::OPT_mno_sse3, "sse3" }, |
| 186 | { options::OPT_mssse3, options::OPT_mno_ssse3, "ssse3" }, |
| 187 | { options::OPT_msse41, options::OPT_mno_sse41, "sse41" }, |
| 188 | { options::OPT_msse42, options::OPT_mno_sse42, "sse42" }, |
| 189 | { options::OPT_msse4a, options::OPT_mno_sse4a, "sse4a" }, |
| 190 | { options::OPT_m3dnow, options::OPT_mno_3dnow, "3dnow" }, |
| 191 | { options::OPT_m3dnowa, options::OPT_mno_3dnowa, "3dnowa" } |
| 192 | }; |
| 193 | const unsigned NumFeatureOptions = |
| 194 | sizeof(FeatureOptions)/sizeof(FeatureOptions[0]); |
| 195 | |
| 196 | // FIXME: Avoid std::string |
| 197 | std::string Attrs; |
| 198 | for (unsigned i=0; i < NumFeatureOptions; ++i) { |
| 199 | if (Args.hasArg(FeatureOptions[i].Pos)) { |
| 200 | Attrs += '+'; |
| 201 | Attrs += FeatureOptions[i].Name; |
| 202 | } else if (Args.hasArg(FeatureOptions[i].Neg)) { |
| 203 | Attrs += '-'; |
| 204 | Attrs += FeatureOptions[i].Name; |
| 205 | } |
| 206 | } |
| 207 | if (!Attrs.empty()) { |
| 208 | CmdArgs.push_back("--mattr"); |
| 209 | CmdArgs.push_back(Args.MakeArgString(Attrs.c_str())); |
| 210 | } |
| 211 | |
| 212 | if (Args.hasFlag(options::OPT_fmath_errno, |
| 213 | options::OPT_fno_math_errno, |
| 214 | getToolChain().IsMathErrnoDefault())) |
| 215 | CmdArgs.push_back("--fmath-errno=1"); |
| 216 | else |
| 217 | CmdArgs.push_back("--fmath-errno=0"); |
| 218 | |
| 219 | if (Arg *A = Args.getLastArg(options::OPT_flimited_precision_EQ)) { |
| 220 | CmdArgs.push_back("--limit-float-precision"); |
| 221 | CmdArgs.push_back(A->getValue(Args)); |
| 222 | } |
| 223 | |
| 224 | // FIXME: Add --stack-protector-buffer-size=<xxx> on |
| 225 | // -fstack-protect. |
| 226 | |
| 227 | Args.AddLastArg(CmdArgs, options::OPT_MD); |
| 228 | Args.AddLastArg(CmdArgs, options::OPT_MM); |
| 229 | Args.AddAllArgs(CmdArgs, options::OPT_MF); |
| 230 | Args.AddLastArg(CmdArgs, options::OPT_MP); |
| 231 | Args.AddAllArgs(CmdArgs, options::OPT_MT); |
| 232 | |
| 233 | Arg *Unsupported = Args.getLastArg(options::OPT_M); |
| 234 | if (!Unsupported) |
| 235 | Unsupported = Args.getLastArg(options::OPT_MM); |
| 236 | if (!Unsupported) |
| 237 | Unsupported = Args.getLastArg(options::OPT_MG); |
| 238 | if (!Unsupported) |
| 239 | Unsupported = Args.getLastArg(options::OPT_MQ); |
| 240 | if (Unsupported) { |
| 241 | const Driver &D = getToolChain().getHost().getDriver(); |
| 242 | D.Diag(clang::diag::err_drv_unsupported_opt) |
| 243 | << Unsupported->getOption().getName(); |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | Args.AddAllArgs(CmdArgs, options::OPT_v); |
| 248 | Args.AddAllArgs(CmdArgs, options::OPT_D, options::OPT_U); |
| 249 | Args.AddAllArgs(CmdArgs, options::OPT_I_Group, options::OPT_F); |
| 250 | Args.AddLastArg(CmdArgs, options::OPT_P); |
| 251 | Args.AddAllArgs(CmdArgs, options::OPT_mmacosx_version_min_EQ); |
| 252 | |
| 253 | // Special case debug options to only pass -g to clang. This is |
| 254 | // wrong. |
| 255 | if (Args.hasArg(options::OPT_g_Group)) |
| 256 | CmdArgs.push_back("-g"); |
| 257 | |
| 258 | Args.AddLastArg(CmdArgs, options::OPT_nostdinc); |
| 259 | |
| 260 | // FIXME: Clang isn't going to accept just anything here. |
| 261 | Args.AddAllArgs(CmdArgs, options::OPT_i_Group); |
| 262 | |
| 263 | // Automatically load .pth or .gch files which match -include |
| 264 | // options. It's wonky, but we include looking for .gch so we can |
| 265 | // support seamless replacement into a build system already set up |
| 266 | // to be generating .gch files. |
| 267 | |
| 268 | // FIXME: Need to use an iterator for this to be efficient. |
| 269 | for (ArgList::const_iterator |
| 270 | it = Args.begin(), ie = Args.end(); it != ie; ++it) { |
| 271 | const Arg *A = *it; |
| 272 | if (A->getOption().matches(options::OPT_include)) { |
| 273 | llvm::sys::Path P(A->getValue(Args)); |
| 274 | P.appendSuffix("pth"); |
| 275 | if (P.exists()) { |
| 276 | CmdArgs.push_back("-token-cache"); |
| 277 | CmdArgs.push_back(Args.MakeArgString(P.c_str())); |
| 278 | } else { |
| 279 | P.eraseSuffix(); |
| 280 | P.appendSuffix("gch"); |
| 281 | if (P.exists()) { |
| 282 | CmdArgs.push_back("-token-cache"); |
| 283 | CmdArgs.push_back(Args.MakeArgString(P.c_str())); |
| 284 | } |
| 285 | } |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | // Manually translate -O to -O1; let clang reject others. |
| 290 | if (Arg *A = Args.getLastArg(options::OPT_O)) { |
| 291 | if (A->getValue(Args)[0] == '\0') |
| 292 | CmdArgs.push_back("-O1"); |
| 293 | else |
Daniel Dunbar | 5697aa0 | 2009-03-18 23:39:35 +0000 | [diff] [blame] | 294 | A->render(Args, CmdArgs); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | Args.AddAllArgs(CmdArgs, options::OPT_clang_W_Group, options::OPT_pedantic_Group); |
| 298 | Args.AddLastArg(CmdArgs, options::OPT_w); |
| 299 | Args.AddAllArgs(CmdArgs, options::OPT_std_EQ, options::OPT_ansi, |
| 300 | options::OPT_trigraphs); |
| 301 | |
| 302 | if (Arg *A = Args.getLastArg(options::OPT_ftemplate_depth_)) { |
| 303 | CmdArgs.push_back("-ftemplate-depth"); |
| 304 | CmdArgs.push_back(A->getValue(Args)); |
| 305 | } |
| 306 | |
| 307 | Args.AddAllArgs(CmdArgs, options::OPT_clang_f_Group); |
| 308 | |
| 309 | Args.AddLastArg(CmdArgs, options::OPT_dM); |
| 310 | |
| 311 | Args.AddAllArgValues(CmdArgs, options::OPT_Xclang); |
| 312 | |
| 313 | // FIXME: Always pass the full triple once we aren't concerned with |
| 314 | // ccc compat. |
| 315 | CmdArgs.push_back("-arch"); |
| 316 | CmdArgs.push_back(getToolChain().getArchName().c_str()); |
| 317 | |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 318 | if (Output.isPipe()) { |
| 319 | CmdArgs.push_back("-o"); |
| 320 | CmdArgs.push_back("-"); |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame^] | 321 | } else if (Output.isFilename()) { |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 322 | CmdArgs.push_back("-o"); |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame^] | 323 | CmdArgs.push_back(Output.getFilename()); |
| 324 | } else { |
| 325 | assert(Output.isNothing() && "Invalid output."); |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 326 | } |
| 327 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 328 | for (InputInfoList::const_iterator |
| 329 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 330 | const InputInfo &II = *it; |
| 331 | CmdArgs.push_back("-x"); |
| 332 | CmdArgs.push_back(types::getTypeName(II.getType())); |
| 333 | if (II.isPipe()) |
| 334 | CmdArgs.push_back("-"); |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame^] | 335 | else if (II.isFilename()) |
| 336 | CmdArgs.push_back(II.getFilename()); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 337 | else |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame^] | 338 | II.getInputArg().renderAsInput(Args, CmdArgs); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | const char *Exec = |
| 342 | Args.MakeArgString(getToolChain().GetProgramPath(C, "clang").c_str()); |
| 343 | Dest.addCommand(new Command(Exec, CmdArgs)); |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 344 | } |
| 345 | |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 346 | void gcc::Common::ConstructJob(Compilation &C, const JobAction &JA, |
| 347 | Job &Dest, |
| 348 | const InputInfo &Output, |
| 349 | const InputInfoList &Inputs, |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 350 | const ArgList &Args, |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 351 | const char *LinkingOutput) const { |
| 352 | ArgStringList CmdArgs; |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 353 | |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 354 | for (ArgList::const_iterator |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 355 | it = Args.begin(), ie = Args.end(); it != ie; ++it) { |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 356 | Arg *A = *it; |
| 357 | if (A->getOption().hasForwardToGCC()) |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 358 | A->render(Args, CmdArgs); |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | RenderExtraToolArgs(CmdArgs); |
| 362 | |
| 363 | // If using a driver driver, force the arch. |
| 364 | if (getToolChain().getHost().useDriverDriver()) { |
| 365 | CmdArgs.push_back("-arch"); |
| 366 | CmdArgs.push_back(getToolChain().getArchName().c_str()); |
| 367 | } |
| 368 | |
| 369 | if (Output.isPipe()) { |
| 370 | CmdArgs.push_back("-o"); |
| 371 | CmdArgs.push_back("-"); |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame^] | 372 | } else if (Output.isFilename()) { |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 373 | CmdArgs.push_back("-o"); |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame^] | 374 | CmdArgs.push_back(Output.getFilename()); |
| 375 | } else { |
| 376 | assert(Output.isNothing() && "Unexpected output"); |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 377 | CmdArgs.push_back("-fsyntax-only"); |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame^] | 378 | } |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 379 | |
| 380 | |
| 381 | // Only pass -x if gcc will understand it; otherwise hope gcc |
| 382 | // understands the suffix correctly. The main use case this would go |
| 383 | // wrong in is for linker inputs if they happened to have an odd |
| 384 | // suffix; really the only way to get this to happen is a command |
| 385 | // like '-x foobar a.c' which will treat a.c like a linker input. |
| 386 | // |
| 387 | // FIXME: For the linker case specifically, can we safely convert |
| 388 | // inputs into '-Wl,' options? |
| 389 | for (InputInfoList::const_iterator |
| 390 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 391 | const InputInfo &II = *it; |
| 392 | if (types::canTypeBeUserSpecified(II.getType())) { |
| 393 | CmdArgs.push_back("-x"); |
| 394 | CmdArgs.push_back(types::getTypeName(II.getType())); |
| 395 | } |
| 396 | |
| 397 | if (II.isPipe()) |
| 398 | CmdArgs.push_back("-"); |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame^] | 399 | else if (II.isFilename()) |
| 400 | CmdArgs.push_back(II.getFilename()); |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 401 | else |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame^] | 402 | // Don't render as input, we need gcc to do the translations. |
| 403 | II.getInputArg().render(Args, CmdArgs); |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 404 | } |
| 405 | |
Daniel Dunbar | 632f50e | 2009-03-18 21:34:08 +0000 | [diff] [blame] | 406 | const char *Exec = |
| 407 | Args.MakeArgString(getToolChain().GetProgramPath(C, "gcc").c_str()); |
| 408 | Dest.addCommand(new Command(Exec, CmdArgs)); |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 409 | } |
| 410 | |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 411 | void gcc::Preprocess::RenderExtraToolArgs(ArgStringList &CmdArgs) const { |
| 412 | CmdArgs.push_back("-E"); |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 413 | } |
| 414 | |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 415 | void gcc::Precompile::RenderExtraToolArgs(ArgStringList &CmdArgs) const { |
| 416 | // The type is good enough. |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 417 | } |
| 418 | |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 419 | void gcc::Compile::RenderExtraToolArgs(ArgStringList &CmdArgs) const { |
| 420 | CmdArgs.push_back("-S"); |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 421 | } |
| 422 | |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 423 | void gcc::Assemble::RenderExtraToolArgs(ArgStringList &CmdArgs) const { |
| 424 | CmdArgs.push_back("-c"); |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 425 | } |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 426 | |
| 427 | void gcc::Link::RenderExtraToolArgs(ArgStringList &CmdArgs) const { |
| 428 | // The types are (hopefully) good enough. |
| 429 | } |
| 430 | |