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"); |
Ted Kremenek | 9b646da | 2009-03-25 00:38:14 +0000 | [diff] [blame] | 71 | CmdArgs.push_back("-analyzer-eagerly-assume"); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 72 | CmdArgs.push_back("-warn-objc-methodsigs"); |
| 73 | // Do not enable the missing -dealloc check. |
| 74 | // '-warn-objc-missing-dealloc', |
| 75 | CmdArgs.push_back("-warn-objc-unused-ivars"); |
| 76 | |
| 77 | CmdArgs.push_back("-analyzer-output=plist"); |
| 78 | |
| 79 | // Add -Xanalyzer arguments when running as analyzer. |
| 80 | Args.AddAllArgValues(CmdArgs, options::OPT_Xanalyzer); |
| 81 | } else { |
| 82 | // Perform argument translation for LLVM backend. This |
| 83 | // takes some care in reconciling with llvm-gcc. The |
| 84 | // issue is that llvm-gcc translates these options based on |
| 85 | // the values in cc1, whereas we are processing based on |
| 86 | // the driver arguments. |
| 87 | // |
| 88 | // FIXME: This is currently broken for -f flags when -fno |
| 89 | // variants are present. |
| 90 | |
| 91 | // This comes from the default translation the driver + cc1 |
| 92 | // would do to enable flag_pic. |
| 93 | // |
| 94 | // FIXME: Centralize this code. |
| 95 | bool PICEnabled = (Args.hasArg(options::OPT_fPIC) || |
| 96 | Args.hasArg(options::OPT_fpic) || |
| 97 | Args.hasArg(options::OPT_fPIE) || |
| 98 | Args.hasArg(options::OPT_fpie)); |
| 99 | bool PICDisabled = (Args.hasArg(options::OPT_mkernel) || |
| 100 | Args.hasArg(options::OPT_static)); |
| 101 | const char *Model = getToolChain().GetForcedPicModel(); |
| 102 | if (!Model) { |
| 103 | if (Args.hasArg(options::OPT_mdynamic_no_pic)) |
| 104 | Model = "dynamic-no-pic"; |
| 105 | else if (PICDisabled) |
| 106 | Model = "static"; |
| 107 | else if (PICEnabled) |
| 108 | Model = "pic"; |
| 109 | else |
| 110 | Model = getToolChain().GetDefaultRelocationModel(); |
| 111 | } |
| 112 | CmdArgs.push_back("--relocation-model"); |
| 113 | CmdArgs.push_back(Model); |
| 114 | |
| 115 | if (Args.hasArg(options::OPT_ftime_report)) |
| 116 | CmdArgs.push_back("--time-passes"); |
| 117 | // FIXME: Set --enable-unsafe-fp-math. |
| 118 | if (!Args.hasArg(options::OPT_fomit_frame_pointer)) |
| 119 | CmdArgs.push_back("--disable-fp-elim"); |
| 120 | if (!Args.hasFlag(options::OPT_fzero_initialized_in_bss, |
| 121 | options::OPT_fno_zero_initialized_in_bss, |
| 122 | true)) |
| 123 | CmdArgs.push_back("--nozero-initialized-in-bss"); |
Daniel Dunbar | b3fd500 | 2009-03-24 17:59:06 +0000 | [diff] [blame] | 124 | if (Args.hasArg(options::OPT_dA) || Args.hasArg(options::OPT_fverbose_asm)) |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 125 | CmdArgs.push_back("--asm-verbose"); |
| 126 | if (Args.hasArg(options::OPT_fdebug_pass_structure)) |
| 127 | CmdArgs.push_back("--debug-pass=Structure"); |
| 128 | if (Args.hasArg(options::OPT_fdebug_pass_arguments)) |
| 129 | CmdArgs.push_back("--debug-pass=Arguments"); |
| 130 | // FIXME: set --inline-threshhold=50 if (optimize_size || optimize |
| 131 | // < 3) |
| 132 | if (Args.hasFlag(options::OPT_funwind_tables, |
| 133 | options::OPT_fno_unwind_tables, |
| 134 | getToolChain().IsUnwindTablesDefault())) |
| 135 | CmdArgs.push_back("--unwind-tables=1"); |
| 136 | else |
| 137 | CmdArgs.push_back("--unwind-tables=0"); |
| 138 | if (!Args.hasFlag(options::OPT_mred_zone, |
| 139 | options::OPT_mno_red_zone, |
| 140 | true)) |
| 141 | CmdArgs.push_back("--disable-red-zone"); |
| 142 | if (Args.hasFlag(options::OPT_msoft_float, |
| 143 | options::OPT_mno_soft_float, |
| 144 | false)) |
| 145 | CmdArgs.push_back("--soft-float"); |
| 146 | |
| 147 | // FIXME: Need target hooks. |
| 148 | if (memcmp(getToolChain().getPlatform().c_str(), "darwin", 6) == 0) { |
| 149 | if (getToolChain().getArchName() == "x86_64") |
| 150 | CmdArgs.push_back("--mcpu=core2"); |
| 151 | else if (getToolChain().getArchName() == "i386") |
| 152 | CmdArgs.push_back("--mcpu=yonah"); |
| 153 | } |
| 154 | |
| 155 | // FIXME: Ignores ordering. Also, we need to find a realistic |
| 156 | // solution for this. |
| 157 | static const struct { |
| 158 | options::ID Pos, Neg; |
| 159 | const char *Name; |
| 160 | } FeatureOptions[] = { |
| 161 | { options::OPT_mmmx, options::OPT_mno_mmx, "mmx" }, |
| 162 | { options::OPT_msse, options::OPT_mno_sse, "sse" }, |
| 163 | { options::OPT_msse2, options::OPT_mno_sse2, "sse2" }, |
| 164 | { options::OPT_msse3, options::OPT_mno_sse3, "sse3" }, |
| 165 | { options::OPT_mssse3, options::OPT_mno_ssse3, "ssse3" }, |
| 166 | { options::OPT_msse41, options::OPT_mno_sse41, "sse41" }, |
| 167 | { options::OPT_msse42, options::OPT_mno_sse42, "sse42" }, |
| 168 | { options::OPT_msse4a, options::OPT_mno_sse4a, "sse4a" }, |
| 169 | { options::OPT_m3dnow, options::OPT_mno_3dnow, "3dnow" }, |
| 170 | { options::OPT_m3dnowa, options::OPT_mno_3dnowa, "3dnowa" } |
| 171 | }; |
| 172 | const unsigned NumFeatureOptions = |
| 173 | sizeof(FeatureOptions)/sizeof(FeatureOptions[0]); |
| 174 | |
| 175 | // FIXME: Avoid std::string |
| 176 | std::string Attrs; |
| 177 | for (unsigned i=0; i < NumFeatureOptions; ++i) { |
| 178 | if (Args.hasArg(FeatureOptions[i].Pos)) { |
Daniel Dunbar | 55b3b5f | 2009-03-19 17:36:04 +0000 | [diff] [blame] | 179 | if (!Attrs.empty()) |
| 180 | Attrs += ','; |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 181 | Attrs += '+'; |
| 182 | Attrs += FeatureOptions[i].Name; |
| 183 | } else if (Args.hasArg(FeatureOptions[i].Neg)) { |
Daniel Dunbar | 55b3b5f | 2009-03-19 17:36:04 +0000 | [diff] [blame] | 184 | if (!Attrs.empty()) |
| 185 | Attrs += ','; |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 186 | Attrs += '-'; |
| 187 | Attrs += FeatureOptions[i].Name; |
| 188 | } |
| 189 | } |
| 190 | if (!Attrs.empty()) { |
| 191 | CmdArgs.push_back("--mattr"); |
| 192 | CmdArgs.push_back(Args.MakeArgString(Attrs.c_str())); |
| 193 | } |
| 194 | |
| 195 | if (Args.hasFlag(options::OPT_fmath_errno, |
| 196 | options::OPT_fno_math_errno, |
| 197 | getToolChain().IsMathErrnoDefault())) |
| 198 | CmdArgs.push_back("--fmath-errno=1"); |
| 199 | else |
| 200 | CmdArgs.push_back("--fmath-errno=0"); |
| 201 | |
| 202 | if (Arg *A = Args.getLastArg(options::OPT_flimited_precision_EQ)) { |
| 203 | CmdArgs.push_back("--limit-float-precision"); |
| 204 | CmdArgs.push_back(A->getValue(Args)); |
| 205 | } |
| 206 | |
| 207 | // FIXME: Add --stack-protector-buffer-size=<xxx> on |
| 208 | // -fstack-protect. |
| 209 | |
| 210 | Args.AddLastArg(CmdArgs, options::OPT_MD); |
Daniel Dunbar | 546654a | 2009-03-24 07:20:59 +0000 | [diff] [blame] | 211 | Args.AddLastArg(CmdArgs, options::OPT_MMD); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 212 | Args.AddAllArgs(CmdArgs, options::OPT_MF); |
| 213 | Args.AddLastArg(CmdArgs, options::OPT_MP); |
| 214 | Args.AddAllArgs(CmdArgs, options::OPT_MT); |
| 215 | |
| 216 | Arg *Unsupported = Args.getLastArg(options::OPT_M); |
| 217 | if (!Unsupported) |
| 218 | Unsupported = Args.getLastArg(options::OPT_MM); |
| 219 | if (!Unsupported) |
| 220 | Unsupported = Args.getLastArg(options::OPT_MG); |
| 221 | if (!Unsupported) |
| 222 | Unsupported = Args.getLastArg(options::OPT_MQ); |
| 223 | if (Unsupported) { |
| 224 | const Driver &D = getToolChain().getHost().getDriver(); |
| 225 | D.Diag(clang::diag::err_drv_unsupported_opt) |
| 226 | << Unsupported->getOption().getName(); |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | Args.AddAllArgs(CmdArgs, options::OPT_v); |
| 231 | Args.AddAllArgs(CmdArgs, options::OPT_D, options::OPT_U); |
| 232 | Args.AddAllArgs(CmdArgs, options::OPT_I_Group, options::OPT_F); |
| 233 | Args.AddLastArg(CmdArgs, options::OPT_P); |
| 234 | Args.AddAllArgs(CmdArgs, options::OPT_mmacosx_version_min_EQ); |
| 235 | |
| 236 | // Special case debug options to only pass -g to clang. This is |
| 237 | // wrong. |
| 238 | if (Args.hasArg(options::OPT_g_Group)) |
| 239 | CmdArgs.push_back("-g"); |
| 240 | |
| 241 | Args.AddLastArg(CmdArgs, options::OPT_nostdinc); |
| 242 | |
| 243 | // FIXME: Clang isn't going to accept just anything here. |
Daniel Dunbar | 049853d | 2009-03-20 19:38:56 +0000 | [diff] [blame] | 244 | // FIXME: Use iterator. |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 245 | |
Daniel Dunbar | 049853d | 2009-03-20 19:38:56 +0000 | [diff] [blame] | 246 | // Add -i* options, and automatically translate to -include-pth for |
| 247 | // transparent PCH support. It's wonky, but we include looking for |
| 248 | // .gch so we can support seamless replacement into a build system |
| 249 | // already set up to be generating .gch files. |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 250 | for (ArgList::const_iterator |
| 251 | it = Args.begin(), ie = Args.end(); it != ie; ++it) { |
| 252 | const Arg *A = *it; |
Daniel Dunbar | 049853d | 2009-03-20 19:38:56 +0000 | [diff] [blame] | 253 | if (!A->getOption().matches(options::OPT_i_Group)) |
| 254 | continue; |
| 255 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 256 | if (A->getOption().matches(options::OPT_include)) { |
Daniel Dunbar | 049853d | 2009-03-20 19:38:56 +0000 | [diff] [blame] | 257 | bool FoundPTH = false; |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 258 | llvm::sys::Path P(A->getValue(Args)); |
| 259 | P.appendSuffix("pth"); |
| 260 | if (P.exists()) { |
Daniel Dunbar | 049853d | 2009-03-20 19:38:56 +0000 | [diff] [blame] | 261 | FoundPTH = true; |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 262 | } else { |
| 263 | P.eraseSuffix(); |
| 264 | P.appendSuffix("gch"); |
Daniel Dunbar | 049853d | 2009-03-20 19:38:56 +0000 | [diff] [blame] | 265 | if (P.exists()) |
| 266 | FoundPTH = true; |
| 267 | } |
| 268 | |
| 269 | if (FoundPTH) { |
| 270 | A->claim(); |
| 271 | CmdArgs.push_back("-include-pth"); |
| 272 | CmdArgs.push_back(Args.MakeArgString(P.c_str())); |
| 273 | continue; |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 274 | } |
| 275 | } |
Daniel Dunbar | 049853d | 2009-03-20 19:38:56 +0000 | [diff] [blame] | 276 | |
| 277 | // Not translated, render as usual. |
| 278 | A->claim(); |
| 279 | A->render(Args, CmdArgs); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 280 | } |
| 281 | |
Daniel Dunbar | 337a627 | 2009-03-24 20:17:30 +0000 | [diff] [blame] | 282 | // Manually translate -O to -O1 and -O4 to -O3; let clang reject |
| 283 | // others. |
| 284 | if (Arg *A = Args.getLastArg(options::OPT_O_Group)) { |
| 285 | if (A->getOption().getId() == options::OPT_O4) |
| 286 | CmdArgs.push_back("-O3"); |
| 287 | else if (A->getValue(Args)[0] == '\0') |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 288 | CmdArgs.push_back("-O1"); |
| 289 | else |
Daniel Dunbar | 5697aa0 | 2009-03-18 23:39:35 +0000 | [diff] [blame] | 290 | A->render(Args, CmdArgs); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 291 | } |
| 292 | |
Daniel Dunbar | ff7488d | 2009-03-20 00:52:38 +0000 | [diff] [blame] | 293 | Args.AddAllArgs(CmdArgs, options::OPT_clang_W_Group, |
| 294 | options::OPT_pedantic_Group); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 295 | Args.AddLastArg(CmdArgs, options::OPT_w); |
| 296 | Args.AddAllArgs(CmdArgs, options::OPT_std_EQ, options::OPT_ansi, |
| 297 | options::OPT_trigraphs); |
| 298 | |
| 299 | if (Arg *A = Args.getLastArg(options::OPT_ftemplate_depth_)) { |
| 300 | CmdArgs.push_back("-ftemplate-depth"); |
| 301 | CmdArgs.push_back(A->getValue(Args)); |
| 302 | } |
| 303 | |
| 304 | Args.AddAllArgs(CmdArgs, options::OPT_clang_f_Group); |
| 305 | |
| 306 | Args.AddLastArg(CmdArgs, options::OPT_dM); |
| 307 | |
| 308 | Args.AddAllArgValues(CmdArgs, options::OPT_Xclang); |
| 309 | |
| 310 | // FIXME: Always pass the full triple once we aren't concerned with |
| 311 | // ccc compat. |
| 312 | CmdArgs.push_back("-arch"); |
| 313 | CmdArgs.push_back(getToolChain().getArchName().c_str()); |
| 314 | |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 315 | if (Output.isPipe()) { |
| 316 | CmdArgs.push_back("-o"); |
| 317 | CmdArgs.push_back("-"); |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 318 | } else if (Output.isFilename()) { |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 319 | CmdArgs.push_back("-o"); |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 320 | CmdArgs.push_back(Output.getFilename()); |
| 321 | } else { |
| 322 | assert(Output.isNothing() && "Invalid output."); |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 323 | } |
| 324 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 325 | for (InputInfoList::const_iterator |
| 326 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 327 | const InputInfo &II = *it; |
| 328 | CmdArgs.push_back("-x"); |
| 329 | CmdArgs.push_back(types::getTypeName(II.getType())); |
| 330 | if (II.isPipe()) |
| 331 | CmdArgs.push_back("-"); |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 332 | else if (II.isFilename()) |
| 333 | CmdArgs.push_back(II.getFilename()); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 334 | else |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 335 | II.getInputArg().renderAsInput(Args, CmdArgs); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | const char *Exec = |
Daniel Dunbar | d7d5f02 | 2009-03-24 02:24:46 +0000 | [diff] [blame] | 339 | Args.MakeArgString(getToolChain().GetProgramPath(C, "clang-cc").c_str()); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 340 | Dest.addCommand(new Command(Exec, CmdArgs)); |
Daniel Dunbar | a880db0 | 2009-03-23 19:03:36 +0000 | [diff] [blame] | 341 | |
| 342 | // Claim some arguments which clang doesn't support, but we don't |
| 343 | // care to warn the user about. |
| 344 | |
| 345 | // FIXME: Use iterator. |
| 346 | for (ArgList::const_iterator |
| 347 | it = Args.begin(), ie = Args.end(); it != ie; ++it) { |
| 348 | const Arg *A = *it; |
| 349 | if (A->getOption().matches(options::OPT_clang_ignored_W_Group) || |
| 350 | A->getOption().matches(options::OPT_clang_ignored_f_Group)) |
| 351 | A->claim(); |
| 352 | } |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 353 | } |
| 354 | |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 355 | void gcc::Common::ConstructJob(Compilation &C, const JobAction &JA, |
| 356 | Job &Dest, |
| 357 | const InputInfo &Output, |
| 358 | const InputInfoList &Inputs, |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 359 | const ArgList &Args, |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 360 | const char *LinkingOutput) const { |
| 361 | ArgStringList CmdArgs; |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 362 | |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 363 | for (ArgList::const_iterator |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 364 | it = Args.begin(), ie = Args.end(); it != ie; ++it) { |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 365 | Arg *A = *it; |
Daniel Dunbar | 7587719 | 2009-03-19 07:55:12 +0000 | [diff] [blame] | 366 | if (A->getOption().hasForwardToGCC()) { |
| 367 | // It is unfortunate that we have to claim here, as this means |
| 368 | // we will basically never report anything interesting for |
| 369 | // platforms using a generic gcc. |
| 370 | A->claim(); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 371 | A->render(Args, CmdArgs); |
Daniel Dunbar | 7587719 | 2009-03-19 07:55:12 +0000 | [diff] [blame] | 372 | } |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | RenderExtraToolArgs(CmdArgs); |
| 376 | |
| 377 | // If using a driver driver, force the arch. |
| 378 | if (getToolChain().getHost().useDriverDriver()) { |
| 379 | CmdArgs.push_back("-arch"); |
| 380 | CmdArgs.push_back(getToolChain().getArchName().c_str()); |
| 381 | } |
| 382 | |
| 383 | if (Output.isPipe()) { |
| 384 | CmdArgs.push_back("-o"); |
| 385 | CmdArgs.push_back("-"); |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 386 | } else if (Output.isFilename()) { |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 387 | CmdArgs.push_back("-o"); |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 388 | CmdArgs.push_back(Output.getFilename()); |
| 389 | } else { |
| 390 | assert(Output.isNothing() && "Unexpected output"); |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 391 | CmdArgs.push_back("-fsyntax-only"); |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 392 | } |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 393 | |
| 394 | |
| 395 | // Only pass -x if gcc will understand it; otherwise hope gcc |
| 396 | // understands the suffix correctly. The main use case this would go |
| 397 | // wrong in is for linker inputs if they happened to have an odd |
| 398 | // suffix; really the only way to get this to happen is a command |
| 399 | // like '-x foobar a.c' which will treat a.c like a linker input. |
| 400 | // |
| 401 | // FIXME: For the linker case specifically, can we safely convert |
| 402 | // inputs into '-Wl,' options? |
| 403 | for (InputInfoList::const_iterator |
| 404 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 405 | const InputInfo &II = *it; |
| 406 | if (types::canTypeBeUserSpecified(II.getType())) { |
| 407 | CmdArgs.push_back("-x"); |
| 408 | CmdArgs.push_back(types::getTypeName(II.getType())); |
| 409 | } |
| 410 | |
| 411 | if (II.isPipe()) |
| 412 | CmdArgs.push_back("-"); |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 413 | else if (II.isFilename()) |
| 414 | CmdArgs.push_back(II.getFilename()); |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 415 | else |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 416 | // Don't render as input, we need gcc to do the translations. |
| 417 | II.getInputArg().render(Args, CmdArgs); |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 418 | } |
| 419 | |
Daniel Dunbar | 632f50e | 2009-03-18 21:34:08 +0000 | [diff] [blame] | 420 | const char *Exec = |
| 421 | Args.MakeArgString(getToolChain().GetProgramPath(C, "gcc").c_str()); |
| 422 | Dest.addCommand(new Command(Exec, CmdArgs)); |
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::Preprocess::RenderExtraToolArgs(ArgStringList &CmdArgs) const { |
| 426 | CmdArgs.push_back("-E"); |
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::Precompile::RenderExtraToolArgs(ArgStringList &CmdArgs) const { |
| 430 | // The type is good enough. |
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::Compile::RenderExtraToolArgs(ArgStringList &CmdArgs) const { |
| 434 | CmdArgs.push_back("-S"); |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 435 | } |
| 436 | |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 437 | void gcc::Assemble::RenderExtraToolArgs(ArgStringList &CmdArgs) const { |
| 438 | CmdArgs.push_back("-c"); |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 439 | } |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 440 | |
| 441 | void gcc::Link::RenderExtraToolArgs(ArgStringList &CmdArgs) const { |
| 442 | // The types are (hopefully) good enough. |
| 443 | } |
| 444 | |
Daniel Dunbar | 8cac5f7 | 2009-03-20 16:06:39 +0000 | [diff] [blame] | 445 | void darwin::Assemble::ConstructJob(Compilation &C, const JobAction &JA, |
| 446 | Job &Dest, const InputInfo &Output, |
| 447 | const InputInfoList &Inputs, |
| 448 | const ArgList &Args, |
| 449 | const char *LinkingOutput) const { |
| 450 | ArgStringList CmdArgs; |
| 451 | |
| 452 | assert(Inputs.size() == 1 && "Unexpected number of inputs."); |
| 453 | const InputInfo &Input = Inputs[0]; |
| 454 | |
| 455 | // Bit of a hack, this is only used for original inputs. |
| 456 | if (Input.isFilename() && |
| 457 | strcmp(Input.getFilename(), Input.getBaseInput()) == 0 && |
| 458 | Args.hasArg(options::OPT_g_Group)) |
| 459 | CmdArgs.push_back("--gstabs"); |
| 460 | |
| 461 | // Derived from asm spec. |
| 462 | CmdArgs.push_back("-arch"); |
| 463 | CmdArgs.push_back(getToolChain().getArchName().c_str()); |
| 464 | |
| 465 | CmdArgs.push_back("-force_cpusubtype_ALL"); |
| 466 | if ((Args.hasArg(options::OPT_mkernel) || |
| 467 | Args.hasArg(options::OPT_static) || |
| 468 | Args.hasArg(options::OPT_fapple_kext)) && |
| 469 | !Args.hasArg(options::OPT_dynamic)) |
| 470 | CmdArgs.push_back("-static"); |
| 471 | |
| 472 | Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, |
| 473 | options::OPT_Xassembler); |
| 474 | |
| 475 | assert(Output.isFilename() && "Unexpected lipo output."); |
| 476 | CmdArgs.push_back("-o"); |
| 477 | CmdArgs.push_back(Output.getFilename()); |
| 478 | |
| 479 | if (Input.isPipe()) { |
| 480 | CmdArgs.push_back("-"); |
| 481 | } else { |
| 482 | assert(Input.isFilename() && "Invalid input."); |
| 483 | CmdArgs.push_back(Input.getFilename()); |
| 484 | } |
| 485 | |
| 486 | // asm_final spec is empty. |
| 487 | |
| 488 | const char *Exec = |
| 489 | Args.MakeArgString(getToolChain().GetProgramPath(C, "as").c_str()); |
| 490 | Dest.addCommand(new Command(Exec, CmdArgs)); |
| 491 | } |
Daniel Dunbar | ff7488d | 2009-03-20 00:52:38 +0000 | [diff] [blame] | 492 | |
| 493 | void darwin::Lipo::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | 8cac5f7 | 2009-03-20 16:06:39 +0000 | [diff] [blame] | 494 | Job &Dest, const InputInfo &Output, |
Daniel Dunbar | ff7488d | 2009-03-20 00:52:38 +0000 | [diff] [blame] | 495 | const InputInfoList &Inputs, |
| 496 | const ArgList &Args, |
| 497 | const char *LinkingOutput) const { |
| 498 | ArgStringList CmdArgs; |
| 499 | |
| 500 | CmdArgs.push_back("-create"); |
| 501 | assert(Output.isFilename() && "Unexpected lipo output."); |
Daniel Dunbar | a428df8 | 2009-03-24 00:24:37 +0000 | [diff] [blame] | 502 | |
| 503 | CmdArgs.push_back("-output"); |
Daniel Dunbar | ff7488d | 2009-03-20 00:52:38 +0000 | [diff] [blame] | 504 | CmdArgs.push_back(Output.getFilename()); |
Daniel Dunbar | a428df8 | 2009-03-24 00:24:37 +0000 | [diff] [blame] | 505 | |
Daniel Dunbar | ff7488d | 2009-03-20 00:52:38 +0000 | [diff] [blame] | 506 | for (InputInfoList::const_iterator |
| 507 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 508 | const InputInfo &II = *it; |
| 509 | assert(II.isFilename() && "Unexpected lipo input."); |
| 510 | CmdArgs.push_back(II.getFilename()); |
| 511 | } |
| 512 | const char *Exec = |
| 513 | Args.MakeArgString(getToolChain().GetProgramPath(C, "lipo").c_str()); |
| 514 | Dest.addCommand(new Command(Exec, CmdArgs)); |
| 515 | } |