Daniel Dunbar | 3ede8d0 | 2009-03-02 19:59:07 +0000 | [diff] [blame] | 1 | //===--- Driver.cpp - Clang GCC Compatible Driver -----------------------*-===// |
| 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 | |
Daniel Dunbar | 3ede8d0 | 2009-03-02 19:59:07 +0000 | [diff] [blame] | 10 | #include "clang/Driver/Driver.h" |
Daniel Dunbar | 3ede8d0 | 2009-03-02 19:59:07 +0000 | [diff] [blame] | 11 | |
Daniel Dunbar | 53ec552 | 2009-03-12 07:58:46 +0000 | [diff] [blame] | 12 | #include "clang/Driver/Action.h" |
Daniel Dunbar | 1b3bb6e | 2009-03-04 20:49:20 +0000 | [diff] [blame] | 13 | #include "clang/Driver/Arg.h" |
| 14 | #include "clang/Driver/ArgList.h" |
| 15 | #include "clang/Driver/Compilation.h" |
Daniel Dunbar | 4ad4b3e | 2009-03-12 08:55:43 +0000 | [diff] [blame] | 16 | #include "clang/Driver/DriverDiagnostic.h" |
Daniel Dunbar | dd98e2c | 2009-03-10 23:41:59 +0000 | [diff] [blame] | 17 | #include "clang/Driver/HostInfo.h" |
Daniel Dunbar | f353c8c | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 18 | #include "clang/Driver/Job.h" |
Daniel Dunbar | 0648262 | 2009-03-05 06:38:47 +0000 | [diff] [blame] | 19 | #include "clang/Driver/Option.h" |
Daniel Dunbar | 1b3bb6e | 2009-03-04 20:49:20 +0000 | [diff] [blame] | 20 | #include "clang/Driver/Options.h" |
Daniel Dunbar | f353c8c | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 21 | #include "clang/Driver/Tool.h" |
| 22 | #include "clang/Driver/ToolChain.h" |
Daniel Dunbar | 53ec552 | 2009-03-12 07:58:46 +0000 | [diff] [blame] | 23 | #include "clang/Driver/Types.h" |
Daniel Dunbar | 0648262 | 2009-03-05 06:38:47 +0000 | [diff] [blame] | 24 | |
Daniel Dunbar | 1368954 | 2009-03-13 20:33:35 +0000 | [diff] [blame] | 25 | #include "llvm/ADT/StringSet.h" |
Daniel Dunbar | 0648262 | 2009-03-05 06:38:47 +0000 | [diff] [blame] | 26 | #include "llvm/Support/raw_ostream.h" |
Daniel Dunbar | 53ec552 | 2009-03-12 07:58:46 +0000 | [diff] [blame] | 27 | #include "llvm/System/Path.h" |
Daniel Dunbar | ba10213 | 2009-03-13 12:19:02 +0000 | [diff] [blame] | 28 | |
Daniel Dunbar | f353c8c | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 29 | #include "InputInfo.h" |
| 30 | |
Daniel Dunbar | ba10213 | 2009-03-13 12:19:02 +0000 | [diff] [blame] | 31 | #include <map> |
| 32 | |
Daniel Dunbar | 1b3bb6e | 2009-03-04 20:49:20 +0000 | [diff] [blame] | 33 | using namespace clang::driver; |
| 34 | |
Daniel Dunbar | dd98e2c | 2009-03-10 23:41:59 +0000 | [diff] [blame] | 35 | Driver::Driver(const char *_Name, const char *_Dir, |
Daniel Dunbar | 4ad4b3e | 2009-03-12 08:55:43 +0000 | [diff] [blame] | 36 | const char *_DefaultHostTriple, |
Daniel Dunbar | f353c8c | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 37 | const char *_DefaultImageName, |
Daniel Dunbar | 4ad4b3e | 2009-03-12 08:55:43 +0000 | [diff] [blame] | 38 | Diagnostic &_Diags) |
| 39 | : Opts(new OptTable()), Diags(_Diags), |
Daniel Dunbar | dd98e2c | 2009-03-10 23:41:59 +0000 | [diff] [blame] | 40 | Name(_Name), Dir(_Dir), DefaultHostTriple(_DefaultHostTriple), |
Daniel Dunbar | f353c8c | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 41 | DefaultImageName(_DefaultImageName), |
Daniel Dunbar | dd98e2c | 2009-03-10 23:41:59 +0000 | [diff] [blame] | 42 | Host(0), |
Daniel Dunbar | 365c02f | 2009-03-10 20:52:46 +0000 | [diff] [blame] | 43 | CCCIsCXX(false), CCCEcho(false), |
Daniel Dunbar | 8b1604e | 2009-03-13 00:17:48 +0000 | [diff] [blame] | 44 | CCCNoClang(false), CCCNoClangCXX(false), CCCNoClangCPP(false), |
| 45 | SuppressMissingInputWarning(false) |
Daniel Dunbar | 365c02f | 2009-03-10 20:52:46 +0000 | [diff] [blame] | 46 | { |
Daniel Dunbar | 3ede8d0 | 2009-03-02 19:59:07 +0000 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | Driver::~Driver() { |
Daniel Dunbar | 1b3bb6e | 2009-03-04 20:49:20 +0000 | [diff] [blame] | 50 | delete Opts; |
Daniel Dunbar | 3ede8d0 | 2009-03-02 19:59:07 +0000 | [diff] [blame] | 51 | } |
| 52 | |
Daniel Dunbar | 0648262 | 2009-03-05 06:38:47 +0000 | [diff] [blame] | 53 | ArgList *Driver::ParseArgStrings(const char **ArgBegin, const char **ArgEnd) { |
| 54 | ArgList *Args = new ArgList(ArgBegin, ArgEnd); |
| 55 | |
Daniel Dunbar | ad2a9af | 2009-03-13 11:38:42 +0000 | [diff] [blame] | 56 | // FIXME: Handle '@' args (or at least error on them). |
| 57 | |
Daniel Dunbar | 0648262 | 2009-03-05 06:38:47 +0000 | [diff] [blame] | 58 | unsigned Index = 0, End = ArgEnd - ArgBegin; |
| 59 | while (Index < End) { |
Daniel Dunbar | 4139340 | 2009-03-13 01:01:44 +0000 | [diff] [blame] | 60 | // gcc's handling of empty arguments doesn't make |
| 61 | // sense, but this is not a common use case. :) |
| 62 | // |
| 63 | // We just ignore them here (note that other things may |
| 64 | // still take them as arguments). |
| 65 | if (Args->getArgString(Index)[0] == '\0') { |
| 66 | ++Index; |
| 67 | continue; |
| 68 | } |
| 69 | |
Daniel Dunbar | 0648262 | 2009-03-05 06:38:47 +0000 | [diff] [blame] | 70 | unsigned Prev = Index; |
| 71 | Arg *A = getOpts().ParseOneArg(*Args, Index, End); |
Daniel Dunbar | 53ec552 | 2009-03-12 07:58:46 +0000 | [diff] [blame] | 72 | if (A) { |
| 73 | if (A->getOption().isUnsupported()) { |
Daniel Dunbar | b897f5d | 2009-03-12 09:13:48 +0000 | [diff] [blame] | 74 | Diag(clang::diag::err_drv_unsupported_opt) << A->getOption().getName(); |
Daniel Dunbar | 53ec552 | 2009-03-12 07:58:46 +0000 | [diff] [blame] | 75 | continue; |
| 76 | } |
| 77 | |
Daniel Dunbar | 0648262 | 2009-03-05 06:38:47 +0000 | [diff] [blame] | 78 | Args->append(A); |
Daniel Dunbar | 53ec552 | 2009-03-12 07:58:46 +0000 | [diff] [blame] | 79 | } |
Daniel Dunbar | 0648262 | 2009-03-05 06:38:47 +0000 | [diff] [blame] | 80 | |
| 81 | assert(Index > Prev && "Parser failed to consume argument."); |
Daniel Dunbar | 70c1684 | 2009-03-17 04:12:06 +0000 | [diff] [blame^] | 82 | (void) Prev; |
Daniel Dunbar | 0648262 | 2009-03-05 06:38:47 +0000 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | return Args; |
| 86 | } |
| 87 | |
Daniel Dunbar | 3ede8d0 | 2009-03-02 19:59:07 +0000 | [diff] [blame] | 88 | Compilation *Driver::BuildCompilation(int argc, const char **argv) { |
Daniel Dunbar | cb88167 | 2009-03-13 00:51:18 +0000 | [diff] [blame] | 89 | // FIXME: Handle environment options which effect driver behavior, |
| 90 | // somewhere (client?). GCC_EXEC_PREFIX, COMPILER_PATH, |
| 91 | // LIBRARY_PATH, LPATH, CC_PRINT_OPTIONS, QA_OVERRIDE_GCC3_OPTIONS. |
| 92 | |
| 93 | // FIXME: What are we going to do with -V and -b? |
| 94 | |
| 95 | // FIXME: Handle CCC_ADD_ARGS. |
| 96 | |
Daniel Dunbar | 365c02f | 2009-03-10 20:52:46 +0000 | [diff] [blame] | 97 | // FIXME: This stuff needs to go into the Compilation, not the |
| 98 | // driver. |
Daniel Dunbar | 53ec552 | 2009-03-12 07:58:46 +0000 | [diff] [blame] | 99 | bool CCCPrintOptions = false, CCCPrintActions = false; |
Daniel Dunbar | 0648262 | 2009-03-05 06:38:47 +0000 | [diff] [blame] | 100 | |
Daniel Dunbar | 365c02f | 2009-03-10 20:52:46 +0000 | [diff] [blame] | 101 | const char **Start = argv + 1, **End = argv + argc; |
Daniel Dunbar | dd98e2c | 2009-03-10 23:41:59 +0000 | [diff] [blame] | 102 | const char *HostTriple = DefaultHostTriple.c_str(); |
Daniel Dunbar | 365c02f | 2009-03-10 20:52:46 +0000 | [diff] [blame] | 103 | |
| 104 | // Read -ccc args. |
| 105 | // |
| 106 | // FIXME: We need to figure out where this behavior should |
| 107 | // live. Most of it should be outside in the client; the parts that |
| 108 | // aren't should have proper options, either by introducing new ones |
| 109 | // or by overloading gcc ones like -V or -b. |
| 110 | for (; Start != End && memcmp(*Start, "-ccc-", 5) == 0; ++Start) { |
| 111 | const char *Opt = *Start + 5; |
| 112 | |
| 113 | if (!strcmp(Opt, "print-options")) { |
| 114 | CCCPrintOptions = true; |
| 115 | } else if (!strcmp(Opt, "print-phases")) { |
Daniel Dunbar | 53ec552 | 2009-03-12 07:58:46 +0000 | [diff] [blame] | 116 | CCCPrintActions = true; |
Daniel Dunbar | 365c02f | 2009-03-10 20:52:46 +0000 | [diff] [blame] | 117 | } else if (!strcmp(Opt, "cxx")) { |
| 118 | CCCIsCXX = true; |
| 119 | } else if (!strcmp(Opt, "echo")) { |
| 120 | CCCEcho = true; |
| 121 | |
| 122 | } else if (!strcmp(Opt, "no-clang")) { |
| 123 | CCCNoClang = true; |
| 124 | } else if (!strcmp(Opt, "no-clang-cxx")) { |
| 125 | CCCNoClangCXX = true; |
| 126 | } else if (!strcmp(Opt, "no-clang-cpp")) { |
| 127 | CCCNoClangCPP = true; |
| 128 | } else if (!strcmp(Opt, "clang-archs")) { |
| 129 | assert(Start+1 < End && "FIXME: -ccc- argument handling."); |
| 130 | const char *Cur = *++Start; |
| 131 | |
| 132 | for (;;) { |
| 133 | const char *Next = strchr(Cur, ','); |
| 134 | |
| 135 | if (Next) { |
| 136 | CCCClangArchs.insert(std::string(Cur, Next)); |
| 137 | Cur = Next + 1; |
| 138 | } else { |
| 139 | CCCClangArchs.insert(std::string(Cur)); |
| 140 | break; |
| 141 | } |
| 142 | } |
| 143 | |
Daniel Dunbar | dd98e2c | 2009-03-10 23:41:59 +0000 | [diff] [blame] | 144 | } else if (!strcmp(Opt, "host-triple")) { |
Daniel Dunbar | 365c02f | 2009-03-10 20:52:46 +0000 | [diff] [blame] | 145 | assert(Start+1 < End && "FIXME: -ccc- argument handling."); |
Daniel Dunbar | dd98e2c | 2009-03-10 23:41:59 +0000 | [diff] [blame] | 146 | HostTriple = *++Start; |
Daniel Dunbar | 365c02f | 2009-03-10 20:52:46 +0000 | [diff] [blame] | 147 | |
| 148 | } else { |
| 149 | // FIXME: Error handling. |
| 150 | llvm::errs() << "invalid option: " << *Start << "\n"; |
| 151 | exit(1); |
| 152 | } |
| 153 | } |
Daniel Dunbar | dd98e2c | 2009-03-10 23:41:59 +0000 | [diff] [blame] | 154 | |
Daniel Dunbar | 365c02f | 2009-03-10 20:52:46 +0000 | [diff] [blame] | 155 | ArgList *Args = ParseArgStrings(Start, End); |
| 156 | |
Daniel Dunbar | cb88167 | 2009-03-13 00:51:18 +0000 | [diff] [blame] | 157 | Host = Driver::GetHostInfo(HostTriple); |
| 158 | DefaultToolChain = Host->getToolChain(*Args); |
| 159 | |
Daniel Dunbar | 365c02f | 2009-03-10 20:52:46 +0000 | [diff] [blame] | 160 | // FIXME: This behavior shouldn't be here. |
| 161 | if (CCCPrintOptions) { |
Daniel Dunbar | 53ec552 | 2009-03-12 07:58:46 +0000 | [diff] [blame] | 162 | PrintOptions(*Args); |
Daniel Dunbar | ab83543 | 2009-03-13 17:24:34 +0000 | [diff] [blame] | 163 | return 0; |
Daniel Dunbar | 365c02f | 2009-03-10 20:52:46 +0000 | [diff] [blame] | 164 | } |
Daniel Dunbar | 53ec552 | 2009-03-12 07:58:46 +0000 | [diff] [blame] | 165 | |
Daniel Dunbar | cb88167 | 2009-03-13 00:51:18 +0000 | [diff] [blame] | 166 | if (!HandleImmediateArgs(*Args)) |
| 167 | return 0; |
| 168 | |
Daniel Dunbar | 53ec552 | 2009-03-12 07:58:46 +0000 | [diff] [blame] | 169 | // Construct the list of abstract actions to perform for this |
| 170 | // compilation. |
Daniel Dunbar | d65bddc | 2009-03-12 18:24:49 +0000 | [diff] [blame] | 171 | ActionList Actions; |
Daniel Dunbar | 53ec552 | 2009-03-12 07:58:46 +0000 | [diff] [blame] | 172 | if (Host->useDriverDriver()) |
| 173 | BuildUniversalActions(*Args, Actions); |
| 174 | else |
| 175 | BuildActions(*Args, Actions); |
| 176 | |
Daniel Dunbar | 53ec552 | 2009-03-12 07:58:46 +0000 | [diff] [blame] | 177 | if (CCCPrintActions) { |
Daniel Dunbar | ba10213 | 2009-03-13 12:19:02 +0000 | [diff] [blame] | 178 | PrintActions(*Args, Actions); |
Daniel Dunbar | ab83543 | 2009-03-13 17:24:34 +0000 | [diff] [blame] | 179 | return 0; |
Daniel Dunbar | 53ec552 | 2009-03-12 07:58:46 +0000 | [diff] [blame] | 180 | } |
Daniel Dunbar | ab83543 | 2009-03-13 17:24:34 +0000 | [diff] [blame] | 181 | |
Daniel Dunbar | 586dc23 | 2009-03-16 06:42:30 +0000 | [diff] [blame] | 182 | // The compilation takes ownership of Args. |
| 183 | Compilation *C = new Compilation(*DefaultToolChain, Args); |
| 184 | BuildJobs(*C, Actions); |
Daniel Dunbar | 8d2554a | 2009-03-15 01:38:15 +0000 | [diff] [blame] | 185 | |
| 186 | return C; |
Daniel Dunbar | 365c02f | 2009-03-10 20:52:46 +0000 | [diff] [blame] | 187 | } |
| 188 | |
Daniel Dunbar | d65bddc | 2009-03-12 18:24:49 +0000 | [diff] [blame] | 189 | void Driver::PrintOptions(const ArgList &Args) const { |
Daniel Dunbar | 0648262 | 2009-03-05 06:38:47 +0000 | [diff] [blame] | 190 | unsigned i = 0; |
Daniel Dunbar | 53ec552 | 2009-03-12 07:58:46 +0000 | [diff] [blame] | 191 | for (ArgList::const_iterator it = Args.begin(), ie = Args.end(); |
Daniel Dunbar | 0648262 | 2009-03-05 06:38:47 +0000 | [diff] [blame] | 192 | it != ie; ++it, ++i) { |
| 193 | Arg *A = *it; |
| 194 | llvm::errs() << "Option " << i << " - " |
| 195 | << "Name: \"" << A->getOption().getName() << "\", " |
| 196 | << "Values: {"; |
| 197 | for (unsigned j = 0; j < A->getNumValues(); ++j) { |
| 198 | if (j) |
| 199 | llvm::errs() << ", "; |
Daniel Dunbar | 53ec552 | 2009-03-12 07:58:46 +0000 | [diff] [blame] | 200 | llvm::errs() << '"' << A->getValue(Args, j) << '"'; |
Daniel Dunbar | 0648262 | 2009-03-05 06:38:47 +0000 | [diff] [blame] | 201 | } |
| 202 | llvm::errs() << "}\n"; |
Daniel Dunbar | 0648262 | 2009-03-05 06:38:47 +0000 | [diff] [blame] | 203 | } |
Daniel Dunbar | 3ede8d0 | 2009-03-02 19:59:07 +0000 | [diff] [blame] | 204 | } |
Daniel Dunbar | dd98e2c | 2009-03-10 23:41:59 +0000 | [diff] [blame] | 205 | |
Daniel Dunbar | cb88167 | 2009-03-13 00:51:18 +0000 | [diff] [blame] | 206 | void Driver::PrintVersion() const { |
| 207 | // FIXME: Get a reasonable version number. |
| 208 | |
| 209 | // FIXME: The following handlers should use a callback mechanism, we |
| 210 | // don't know what the client would like to do. |
| 211 | llvm::outs() << "ccc version 1.0" << "\n"; |
| 212 | } |
| 213 | |
| 214 | bool Driver::HandleImmediateArgs(const ArgList &Args) { |
| 215 | // The order these options are handled in in gcc is all over the |
| 216 | // place, but we don't expect inconsistencies w.r.t. that to matter |
| 217 | // in practice. |
| 218 | if (Args.hasArg(options::OPT_v) || |
| 219 | Args.hasArg(options::OPT__HASH_HASH_HASH)) { |
| 220 | PrintVersion(); |
| 221 | SuppressMissingInputWarning = true; |
| 222 | } |
| 223 | |
| 224 | // FIXME: The following handlers should use a callback mechanism, we |
| 225 | // don't know what the client would like to do. |
| 226 | if (Arg *A = Args.getLastArg(options::OPT_print_file_name_EQ)) { |
| 227 | llvm::outs() << GetFilePath(A->getValue(Args)).toString() << "\n"; |
| 228 | return false; |
| 229 | } |
| 230 | |
| 231 | if (Arg *A = Args.getLastArg(options::OPT_print_prog_name_EQ)) { |
| 232 | llvm::outs() << GetProgramPath(A->getValue(Args)).toString() << "\n"; |
| 233 | return false; |
| 234 | } |
| 235 | |
Daniel Dunbar | 4139340 | 2009-03-13 01:01:44 +0000 | [diff] [blame] | 236 | if (Args.hasArg(options::OPT_print_libgcc_file_name)) { |
Daniel Dunbar | cb88167 | 2009-03-13 00:51:18 +0000 | [diff] [blame] | 237 | llvm::outs() << GetProgramPath("libgcc.a").toString() << "\n"; |
| 238 | return false; |
| 239 | } |
| 240 | |
| 241 | return true; |
| 242 | } |
| 243 | |
Daniel Dunbar | ba10213 | 2009-03-13 12:19:02 +0000 | [diff] [blame] | 244 | static unsigned PrintActions1(const ArgList &Args, |
| 245 | Action *A, |
| 246 | std::map<Action*, unsigned> &Ids) { |
| 247 | if (Ids.count(A)) |
| 248 | return Ids[A]; |
| 249 | |
| 250 | std::string str; |
| 251 | llvm::raw_string_ostream os(str); |
| 252 | |
| 253 | os << Action::getClassName(A->getKind()) << ", "; |
| 254 | if (InputAction *IA = dyn_cast<InputAction>(A)) { |
Daniel Dunbar | 3dbd6c5 | 2009-03-13 17:46:02 +0000 | [diff] [blame] | 255 | os << "\"" << IA->getInputArg().getValue(Args) << "\""; |
Daniel Dunbar | ba10213 | 2009-03-13 12:19:02 +0000 | [diff] [blame] | 256 | } else if (BindArchAction *BIA = dyn_cast<BindArchAction>(A)) { |
| 257 | os << "\"" << BIA->getArchName() << "\", " |
| 258 | << "{" << PrintActions1(Args, *BIA->begin(), Ids) << "}"; |
| 259 | } else { |
| 260 | os << "{"; |
| 261 | for (Action::iterator it = A->begin(), ie = A->end(); it != ie;) { |
| 262 | os << PrintActions1(Args, *it, Ids); |
| 263 | ++it; |
| 264 | if (it != ie) |
| 265 | os << ", "; |
| 266 | } |
| 267 | os << "}"; |
| 268 | } |
| 269 | |
| 270 | unsigned Id = Ids.size(); |
| 271 | Ids[A] = Id; |
Daniel Dunbar | b269c32 | 2009-03-13 17:20:20 +0000 | [diff] [blame] | 272 | llvm::errs() << Id << ": " << os.str() << ", " |
Daniel Dunbar | ba10213 | 2009-03-13 12:19:02 +0000 | [diff] [blame] | 273 | << types::getTypeName(A->getType()) << "\n"; |
| 274 | |
| 275 | return Id; |
| 276 | } |
| 277 | |
| 278 | void Driver::PrintActions(const ArgList &Args, |
| 279 | const ActionList &Actions) const { |
| 280 | std::map<Action*, unsigned> Ids; |
| 281 | for (ActionList::const_iterator it = Actions.begin(), ie = Actions.end(); |
Daniel Dunbar | b269c32 | 2009-03-13 17:20:20 +0000 | [diff] [blame] | 282 | it != ie; ++it) |
Daniel Dunbar | ba10213 | 2009-03-13 12:19:02 +0000 | [diff] [blame] | 283 | PrintActions1(Args, *it, Ids); |
Daniel Dunbar | 53ec552 | 2009-03-12 07:58:46 +0000 | [diff] [blame] | 284 | } |
| 285 | |
Daniel Dunbar | 57b704d | 2009-03-13 22:12:33 +0000 | [diff] [blame] | 286 | void Driver::BuildUniversalActions(ArgList &Args, ActionList &Actions) const { |
Daniel Dunbar | 1368954 | 2009-03-13 20:33:35 +0000 | [diff] [blame] | 287 | // Collect the list of architectures. Duplicates are allowed, but |
| 288 | // should only be handled once (in the order seen). |
| 289 | llvm::StringSet<> ArchNames; |
| 290 | llvm::SmallVector<const char *, 4> Archs; |
Daniel Dunbar | 2fe63e6 | 2009-03-12 18:40:18 +0000 | [diff] [blame] | 291 | for (ArgList::const_iterator it = Args.begin(), ie = Args.end(); |
| 292 | it != ie; ++it) { |
| 293 | Arg *A = *it; |
| 294 | |
| 295 | if (A->getOption().getId() == options::OPT_arch) { |
Daniel Dunbar | 1368954 | 2009-03-13 20:33:35 +0000 | [diff] [blame] | 296 | const char *Name = A->getValue(Args); |
| 297 | |
Daniel Dunbar | 2fe63e6 | 2009-03-12 18:40:18 +0000 | [diff] [blame] | 298 | // FIXME: We need to handle canonicalization of the specified |
| 299 | // arch? |
| 300 | |
Daniel Dunbar | 1368954 | 2009-03-13 20:33:35 +0000 | [diff] [blame] | 301 | if (ArchNames.insert(Name)) |
| 302 | Archs.push_back(Name); |
Daniel Dunbar | 2fe63e6 | 2009-03-12 18:40:18 +0000 | [diff] [blame] | 303 | } |
| 304 | } |
| 305 | |
| 306 | // When there is no explicit arch for this platform, get one from |
| 307 | // the host so that -Xarch_ is handled correctly. |
| 308 | if (!Archs.size()) { |
| 309 | const char *Arch = Host->getArchName().c_str(); |
Daniel Dunbar | 1368954 | 2009-03-13 20:33:35 +0000 | [diff] [blame] | 310 | Archs.push_back(Arch); |
Daniel Dunbar | 2fe63e6 | 2009-03-12 18:40:18 +0000 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | // FIXME: We killed off some others but these aren't yet detected in |
| 314 | // a functional manner. If we added information to jobs about which |
| 315 | // "auxiliary" files they wrote then we could detect the conflict |
| 316 | // these cause downstream. |
| 317 | if (Archs.size() > 1) { |
| 318 | // No recovery needed, the point of this is just to prevent |
| 319 | // overwriting the same files. |
| 320 | if (const Arg *A = Args.getLastArg(options::OPT_M_Group)) |
| 321 | Diag(clang::diag::err_drv_invalid_opt_with_multiple_archs) |
| 322 | << A->getOption().getName(); |
| 323 | if (const Arg *A = Args.getLastArg(options::OPT_save_temps)) |
| 324 | Diag(clang::diag::err_drv_invalid_opt_with_multiple_archs) |
| 325 | << A->getOption().getName(); |
| 326 | } |
| 327 | |
| 328 | ActionList SingleActions; |
| 329 | BuildActions(Args, SingleActions); |
| 330 | |
| 331 | // Add in arch binding and lipo (if necessary) for every top level |
| 332 | // action. |
| 333 | for (unsigned i = 0, e = SingleActions.size(); i != e; ++i) { |
| 334 | Action *Act = SingleActions[i]; |
| 335 | |
| 336 | // Make sure we can lipo this kind of output. If not (and it is an |
| 337 | // actual output) then we disallow, since we can't create an |
| 338 | // output file with the right name without overwriting it. We |
| 339 | // could remove this oddity by just changing the output names to |
| 340 | // include the arch, which would also fix |
| 341 | // -save-temps. Compatibility wins for now. |
| 342 | |
Daniel Dunbar | 3dbd6c5 | 2009-03-13 17:46:02 +0000 | [diff] [blame] | 343 | if (Archs.size() > 1 && !types::canLipoType(Act->getType())) |
Daniel Dunbar | 2fe63e6 | 2009-03-12 18:40:18 +0000 | [diff] [blame] | 344 | Diag(clang::diag::err_drv_invalid_output_with_multiple_archs) |
| 345 | << types::getTypeName(Act->getType()); |
| 346 | |
| 347 | ActionList Inputs; |
Daniel Dunbar | 1368954 | 2009-03-13 20:33:35 +0000 | [diff] [blame] | 348 | for (unsigned i = 0, e = Archs.size(); i != e; ++i ) |
| 349 | Inputs.push_back(new BindArchAction(Act, Archs[i])); |
Daniel Dunbar | 2fe63e6 | 2009-03-12 18:40:18 +0000 | [diff] [blame] | 350 | |
| 351 | // Lipo if necessary, We do it this way because we need to set the |
| 352 | // arch flag so that -Xarch_ gets overwritten. |
| 353 | if (Inputs.size() == 1 || Act->getType() == types::TY_Nothing) |
| 354 | Actions.append(Inputs.begin(), Inputs.end()); |
| 355 | else |
| 356 | Actions.push_back(new LipoJobAction(Inputs, Act->getType())); |
| 357 | } |
Daniel Dunbar | 53ec552 | 2009-03-12 07:58:46 +0000 | [diff] [blame] | 358 | } |
| 359 | |
Daniel Dunbar | 57b704d | 2009-03-13 22:12:33 +0000 | [diff] [blame] | 360 | void Driver::BuildActions(ArgList &Args, ActionList &Actions) const { |
Daniel Dunbar | af61c71 | 2009-03-12 23:55:14 +0000 | [diff] [blame] | 361 | // Start by constructing the list of inputs and their types. |
| 362 | |
Daniel Dunbar | 83dd21f | 2009-03-13 17:57:10 +0000 | [diff] [blame] | 363 | // Track the current user specified (-x) input. We also explicitly |
| 364 | // track the argument used to set the type; we only want to claim |
| 365 | // the type when we actually use it, so we warn about unused -x |
| 366 | // arguments. |
| 367 | types::ID InputType = types::TY_Nothing; |
| 368 | Arg *InputTypeArg = 0; |
| 369 | |
Daniel Dunbar | 53ec552 | 2009-03-12 07:58:46 +0000 | [diff] [blame] | 370 | llvm::SmallVector<std::pair<types::ID, const Arg*>, 16> Inputs; |
| 371 | for (ArgList::const_iterator it = Args.begin(), ie = Args.end(); |
| 372 | it != ie; ++it) { |
| 373 | Arg *A = *it; |
| 374 | |
| 375 | if (isa<InputOption>(A->getOption())) { |
| 376 | const char *Value = A->getValue(Args); |
| 377 | types::ID Ty = types::TY_INVALID; |
| 378 | |
| 379 | // Infer the input type if necessary. |
Daniel Dunbar | 83dd21f | 2009-03-13 17:57:10 +0000 | [diff] [blame] | 380 | if (InputType == types::TY_Nothing) { |
| 381 | // If there was an explicit arg for this, claim it. |
| 382 | if (InputTypeArg) |
| 383 | InputTypeArg->claim(); |
| 384 | |
Daniel Dunbar | 53ec552 | 2009-03-12 07:58:46 +0000 | [diff] [blame] | 385 | // stdin must be handled specially. |
| 386 | if (memcmp(Value, "-", 2) == 0) { |
| 387 | // If running with -E, treat as a C input (this changes the |
| 388 | // builtin macros, for example). This may be overridden by |
| 389 | // -ObjC below. |
| 390 | // |
| 391 | // Otherwise emit an error but still use a valid type to |
| 392 | // avoid spurious errors (e.g., no inputs). |
Daniel Dunbar | 8022fd4 | 2009-03-15 00:48:16 +0000 | [diff] [blame] | 393 | if (!Args.hasArg(options::OPT_E, false)) |
Daniel Dunbar | b897f5d | 2009-03-12 09:13:48 +0000 | [diff] [blame] | 394 | Diag(clang::diag::err_drv_unknown_stdin_type); |
Daniel Dunbar | 53ec552 | 2009-03-12 07:58:46 +0000 | [diff] [blame] | 395 | Ty = types::TY_C; |
| 396 | } else { |
| 397 | // Otherwise lookup by extension, and fallback to ObjectType |
| 398 | // if not found. |
| 399 | if (const char *Ext = strrchr(Value, '.')) |
| 400 | Ty = types::lookupTypeForExtension(Ext + 1); |
| 401 | if (Ty == types::TY_INVALID) |
| 402 | Ty = types::TY_Object; |
| 403 | } |
| 404 | |
| 405 | // -ObjC and -ObjC++ override the default language, but only |
| 406 | // -for "source files". We just treat everything that isn't a |
| 407 | // -linker input as a source file. |
| 408 | // |
| 409 | // FIXME: Clean this up if we move the phase sequence into the |
| 410 | // type. |
| 411 | if (Ty != types::TY_Object) { |
| 412 | if (Args.hasArg(options::OPT_ObjC)) |
| 413 | Ty = types::TY_ObjC; |
| 414 | else if (Args.hasArg(options::OPT_ObjCXX)) |
| 415 | Ty = types::TY_ObjCXX; |
| 416 | } |
| 417 | } else { |
| 418 | assert(InputTypeArg && "InputType set w/o InputTypeArg"); |
| 419 | InputTypeArg->claim(); |
| 420 | Ty = InputType; |
| 421 | } |
| 422 | |
| 423 | // Check that the file exists. It isn't clear this is worth |
| 424 | // doing, since the tool presumably does this anyway, and this |
| 425 | // just adds an extra stat to the equation, but this is gcc |
| 426 | // compatible. |
Daniel Dunbar | 411f2e4 | 2009-03-15 01:40:22 +0000 | [diff] [blame] | 427 | A->claim(); |
Daniel Dunbar | 53ec552 | 2009-03-12 07:58:46 +0000 | [diff] [blame] | 428 | if (memcmp(Value, "-", 2) != 0 && !llvm::sys::Path(Value).exists()) |
Daniel Dunbar | b897f5d | 2009-03-12 09:13:48 +0000 | [diff] [blame] | 429 | Diag(clang::diag::err_drv_no_such_file) << A->getValue(Args); |
Daniel Dunbar | 53ec552 | 2009-03-12 07:58:46 +0000 | [diff] [blame] | 430 | else |
| 431 | Inputs.push_back(std::make_pair(Ty, A)); |
| 432 | |
| 433 | } else if (A->getOption().isLinkerInput()) { |
| 434 | // Just treat as object type, we could make a special type for |
| 435 | // this if necessary. |
Daniel Dunbar | 411f2e4 | 2009-03-15 01:40:22 +0000 | [diff] [blame] | 436 | A->claim(); |
Daniel Dunbar | 53ec552 | 2009-03-12 07:58:46 +0000 | [diff] [blame] | 437 | Inputs.push_back(std::make_pair(types::TY_Object, A)); |
| 438 | |
| 439 | } else if (A->getOption().getId() == options::OPT_x) { |
| 440 | InputTypeArg = A; |
| 441 | InputType = types::lookupTypeForTypeSpecifier(A->getValue(Args)); |
| 442 | |
| 443 | // Follow gcc behavior and treat as linker input for invalid -x |
| 444 | // options. Its not clear why we shouldn't just revert to |
| 445 | // unknown; but this isn't very important, we might as well be |
| 446 | // bug comatible. |
| 447 | if (!InputType) { |
Daniel Dunbar | b897f5d | 2009-03-12 09:13:48 +0000 | [diff] [blame] | 448 | Diag(clang::diag::err_drv_unknown_language) << A->getValue(Args); |
Daniel Dunbar | 53ec552 | 2009-03-12 07:58:46 +0000 | [diff] [blame] | 449 | InputType = types::TY_Object; |
| 450 | } |
| 451 | } |
| 452 | } |
| 453 | |
Daniel Dunbar | 8b1604e | 2009-03-13 00:17:48 +0000 | [diff] [blame] | 454 | if (!SuppressMissingInputWarning && Inputs.empty()) { |
Daniel Dunbar | af61c71 | 2009-03-12 23:55:14 +0000 | [diff] [blame] | 455 | Diag(clang::diag::err_drv_no_input_files); |
| 456 | return; |
| 457 | } |
| 458 | |
| 459 | // Determine which compilation mode we are in. We look for options |
| 460 | // which affect the phase, starting with the earliest phases, and |
| 461 | // record which option we used to determine the final phase. |
Daniel Dunbar | ad2a9af | 2009-03-13 11:38:42 +0000 | [diff] [blame] | 462 | Arg *FinalPhaseArg = 0; |
| 463 | phases::ID FinalPhase; |
Daniel Dunbar | af61c71 | 2009-03-12 23:55:14 +0000 | [diff] [blame] | 464 | |
| 465 | // -{E,M,MM} only run the preprocessor. |
Daniel Dunbar | ad2a9af | 2009-03-13 11:38:42 +0000 | [diff] [blame] | 466 | if ((FinalPhaseArg = Args.getLastArg(options::OPT_E)) || |
| 467 | (FinalPhaseArg = Args.getLastArg(options::OPT_M)) || |
| 468 | (FinalPhaseArg = Args.getLastArg(options::OPT_MM))) { |
| 469 | FinalPhase = phases::Preprocess; |
Daniel Dunbar | af61c71 | 2009-03-12 23:55:14 +0000 | [diff] [blame] | 470 | |
Daniel Dunbar | 8022fd4 | 2009-03-15 00:48:16 +0000 | [diff] [blame] | 471 | // -{fsyntax-only,-analyze,emit-llvm,S} only run up to the compiler. |
| 472 | } else if ((FinalPhaseArg = Args.getLastArg(options::OPT_fsyntax_only)) || |
| 473 | (FinalPhaseArg = Args.getLastArg(options::OPT__analyze)) || |
| 474 | (FinalPhaseArg = Args.getLastArg(options::OPT_emit_llvm)) || |
Daniel Dunbar | ad2a9af | 2009-03-13 11:38:42 +0000 | [diff] [blame] | 475 | (FinalPhaseArg = Args.getLastArg(options::OPT_S))) { |
| 476 | FinalPhase = phases::Compile; |
Daniel Dunbar | af61c71 | 2009-03-12 23:55:14 +0000 | [diff] [blame] | 477 | |
| 478 | // -c only runs up to the assembler. |
Daniel Dunbar | ad2a9af | 2009-03-13 11:38:42 +0000 | [diff] [blame] | 479 | } else if ((FinalPhaseArg = Args.getLastArg(options::OPT_c))) { |
| 480 | FinalPhase = phases::Assemble; |
Daniel Dunbar | af61c71 | 2009-03-12 23:55:14 +0000 | [diff] [blame] | 481 | |
| 482 | // Otherwise do everything. |
| 483 | } else |
Daniel Dunbar | ad2a9af | 2009-03-13 11:38:42 +0000 | [diff] [blame] | 484 | FinalPhase = phases::Link; |
Daniel Dunbar | af61c71 | 2009-03-12 23:55:14 +0000 | [diff] [blame] | 485 | |
Daniel Dunbar | af61c71 | 2009-03-12 23:55:14 +0000 | [diff] [blame] | 486 | // Reject -Z* at the top level, these options should never have been |
| 487 | // exposed by gcc. |
| 488 | if (Arg *A = Args.getLastArg(options::OPT_Z)) |
| 489 | Diag(clang::diag::err_drv_use_of_Z_option) << A->getValue(Args); |
| 490 | |
Daniel Dunbar | ad2a9af | 2009-03-13 11:38:42 +0000 | [diff] [blame] | 491 | // Construct the actions to perform. |
| 492 | ActionList LinkerInputs; |
Daniel Dunbar | 53ec552 | 2009-03-12 07:58:46 +0000 | [diff] [blame] | 493 | for (unsigned i = 0, e = Inputs.size(); i != e; ++i) { |
Daniel Dunbar | ad2a9af | 2009-03-13 11:38:42 +0000 | [diff] [blame] | 494 | types::ID InputType = Inputs[i].first; |
| 495 | const Arg *InputArg = Inputs[i].second; |
| 496 | |
| 497 | unsigned NumSteps = types::getNumCompilationPhases(InputType); |
| 498 | assert(NumSteps && "Invalid number of steps!"); |
| 499 | |
| 500 | // If the first step comes after the final phase we are doing as |
| 501 | // part of this compilation, warn the user about it. |
| 502 | phases::ID InitialPhase = types::getCompilationPhase(InputType, 0); |
| 503 | if (InitialPhase > FinalPhase) { |
| 504 | Diag(clang::diag::warn_drv_input_file_unused) |
| 505 | << InputArg->getValue(Args) |
| 506 | << getPhaseName(InitialPhase) |
| 507 | << FinalPhaseArg->getOption().getName(); |
| 508 | continue; |
| 509 | } |
| 510 | |
| 511 | // Build the pipeline for this file. |
| 512 | Action *Current = new InputAction(*InputArg, InputType); |
| 513 | for (unsigned i = 0; i != NumSteps; ++i) { |
| 514 | phases::ID Phase = types::getCompilationPhase(InputType, i); |
| 515 | |
| 516 | // We are done if this step is past what the user requested. |
| 517 | if (Phase > FinalPhase) |
| 518 | break; |
| 519 | |
| 520 | // Queue linker inputs. |
| 521 | if (Phase == phases::Link) { |
| 522 | assert(i + 1 == NumSteps && "linking must be final compilation step."); |
| 523 | LinkerInputs.push_back(Current); |
| 524 | Current = 0; |
| 525 | break; |
| 526 | } |
| 527 | |
| 528 | // Otherwise construct the appropriate action. |
| 529 | Current = ConstructPhaseAction(Args, Phase, Current); |
| 530 | if (Current->getType() == types::TY_Nothing) |
| 531 | break; |
| 532 | } |
| 533 | |
| 534 | // If we ended with something, add to the output list. |
| 535 | if (Current) |
| 536 | Actions.push_back(Current); |
Daniel Dunbar | 53ec552 | 2009-03-12 07:58:46 +0000 | [diff] [blame] | 537 | } |
Daniel Dunbar | ad2a9af | 2009-03-13 11:38:42 +0000 | [diff] [blame] | 538 | |
| 539 | // Add a link action if necessary. |
| 540 | if (!LinkerInputs.empty()) |
| 541 | Actions.push_back(new LinkJobAction(LinkerInputs, types::TY_Image)); |
| 542 | } |
| 543 | |
| 544 | Action *Driver::ConstructPhaseAction(const ArgList &Args, phases::ID Phase, |
| 545 | Action *Input) const { |
| 546 | // Build the appropriate action. |
| 547 | switch (Phase) { |
| 548 | case phases::Link: assert(0 && "link action invalid here."); |
| 549 | case phases::Preprocess: { |
| 550 | types::ID OutputTy = types::getPreprocessedType(Input->getType()); |
| 551 | assert(OutputTy != types::TY_INVALID && |
| 552 | "Cannot preprocess this input type!"); |
| 553 | return new PreprocessJobAction(Input, OutputTy); |
| 554 | } |
| 555 | case phases::Precompile: |
| 556 | return new PrecompileJobAction(Input, types::TY_PCH); |
| 557 | case phases::Compile: { |
| 558 | if (Args.hasArg(options::OPT_fsyntax_only)) { |
| 559 | return new CompileJobAction(Input, types::TY_Nothing); |
| 560 | } else if (Args.hasArg(options::OPT__analyze)) { |
| 561 | return new AnalyzeJobAction(Input, types::TY_Plist); |
| 562 | } else if (Args.hasArg(options::OPT_emit_llvm)) { |
| 563 | types::ID Output = |
| 564 | Args.hasArg(options::OPT_S) ? types::TY_LLVMAsm : types::TY_LLVMBC; |
| 565 | return new CompileJobAction(Input, Output); |
| 566 | } else { |
| 567 | return new CompileJobAction(Input, types::TY_PP_Asm); |
| 568 | } |
| 569 | } |
| 570 | case phases::Assemble: |
| 571 | return new AssembleJobAction(Input, types::TY_Object); |
| 572 | } |
| 573 | |
| 574 | assert(0 && "invalid phase in ConstructPhaseAction"); |
| 575 | return 0; |
Daniel Dunbar | 53ec552 | 2009-03-12 07:58:46 +0000 | [diff] [blame] | 576 | } |
| 577 | |
Daniel Dunbar | f353c8c | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 578 | void Driver::BuildJobs(Compilation &C, const ActionList &Actions) const { |
| 579 | bool SaveTemps = C.getArgs().hasArg(options::OPT_save_temps); |
| 580 | bool UsePipes = C.getArgs().hasArg(options::OPT_pipe); |
| 581 | |
| 582 | // -save-temps inhibits pipes. |
| 583 | if (SaveTemps && UsePipes) { |
| 584 | Diag(clang::diag::warn_drv_pipe_ignored_with_save_temps); |
| 585 | UsePipes = true; |
| 586 | } |
| 587 | |
| 588 | Arg *FinalOutput = C.getArgs().getLastArg(options::OPT_o); |
| 589 | |
| 590 | // It is an error to provide a -o option if we are making multiple |
| 591 | // output files. |
| 592 | if (FinalOutput) { |
| 593 | unsigned NumOutputs = 0; |
| 594 | for (ActionList::const_iterator it = Actions.begin(), ie = Actions.end(); |
| 595 | it != ie; ++it) |
| 596 | if ((*it)->getType() != types::TY_Nothing) |
| 597 | ++NumOutputs; |
| 598 | |
| 599 | if (NumOutputs > 1) { |
| 600 | Diag(clang::diag::err_drv_output_argument_with_multiple_files); |
| 601 | FinalOutput = 0; |
| 602 | } |
| 603 | } |
| 604 | |
| 605 | for (ActionList::const_iterator it = Actions.begin(), ie = Actions.end(); |
| 606 | it != ie; ++it) { |
| 607 | Action *A = *it; |
| 608 | |
| 609 | // If we are linking an image for multiple archs then the linker |
| 610 | // wants -arch_multiple and -final_output <final image |
| 611 | // name>. Unfortunately, this doesn't fit in cleanly because we |
| 612 | // have to pass this information down. |
| 613 | // |
| 614 | // FIXME: This is a hack; find a cleaner way to integrate this |
| 615 | // into the process. |
| 616 | const char *LinkingOutput = 0; |
| 617 | if (isa<LinkJobAction>(A)) { |
| 618 | if (FinalOutput) |
| 619 | LinkingOutput = FinalOutput->getValue(C.getArgs()); |
| 620 | else |
| 621 | LinkingOutput = DefaultImageName.c_str(); |
| 622 | } |
| 623 | |
| 624 | InputInfo II; |
| 625 | BuildJobsForAction(C, |
| 626 | A, DefaultToolChain, |
| 627 | /*CanAcceptPipe*/ true, |
| 628 | /*AtTopLevel*/ true, |
| 629 | /*LinkingOutput*/ LinkingOutput, |
| 630 | II); |
| 631 | } |
Daniel Dunbar | 586dc23 | 2009-03-16 06:42:30 +0000 | [diff] [blame] | 632 | |
| 633 | // If there were no errors, warn about any unused arguments. |
| 634 | for (ArgList::const_iterator it = C.getArgs().begin(), ie = C.getArgs().end(); |
| 635 | it != ie; ++it) { |
| 636 | Arg *A = *it; |
| 637 | |
| 638 | // FIXME: It would be nice to be able to send the argument to the |
| 639 | // Diagnostic, so that extra values, position, and so on could be |
| 640 | // printed. |
| 641 | if (!A->isClaimed()) |
| 642 | Diag(clang::diag::warn_drv_unused_argument) |
| 643 | << A->getOption().getName(); |
| 644 | } |
Daniel Dunbar | 57b704d | 2009-03-13 22:12:33 +0000 | [diff] [blame] | 645 | } |
| 646 | |
Daniel Dunbar | f353c8c | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 647 | void Driver::BuildJobsForAction(Compilation &C, |
| 648 | const Action *A, |
| 649 | const ToolChain *TC, |
| 650 | bool CanAcceptPipe, |
| 651 | bool AtTopLevel, |
| 652 | const char *LinkingOutput, |
| 653 | InputInfo &Result) const { |
| 654 | if (const InputAction *IA = dyn_cast<InputAction>(A)) { |
| 655 | const char *Name = IA->getInputArg().getValue(C.getArgs()); |
| 656 | Result = InputInfo(Name, A->getType(), Name); |
| 657 | return; |
| 658 | } |
| 659 | |
| 660 | if (const BindArchAction *BAA = dyn_cast<BindArchAction>(A)) { |
| 661 | const char *ArchName = BAA->getArchName(); |
| 662 | BuildJobsForAction(C, |
| 663 | *BAA->begin(), |
| 664 | Host->getToolChain(C.getArgs(), ArchName), |
| 665 | CanAcceptPipe, |
| 666 | AtTopLevel, |
| 667 | LinkingOutput, |
| 668 | Result); |
| 669 | return; |
| 670 | } |
| 671 | |
| 672 | const JobAction *JA = cast<JobAction>(A); |
| 673 | const Tool &T = TC->SelectTool(C, *JA); |
| 674 | |
| 675 | // See if we should use an integrated preprocessor. We do so when we |
| 676 | // have exactly one input, since this is the only use case we care |
| 677 | // about (irrelevant since we don't support combine yet). |
| 678 | bool UseIntegratedCPP = false; |
| 679 | const ActionList *Inputs = &A->getInputs(); |
| 680 | if (Inputs->size() == 1 && isa<PreprocessJobAction>(*Inputs->begin())) { |
| 681 | if (!C.getArgs().hasArg(options::OPT_no_integrated_cpp) && |
| 682 | !C.getArgs().hasArg(options::OPT_traditional_cpp) && |
| 683 | !C.getArgs().hasArg(options::OPT_save_temps) && |
| 684 | T.hasIntegratedCPP()) { |
| 685 | UseIntegratedCPP = true; |
| 686 | Inputs = &(*Inputs)[0]->getInputs(); |
| 687 | } |
| 688 | } |
| 689 | |
| 690 | // Only use pipes when there is exactly one input. |
| 691 | bool TryToUsePipeInput = Inputs->size() == 1 && T.acceptsPipedInput(); |
| 692 | llvm::SmallVector<InputInfo, 4> InputInfos; |
| 693 | for (ActionList::const_iterator it = Inputs->begin(), ie = Inputs->end(); |
| 694 | it != ie; ++it) { |
| 695 | InputInfo II; |
| 696 | BuildJobsForAction(C, *it, TC, TryToUsePipeInput, |
| 697 | /*AtTopLevel*/false, |
| 698 | LinkingOutput, |
| 699 | II); |
| 700 | InputInfos.push_back(II); |
| 701 | } |
| 702 | |
| 703 | // Determine if we should output to a pipe. |
| 704 | bool OutputToPipe = false; |
| 705 | if (CanAcceptPipe && T.canPipeOutput()) { |
| 706 | // Some actions default to writing to a pipe if they are the top |
| 707 | // level phase and there was no user override. |
| 708 | // |
| 709 | // FIXME: Is there a better way to handle this? |
| 710 | if (AtTopLevel) { |
| 711 | if (isa<PreprocessJobAction>(A) && !C.getArgs().hasArg(options::OPT_o)) |
| 712 | OutputToPipe = true; |
| 713 | } else if (C.getArgs().hasArg(options::OPT_pipe)) |
| 714 | OutputToPipe = true; |
| 715 | } |
| 716 | |
| 717 | // Figure out where to put the job (pipes). |
| 718 | Job *Dest = &C.getJobs(); |
| 719 | if (InputInfos[0].isPipe()) { |
| 720 | assert(InputInfos.size() == 1 && "Unexpected pipe with multiple inputs."); |
| 721 | Dest = &InputInfos[0].getPipe(); |
| 722 | } |
| 723 | |
| 724 | // Always use the first input as the base input. |
| 725 | const char *BaseInput = InputInfos[0].getBaseInput(); |
| 726 | const char *Output = "foo"; |
| 727 | // FIXME: Make the job. |
| 728 | |
| 729 | Result = InputInfo(Output, A->getType(), BaseInput); |
| 730 | } |
| 731 | |
Daniel Dunbar | 2ba38ba | 2009-03-16 05:25:36 +0000 | [diff] [blame] | 732 | llvm::sys::Path Driver::GetFilePath(const char *Name, |
| 733 | const ToolChain *TC) const { |
Daniel Dunbar | cb88167 | 2009-03-13 00:51:18 +0000 | [diff] [blame] | 734 | // FIXME: Implement. |
Daniel Dunbar | 2ba38ba | 2009-03-16 05:25:36 +0000 | [diff] [blame] | 735 | if (!TC) TC = DefaultToolChain; |
| 736 | |
Daniel Dunbar | cb88167 | 2009-03-13 00:51:18 +0000 | [diff] [blame] | 737 | return llvm::sys::Path(Name); |
| 738 | } |
| 739 | |
Daniel Dunbar | 2ba38ba | 2009-03-16 05:25:36 +0000 | [diff] [blame] | 740 | llvm::sys::Path Driver::GetProgramPath(const char *Name, |
| 741 | const ToolChain *TC) const { |
Daniel Dunbar | cb88167 | 2009-03-13 00:51:18 +0000 | [diff] [blame] | 742 | // FIXME: Implement. |
Daniel Dunbar | 2ba38ba | 2009-03-16 05:25:36 +0000 | [diff] [blame] | 743 | if (!TC) TC = DefaultToolChain; |
| 744 | |
Daniel Dunbar | cb88167 | 2009-03-13 00:51:18 +0000 | [diff] [blame] | 745 | return llvm::sys::Path(Name); |
| 746 | } |
| 747 | |
Daniel Dunbar | dd98e2c | 2009-03-10 23:41:59 +0000 | [diff] [blame] | 748 | HostInfo *Driver::GetHostInfo(const char *Triple) { |
| 749 | // Dice into arch, platform, and OS. This matches |
| 750 | // arch,platform,os = '(.*?)-(.*?)-(.*?)' |
| 751 | // and missing fields are left empty. |
| 752 | std::string Arch, Platform, OS; |
| 753 | |
| 754 | if (const char *ArchEnd = strchr(Triple, '-')) { |
| 755 | Arch = std::string(Triple, ArchEnd); |
| 756 | |
| 757 | if (const char *PlatformEnd = strchr(ArchEnd+1, '-')) { |
| 758 | Platform = std::string(ArchEnd+1, PlatformEnd); |
| 759 | OS = PlatformEnd+1; |
| 760 | } else |
| 761 | Platform = ArchEnd+1; |
| 762 | } else |
| 763 | Arch = Triple; |
| 764 | |
Daniel Dunbar | a88162c | 2009-03-13 12:23:29 +0000 | [diff] [blame] | 765 | if (memcmp(&OS[0], "darwin", 6) == 0) |
Daniel Dunbar | dd98e2c | 2009-03-10 23:41:59 +0000 | [diff] [blame] | 766 | return new DarwinHostInfo(Arch.c_str(), Platform.c_str(), OS.c_str()); |
| 767 | |
| 768 | return new UnknownHostInfo(Arch.c_str(), Platform.c_str(), OS.c_str()); |
| 769 | } |