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. |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 48 | } 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 Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 60 | } |
| 61 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 62 | // 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"); |
| 123 | if (Args.hasArg(options::OPT_dA)) |
| 124 | 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 Dunbar | 55b3b5f | 2009-03-19 17:36:04 +0000 | [diff] [blame] | 178 | if (!Attrs.empty()) |
| 179 | Attrs += ','; |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 180 | Attrs += '+'; |
| 181 | Attrs += FeatureOptions[i].Name; |
| 182 | } else if (Args.hasArg(FeatureOptions[i].Neg)) { |
Daniel Dunbar | 55b3b5f | 2009-03-19 17:36:04 +0000 | [diff] [blame] | 183 | if (!Attrs.empty()) |
| 184 | Attrs += ','; |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 185 | 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 Dunbar | 546654a | 2009-03-24 07:20:59 +0000 | [diff] [blame^] | 210 | Args.AddLastArg(CmdArgs, options::OPT_MMD); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 211 | 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 Dunbar | 049853d | 2009-03-20 19:38:56 +0000 | [diff] [blame] | 243 | // FIXME: Use iterator. |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 244 | |
Daniel Dunbar | 049853d | 2009-03-20 19:38:56 +0000 | [diff] [blame] | 245 | // 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 Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 249 | for (ArgList::const_iterator |
| 250 | it = Args.begin(), ie = Args.end(); it != ie; ++it) { |
| 251 | const Arg *A = *it; |
Daniel Dunbar | 049853d | 2009-03-20 19:38:56 +0000 | [diff] [blame] | 252 | if (!A->getOption().matches(options::OPT_i_Group)) |
| 253 | continue; |
| 254 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 255 | if (A->getOption().matches(options::OPT_include)) { |
Daniel Dunbar | 049853d | 2009-03-20 19:38:56 +0000 | [diff] [blame] | 256 | bool FoundPTH = false; |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 257 | llvm::sys::Path P(A->getValue(Args)); |
| 258 | P.appendSuffix("pth"); |
| 259 | if (P.exists()) { |
Daniel Dunbar | 049853d | 2009-03-20 19:38:56 +0000 | [diff] [blame] | 260 | FoundPTH = true; |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 261 | } else { |
| 262 | P.eraseSuffix(); |
| 263 | P.appendSuffix("gch"); |
Daniel Dunbar | 049853d | 2009-03-20 19:38:56 +0000 | [diff] [blame] | 264 | 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 Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 273 | } |
| 274 | } |
Daniel Dunbar | 049853d | 2009-03-20 19:38:56 +0000 | [diff] [blame] | 275 | |
| 276 | // Not translated, render as usual. |
| 277 | A->claim(); |
| 278 | A->render(Args, CmdArgs); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | // Manually translate -O to -O1; let clang reject others. |
| 282 | if (Arg *A = Args.getLastArg(options::OPT_O)) { |
| 283 | if (A->getValue(Args)[0] == '\0') |
| 284 | CmdArgs.push_back("-O1"); |
| 285 | else |
Daniel Dunbar | 5697aa0 | 2009-03-18 23:39:35 +0000 | [diff] [blame] | 286 | A->render(Args, CmdArgs); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 287 | } |
| 288 | |
Daniel Dunbar | ff7488d | 2009-03-20 00:52:38 +0000 | [diff] [blame] | 289 | Args.AddAllArgs(CmdArgs, options::OPT_clang_W_Group, |
| 290 | options::OPT_pedantic_Group); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 291 | Args.AddLastArg(CmdArgs, options::OPT_w); |
| 292 | Args.AddAllArgs(CmdArgs, options::OPT_std_EQ, options::OPT_ansi, |
| 293 | options::OPT_trigraphs); |
| 294 | |
| 295 | if (Arg *A = Args.getLastArg(options::OPT_ftemplate_depth_)) { |
| 296 | CmdArgs.push_back("-ftemplate-depth"); |
| 297 | CmdArgs.push_back(A->getValue(Args)); |
| 298 | } |
| 299 | |
| 300 | Args.AddAllArgs(CmdArgs, options::OPT_clang_f_Group); |
| 301 | |
| 302 | Args.AddLastArg(CmdArgs, options::OPT_dM); |
| 303 | |
| 304 | Args.AddAllArgValues(CmdArgs, options::OPT_Xclang); |
| 305 | |
| 306 | // FIXME: Always pass the full triple once we aren't concerned with |
| 307 | // ccc compat. |
| 308 | CmdArgs.push_back("-arch"); |
| 309 | CmdArgs.push_back(getToolChain().getArchName().c_str()); |
| 310 | |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 311 | if (Output.isPipe()) { |
| 312 | CmdArgs.push_back("-o"); |
| 313 | CmdArgs.push_back("-"); |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 314 | } else if (Output.isFilename()) { |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 315 | CmdArgs.push_back("-o"); |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 316 | CmdArgs.push_back(Output.getFilename()); |
| 317 | } else { |
| 318 | assert(Output.isNothing() && "Invalid output."); |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 319 | } |
| 320 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 321 | for (InputInfoList::const_iterator |
| 322 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 323 | const InputInfo &II = *it; |
| 324 | CmdArgs.push_back("-x"); |
| 325 | CmdArgs.push_back(types::getTypeName(II.getType())); |
| 326 | if (II.isPipe()) |
| 327 | CmdArgs.push_back("-"); |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 328 | else if (II.isFilename()) |
| 329 | CmdArgs.push_back(II.getFilename()); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 330 | else |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 331 | II.getInputArg().renderAsInput(Args, CmdArgs); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | const char *Exec = |
Daniel Dunbar | d7d5f02 | 2009-03-24 02:24:46 +0000 | [diff] [blame] | 335 | Args.MakeArgString(getToolChain().GetProgramPath(C, "clang-cc").c_str()); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 336 | Dest.addCommand(new Command(Exec, CmdArgs)); |
Daniel Dunbar | a880db0 | 2009-03-23 19:03:36 +0000 | [diff] [blame] | 337 | |
| 338 | // Claim some arguments which clang doesn't support, but we don't |
| 339 | // care to warn the user about. |
| 340 | |
| 341 | // FIXME: Use iterator. |
| 342 | for (ArgList::const_iterator |
| 343 | it = Args.begin(), ie = Args.end(); it != ie; ++it) { |
| 344 | const Arg *A = *it; |
| 345 | if (A->getOption().matches(options::OPT_clang_ignored_W_Group) || |
| 346 | A->getOption().matches(options::OPT_clang_ignored_f_Group)) |
| 347 | A->claim(); |
| 348 | } |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 349 | } |
| 350 | |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 351 | void gcc::Common::ConstructJob(Compilation &C, const JobAction &JA, |
| 352 | Job &Dest, |
| 353 | const InputInfo &Output, |
| 354 | const InputInfoList &Inputs, |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 355 | const ArgList &Args, |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 356 | const char *LinkingOutput) const { |
| 357 | ArgStringList CmdArgs; |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 358 | |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 359 | for (ArgList::const_iterator |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 360 | it = Args.begin(), ie = Args.end(); it != ie; ++it) { |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 361 | Arg *A = *it; |
Daniel Dunbar | 7587719 | 2009-03-19 07:55:12 +0000 | [diff] [blame] | 362 | if (A->getOption().hasForwardToGCC()) { |
| 363 | // It is unfortunate that we have to claim here, as this means |
| 364 | // we will basically never report anything interesting for |
| 365 | // platforms using a generic gcc. |
| 366 | A->claim(); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 367 | A->render(Args, CmdArgs); |
Daniel Dunbar | 7587719 | 2009-03-19 07:55:12 +0000 | [diff] [blame] | 368 | } |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | RenderExtraToolArgs(CmdArgs); |
| 372 | |
| 373 | // If using a driver driver, force the arch. |
| 374 | if (getToolChain().getHost().useDriverDriver()) { |
| 375 | CmdArgs.push_back("-arch"); |
| 376 | CmdArgs.push_back(getToolChain().getArchName().c_str()); |
| 377 | } |
| 378 | |
| 379 | if (Output.isPipe()) { |
| 380 | CmdArgs.push_back("-o"); |
| 381 | CmdArgs.push_back("-"); |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 382 | } else if (Output.isFilename()) { |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 383 | CmdArgs.push_back("-o"); |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 384 | CmdArgs.push_back(Output.getFilename()); |
| 385 | } else { |
| 386 | assert(Output.isNothing() && "Unexpected output"); |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 387 | CmdArgs.push_back("-fsyntax-only"); |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 388 | } |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 389 | |
| 390 | |
| 391 | // Only pass -x if gcc will understand it; otherwise hope gcc |
| 392 | // understands the suffix correctly. The main use case this would go |
| 393 | // wrong in is for linker inputs if they happened to have an odd |
| 394 | // suffix; really the only way to get this to happen is a command |
| 395 | // like '-x foobar a.c' which will treat a.c like a linker input. |
| 396 | // |
| 397 | // FIXME: For the linker case specifically, can we safely convert |
| 398 | // inputs into '-Wl,' options? |
| 399 | for (InputInfoList::const_iterator |
| 400 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 401 | const InputInfo &II = *it; |
| 402 | if (types::canTypeBeUserSpecified(II.getType())) { |
| 403 | CmdArgs.push_back("-x"); |
| 404 | CmdArgs.push_back(types::getTypeName(II.getType())); |
| 405 | } |
| 406 | |
| 407 | if (II.isPipe()) |
| 408 | CmdArgs.push_back("-"); |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 409 | else if (II.isFilename()) |
| 410 | CmdArgs.push_back(II.getFilename()); |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 411 | else |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 412 | // Don't render as input, we need gcc to do the translations. |
| 413 | II.getInputArg().render(Args, CmdArgs); |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 414 | } |
| 415 | |
Daniel Dunbar | 632f50e | 2009-03-18 21:34:08 +0000 | [diff] [blame] | 416 | const char *Exec = |
| 417 | Args.MakeArgString(getToolChain().GetProgramPath(C, "gcc").c_str()); |
| 418 | Dest.addCommand(new Command(Exec, CmdArgs)); |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 419 | } |
| 420 | |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 421 | void gcc::Preprocess::RenderExtraToolArgs(ArgStringList &CmdArgs) const { |
| 422 | CmdArgs.push_back("-E"); |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 423 | } |
| 424 | |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 425 | void gcc::Precompile::RenderExtraToolArgs(ArgStringList &CmdArgs) const { |
| 426 | // The type is good enough. |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 427 | } |
| 428 | |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 429 | void gcc::Compile::RenderExtraToolArgs(ArgStringList &CmdArgs) const { |
| 430 | CmdArgs.push_back("-S"); |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 431 | } |
| 432 | |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 433 | void gcc::Assemble::RenderExtraToolArgs(ArgStringList &CmdArgs) const { |
| 434 | CmdArgs.push_back("-c"); |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 435 | } |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 436 | |
| 437 | void gcc::Link::RenderExtraToolArgs(ArgStringList &CmdArgs) const { |
| 438 | // The types are (hopefully) good enough. |
| 439 | } |
| 440 | |
Daniel Dunbar | 8cac5f7 | 2009-03-20 16:06:39 +0000 | [diff] [blame] | 441 | void darwin::Assemble::ConstructJob(Compilation &C, const JobAction &JA, |
| 442 | Job &Dest, const InputInfo &Output, |
| 443 | const InputInfoList &Inputs, |
| 444 | const ArgList &Args, |
| 445 | const char *LinkingOutput) const { |
| 446 | ArgStringList CmdArgs; |
| 447 | |
| 448 | assert(Inputs.size() == 1 && "Unexpected number of inputs."); |
| 449 | const InputInfo &Input = Inputs[0]; |
| 450 | |
| 451 | // Bit of a hack, this is only used for original inputs. |
| 452 | if (Input.isFilename() && |
| 453 | strcmp(Input.getFilename(), Input.getBaseInput()) == 0 && |
| 454 | Args.hasArg(options::OPT_g_Group)) |
| 455 | CmdArgs.push_back("--gstabs"); |
| 456 | |
| 457 | // Derived from asm spec. |
| 458 | CmdArgs.push_back("-arch"); |
| 459 | CmdArgs.push_back(getToolChain().getArchName().c_str()); |
| 460 | |
| 461 | CmdArgs.push_back("-force_cpusubtype_ALL"); |
| 462 | if ((Args.hasArg(options::OPT_mkernel) || |
| 463 | Args.hasArg(options::OPT_static) || |
| 464 | Args.hasArg(options::OPT_fapple_kext)) && |
| 465 | !Args.hasArg(options::OPT_dynamic)) |
| 466 | CmdArgs.push_back("-static"); |
| 467 | |
| 468 | Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, |
| 469 | options::OPT_Xassembler); |
| 470 | |
| 471 | assert(Output.isFilename() && "Unexpected lipo output."); |
| 472 | CmdArgs.push_back("-o"); |
| 473 | CmdArgs.push_back(Output.getFilename()); |
| 474 | |
| 475 | if (Input.isPipe()) { |
| 476 | CmdArgs.push_back("-"); |
| 477 | } else { |
| 478 | assert(Input.isFilename() && "Invalid input."); |
| 479 | CmdArgs.push_back(Input.getFilename()); |
| 480 | } |
| 481 | |
| 482 | // asm_final spec is empty. |
| 483 | |
| 484 | const char *Exec = |
| 485 | Args.MakeArgString(getToolChain().GetProgramPath(C, "as").c_str()); |
| 486 | Dest.addCommand(new Command(Exec, CmdArgs)); |
| 487 | } |
Daniel Dunbar | ff7488d | 2009-03-20 00:52:38 +0000 | [diff] [blame] | 488 | |
| 489 | void darwin::Lipo::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | 8cac5f7 | 2009-03-20 16:06:39 +0000 | [diff] [blame] | 490 | Job &Dest, const InputInfo &Output, |
Daniel Dunbar | ff7488d | 2009-03-20 00:52:38 +0000 | [diff] [blame] | 491 | const InputInfoList &Inputs, |
| 492 | const ArgList &Args, |
| 493 | const char *LinkingOutput) const { |
| 494 | ArgStringList CmdArgs; |
| 495 | |
| 496 | CmdArgs.push_back("-create"); |
| 497 | assert(Output.isFilename() && "Unexpected lipo output."); |
Daniel Dunbar | a428df8 | 2009-03-24 00:24:37 +0000 | [diff] [blame] | 498 | |
| 499 | CmdArgs.push_back("-output"); |
Daniel Dunbar | ff7488d | 2009-03-20 00:52:38 +0000 | [diff] [blame] | 500 | CmdArgs.push_back(Output.getFilename()); |
Daniel Dunbar | a428df8 | 2009-03-24 00:24:37 +0000 | [diff] [blame] | 501 | |
Daniel Dunbar | ff7488d | 2009-03-20 00:52:38 +0000 | [diff] [blame] | 502 | for (InputInfoList::const_iterator |
| 503 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 504 | const InputInfo &II = *it; |
| 505 | assert(II.isFilename() && "Unexpected lipo input."); |
| 506 | CmdArgs.push_back(II.getFilename()); |
| 507 | } |
| 508 | const char *Exec = |
| 509 | Args.MakeArgString(getToolChain().GetProgramPath(C, "lipo").c_str()); |
| 510 | Dest.addCommand(new Command(Exec, CmdArgs)); |
| 511 | } |