blob: fd2ff4813824207d361bc225b4f7b53cd81da31c [file] [log] [blame]
Daniel Dunbar3ede8d02009-03-02 19:59:07 +00001//===--- 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 Dunbar3ede8d02009-03-02 19:59:07 +000010#include "clang/Driver/Driver.h"
Daniel Dunbar3ede8d02009-03-02 19:59:07 +000011
Daniel Dunbar53ec5522009-03-12 07:58:46 +000012#include "clang/Driver/Action.h"
Daniel Dunbar1b3bb6e2009-03-04 20:49:20 +000013#include "clang/Driver/Arg.h"
14#include "clang/Driver/ArgList.h"
15#include "clang/Driver/Compilation.h"
Daniel Dunbar4ad4b3e2009-03-12 08:55:43 +000016#include "clang/Driver/DriverDiagnostic.h"
Daniel Dunbardd98e2c2009-03-10 23:41:59 +000017#include "clang/Driver/HostInfo.h"
Daniel Dunbarf353c8c2009-03-16 06:56:51 +000018#include "clang/Driver/Job.h"
Daniel Dunbar06482622009-03-05 06:38:47 +000019#include "clang/Driver/Option.h"
Daniel Dunbar1b3bb6e2009-03-04 20:49:20 +000020#include "clang/Driver/Options.h"
Daniel Dunbarf353c8c2009-03-16 06:56:51 +000021#include "clang/Driver/Tool.h"
22#include "clang/Driver/ToolChain.h"
Daniel Dunbar53ec5522009-03-12 07:58:46 +000023#include "clang/Driver/Types.h"
Daniel Dunbar06482622009-03-05 06:38:47 +000024
Daniel Dunbar13689542009-03-13 20:33:35 +000025#include "llvm/ADT/StringSet.h"
Daniel Dunbar8f25c792009-03-18 01:38:48 +000026#include "llvm/Support/PrettyStackTrace.h"
Daniel Dunbar06482622009-03-05 06:38:47 +000027#include "llvm/Support/raw_ostream.h"
Daniel Dunbar53ec5522009-03-12 07:58:46 +000028#include "llvm/System/Path.h"
Daniel Dunbarba102132009-03-13 12:19:02 +000029
Daniel Dunbarf353c8c2009-03-16 06:56:51 +000030#include "InputInfo.h"
31
Daniel Dunbarba102132009-03-13 12:19:02 +000032#include <map>
33
Daniel Dunbar1b3bb6e2009-03-04 20:49:20 +000034using namespace clang::driver;
35
Daniel Dunbardd98e2c2009-03-10 23:41:59 +000036Driver::Driver(const char *_Name, const char *_Dir,
Daniel Dunbar4ad4b3e2009-03-12 08:55:43 +000037 const char *_DefaultHostTriple,
Daniel Dunbarf353c8c2009-03-16 06:56:51 +000038 const char *_DefaultImageName,
Daniel Dunbar4ad4b3e2009-03-12 08:55:43 +000039 Diagnostic &_Diags)
40 : Opts(new OptTable()), Diags(_Diags),
Daniel Dunbardd98e2c2009-03-10 23:41:59 +000041 Name(_Name), Dir(_Dir), DefaultHostTriple(_DefaultHostTriple),
Daniel Dunbarf353c8c2009-03-16 06:56:51 +000042 DefaultImageName(_DefaultImageName),
Daniel Dunbardd98e2c2009-03-10 23:41:59 +000043 Host(0),
Daniel Dunbar5c3c1d72009-03-17 22:47:06 +000044 CCCIsCXX(false), CCCEcho(false), CCCPrintBindings(false),
Daniel Dunbar8b1604e2009-03-13 00:17:48 +000045 CCCNoClang(false), CCCNoClangCXX(false), CCCNoClangCPP(false),
46 SuppressMissingInputWarning(false)
Daniel Dunbar365c02f2009-03-10 20:52:46 +000047{
Daniel Dunbar3ede8d02009-03-02 19:59:07 +000048}
49
50Driver::~Driver() {
Daniel Dunbar1b3bb6e2009-03-04 20:49:20 +000051 delete Opts;
Daniel Dunbar7e4534d2009-03-18 01:09:40 +000052 delete Host;
Daniel Dunbar3ede8d02009-03-02 19:59:07 +000053}
54
Daniel Dunbar06482622009-03-05 06:38:47 +000055ArgList *Driver::ParseArgStrings(const char **ArgBegin, const char **ArgEnd) {
Daniel Dunbar8f25c792009-03-18 01:38:48 +000056 llvm::PrettyStackTraceString CrashInfo("Command line argument parsing");
Daniel Dunbar06482622009-03-05 06:38:47 +000057 ArgList *Args = new ArgList(ArgBegin, ArgEnd);
58
Daniel Dunbarad2a9af2009-03-13 11:38:42 +000059 // FIXME: Handle '@' args (or at least error on them).
60
Daniel Dunbar06482622009-03-05 06:38:47 +000061 unsigned Index = 0, End = ArgEnd - ArgBegin;
62 while (Index < End) {
Daniel Dunbar41393402009-03-13 01:01:44 +000063 // gcc's handling of empty arguments doesn't make
64 // sense, but this is not a common use case. :)
65 //
66 // We just ignore them here (note that other things may
67 // still take them as arguments).
68 if (Args->getArgString(Index)[0] == '\0') {
69 ++Index;
70 continue;
71 }
72
Daniel Dunbar06482622009-03-05 06:38:47 +000073 unsigned Prev = Index;
74 Arg *A = getOpts().ParseOneArg(*Args, Index, End);
Daniel Dunbar53ec5522009-03-12 07:58:46 +000075 if (A) {
76 if (A->getOption().isUnsupported()) {
Daniel Dunbarb897f5d2009-03-12 09:13:48 +000077 Diag(clang::diag::err_drv_unsupported_opt) << A->getOption().getName();
Daniel Dunbar53ec5522009-03-12 07:58:46 +000078 continue;
79 }
80
Daniel Dunbar06482622009-03-05 06:38:47 +000081 Args->append(A);
Daniel Dunbar53ec5522009-03-12 07:58:46 +000082 }
Daniel Dunbar06482622009-03-05 06:38:47 +000083
84 assert(Index > Prev && "Parser failed to consume argument.");
Daniel Dunbar70c16842009-03-17 04:12:06 +000085 (void) Prev;
Daniel Dunbar06482622009-03-05 06:38:47 +000086 }
87
88 return Args;
89}
90
Daniel Dunbar3ede8d02009-03-02 19:59:07 +000091Compilation *Driver::BuildCompilation(int argc, const char **argv) {
Daniel Dunbar8f25c792009-03-18 01:38:48 +000092 llvm::PrettyStackTraceString CrashInfo("Compilation construction");
93
Daniel Dunbarcb881672009-03-13 00:51:18 +000094 // FIXME: Handle environment options which effect driver behavior,
95 // somewhere (client?). GCC_EXEC_PREFIX, COMPILER_PATH,
96 // LIBRARY_PATH, LPATH, CC_PRINT_OPTIONS, QA_OVERRIDE_GCC3_OPTIONS.
97
98 // FIXME: What are we going to do with -V and -b?
99
100 // FIXME: Handle CCC_ADD_ARGS.
101
Daniel Dunbar365c02f2009-03-10 20:52:46 +0000102 // FIXME: This stuff needs to go into the Compilation, not the
103 // driver.
Daniel Dunbar53ec5522009-03-12 07:58:46 +0000104 bool CCCPrintOptions = false, CCCPrintActions = false;
Daniel Dunbar06482622009-03-05 06:38:47 +0000105
Daniel Dunbar365c02f2009-03-10 20:52:46 +0000106 const char **Start = argv + 1, **End = argv + argc;
Daniel Dunbardd98e2c2009-03-10 23:41:59 +0000107 const char *HostTriple = DefaultHostTriple.c_str();
Daniel Dunbar365c02f2009-03-10 20:52:46 +0000108
109 // Read -ccc args.
110 //
111 // FIXME: We need to figure out where this behavior should
112 // live. Most of it should be outside in the client; the parts that
113 // aren't should have proper options, either by introducing new ones
114 // or by overloading gcc ones like -V or -b.
115 for (; Start != End && memcmp(*Start, "-ccc-", 5) == 0; ++Start) {
116 const char *Opt = *Start + 5;
117
118 if (!strcmp(Opt, "print-options")) {
119 CCCPrintOptions = true;
120 } else if (!strcmp(Opt, "print-phases")) {
Daniel Dunbar53ec5522009-03-12 07:58:46 +0000121 CCCPrintActions = true;
Daniel Dunbar5c3c1d72009-03-17 22:47:06 +0000122 } else if (!strcmp(Opt, "print-bindings")) {
123 CCCPrintBindings = true;
Daniel Dunbar365c02f2009-03-10 20:52:46 +0000124 } else if (!strcmp(Opt, "cxx")) {
125 CCCIsCXX = true;
126 } else if (!strcmp(Opt, "echo")) {
127 CCCEcho = true;
128
129 } else if (!strcmp(Opt, "no-clang")) {
130 CCCNoClang = true;
131 } else if (!strcmp(Opt, "no-clang-cxx")) {
132 CCCNoClangCXX = true;
133 } else if (!strcmp(Opt, "no-clang-cpp")) {
134 CCCNoClangCPP = true;
135 } else if (!strcmp(Opt, "clang-archs")) {
136 assert(Start+1 < End && "FIXME: -ccc- argument handling.");
137 const char *Cur = *++Start;
138
139 for (;;) {
140 const char *Next = strchr(Cur, ',');
141
142 if (Next) {
143 CCCClangArchs.insert(std::string(Cur, Next));
144 Cur = Next + 1;
145 } else {
146 CCCClangArchs.insert(std::string(Cur));
147 break;
148 }
149 }
150
Daniel Dunbardd98e2c2009-03-10 23:41:59 +0000151 } else if (!strcmp(Opt, "host-triple")) {
Daniel Dunbar365c02f2009-03-10 20:52:46 +0000152 assert(Start+1 < End && "FIXME: -ccc- argument handling.");
Daniel Dunbardd98e2c2009-03-10 23:41:59 +0000153 HostTriple = *++Start;
Daniel Dunbar365c02f2009-03-10 20:52:46 +0000154
155 } else {
156 // FIXME: Error handling.
157 llvm::errs() << "invalid option: " << *Start << "\n";
158 exit(1);
159 }
160 }
Daniel Dunbardd98e2c2009-03-10 23:41:59 +0000161
Daniel Dunbar365c02f2009-03-10 20:52:46 +0000162 ArgList *Args = ParseArgStrings(Start, End);
163
Daniel Dunbare5049522009-03-17 20:45:45 +0000164 Host = GetHostInfo(HostTriple);
Daniel Dunbarcb881672009-03-13 00:51:18 +0000165
Daniel Dunbar586dc232009-03-16 06:42:30 +0000166 // The compilation takes ownership of Args.
Daniel Dunbar10ffa9a2009-03-18 03:13:20 +0000167 Compilation *C = new Compilation(*Host->getToolChain(*Args), Args);
Daniel Dunbar21549232009-03-18 02:55:38 +0000168
169 // FIXME: This behavior shouldn't be here.
170 if (CCCPrintOptions) {
171 PrintOptions(C->getArgs());
172 return C;
173 }
174
175 if (!HandleImmediateArgs(*C))
176 return C;
177
178 // Construct the list of abstract actions to perform for this
179 // compilation. We avoid passing a Compilation here simply to
180 // enforce the abstraction that pipelining is not host or toolchain
181 // dependent (other than the driver driver test).
182 if (Host->useDriverDriver())
183 BuildUniversalActions(C->getArgs(), C->getActions());
184 else
185 BuildActions(C->getArgs(), C->getActions());
186
187 if (CCCPrintActions) {
Daniel Dunbar10ffa9a2009-03-18 03:13:20 +0000188 PrintActions(*C);
Daniel Dunbar21549232009-03-18 02:55:38 +0000189 return C;
190 }
191
192 BuildJobs(*C);
Daniel Dunbar8d2554a2009-03-15 01:38:15 +0000193
194 return C;
Daniel Dunbar365c02f2009-03-10 20:52:46 +0000195}
196
Daniel Dunbard65bddc2009-03-12 18:24:49 +0000197void Driver::PrintOptions(const ArgList &Args) const {
Daniel Dunbar06482622009-03-05 06:38:47 +0000198 unsigned i = 0;
Daniel Dunbar53ec5522009-03-12 07:58:46 +0000199 for (ArgList::const_iterator it = Args.begin(), ie = Args.end();
Daniel Dunbar06482622009-03-05 06:38:47 +0000200 it != ie; ++it, ++i) {
201 Arg *A = *it;
202 llvm::errs() << "Option " << i << " - "
203 << "Name: \"" << A->getOption().getName() << "\", "
204 << "Values: {";
205 for (unsigned j = 0; j < A->getNumValues(); ++j) {
206 if (j)
207 llvm::errs() << ", ";
Daniel Dunbar53ec5522009-03-12 07:58:46 +0000208 llvm::errs() << '"' << A->getValue(Args, j) << '"';
Daniel Dunbar06482622009-03-05 06:38:47 +0000209 }
210 llvm::errs() << "}\n";
Daniel Dunbar06482622009-03-05 06:38:47 +0000211 }
Daniel Dunbar3ede8d02009-03-02 19:59:07 +0000212}
Daniel Dunbardd98e2c2009-03-10 23:41:59 +0000213
Daniel Dunbarcb881672009-03-13 00:51:18 +0000214void Driver::PrintVersion() const {
Mike Stump5d023c32009-03-18 14:00:02 +0000215 static char buf[] = "$URL$";
216 char *zap = strstr(buf, "/lib/Driver");
217 if (zap)
218 *zap = 0;
219 zap = strstr(buf, "/clang/tools/clang");
220 if (zap)
221 *zap = 0;
222 const char *vers = buf+10;
Daniel Dunbarcb881672009-03-13 00:51:18 +0000223
224 // FIXME: The following handlers should use a callback mechanism, we
225 // don't know what the client would like to do.
Mike Stump5d023c32009-03-18 14:00:02 +0000226 llvm::errs() << "ccc version 1.0 (" << vers << ")" << "\n";
227 // FIXME: Add cmake support and remove #ifdef
228#ifdef TARGET_TRIPLE
229 llvm::errs() << "Target: " << TARGET_TRIPLE << "\n";
230#endif
Daniel Dunbarcb881672009-03-13 00:51:18 +0000231}
232
Daniel Dunbar21549232009-03-18 02:55:38 +0000233bool Driver::HandleImmediateArgs(const Compilation &C) {
Daniel Dunbarcb881672009-03-13 00:51:18 +0000234 // The order these options are handled in in gcc is all over the
235 // place, but we don't expect inconsistencies w.r.t. that to matter
236 // in practice.
Daniel Dunbar21549232009-03-18 02:55:38 +0000237 if (C.getArgs().hasArg(options::OPT_v) ||
238 C.getArgs().hasArg(options::OPT__HASH_HASH_HASH)) {
Daniel Dunbarcb881672009-03-13 00:51:18 +0000239 PrintVersion();
240 SuppressMissingInputWarning = true;
241 }
242
Daniel Dunbar21549232009-03-18 02:55:38 +0000243 const ToolChain &TC = C.getDefaultToolChain();
Daniel Dunbarcb881672009-03-13 00:51:18 +0000244 // FIXME: The following handlers should use a callback mechanism, we
245 // don't know what the client would like to do.
Daniel Dunbar21549232009-03-18 02:55:38 +0000246 if (Arg *A = C.getArgs().getLastArg(options::OPT_print_file_name_EQ)) {
247 llvm::outs() << GetFilePath(A->getValue(C.getArgs()), TC).toString()
248 << "\n";
Daniel Dunbarcb881672009-03-13 00:51:18 +0000249 return false;
250 }
251
Daniel Dunbar21549232009-03-18 02:55:38 +0000252 if (Arg *A = C.getArgs().getLastArg(options::OPT_print_prog_name_EQ)) {
253 llvm::outs() << GetProgramPath(A->getValue(C.getArgs()), TC).toString()
254 << "\n";
Daniel Dunbarcb881672009-03-13 00:51:18 +0000255 return false;
256 }
257
Daniel Dunbar21549232009-03-18 02:55:38 +0000258 if (C.getArgs().hasArg(options::OPT_print_libgcc_file_name)) {
259 llvm::outs() << GetProgramPath("libgcc.a", TC).toString() << "\n";
Daniel Dunbarcb881672009-03-13 00:51:18 +0000260 return false;
261 }
262
263 return true;
264}
265
Daniel Dunbar10ffa9a2009-03-18 03:13:20 +0000266static unsigned PrintActions1(const Compilation &C,
Daniel Dunbarba102132009-03-13 12:19:02 +0000267 Action *A,
268 std::map<Action*, unsigned> &Ids) {
269 if (Ids.count(A))
270 return Ids[A];
271
272 std::string str;
273 llvm::raw_string_ostream os(str);
274
275 os << Action::getClassName(A->getKind()) << ", ";
276 if (InputAction *IA = dyn_cast<InputAction>(A)) {
Daniel Dunbar10ffa9a2009-03-18 03:13:20 +0000277 os << "\"" << IA->getInputArg().getValue(C.getArgs()) << "\"";
Daniel Dunbarba102132009-03-13 12:19:02 +0000278 } else if (BindArchAction *BIA = dyn_cast<BindArchAction>(A)) {
Daniel Dunbar10ffa9a2009-03-18 03:13:20 +0000279 os << '"' << (BIA->getArchName() ? BIA->getArchName() :
280 C.getDefaultToolChain().getArchName()) << '"'
281 << ", {" << PrintActions1(C, *BIA->begin(), Ids) << "}";
Daniel Dunbarba102132009-03-13 12:19:02 +0000282 } else {
283 os << "{";
284 for (Action::iterator it = A->begin(), ie = A->end(); it != ie;) {
Daniel Dunbar10ffa9a2009-03-18 03:13:20 +0000285 os << PrintActions1(C, *it, Ids);
Daniel Dunbarba102132009-03-13 12:19:02 +0000286 ++it;
287 if (it != ie)
288 os << ", ";
289 }
290 os << "}";
291 }
292
293 unsigned Id = Ids.size();
294 Ids[A] = Id;
Daniel Dunbarb269c322009-03-13 17:20:20 +0000295 llvm::errs() << Id << ": " << os.str() << ", "
Daniel Dunbarba102132009-03-13 12:19:02 +0000296 << types::getTypeName(A->getType()) << "\n";
297
298 return Id;
299}
300
Daniel Dunbar10ffa9a2009-03-18 03:13:20 +0000301void Driver::PrintActions(const Compilation &C) const {
Daniel Dunbarba102132009-03-13 12:19:02 +0000302 std::map<Action*, unsigned> Ids;
Daniel Dunbar10ffa9a2009-03-18 03:13:20 +0000303 for (ActionList::const_iterator it = C.getActions().begin(),
304 ie = C.getActions().end(); it != ie; ++it)
305 PrintActions1(C, *it, Ids);
Daniel Dunbar53ec5522009-03-12 07:58:46 +0000306}
307
Daniel Dunbar21549232009-03-18 02:55:38 +0000308void Driver::BuildUniversalActions(const ArgList &Args,
309 ActionList &Actions) const {
Daniel Dunbar8f25c792009-03-18 01:38:48 +0000310 llvm::PrettyStackTraceString CrashInfo("Building actions for universal build");
Daniel Dunbar13689542009-03-13 20:33:35 +0000311 // Collect the list of architectures. Duplicates are allowed, but
312 // should only be handled once (in the order seen).
313 llvm::StringSet<> ArchNames;
314 llvm::SmallVector<const char *, 4> Archs;
Daniel Dunbar2fe63e62009-03-12 18:40:18 +0000315 for (ArgList::const_iterator it = Args.begin(), ie = Args.end();
316 it != ie; ++it) {
317 Arg *A = *it;
318
319 if (A->getOption().getId() == options::OPT_arch) {
Daniel Dunbar13689542009-03-13 20:33:35 +0000320 const char *Name = A->getValue(Args);
321
Daniel Dunbar2fe63e62009-03-12 18:40:18 +0000322 // FIXME: We need to handle canonicalization of the specified
323 // arch?
324
Daniel Dunbar13689542009-03-13 20:33:35 +0000325 if (ArchNames.insert(Name))
326 Archs.push_back(Name);
Daniel Dunbar2fe63e62009-03-12 18:40:18 +0000327 }
328 }
329
Daniel Dunbar10ffa9a2009-03-18 03:13:20 +0000330 // When there is no explicit arch for this platform, make sure we
331 // still bind the architecture (to the default) so that -Xarch_ is
332 // handled correctly.
333 if (!Archs.size())
334 Archs.push_back(0);
Daniel Dunbar2fe63e62009-03-12 18:40:18 +0000335
336 // FIXME: We killed off some others but these aren't yet detected in
337 // a functional manner. If we added information to jobs about which
338 // "auxiliary" files they wrote then we could detect the conflict
339 // these cause downstream.
340 if (Archs.size() > 1) {
341 // No recovery needed, the point of this is just to prevent
342 // overwriting the same files.
343 if (const Arg *A = Args.getLastArg(options::OPT_M_Group))
344 Diag(clang::diag::err_drv_invalid_opt_with_multiple_archs)
345 << A->getOption().getName();
346 if (const Arg *A = Args.getLastArg(options::OPT_save_temps))
347 Diag(clang::diag::err_drv_invalid_opt_with_multiple_archs)
348 << A->getOption().getName();
349 }
350
351 ActionList SingleActions;
352 BuildActions(Args, SingleActions);
353
354 // Add in arch binding and lipo (if necessary) for every top level
355 // action.
356 for (unsigned i = 0, e = SingleActions.size(); i != e; ++i) {
357 Action *Act = SingleActions[i];
358
359 // Make sure we can lipo this kind of output. If not (and it is an
360 // actual output) then we disallow, since we can't create an
361 // output file with the right name without overwriting it. We
362 // could remove this oddity by just changing the output names to
363 // include the arch, which would also fix
364 // -save-temps. Compatibility wins for now.
365
Daniel Dunbar3dbd6c52009-03-13 17:46:02 +0000366 if (Archs.size() > 1 && !types::canLipoType(Act->getType()))
Daniel Dunbar2fe63e62009-03-12 18:40:18 +0000367 Diag(clang::diag::err_drv_invalid_output_with_multiple_archs)
368 << types::getTypeName(Act->getType());
369
370 ActionList Inputs;
Daniel Dunbar13689542009-03-13 20:33:35 +0000371 for (unsigned i = 0, e = Archs.size(); i != e; ++i )
372 Inputs.push_back(new BindArchAction(Act, Archs[i]));
Daniel Dunbar2fe63e62009-03-12 18:40:18 +0000373
374 // Lipo if necessary, We do it this way because we need to set the
375 // arch flag so that -Xarch_ gets overwritten.
376 if (Inputs.size() == 1 || Act->getType() == types::TY_Nothing)
377 Actions.append(Inputs.begin(), Inputs.end());
378 else
379 Actions.push_back(new LipoJobAction(Inputs, Act->getType()));
380 }
Daniel Dunbar53ec5522009-03-12 07:58:46 +0000381}
382
Daniel Dunbar21549232009-03-18 02:55:38 +0000383void Driver::BuildActions(const ArgList &Args, ActionList &Actions) const {
Daniel Dunbar8f25c792009-03-18 01:38:48 +0000384 llvm::PrettyStackTraceString CrashInfo("Building compilation actions");
Daniel Dunbaraf61c712009-03-12 23:55:14 +0000385 // Start by constructing the list of inputs and their types.
386
Daniel Dunbar83dd21f2009-03-13 17:57:10 +0000387 // Track the current user specified (-x) input. We also explicitly
388 // track the argument used to set the type; we only want to claim
389 // the type when we actually use it, so we warn about unused -x
390 // arguments.
391 types::ID InputType = types::TY_Nothing;
392 Arg *InputTypeArg = 0;
393
Daniel Dunbar53ec5522009-03-12 07:58:46 +0000394 llvm::SmallVector<std::pair<types::ID, const Arg*>, 16> Inputs;
395 for (ArgList::const_iterator it = Args.begin(), ie = Args.end();
396 it != ie; ++it) {
397 Arg *A = *it;
398
399 if (isa<InputOption>(A->getOption())) {
400 const char *Value = A->getValue(Args);
401 types::ID Ty = types::TY_INVALID;
402
403 // Infer the input type if necessary.
Daniel Dunbar83dd21f2009-03-13 17:57:10 +0000404 if (InputType == types::TY_Nothing) {
405 // If there was an explicit arg for this, claim it.
406 if (InputTypeArg)
407 InputTypeArg->claim();
408
Daniel Dunbar53ec5522009-03-12 07:58:46 +0000409 // stdin must be handled specially.
410 if (memcmp(Value, "-", 2) == 0) {
411 // If running with -E, treat as a C input (this changes the
412 // builtin macros, for example). This may be overridden by
413 // -ObjC below.
414 //
415 // Otherwise emit an error but still use a valid type to
416 // avoid spurious errors (e.g., no inputs).
Daniel Dunbar8022fd42009-03-15 00:48:16 +0000417 if (!Args.hasArg(options::OPT_E, false))
Daniel Dunbarb897f5d2009-03-12 09:13:48 +0000418 Diag(clang::diag::err_drv_unknown_stdin_type);
Daniel Dunbar53ec5522009-03-12 07:58:46 +0000419 Ty = types::TY_C;
420 } else {
421 // Otherwise lookup by extension, and fallback to ObjectType
422 // if not found.
423 if (const char *Ext = strrchr(Value, '.'))
424 Ty = types::lookupTypeForExtension(Ext + 1);
425 if (Ty == types::TY_INVALID)
426 Ty = types::TY_Object;
427 }
428
429 // -ObjC and -ObjC++ override the default language, but only
430 // -for "source files". We just treat everything that isn't a
431 // -linker input as a source file.
432 //
433 // FIXME: Clean this up if we move the phase sequence into the
434 // type.
435 if (Ty != types::TY_Object) {
436 if (Args.hasArg(options::OPT_ObjC))
437 Ty = types::TY_ObjC;
438 else if (Args.hasArg(options::OPT_ObjCXX))
439 Ty = types::TY_ObjCXX;
440 }
441 } else {
442 assert(InputTypeArg && "InputType set w/o InputTypeArg");
443 InputTypeArg->claim();
444 Ty = InputType;
445 }
446
447 // Check that the file exists. It isn't clear this is worth
448 // doing, since the tool presumably does this anyway, and this
449 // just adds an extra stat to the equation, but this is gcc
450 // compatible.
451 if (memcmp(Value, "-", 2) != 0 && !llvm::sys::Path(Value).exists())
Daniel Dunbarb897f5d2009-03-12 09:13:48 +0000452 Diag(clang::diag::err_drv_no_such_file) << A->getValue(Args);
Daniel Dunbar53ec5522009-03-12 07:58:46 +0000453 else
454 Inputs.push_back(std::make_pair(Ty, A));
455
456 } else if (A->getOption().isLinkerInput()) {
457 // Just treat as object type, we could make a special type for
458 // this if necessary.
459 Inputs.push_back(std::make_pair(types::TY_Object, A));
460
461 } else if (A->getOption().getId() == options::OPT_x) {
462 InputTypeArg = A;
463 InputType = types::lookupTypeForTypeSpecifier(A->getValue(Args));
464
465 // Follow gcc behavior and treat as linker input for invalid -x
466 // options. Its not clear why we shouldn't just revert to
467 // unknown; but this isn't very important, we might as well be
468 // bug comatible.
469 if (!InputType) {
Daniel Dunbarb897f5d2009-03-12 09:13:48 +0000470 Diag(clang::diag::err_drv_unknown_language) << A->getValue(Args);
Daniel Dunbar53ec5522009-03-12 07:58:46 +0000471 InputType = types::TY_Object;
472 }
473 }
474 }
475
Daniel Dunbar8b1604e2009-03-13 00:17:48 +0000476 if (!SuppressMissingInputWarning && Inputs.empty()) {
Daniel Dunbaraf61c712009-03-12 23:55:14 +0000477 Diag(clang::diag::err_drv_no_input_files);
478 return;
479 }
480
481 // Determine which compilation mode we are in. We look for options
482 // which affect the phase, starting with the earliest phases, and
483 // record which option we used to determine the final phase.
Daniel Dunbarad2a9af2009-03-13 11:38:42 +0000484 Arg *FinalPhaseArg = 0;
485 phases::ID FinalPhase;
Daniel Dunbaraf61c712009-03-12 23:55:14 +0000486
487 // -{E,M,MM} only run the preprocessor.
Daniel Dunbarad2a9af2009-03-13 11:38:42 +0000488 if ((FinalPhaseArg = Args.getLastArg(options::OPT_E)) ||
489 (FinalPhaseArg = Args.getLastArg(options::OPT_M)) ||
490 (FinalPhaseArg = Args.getLastArg(options::OPT_MM))) {
491 FinalPhase = phases::Preprocess;
Daniel Dunbaraf61c712009-03-12 23:55:14 +0000492
Daniel Dunbar8022fd42009-03-15 00:48:16 +0000493 // -{fsyntax-only,-analyze,emit-llvm,S} only run up to the compiler.
494 } else if ((FinalPhaseArg = Args.getLastArg(options::OPT_fsyntax_only)) ||
495 (FinalPhaseArg = Args.getLastArg(options::OPT__analyze)) ||
496 (FinalPhaseArg = Args.getLastArg(options::OPT_emit_llvm)) ||
Daniel Dunbarad2a9af2009-03-13 11:38:42 +0000497 (FinalPhaseArg = Args.getLastArg(options::OPT_S))) {
498 FinalPhase = phases::Compile;
Daniel Dunbaraf61c712009-03-12 23:55:14 +0000499
500 // -c only runs up to the assembler.
Daniel Dunbarad2a9af2009-03-13 11:38:42 +0000501 } else if ((FinalPhaseArg = Args.getLastArg(options::OPT_c))) {
502 FinalPhase = phases::Assemble;
Daniel Dunbaraf61c712009-03-12 23:55:14 +0000503
504 // Otherwise do everything.
505 } else
Daniel Dunbarad2a9af2009-03-13 11:38:42 +0000506 FinalPhase = phases::Link;
Daniel Dunbaraf61c712009-03-12 23:55:14 +0000507
Daniel Dunbaraf61c712009-03-12 23:55:14 +0000508 // Reject -Z* at the top level, these options should never have been
509 // exposed by gcc.
510 if (Arg *A = Args.getLastArg(options::OPT_Z))
511 Diag(clang::diag::err_drv_use_of_Z_option) << A->getValue(Args);
512
Daniel Dunbarad2a9af2009-03-13 11:38:42 +0000513 // Construct the actions to perform.
514 ActionList LinkerInputs;
Daniel Dunbar53ec5522009-03-12 07:58:46 +0000515 for (unsigned i = 0, e = Inputs.size(); i != e; ++i) {
Daniel Dunbarad2a9af2009-03-13 11:38:42 +0000516 types::ID InputType = Inputs[i].first;
517 const Arg *InputArg = Inputs[i].second;
518
519 unsigned NumSteps = types::getNumCompilationPhases(InputType);
520 assert(NumSteps && "Invalid number of steps!");
521
522 // If the first step comes after the final phase we are doing as
523 // part of this compilation, warn the user about it.
524 phases::ID InitialPhase = types::getCompilationPhase(InputType, 0);
525 if (InitialPhase > FinalPhase) {
526 Diag(clang::diag::warn_drv_input_file_unused)
527 << InputArg->getValue(Args)
528 << getPhaseName(InitialPhase)
529 << FinalPhaseArg->getOption().getName();
530 continue;
531 }
532
533 // Build the pipeline for this file.
534 Action *Current = new InputAction(*InputArg, InputType);
535 for (unsigned i = 0; i != NumSteps; ++i) {
536 phases::ID Phase = types::getCompilationPhase(InputType, i);
537
538 // We are done if this step is past what the user requested.
539 if (Phase > FinalPhase)
540 break;
541
542 // Queue linker inputs.
543 if (Phase == phases::Link) {
544 assert(i + 1 == NumSteps && "linking must be final compilation step.");
545 LinkerInputs.push_back(Current);
546 Current = 0;
547 break;
548 }
549
550 // Otherwise construct the appropriate action.
551 Current = ConstructPhaseAction(Args, Phase, Current);
552 if (Current->getType() == types::TY_Nothing)
553 break;
554 }
555
556 // If we ended with something, add to the output list.
557 if (Current)
558 Actions.push_back(Current);
Daniel Dunbar53ec5522009-03-12 07:58:46 +0000559 }
Daniel Dunbarad2a9af2009-03-13 11:38:42 +0000560
561 // Add a link action if necessary.
562 if (!LinkerInputs.empty())
563 Actions.push_back(new LinkJobAction(LinkerInputs, types::TY_Image));
564}
565
566Action *Driver::ConstructPhaseAction(const ArgList &Args, phases::ID Phase,
567 Action *Input) const {
Daniel Dunbar8f25c792009-03-18 01:38:48 +0000568 llvm::PrettyStackTraceString CrashInfo("Constructing phase actions");
Daniel Dunbarad2a9af2009-03-13 11:38:42 +0000569 // Build the appropriate action.
570 switch (Phase) {
571 case phases::Link: assert(0 && "link action invalid here.");
572 case phases::Preprocess: {
573 types::ID OutputTy = types::getPreprocessedType(Input->getType());
574 assert(OutputTy != types::TY_INVALID &&
575 "Cannot preprocess this input type!");
576 return new PreprocessJobAction(Input, OutputTy);
577 }
578 case phases::Precompile:
579 return new PrecompileJobAction(Input, types::TY_PCH);
580 case phases::Compile: {
581 if (Args.hasArg(options::OPT_fsyntax_only)) {
582 return new CompileJobAction(Input, types::TY_Nothing);
583 } else if (Args.hasArg(options::OPT__analyze)) {
584 return new AnalyzeJobAction(Input, types::TY_Plist);
585 } else if (Args.hasArg(options::OPT_emit_llvm)) {
586 types::ID Output =
587 Args.hasArg(options::OPT_S) ? types::TY_LLVMAsm : types::TY_LLVMBC;
588 return new CompileJobAction(Input, Output);
589 } else {
590 return new CompileJobAction(Input, types::TY_PP_Asm);
591 }
592 }
593 case phases::Assemble:
594 return new AssembleJobAction(Input, types::TY_Object);
595 }
596
597 assert(0 && "invalid phase in ConstructPhaseAction");
598 return 0;
Daniel Dunbar53ec5522009-03-12 07:58:46 +0000599}
600
Daniel Dunbar21549232009-03-18 02:55:38 +0000601void Driver::BuildJobs(Compilation &C) const {
Daniel Dunbar8f25c792009-03-18 01:38:48 +0000602 llvm::PrettyStackTraceString CrashInfo("Building compilation jobs");
Daniel Dunbarf353c8c2009-03-16 06:56:51 +0000603 bool SaveTemps = C.getArgs().hasArg(options::OPT_save_temps);
604 bool UsePipes = C.getArgs().hasArg(options::OPT_pipe);
605
606 // -save-temps inhibits pipes.
607 if (SaveTemps && UsePipes) {
608 Diag(clang::diag::warn_drv_pipe_ignored_with_save_temps);
609 UsePipes = true;
610 }
611
612 Arg *FinalOutput = C.getArgs().getLastArg(options::OPT_o);
613
614 // It is an error to provide a -o option if we are making multiple
615 // output files.
616 if (FinalOutput) {
617 unsigned NumOutputs = 0;
Daniel Dunbar21549232009-03-18 02:55:38 +0000618 for (ActionList::const_iterator it = C.getActions().begin(),
619 ie = C.getActions().end(); it != ie; ++it)
Daniel Dunbarf353c8c2009-03-16 06:56:51 +0000620 if ((*it)->getType() != types::TY_Nothing)
621 ++NumOutputs;
622
623 if (NumOutputs > 1) {
624 Diag(clang::diag::err_drv_output_argument_with_multiple_files);
625 FinalOutput = 0;
626 }
627 }
628
Daniel Dunbar21549232009-03-18 02:55:38 +0000629 for (ActionList::const_iterator it = C.getActions().begin(),
630 ie = C.getActions().end(); it != ie; ++it) {
Daniel Dunbarf353c8c2009-03-16 06:56:51 +0000631 Action *A = *it;
632
633 // If we are linking an image for multiple archs then the linker
634 // wants -arch_multiple and -final_output <final image
635 // name>. Unfortunately, this doesn't fit in cleanly because we
636 // have to pass this information down.
637 //
638 // FIXME: This is a hack; find a cleaner way to integrate this
639 // into the process.
640 const char *LinkingOutput = 0;
641 if (isa<LinkJobAction>(A)) {
642 if (FinalOutput)
643 LinkingOutput = FinalOutput->getValue(C.getArgs());
644 else
645 LinkingOutput = DefaultImageName.c_str();
646 }
647
648 InputInfo II;
Daniel Dunbar10ffa9a2009-03-18 03:13:20 +0000649 BuildJobsForAction(C, A, &C.getDefaultToolChain(),
Daniel Dunbarf353c8c2009-03-16 06:56:51 +0000650 /*CanAcceptPipe*/ true,
651 /*AtTopLevel*/ true,
652 /*LinkingOutput*/ LinkingOutput,
653 II);
654 }
Daniel Dunbar586dc232009-03-16 06:42:30 +0000655
656 // If there were no errors, warn about any unused arguments.
657 for (ArgList::const_iterator it = C.getArgs().begin(), ie = C.getArgs().end();
658 it != ie; ++it) {
659 Arg *A = *it;
660
661 // FIXME: It would be nice to be able to send the argument to the
662 // Diagnostic, so that extra values, position, and so on could be
663 // printed.
664 if (!A->isClaimed())
665 Diag(clang::diag::warn_drv_unused_argument)
666 << A->getOption().getName();
667 }
Daniel Dunbar57b704d2009-03-13 22:12:33 +0000668}
669
Daniel Dunbarf353c8c2009-03-16 06:56:51 +0000670void Driver::BuildJobsForAction(Compilation &C,
671 const Action *A,
672 const ToolChain *TC,
673 bool CanAcceptPipe,
674 bool AtTopLevel,
675 const char *LinkingOutput,
676 InputInfo &Result) const {
Daniel Dunbar8f25c792009-03-18 01:38:48 +0000677 llvm::PrettyStackTraceString CrashInfo("Building compilation jobs for action");
Daniel Dunbarf353c8c2009-03-16 06:56:51 +0000678 if (const InputAction *IA = dyn_cast<InputAction>(A)) {
Daniel Dunbard09986a2009-03-18 08:02:40 +0000679 // FIXME: This is broken, linker inputs won't work here.
680 assert(isa<PositionalArg>(IA->getInputArg()) && "FIXME: Linker inputs");
681
Daniel Dunbar5ab483b2009-03-18 06:21:12 +0000682 IA->getInputArg().claim();
Daniel Dunbarf353c8c2009-03-16 06:56:51 +0000683 const char *Name = IA->getInputArg().getValue(C.getArgs());
684 Result = InputInfo(Name, A->getType(), Name);
685 return;
686 }
687
688 if (const BindArchAction *BAA = dyn_cast<BindArchAction>(A)) {
689 const char *ArchName = BAA->getArchName();
Daniel Dunbar10ffa9a2009-03-18 03:13:20 +0000690 if (!ArchName)
691 ArchName = C.getDefaultToolChain().getArchName().c_str();
Daniel Dunbarf353c8c2009-03-16 06:56:51 +0000692 BuildJobsForAction(C,
693 *BAA->begin(),
694 Host->getToolChain(C.getArgs(), ArchName),
695 CanAcceptPipe,
696 AtTopLevel,
697 LinkingOutput,
698 Result);
699 return;
700 }
701
702 const JobAction *JA = cast<JobAction>(A);
703 const Tool &T = TC->SelectTool(C, *JA);
704
705 // See if we should use an integrated preprocessor. We do so when we
706 // have exactly one input, since this is the only use case we care
707 // about (irrelevant since we don't support combine yet).
708 bool UseIntegratedCPP = false;
709 const ActionList *Inputs = &A->getInputs();
710 if (Inputs->size() == 1 && isa<PreprocessJobAction>(*Inputs->begin())) {
711 if (!C.getArgs().hasArg(options::OPT_no_integrated_cpp) &&
712 !C.getArgs().hasArg(options::OPT_traditional_cpp) &&
713 !C.getArgs().hasArg(options::OPT_save_temps) &&
714 T.hasIntegratedCPP()) {
715 UseIntegratedCPP = true;
716 Inputs = &(*Inputs)[0]->getInputs();
717 }
718 }
719
720 // Only use pipes when there is exactly one input.
721 bool TryToUsePipeInput = Inputs->size() == 1 && T.acceptsPipedInput();
Daniel Dunbar47ac7d22009-03-18 06:00:36 +0000722 InputInfoList InputInfos;
Daniel Dunbarf353c8c2009-03-16 06:56:51 +0000723 for (ActionList::const_iterator it = Inputs->begin(), ie = Inputs->end();
724 it != ie; ++it) {
725 InputInfo II;
726 BuildJobsForAction(C, *it, TC, TryToUsePipeInput,
727 /*AtTopLevel*/false,
728 LinkingOutput,
729 II);
730 InputInfos.push_back(II);
731 }
732
733 // Determine if we should output to a pipe.
734 bool OutputToPipe = false;
735 if (CanAcceptPipe && T.canPipeOutput()) {
736 // Some actions default to writing to a pipe if they are the top
737 // level phase and there was no user override.
738 //
739 // FIXME: Is there a better way to handle this?
740 if (AtTopLevel) {
741 if (isa<PreprocessJobAction>(A) && !C.getArgs().hasArg(options::OPT_o))
742 OutputToPipe = true;
743 } else if (C.getArgs().hasArg(options::OPT_pipe))
744 OutputToPipe = true;
745 }
746
747 // Figure out where to put the job (pipes).
748 Job *Dest = &C.getJobs();
749 if (InputInfos[0].isPipe()) {
Daniel Dunbar441d0602009-03-17 17:53:55 +0000750 assert(TryToUsePipeInput && "Unrequested pipe!");
Daniel Dunbarf353c8c2009-03-16 06:56:51 +0000751 assert(InputInfos.size() == 1 && "Unexpected pipe with multiple inputs.");
752 Dest = &InputInfos[0].getPipe();
753 }
754
755 // Always use the first input as the base input.
756 const char *BaseInput = InputInfos[0].getBaseInput();
Daniel Dunbar441d0602009-03-17 17:53:55 +0000757
758 // Determine the place to write output to (nothing, pipe, or
759 // filename) and where to put the new job.
Daniel Dunbar441d0602009-03-17 17:53:55 +0000760 if (JA->getType() == types::TY_Nothing) {
Daniel Dunbar5c3c1d72009-03-17 22:47:06 +0000761 Result = InputInfo(A->getType(), BaseInput);
Daniel Dunbar441d0602009-03-17 17:53:55 +0000762 } else if (OutputToPipe) {
763 // Append to current piped job or create a new one as appropriate.
Daniel Dunbar5c3c1d72009-03-17 22:47:06 +0000764 PipedJob *PJ = dyn_cast<PipedJob>(Dest);
765 if (!PJ) {
766 PJ = new PipedJob();
767 cast<JobList>(Dest)->addJob(PJ);
Daniel Dunbar871adcf2009-03-18 07:06:02 +0000768 Dest = PJ;
Daniel Dunbar441d0602009-03-17 17:53:55 +0000769 }
Daniel Dunbar5c3c1d72009-03-17 22:47:06 +0000770 Result = InputInfo(PJ, A->getType(), BaseInput);
Daniel Dunbar441d0602009-03-17 17:53:55 +0000771 } else {
Daniel Dunbar5c3c1d72009-03-17 22:47:06 +0000772 Result = InputInfo(GetNamedOutputPath(C, *JA, BaseInput, AtTopLevel),
773 A->getType(), BaseInput);
Daniel Dunbar441d0602009-03-17 17:53:55 +0000774 }
775
Daniel Dunbar5c3c1d72009-03-17 22:47:06 +0000776 if (CCCPrintBindings) {
777 llvm::errs() << "bind - \"" << T.getName() << "\", inputs: [";
778 for (unsigned i = 0, e = InputInfos.size(); i != e; ++i) {
779 llvm::errs() << InputInfos[i].getAsString();
780 if (i + 1 != e)
781 llvm::errs() << ", ";
782 }
783 llvm::errs() << "], output: " << Result.getAsString() << "\n";
784 } else {
Daniel Dunbar47ac7d22009-03-18 06:00:36 +0000785 const ArgList &TCArgs = C.getArgsForToolChain(TC);
Daniel Dunbar871adcf2009-03-18 07:06:02 +0000786 T.ConstructJob(C, *JA, *Dest, Result, InputInfos, TCArgs, LinkingOutput);
Daniel Dunbar5c3c1d72009-03-17 22:47:06 +0000787 }
Daniel Dunbarf353c8c2009-03-16 06:56:51 +0000788}
789
Daniel Dunbar441d0602009-03-17 17:53:55 +0000790const char *Driver::GetNamedOutputPath(Compilation &C,
791 const JobAction &JA,
792 const char *BaseInput,
793 bool AtTopLevel) const {
Daniel Dunbar8f25c792009-03-18 01:38:48 +0000794 llvm::PrettyStackTraceString CrashInfo("Computing output path");
Daniel Dunbar441d0602009-03-17 17:53:55 +0000795 // Output to a user requested destination?
796 if (AtTopLevel) {
797 if (Arg *FinalOutput = C.getArgs().getLastArg(options::OPT_o))
798 return C.addResultFile(FinalOutput->getValue(C.getArgs()));
799 }
800
801 // Output to a temporary file?
802 if (!AtTopLevel && !C.getArgs().hasArg(options::OPT_save_temps)) {
803 // FIXME: Get temporary name.
804 std::string Name("/tmp/foo");
805 Name += '.';
806 Name += types::getTypeTempSuffix(JA.getType());
807 return C.addTempFile(C.getArgs().MakeArgString(Name.c_str()));
808 }
809
810 llvm::sys::Path BasePath(BaseInput);
Daniel Dunbar5796bf42009-03-18 02:00:31 +0000811 std::string BaseName(BasePath.getLast());
Daniel Dunbar441d0602009-03-17 17:53:55 +0000812
813 // Determine what the derived output name should be.
814 const char *NamedOutput;
815 if (JA.getType() == types::TY_Image) {
816 NamedOutput = DefaultImageName.c_str();
817 } else {
818 const char *Suffix = types::getTypeTempSuffix(JA.getType());
819 assert(Suffix && "All types used for output should have a suffix.");
820
821 std::string::size_type End = std::string::npos;
822 if (!types::appendSuffixForType(JA.getType()))
823 End = BaseName.rfind('.');
824 std::string Suffixed(BaseName.substr(0, End));
825 Suffixed += '.';
826 Suffixed += Suffix;
827 NamedOutput = C.getArgs().MakeArgString(Suffixed.c_str());
828 }
829
830 // As an annoying special case, PCH generation doesn't strip the
831 // pathname.
832 if (JA.getType() == types::TY_PCH) {
833 BasePath.eraseComponent();
Daniel Dunbar56c55942009-03-18 09:58:30 +0000834 if (BasePath.isEmpty())
835 BasePath = NamedOutput;
836 else
837 BasePath.appendComponent(NamedOutput);
Daniel Dunbar441d0602009-03-17 17:53:55 +0000838 return C.addResultFile(C.getArgs().MakeArgString(BasePath.c_str()));
839 } else {
840 return C.addResultFile(NamedOutput);
841 }
842}
843
Daniel Dunbar2ba38ba2009-03-16 05:25:36 +0000844llvm::sys::Path Driver::GetFilePath(const char *Name,
Daniel Dunbar21549232009-03-18 02:55:38 +0000845 const ToolChain &TC) const {
Daniel Dunbarcb881672009-03-13 00:51:18 +0000846 // FIXME: Implement.
847 return llvm::sys::Path(Name);
848}
849
Daniel Dunbar2ba38ba2009-03-16 05:25:36 +0000850llvm::sys::Path Driver::GetProgramPath(const char *Name,
Daniel Dunbar21549232009-03-18 02:55:38 +0000851 const ToolChain &TC) const {
Daniel Dunbarcb881672009-03-13 00:51:18 +0000852 // FIXME: Implement.
853 return llvm::sys::Path(Name);
854}
855
Daniel Dunbare5049522009-03-17 20:45:45 +0000856const HostInfo *Driver::GetHostInfo(const char *Triple) const {
Daniel Dunbar8f25c792009-03-18 01:38:48 +0000857 llvm::PrettyStackTraceString CrashInfo("Constructing host");
Daniel Dunbardd98e2c2009-03-10 23:41:59 +0000858 // Dice into arch, platform, and OS. This matches
859 // arch,platform,os = '(.*?)-(.*?)-(.*?)'
860 // and missing fields are left empty.
861 std::string Arch, Platform, OS;
862
863 if (const char *ArchEnd = strchr(Triple, '-')) {
864 Arch = std::string(Triple, ArchEnd);
865
866 if (const char *PlatformEnd = strchr(ArchEnd+1, '-')) {
867 Platform = std::string(ArchEnd+1, PlatformEnd);
868 OS = PlatformEnd+1;
869 } else
870 Platform = ArchEnd+1;
871 } else
872 Arch = Triple;
873
Daniel Dunbar1fd6c4b2009-03-17 19:00:50 +0000874 // Normalize Arch a bit.
875 //
876 // FIXME: This is very incomplete.
877 if (Arch == "i686")
878 Arch = "i386";
879 else if (Arch == "amd64")
880 Arch = "x86_64";
Daniel Dunbarc811b6c2009-03-18 04:41:46 +0000881 else if (Arch == "powerpc" || Arch == "Power Macintosh")
882 Arch = "ppc";
Daniel Dunbar1fd6c4b2009-03-17 19:00:50 +0000883
Daniel Dunbara88162c2009-03-13 12:23:29 +0000884 if (memcmp(&OS[0], "darwin", 6) == 0)
Daniel Dunbare5049522009-03-17 20:45:45 +0000885 return createDarwinHostInfo(*this, Arch.c_str(), Platform.c_str(),
886 OS.c_str());
Daniel Dunbardd98e2c2009-03-10 23:41:59 +0000887
Daniel Dunbare5049522009-03-17 20:45:45 +0000888 return createUnknownHostInfo(*this, Arch.c_str(), Platform.c_str(),
889 OS.c_str());
Daniel Dunbardd98e2c2009-03-10 23:41:59 +0000890}