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 | |
Douglas Gregor | ab41e63 | 2009-04-27 22:23:34 +0000 | [diff] [blame] | 25 | #include "clang/Basic/Version.h" |
| 26 | |
Daniel Dunbar | 1368954 | 2009-03-13 20:33:35 +0000 | [diff] [blame] | 27 | #include "llvm/ADT/StringSet.h" |
Daniel Dunbar | 8f25c79 | 2009-03-18 01:38:48 +0000 | [diff] [blame] | 28 | #include "llvm/Support/PrettyStackTrace.h" |
Daniel Dunbar | 0648262 | 2009-03-05 06:38:47 +0000 | [diff] [blame] | 29 | #include "llvm/Support/raw_ostream.h" |
Daniel Dunbar | 53ec552 | 2009-03-12 07:58:46 +0000 | [diff] [blame] | 30 | #include "llvm/System/Path.h" |
Daniel Dunbar | 632f50e | 2009-03-18 21:34:08 +0000 | [diff] [blame] | 31 | #include "llvm/System/Program.h" |
Daniel Dunbar | ba10213 | 2009-03-13 12:19:02 +0000 | [diff] [blame] | 32 | |
Daniel Dunbar | f353c8c | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 33 | #include "InputInfo.h" |
| 34 | |
Daniel Dunbar | ba10213 | 2009-03-13 12:19:02 +0000 | [diff] [blame] | 35 | #include <map> |
| 36 | |
Daniel Dunbar | 1b3bb6e | 2009-03-04 20:49:20 +0000 | [diff] [blame] | 37 | using namespace clang::driver; |
Chris Lattner | 92b3699 | 2009-03-26 05:56:24 +0000 | [diff] [blame] | 38 | using namespace clang; |
Daniel Dunbar | 1b3bb6e | 2009-03-04 20:49:20 +0000 | [diff] [blame] | 39 | |
Daniel Dunbar | 4a12408 | 2009-08-23 18:42:54 +0000 | [diff] [blame] | 40 | // Used to set values for "production" clang, for releases. |
Daniel Dunbar | 8bde505 | 2009-08-23 19:41:53 +0000 | [diff] [blame] | 41 | // #define USE_PRODUCTION_CLANG |
Daniel Dunbar | 4a12408 | 2009-08-23 18:42:54 +0000 | [diff] [blame] | 42 | |
Daniel Dunbar | dd98e2c | 2009-03-10 23:41:59 +0000 | [diff] [blame] | 43 | Driver::Driver(const char *_Name, const char *_Dir, |
Daniel Dunbar | 4ad4b3e | 2009-03-12 08:55:43 +0000 | [diff] [blame] | 44 | const char *_DefaultHostTriple, |
Daniel Dunbar | f353c8c | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 45 | const char *_DefaultImageName, |
Daniel Dunbar | f44c585 | 2009-09-22 22:31:13 +0000 | [diff] [blame] | 46 | bool IsProduction, Diagnostic &_Diags) |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 47 | : Opts(new OptTable()), Diags(_Diags), |
Daniel Dunbar | dd98e2c | 2009-03-10 23:41:59 +0000 | [diff] [blame] | 48 | Name(_Name), Dir(_Dir), DefaultHostTriple(_DefaultHostTriple), |
Daniel Dunbar | f353c8c | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 49 | DefaultImageName(_DefaultImageName), |
Daniel Dunbar | dd98e2c | 2009-03-10 23:41:59 +0000 | [diff] [blame] | 50 | Host(0), |
Daniel Dunbar | 5c3c1d7 | 2009-03-17 22:47:06 +0000 | [diff] [blame] | 51 | CCCIsCXX(false), CCCEcho(false), CCCPrintBindings(false), |
Daniel Dunbar | 4a12408 | 2009-08-23 18:42:54 +0000 | [diff] [blame] | 52 | CCCGenericGCCName("gcc"), CCCUseClang(true), |
Daniel Dunbar | f44c585 | 2009-09-22 22:31:13 +0000 | [diff] [blame] | 53 | CCCUseClangCXX(true), CCCUseClangCPP(true), CCCUsePCH(true), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 54 | SuppressMissingInputWarning(false) { |
Daniel Dunbar | f44c585 | 2009-09-22 22:31:13 +0000 | [diff] [blame] | 55 | if (IsProduction) { |
| 56 | // In a "production" build, only use clang on architectures we expect to |
| 57 | // work, and don't use clang C++. |
| 58 | // |
| 59 | // During development its more convenient to always have the driver use |
| 60 | // clang, but we don't want users to be confused when things don't work, or |
| 61 | // to file bugs for things we don't support. |
| 62 | CCCClangArchs.insert(llvm::Triple::x86); |
| 63 | CCCClangArchs.insert(llvm::Triple::x86_64); |
| 64 | CCCClangArchs.insert(llvm::Triple::arm); |
| 65 | |
| 66 | CCCUseClangCXX = false; |
| 67 | } |
Daniel Dunbar | 3ede8d0 | 2009-03-02 19:59:07 +0000 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | Driver::~Driver() { |
Daniel Dunbar | 1b3bb6e | 2009-03-04 20:49:20 +0000 | [diff] [blame] | 71 | delete Opts; |
Daniel Dunbar | 7e4534d | 2009-03-18 01:09:40 +0000 | [diff] [blame] | 72 | delete Host; |
Daniel Dunbar | 3ede8d0 | 2009-03-02 19:59:07 +0000 | [diff] [blame] | 73 | } |
| 74 | |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 75 | InputArgList *Driver::ParseArgStrings(const char **ArgBegin, |
Daniel Dunbar | f3cad36 | 2009-03-25 04:13:45 +0000 | [diff] [blame] | 76 | const char **ArgEnd) { |
Daniel Dunbar | 8f25c79 | 2009-03-18 01:38:48 +0000 | [diff] [blame] | 77 | llvm::PrettyStackTraceString CrashInfo("Command line argument parsing"); |
Daniel Dunbar | f3cad36 | 2009-03-25 04:13:45 +0000 | [diff] [blame] | 78 | InputArgList *Args = new InputArgList(ArgBegin, ArgEnd); |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 79 | |
Daniel Dunbar | ad2a9af | 2009-03-13 11:38:42 +0000 | [diff] [blame] | 80 | // FIXME: Handle '@' args (or at least error on them). |
| 81 | |
Daniel Dunbar | 0648262 | 2009-03-05 06:38:47 +0000 | [diff] [blame] | 82 | unsigned Index = 0, End = ArgEnd - ArgBegin; |
| 83 | while (Index < End) { |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 84 | // gcc's handling of empty arguments doesn't make sense, but this is not a |
| 85 | // common use case. :) |
Daniel Dunbar | 4139340 | 2009-03-13 01:01:44 +0000 | [diff] [blame] | 86 | // |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 87 | // We just ignore them here (note that other things may still take them as |
| 88 | // arguments). |
Daniel Dunbar | 4139340 | 2009-03-13 01:01:44 +0000 | [diff] [blame] | 89 | if (Args->getArgString(Index)[0] == '\0') { |
| 90 | ++Index; |
| 91 | continue; |
| 92 | } |
| 93 | |
Daniel Dunbar | 0648262 | 2009-03-05 06:38:47 +0000 | [diff] [blame] | 94 | unsigned Prev = Index; |
Daniel Dunbar | b0c4df5 | 2009-03-22 23:26:43 +0000 | [diff] [blame] | 95 | Arg *A = getOpts().ParseOneArg(*Args, Index); |
| 96 | assert(Index > Prev && "Parser failed to consume argument."); |
Daniel Dunbar | 53ec552 | 2009-03-12 07:58:46 +0000 | [diff] [blame] | 97 | |
Daniel Dunbar | b0c4df5 | 2009-03-22 23:26:43 +0000 | [diff] [blame] | 98 | // Check for missing argument error. |
| 99 | if (!A) { |
| 100 | assert(Index >= End && "Unexpected parser error."); |
| 101 | Diag(clang::diag::err_drv_missing_argument) |
| 102 | << Args->getArgString(Prev) |
| 103 | << (Index - Prev - 1); |
| 104 | break; |
Daniel Dunbar | 53ec552 | 2009-03-12 07:58:46 +0000 | [diff] [blame] | 105 | } |
Daniel Dunbar | 0648262 | 2009-03-05 06:38:47 +0000 | [diff] [blame] | 106 | |
Daniel Dunbar | b0c4df5 | 2009-03-22 23:26:43 +0000 | [diff] [blame] | 107 | if (A->getOption().isUnsupported()) { |
| 108 | Diag(clang::diag::err_drv_unsupported_opt) << A->getAsString(*Args); |
| 109 | continue; |
| 110 | } |
| 111 | Args->append(A); |
Daniel Dunbar | 0648262 | 2009-03-05 06:38:47 +0000 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | return Args; |
| 115 | } |
| 116 | |
Daniel Dunbar | 3ede8d0 | 2009-03-02 19:59:07 +0000 | [diff] [blame] | 117 | Compilation *Driver::BuildCompilation(int argc, const char **argv) { |
Daniel Dunbar | 8f25c79 | 2009-03-18 01:38:48 +0000 | [diff] [blame] | 118 | llvm::PrettyStackTraceString CrashInfo("Compilation construction"); |
| 119 | |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 120 | // FIXME: Handle environment options which effect driver behavior, somewhere |
| 121 | // (client?). GCC_EXEC_PREFIX, COMPILER_PATH, LIBRARY_PATH, LPATH, |
| 122 | // CC_PRINT_OPTIONS. |
Daniel Dunbar | cb88167 | 2009-03-13 00:51:18 +0000 | [diff] [blame] | 123 | |
| 124 | // FIXME: What are we going to do with -V and -b? |
| 125 | |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 126 | // FIXME: This stuff needs to go into the Compilation, not the driver. |
Daniel Dunbar | 53ec552 | 2009-03-12 07:58:46 +0000 | [diff] [blame] | 127 | bool CCCPrintOptions = false, CCCPrintActions = false; |
Daniel Dunbar | 0648262 | 2009-03-05 06:38:47 +0000 | [diff] [blame] | 128 | |
Daniel Dunbar | 365c02f | 2009-03-10 20:52:46 +0000 | [diff] [blame] | 129 | const char **Start = argv + 1, **End = argv + argc; |
Daniel Dunbar | dd98e2c | 2009-03-10 23:41:59 +0000 | [diff] [blame] | 130 | const char *HostTriple = DefaultHostTriple.c_str(); |
Daniel Dunbar | 365c02f | 2009-03-10 20:52:46 +0000 | [diff] [blame] | 131 | |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 132 | // Read -ccc args. |
Daniel Dunbar | 365c02f | 2009-03-10 20:52:46 +0000 | [diff] [blame] | 133 | // |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 134 | // FIXME: We need to figure out where this behavior should live. Most of it |
| 135 | // should be outside in the client; the parts that aren't should have proper |
| 136 | // options, either by introducing new ones or by overloading gcc ones like -V |
| 137 | // or -b. |
Daniel Dunbar | 365c02f | 2009-03-10 20:52:46 +0000 | [diff] [blame] | 138 | for (; Start != End && memcmp(*Start, "-ccc-", 5) == 0; ++Start) { |
| 139 | const char *Opt = *Start + 5; |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 140 | |
Daniel Dunbar | 365c02f | 2009-03-10 20:52:46 +0000 | [diff] [blame] | 141 | if (!strcmp(Opt, "print-options")) { |
| 142 | CCCPrintOptions = true; |
| 143 | } else if (!strcmp(Opt, "print-phases")) { |
Daniel Dunbar | 53ec552 | 2009-03-12 07:58:46 +0000 | [diff] [blame] | 144 | CCCPrintActions = true; |
Daniel Dunbar | 5c3c1d7 | 2009-03-17 22:47:06 +0000 | [diff] [blame] | 145 | } else if (!strcmp(Opt, "print-bindings")) { |
| 146 | CCCPrintBindings = true; |
Daniel Dunbar | 365c02f | 2009-03-10 20:52:46 +0000 | [diff] [blame] | 147 | } else if (!strcmp(Opt, "cxx")) { |
| 148 | CCCIsCXX = true; |
| 149 | } else if (!strcmp(Opt, "echo")) { |
| 150 | CCCEcho = true; |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 151 | |
Daniel Dunbar | 78d8a08 | 2009-04-01 23:34:41 +0000 | [diff] [blame] | 152 | } else if (!strcmp(Opt, "gcc-name")) { |
| 153 | assert(Start+1 < End && "FIXME: -ccc- argument handling."); |
| 154 | CCCGenericGCCName = *++Start; |
| 155 | |
Daniel Dunbar | 0f99d2e | 2009-03-24 19:02:31 +0000 | [diff] [blame] | 156 | } else if (!strcmp(Opt, "clang-cxx")) { |
| 157 | CCCUseClangCXX = true; |
Daniel Dunbar | dfaf4b3 | 2009-07-23 17:48:59 +0000 | [diff] [blame] | 158 | } else if (!strcmp(Opt, "no-clang-cxx")) { |
| 159 | CCCUseClangCXX = false; |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 160 | } else if (!strcmp(Opt, "pch-is-pch")) { |
| 161 | CCCUsePCH = true; |
| 162 | } else if (!strcmp(Opt, "pch-is-pth")) { |
| 163 | CCCUsePCH = false; |
Daniel Dunbar | 365c02f | 2009-03-10 20:52:46 +0000 | [diff] [blame] | 164 | } else if (!strcmp(Opt, "no-clang")) { |
Daniel Dunbar | 0f99d2e | 2009-03-24 19:02:31 +0000 | [diff] [blame] | 165 | CCCUseClang = false; |
Daniel Dunbar | 365c02f | 2009-03-10 20:52:46 +0000 | [diff] [blame] | 166 | } else if (!strcmp(Opt, "no-clang-cpp")) { |
Daniel Dunbar | 0f99d2e | 2009-03-24 19:02:31 +0000 | [diff] [blame] | 167 | CCCUseClangCPP = false; |
Daniel Dunbar | 365c02f | 2009-03-10 20:52:46 +0000 | [diff] [blame] | 168 | } else if (!strcmp(Opt, "clang-archs")) { |
| 169 | assert(Start+1 < End && "FIXME: -ccc- argument handling."); |
Daniel Dunbar | a6046be | 2009-09-08 23:36:55 +0000 | [diff] [blame] | 170 | llvm::StringRef Cur = *++Start; |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 171 | |
Daniel Dunbar | 0f99d2e | 2009-03-24 19:02:31 +0000 | [diff] [blame] | 172 | CCCClangArchs.clear(); |
Daniel Dunbar | a6046be | 2009-09-08 23:36:55 +0000 | [diff] [blame] | 173 | while (!Cur.empty()) { |
| 174 | std::pair<llvm::StringRef, llvm::StringRef> Split = Cur.split(','); |
Daniel Dunbar | 365c02f | 2009-03-10 20:52:46 +0000 | [diff] [blame] | 175 | |
Daniel Dunbar | a6046be | 2009-09-08 23:36:55 +0000 | [diff] [blame] | 176 | if (!Split.first.empty()) { |
| 177 | llvm::Triple::ArchType Arch = |
| 178 | llvm::Triple(Split.first, "", "").getArch(); |
| 179 | |
| 180 | if (Arch == llvm::Triple::UnknownArch) { |
| 181 | // FIXME: Error handling. |
| 182 | llvm::errs() << "invalid arch name: " << Split.first << "\n"; |
| 183 | exit(1); |
| 184 | } |
| 185 | |
| 186 | CCCClangArchs.insert(Arch); |
Daniel Dunbar | 365c02f | 2009-03-10 20:52:46 +0000 | [diff] [blame] | 187 | } |
Daniel Dunbar | 365c02f | 2009-03-10 20:52:46 +0000 | [diff] [blame] | 188 | |
Daniel Dunbar | a6046be | 2009-09-08 23:36:55 +0000 | [diff] [blame] | 189 | Cur = Split.second; |
| 190 | } |
Daniel Dunbar | dd98e2c | 2009-03-10 23:41:59 +0000 | [diff] [blame] | 191 | } else if (!strcmp(Opt, "host-triple")) { |
Daniel Dunbar | 365c02f | 2009-03-10 20:52:46 +0000 | [diff] [blame] | 192 | assert(Start+1 < End && "FIXME: -ccc- argument handling."); |
Daniel Dunbar | dd98e2c | 2009-03-10 23:41:59 +0000 | [diff] [blame] | 193 | HostTriple = *++Start; |
Daniel Dunbar | 365c02f | 2009-03-10 20:52:46 +0000 | [diff] [blame] | 194 | |
Daniel Dunbar | da64141 | 2009-09-04 18:35:03 +0000 | [diff] [blame] | 195 | } else if (!strcmp(Opt, "install-dir")) { |
| 196 | assert(Start+1 < End && "FIXME: -ccc- argument handling."); |
| 197 | Dir = *++Start; |
| 198 | |
Daniel Dunbar | 365c02f | 2009-03-10 20:52:46 +0000 | [diff] [blame] | 199 | } else { |
| 200 | // FIXME: Error handling. |
| 201 | llvm::errs() << "invalid option: " << *Start << "\n"; |
| 202 | exit(1); |
| 203 | } |
| 204 | } |
Daniel Dunbar | dd98e2c | 2009-03-10 23:41:59 +0000 | [diff] [blame] | 205 | |
Daniel Dunbar | f3cad36 | 2009-03-25 04:13:45 +0000 | [diff] [blame] | 206 | InputArgList *Args = ParseArgStrings(Start, End); |
Daniel Dunbar | 365c02f | 2009-03-10 20:52:46 +0000 | [diff] [blame] | 207 | |
Daniel Dunbar | e504952 | 2009-03-17 20:45:45 +0000 | [diff] [blame] | 208 | Host = GetHostInfo(HostTriple); |
Daniel Dunbar | cb88167 | 2009-03-13 00:51:18 +0000 | [diff] [blame] | 209 | |
Daniel Dunbar | 586dc23 | 2009-03-16 06:42:30 +0000 | [diff] [blame] | 210 | // The compilation takes ownership of Args. |
Daniel Dunbar | d7502d0 | 2009-09-08 23:37:19 +0000 | [diff] [blame] | 211 | Compilation *C = new Compilation(*this, *Host->CreateToolChain(*Args), Args); |
Daniel Dunbar | 2154923 | 2009-03-18 02:55:38 +0000 | [diff] [blame] | 212 | |
| 213 | // FIXME: This behavior shouldn't be here. |
| 214 | if (CCCPrintOptions) { |
| 215 | PrintOptions(C->getArgs()); |
| 216 | return C; |
| 217 | } |
| 218 | |
| 219 | if (!HandleImmediateArgs(*C)) |
| 220 | return C; |
| 221 | |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 222 | // Construct the list of abstract actions to perform for this compilation. We |
| 223 | // avoid passing a Compilation here simply to enforce the abstraction that |
| 224 | // pipelining is not host or toolchain dependent (other than the driver driver |
| 225 | // test). |
Daniel Dunbar | 2154923 | 2009-03-18 02:55:38 +0000 | [diff] [blame] | 226 | if (Host->useDriverDriver()) |
| 227 | BuildUniversalActions(C->getArgs(), C->getActions()); |
| 228 | else |
| 229 | BuildActions(C->getArgs(), C->getActions()); |
| 230 | |
| 231 | if (CCCPrintActions) { |
Daniel Dunbar | 10ffa9a | 2009-03-18 03:13:20 +0000 | [diff] [blame] | 232 | PrintActions(*C); |
Daniel Dunbar | 2154923 | 2009-03-18 02:55:38 +0000 | [diff] [blame] | 233 | return C; |
| 234 | } |
| 235 | |
| 236 | BuildJobs(*C); |
Daniel Dunbar | 8d2554a | 2009-03-15 01:38:15 +0000 | [diff] [blame] | 237 | |
| 238 | return C; |
Daniel Dunbar | 365c02f | 2009-03-10 20:52:46 +0000 | [diff] [blame] | 239 | } |
| 240 | |
Daniel Dunbar | c88a88f | 2009-07-01 20:03:04 +0000 | [diff] [blame] | 241 | int Driver::ExecuteCompilation(const Compilation &C) const { |
| 242 | // Just print if -### was present. |
| 243 | if (C.getArgs().hasArg(options::OPT__HASH_HASH_HASH)) { |
| 244 | C.PrintJob(llvm::errs(), C.getJobs(), "\n", true); |
| 245 | return 0; |
| 246 | } |
| 247 | |
| 248 | // If there were errors building the compilation, quit now. |
| 249 | if (getDiags().getNumErrors()) |
| 250 | return 1; |
| 251 | |
| 252 | const Command *FailingCommand = 0; |
| 253 | int Res = C.ExecuteJob(C.getJobs(), FailingCommand); |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 254 | |
Daniel Dunbar | c88a88f | 2009-07-01 20:03:04 +0000 | [diff] [blame] | 255 | // Remove temp files. |
| 256 | C.CleanupFileList(C.getTempFiles()); |
| 257 | |
| 258 | // If the compilation failed, remove result files as well. |
| 259 | if (Res != 0 && !C.getArgs().hasArg(options::OPT_save_temps)) |
| 260 | C.CleanupFileList(C.getResultFiles(), true); |
| 261 | |
| 262 | // Print extra information about abnormal failures, if possible. |
| 263 | if (Res) { |
| 264 | // This is ad-hoc, but we don't want to be excessively noisy. If the result |
| 265 | // status was 1, assume the command failed normally. In particular, if it |
| 266 | // was the compiler then assume it gave a reasonable error code. Failures in |
| 267 | // other tools are less common, and they generally have worse diagnostics, |
| 268 | // so always print the diagnostic there. |
| 269 | const Action &Source = FailingCommand->getSource(); |
| 270 | bool IsFriendlyTool = (isa<PreprocessJobAction>(Source) || |
| 271 | isa<PrecompileJobAction>(Source) || |
| 272 | isa<AnalyzeJobAction>(Source) || |
| 273 | isa<CompileJobAction>(Source)); |
| 274 | |
| 275 | if (!IsFriendlyTool || Res != 1) { |
| 276 | // FIXME: See FIXME above regarding result code interpretation. |
| 277 | if (Res < 0) |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 278 | Diag(clang::diag::err_drv_command_signalled) |
Daniel Dunbar | c88a88f | 2009-07-01 20:03:04 +0000 | [diff] [blame] | 279 | << Source.getClassName() << -Res; |
| 280 | else |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 281 | Diag(clang::diag::err_drv_command_failed) |
Daniel Dunbar | c88a88f | 2009-07-01 20:03:04 +0000 | [diff] [blame] | 282 | << Source.getClassName() << Res; |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | return Res; |
| 287 | } |
| 288 | |
Daniel Dunbar | d65bddc | 2009-03-12 18:24:49 +0000 | [diff] [blame] | 289 | void Driver::PrintOptions(const ArgList &Args) const { |
Daniel Dunbar | 0648262 | 2009-03-05 06:38:47 +0000 | [diff] [blame] | 290 | unsigned i = 0; |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 291 | for (ArgList::const_iterator it = Args.begin(), ie = Args.end(); |
Daniel Dunbar | 0648262 | 2009-03-05 06:38:47 +0000 | [diff] [blame] | 292 | it != ie; ++it, ++i) { |
| 293 | Arg *A = *it; |
| 294 | llvm::errs() << "Option " << i << " - " |
| 295 | << "Name: \"" << A->getOption().getName() << "\", " |
| 296 | << "Values: {"; |
| 297 | for (unsigned j = 0; j < A->getNumValues(); ++j) { |
| 298 | if (j) |
| 299 | llvm::errs() << ", "; |
Daniel Dunbar | 53ec552 | 2009-03-12 07:58:46 +0000 | [diff] [blame] | 300 | llvm::errs() << '"' << A->getValue(Args, j) << '"'; |
Daniel Dunbar | 0648262 | 2009-03-05 06:38:47 +0000 | [diff] [blame] | 301 | } |
| 302 | llvm::errs() << "}\n"; |
Daniel Dunbar | 0648262 | 2009-03-05 06:38:47 +0000 | [diff] [blame] | 303 | } |
Daniel Dunbar | 3ede8d0 | 2009-03-02 19:59:07 +0000 | [diff] [blame] | 304 | } |
Daniel Dunbar | dd98e2c | 2009-03-10 23:41:59 +0000 | [diff] [blame] | 305 | |
Daniel Dunbar | 91e28af | 2009-03-31 21:38:17 +0000 | [diff] [blame] | 306 | static std::string getOptionHelpName(const OptTable &Opts, options::ID Id) { |
| 307 | std::string Name = Opts.getOptionName(Id); |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 308 | |
Daniel Dunbar | 91e28af | 2009-03-31 21:38:17 +0000 | [diff] [blame] | 309 | // Add metavar, if used. |
| 310 | switch (Opts.getOptionKind(Id)) { |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 311 | case Option::GroupClass: case Option::InputClass: case Option::UnknownClass: |
Daniel Dunbar | 91e28af | 2009-03-31 21:38:17 +0000 | [diff] [blame] | 312 | assert(0 && "Invalid option with help text."); |
| 313 | |
| 314 | case Option::MultiArgClass: case Option::JoinedAndSeparateClass: |
| 315 | assert(0 && "Cannot print metavar for this kind of option."); |
| 316 | |
| 317 | case Option::FlagClass: |
| 318 | break; |
| 319 | |
| 320 | case Option::SeparateClass: case Option::JoinedOrSeparateClass: |
| 321 | Name += ' '; |
| 322 | // FALLTHROUGH |
| 323 | case Option::JoinedClass: case Option::CommaJoinedClass: |
| 324 | Name += Opts.getOptionMetaVar(Id); |
| 325 | break; |
| 326 | } |
| 327 | |
| 328 | return Name; |
| 329 | } |
| 330 | |
Daniel Dunbar | c35d71f | 2009-04-15 16:34:29 +0000 | [diff] [blame] | 331 | void Driver::PrintHelp(bool ShowHidden) const { |
Daniel Dunbar | 91e28af | 2009-03-31 21:38:17 +0000 | [diff] [blame] | 332 | llvm::raw_ostream &OS = llvm::outs(); |
| 333 | |
| 334 | OS << "OVERVIEW: clang \"gcc-compatible\" driver\n"; |
| 335 | OS << '\n'; |
| 336 | OS << "USAGE: " << Name << " [options] <input files>\n"; |
| 337 | OS << '\n'; |
| 338 | OS << "OPTIONS:\n"; |
| 339 | |
| 340 | // Render help text into (option, help) pairs. |
| 341 | std::vector< std::pair<std::string, const char*> > OptionHelp; |
| 342 | |
| 343 | for (unsigned i = options::OPT_INPUT, e = options::LastOption; i != e; ++i) { |
| 344 | options::ID Id = (options::ID) i; |
| 345 | if (const char *Text = getOpts().getOptionHelpText(Id)) |
| 346 | OptionHelp.push_back(std::make_pair(getOptionHelpName(getOpts(), Id), |
| 347 | Text)); |
| 348 | } |
| 349 | |
Daniel Dunbar | c35d71f | 2009-04-15 16:34:29 +0000 | [diff] [blame] | 350 | if (ShowHidden) { |
| 351 | OptionHelp.push_back(std::make_pair("\nDRIVER OPTIONS:","")); |
| 352 | OptionHelp.push_back(std::make_pair("-ccc-cxx", |
| 353 | "Act as a C++ driver")); |
| 354 | OptionHelp.push_back(std::make_pair("-ccc-gcc-name", |
| 355 | "Name for native GCC compiler")); |
| 356 | OptionHelp.push_back(std::make_pair("-ccc-clang-cxx", |
Daniel Dunbar | 5915fbf | 2009-09-01 16:57:46 +0000 | [diff] [blame] | 357 | "Enable the clang compiler for C++")); |
| 358 | OptionHelp.push_back(std::make_pair("-ccc-no-clang-cxx", |
| 359 | "Disable the clang compiler for C++")); |
Daniel Dunbar | c35d71f | 2009-04-15 16:34:29 +0000 | [diff] [blame] | 360 | OptionHelp.push_back(std::make_pair("-ccc-no-clang", |
Daniel Dunbar | 5915fbf | 2009-09-01 16:57:46 +0000 | [diff] [blame] | 361 | "Disable the clang compiler")); |
Daniel Dunbar | c35d71f | 2009-04-15 16:34:29 +0000 | [diff] [blame] | 362 | OptionHelp.push_back(std::make_pair("-ccc-no-clang-cpp", |
Daniel Dunbar | 5915fbf | 2009-09-01 16:57:46 +0000 | [diff] [blame] | 363 | "Disable the clang preprocessor")); |
Daniel Dunbar | c35d71f | 2009-04-15 16:34:29 +0000 | [diff] [blame] | 364 | OptionHelp.push_back(std::make_pair("-ccc-clang-archs", |
| 365 | "Comma separate list of architectures " |
| 366 | "to use the clang compiler for")); |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 367 | OptionHelp.push_back(std::make_pair("-ccc-pch-is-pch", |
| 368 | "Use lazy PCH for precompiled headers")); |
| 369 | OptionHelp.push_back(std::make_pair("-ccc-pch-is-pth", |
| 370 | "Use pretokenized headers for precompiled headers")); |
Daniel Dunbar | c35d71f | 2009-04-15 16:34:29 +0000 | [diff] [blame] | 371 | |
| 372 | OptionHelp.push_back(std::make_pair("\nDEBUG/DEVELOPMENT OPTIONS:","")); |
| 373 | OptionHelp.push_back(std::make_pair("-ccc-host-triple", |
Daniel Dunbar | da64141 | 2009-09-04 18:35:03 +0000 | [diff] [blame] | 374 | "Simulate running on the given target")); |
| 375 | OptionHelp.push_back(std::make_pair("-ccc-install-dir", |
| 376 | "Simulate installation in the given directory")); |
Daniel Dunbar | c35d71f | 2009-04-15 16:34:29 +0000 | [diff] [blame] | 377 | OptionHelp.push_back(std::make_pair("-ccc-print-options", |
| 378 | "Dump parsed command line arguments")); |
| 379 | OptionHelp.push_back(std::make_pair("-ccc-print-phases", |
| 380 | "Dump list of actions to perform")); |
| 381 | OptionHelp.push_back(std::make_pair("-ccc-print-bindings", |
| 382 | "Show bindings of tools to actions")); |
| 383 | OptionHelp.push_back(std::make_pair("CCC_ADD_ARGS", |
| 384 | "(ENVIRONMENT VARIABLE) Comma separated list of " |
| 385 | "arguments to prepend to the command line")); |
| 386 | } |
| 387 | |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 388 | // Find the maximum option length. |
Daniel Dunbar | 91e28af | 2009-03-31 21:38:17 +0000 | [diff] [blame] | 389 | unsigned OptionFieldWidth = 0; |
| 390 | for (unsigned i = 0, e = OptionHelp.size(); i != e; ++i) { |
Daniel Dunbar | c35d71f | 2009-04-15 16:34:29 +0000 | [diff] [blame] | 391 | // Skip titles. |
| 392 | if (!OptionHelp[i].second) |
| 393 | continue; |
| 394 | |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 395 | // Limit the amount of padding we are willing to give up for alignment. |
Daniel Dunbar | 91e28af | 2009-03-31 21:38:17 +0000 | [diff] [blame] | 396 | unsigned Length = OptionHelp[i].first.size(); |
| 397 | if (Length <= 23) |
| 398 | OptionFieldWidth = std::max(OptionFieldWidth, Length); |
| 399 | } |
| 400 | |
| 401 | for (unsigned i = 0, e = OptionHelp.size(); i != e; ++i) { |
| 402 | const std::string &Option = OptionHelp[i].first; |
| 403 | OS << " " << Option; |
| 404 | for (int j = Option.length(), e = OptionFieldWidth; j < e; ++j) |
| 405 | OS << ' '; |
| 406 | OS << ' ' << OptionHelp[i].second << '\n'; |
| 407 | } |
| 408 | |
| 409 | OS.flush(); |
| 410 | } |
| 411 | |
Daniel Dunbar | 7930072 | 2009-07-21 20:06:58 +0000 | [diff] [blame] | 412 | void Driver::PrintVersion(const Compilation &C, llvm::raw_ostream &OS) const { |
Mike Stump | 5d023c3 | 2009-03-18 14:00:02 +0000 | [diff] [blame] | 413 | static char buf[] = "$URL$"; |
| 414 | char *zap = strstr(buf, "/lib/Driver"); |
| 415 | if (zap) |
| 416 | *zap = 0; |
| 417 | zap = strstr(buf, "/clang/tools/clang"); |
| 418 | if (zap) |
| 419 | *zap = 0; |
Mike Stump | e70295b | 2009-03-18 15:19:35 +0000 | [diff] [blame] | 420 | const char *vers = buf+6; |
Mike Stump | 8944c38 | 2009-03-18 18:45:55 +0000 | [diff] [blame] | 421 | // FIXME: Add cmake support and remove #ifdef |
| 422 | #ifdef SVN_REVISION |
| 423 | const char *revision = SVN_REVISION; |
| 424 | #else |
| 425 | const char *revision = ""; |
| 426 | #endif |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 427 | // FIXME: The following handlers should use a callback mechanism, we don't |
| 428 | // know what the client would like to do. |
| 429 | OS << "clang version " CLANG_VERSION_STRING " (" |
| 430 | << vers << " " << revision << ")" << '\n'; |
Daniel Dunbar | 70c8db1 | 2009-03-26 16:09:13 +0000 | [diff] [blame] | 431 | |
| 432 | const ToolChain &TC = C.getDefaultToolChain(); |
Daniel Dunbar | 7930072 | 2009-07-21 20:06:58 +0000 | [diff] [blame] | 433 | OS << "Target: " << TC.getTripleString() << '\n'; |
Daniel Dunbar | 3ee96ba | 2009-06-16 23:32:58 +0000 | [diff] [blame] | 434 | |
| 435 | // Print the threading model. |
| 436 | // |
| 437 | // FIXME: Implement correctly. |
Daniel Dunbar | 7930072 | 2009-07-21 20:06:58 +0000 | [diff] [blame] | 438 | OS << "Thread model: " << "posix" << '\n'; |
Daniel Dunbar | cb88167 | 2009-03-13 00:51:18 +0000 | [diff] [blame] | 439 | } |
| 440 | |
Daniel Dunbar | 2154923 | 2009-03-18 02:55:38 +0000 | [diff] [blame] | 441 | bool Driver::HandleImmediateArgs(const Compilation &C) { |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 442 | // The order these options are handled in in gcc is all over the place, but we |
| 443 | // don't expect inconsistencies w.r.t. that to matter in practice. |
Daniel Dunbar | 91e28af | 2009-03-31 21:38:17 +0000 | [diff] [blame] | 444 | |
Daniel Dunbar | e06dc21 | 2009-04-04 05:17:38 +0000 | [diff] [blame] | 445 | if (C.getArgs().hasArg(options::OPT_dumpversion)) { |
Douglas Gregor | ab41e63 | 2009-04-27 22:23:34 +0000 | [diff] [blame] | 446 | llvm::outs() << CLANG_VERSION_STRING "\n"; |
Daniel Dunbar | e06dc21 | 2009-04-04 05:17:38 +0000 | [diff] [blame] | 447 | return false; |
| 448 | } |
| 449 | |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 450 | if (C.getArgs().hasArg(options::OPT__help) || |
Daniel Dunbar | c35d71f | 2009-04-15 16:34:29 +0000 | [diff] [blame] | 451 | C.getArgs().hasArg(options::OPT__help_hidden)) { |
| 452 | PrintHelp(C.getArgs().hasArg(options::OPT__help_hidden)); |
Daniel Dunbar | 91e28af | 2009-03-31 21:38:17 +0000 | [diff] [blame] | 453 | return false; |
| 454 | } |
| 455 | |
Daniel Dunbar | 6cc73de | 2009-04-02 15:05:41 +0000 | [diff] [blame] | 456 | if (C.getArgs().hasArg(options::OPT__version)) { |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 457 | // Follow gcc behavior and use stdout for --version and stderr for -v. |
Daniel Dunbar | 7930072 | 2009-07-21 20:06:58 +0000 | [diff] [blame] | 458 | PrintVersion(C, llvm::outs()); |
Daniel Dunbar | 6cc73de | 2009-04-02 15:05:41 +0000 | [diff] [blame] | 459 | return false; |
| 460 | } |
| 461 | |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 462 | if (C.getArgs().hasArg(options::OPT_v) || |
Daniel Dunbar | 2154923 | 2009-03-18 02:55:38 +0000 | [diff] [blame] | 463 | C.getArgs().hasArg(options::OPT__HASH_HASH_HASH)) { |
Daniel Dunbar | 7930072 | 2009-07-21 20:06:58 +0000 | [diff] [blame] | 464 | PrintVersion(C, llvm::errs()); |
Daniel Dunbar | cb88167 | 2009-03-13 00:51:18 +0000 | [diff] [blame] | 465 | SuppressMissingInputWarning = true; |
| 466 | } |
| 467 | |
Daniel Dunbar | 2154923 | 2009-03-18 02:55:38 +0000 | [diff] [blame] | 468 | const ToolChain &TC = C.getDefaultToolChain(); |
Daniel Dunbar | ca3459e | 2009-03-20 04:37:21 +0000 | [diff] [blame] | 469 | if (C.getArgs().hasArg(options::OPT_print_search_dirs)) { |
| 470 | llvm::outs() << "programs: ="; |
| 471 | for (ToolChain::path_list::const_iterator it = TC.getProgramPaths().begin(), |
| 472 | ie = TC.getProgramPaths().end(); it != ie; ++it) { |
| 473 | if (it != TC.getProgramPaths().begin()) |
| 474 | llvm::outs() << ':'; |
| 475 | llvm::outs() << *it; |
| 476 | } |
| 477 | llvm::outs() << "\n"; |
| 478 | llvm::outs() << "libraries: ="; |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 479 | for (ToolChain::path_list::const_iterator it = TC.getFilePaths().begin(), |
Daniel Dunbar | ca3459e | 2009-03-20 04:37:21 +0000 | [diff] [blame] | 480 | ie = TC.getFilePaths().end(); it != ie; ++it) { |
| 481 | if (it != TC.getFilePaths().begin()) |
| 482 | llvm::outs() << ':'; |
| 483 | llvm::outs() << *it; |
| 484 | } |
| 485 | llvm::outs() << "\n"; |
Daniel Dunbar | 91e28af | 2009-03-31 21:38:17 +0000 | [diff] [blame] | 486 | return false; |
Daniel Dunbar | ca3459e | 2009-03-20 04:37:21 +0000 | [diff] [blame] | 487 | } |
| 488 | |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 489 | // FIXME: The following handlers should use a callback mechanism, we don't |
| 490 | // know what the client would like to do. |
Daniel Dunbar | 2154923 | 2009-03-18 02:55:38 +0000 | [diff] [blame] | 491 | if (Arg *A = C.getArgs().getLastArg(options::OPT_print_file_name_EQ)) { |
Daniel Dunbar | 5ed34f4 | 2009-09-09 22:33:00 +0000 | [diff] [blame] | 492 | llvm::outs() << GetFilePath(A->getValue(C.getArgs()), TC) << "\n"; |
Daniel Dunbar | cb88167 | 2009-03-13 00:51:18 +0000 | [diff] [blame] | 493 | return false; |
| 494 | } |
| 495 | |
Daniel Dunbar | 2154923 | 2009-03-18 02:55:38 +0000 | [diff] [blame] | 496 | if (Arg *A = C.getArgs().getLastArg(options::OPT_print_prog_name_EQ)) { |
Daniel Dunbar | 5ed34f4 | 2009-09-09 22:33:00 +0000 | [diff] [blame] | 497 | llvm::outs() << GetProgramPath(A->getValue(C.getArgs()), TC) << "\n"; |
Daniel Dunbar | cb88167 | 2009-03-13 00:51:18 +0000 | [diff] [blame] | 498 | return false; |
| 499 | } |
| 500 | |
Daniel Dunbar | 2154923 | 2009-03-18 02:55:38 +0000 | [diff] [blame] | 501 | if (C.getArgs().hasArg(options::OPT_print_libgcc_file_name)) { |
Daniel Dunbar | 5ed34f4 | 2009-09-09 22:33:00 +0000 | [diff] [blame] | 502 | llvm::outs() << GetFilePath("libgcc.a", TC) << "\n"; |
Daniel Dunbar | cb88167 | 2009-03-13 00:51:18 +0000 | [diff] [blame] | 503 | return false; |
| 504 | } |
| 505 | |
Daniel Dunbar | 12cfe03 | 2009-06-16 23:25:22 +0000 | [diff] [blame] | 506 | if (C.getArgs().hasArg(options::OPT_print_multi_lib)) { |
| 507 | // FIXME: We need tool chain support for this. |
| 508 | llvm::outs() << ".;\n"; |
| 509 | |
| 510 | switch (C.getDefaultToolChain().getTriple().getArch()) { |
| 511 | default: |
| 512 | break; |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 513 | |
Daniel Dunbar | 12cfe03 | 2009-06-16 23:25:22 +0000 | [diff] [blame] | 514 | case llvm::Triple::x86_64: |
| 515 | llvm::outs() << "x86_64;@m64" << "\n"; |
| 516 | break; |
| 517 | |
| 518 | case llvm::Triple::ppc64: |
| 519 | llvm::outs() << "ppc64;@m64" << "\n"; |
| 520 | break; |
| 521 | } |
| 522 | return false; |
| 523 | } |
| 524 | |
| 525 | // FIXME: What is the difference between print-multi-directory and |
| 526 | // print-multi-os-directory? |
| 527 | if (C.getArgs().hasArg(options::OPT_print_multi_directory) || |
| 528 | C.getArgs().hasArg(options::OPT_print_multi_os_directory)) { |
| 529 | switch (C.getDefaultToolChain().getTriple().getArch()) { |
| 530 | default: |
| 531 | case llvm::Triple::x86: |
| 532 | case llvm::Triple::ppc: |
| 533 | llvm::outs() << "." << "\n"; |
| 534 | break; |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 535 | |
Daniel Dunbar | 12cfe03 | 2009-06-16 23:25:22 +0000 | [diff] [blame] | 536 | case llvm::Triple::x86_64: |
| 537 | llvm::outs() << "x86_64" << "\n"; |
| 538 | break; |
| 539 | |
| 540 | case llvm::Triple::ppc64: |
| 541 | llvm::outs() << "ppc64" << "\n"; |
| 542 | break; |
| 543 | } |
| 544 | return false; |
| 545 | } |
| 546 | |
Daniel Dunbar | cb88167 | 2009-03-13 00:51:18 +0000 | [diff] [blame] | 547 | return true; |
| 548 | } |
| 549 | |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 550 | static unsigned PrintActions1(const Compilation &C, Action *A, |
Daniel Dunbar | ba10213 | 2009-03-13 12:19:02 +0000 | [diff] [blame] | 551 | std::map<Action*, unsigned> &Ids) { |
| 552 | if (Ids.count(A)) |
| 553 | return Ids[A]; |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 554 | |
Daniel Dunbar | ba10213 | 2009-03-13 12:19:02 +0000 | [diff] [blame] | 555 | std::string str; |
| 556 | llvm::raw_string_ostream os(str); |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 557 | |
Daniel Dunbar | ba10213 | 2009-03-13 12:19:02 +0000 | [diff] [blame] | 558 | os << Action::getClassName(A->getKind()) << ", "; |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 559 | if (InputAction *IA = dyn_cast<InputAction>(A)) { |
Daniel Dunbar | 10ffa9a | 2009-03-18 03:13:20 +0000 | [diff] [blame] | 560 | os << "\"" << IA->getInputArg().getValue(C.getArgs()) << "\""; |
Daniel Dunbar | ba10213 | 2009-03-13 12:19:02 +0000 | [diff] [blame] | 561 | } else if (BindArchAction *BIA = dyn_cast<BindArchAction>(A)) { |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 562 | os << '"' << (BIA->getArchName() ? BIA->getArchName() : |
Daniel Dunbar | 10ffa9a | 2009-03-18 03:13:20 +0000 | [diff] [blame] | 563 | C.getDefaultToolChain().getArchName()) << '"' |
| 564 | << ", {" << PrintActions1(C, *BIA->begin(), Ids) << "}"; |
Daniel Dunbar | ba10213 | 2009-03-13 12:19:02 +0000 | [diff] [blame] | 565 | } else { |
| 566 | os << "{"; |
| 567 | for (Action::iterator it = A->begin(), ie = A->end(); it != ie;) { |
Daniel Dunbar | 10ffa9a | 2009-03-18 03:13:20 +0000 | [diff] [blame] | 568 | os << PrintActions1(C, *it, Ids); |
Daniel Dunbar | ba10213 | 2009-03-13 12:19:02 +0000 | [diff] [blame] | 569 | ++it; |
| 570 | if (it != ie) |
| 571 | os << ", "; |
| 572 | } |
| 573 | os << "}"; |
| 574 | } |
| 575 | |
| 576 | unsigned Id = Ids.size(); |
| 577 | Ids[A] = Id; |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 578 | llvm::errs() << Id << ": " << os.str() << ", " |
Daniel Dunbar | ba10213 | 2009-03-13 12:19:02 +0000 | [diff] [blame] | 579 | << types::getTypeName(A->getType()) << "\n"; |
| 580 | |
| 581 | return Id; |
| 582 | } |
| 583 | |
Daniel Dunbar | 10ffa9a | 2009-03-18 03:13:20 +0000 | [diff] [blame] | 584 | void Driver::PrintActions(const Compilation &C) const { |
Daniel Dunbar | ba10213 | 2009-03-13 12:19:02 +0000 | [diff] [blame] | 585 | std::map<Action*, unsigned> Ids; |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 586 | for (ActionList::const_iterator it = C.getActions().begin(), |
Daniel Dunbar | 10ffa9a | 2009-03-18 03:13:20 +0000 | [diff] [blame] | 587 | ie = C.getActions().end(); it != ie; ++it) |
| 588 | PrintActions1(C, *it, Ids); |
Daniel Dunbar | 53ec552 | 2009-03-12 07:58:46 +0000 | [diff] [blame] | 589 | } |
| 590 | |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 591 | void Driver::BuildUniversalActions(const ArgList &Args, |
Daniel Dunbar | 2154923 | 2009-03-18 02:55:38 +0000 | [diff] [blame] | 592 | ActionList &Actions) const { |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 593 | llvm::PrettyStackTraceString CrashInfo("Building universal build actions"); |
| 594 | // Collect the list of architectures. Duplicates are allowed, but should only |
| 595 | // be handled once (in the order seen). |
Daniel Dunbar | 1368954 | 2009-03-13 20:33:35 +0000 | [diff] [blame] | 596 | llvm::StringSet<> ArchNames; |
| 597 | llvm::SmallVector<const char *, 4> Archs; |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 598 | for (ArgList::const_iterator it = Args.begin(), ie = Args.end(); |
Daniel Dunbar | 2fe63e6 | 2009-03-12 18:40:18 +0000 | [diff] [blame] | 599 | it != ie; ++it) { |
| 600 | Arg *A = *it; |
| 601 | |
| 602 | if (A->getOption().getId() == options::OPT_arch) { |
Daniel Dunbar | 36df290 | 2009-09-08 23:37:30 +0000 | [diff] [blame] | 603 | // Validate the option here; we don't save the type here because its |
| 604 | // particular spelling may participate in other driver choices. |
| 605 | llvm::Triple::ArchType Arch = |
| 606 | llvm::Triple::getArchTypeForDarwinArchName(A->getValue(Args)); |
| 607 | if (Arch == llvm::Triple::UnknownArch) { |
| 608 | Diag(clang::diag::err_drv_invalid_arch_name) |
| 609 | << A->getAsString(Args); |
| 610 | continue; |
| 611 | } |
| 612 | |
Daniel Dunbar | 7587719 | 2009-03-19 07:55:12 +0000 | [diff] [blame] | 613 | A->claim(); |
Daniel Dunbar | 3f30ddf | 2009-09-08 23:37:02 +0000 | [diff] [blame] | 614 | if (ArchNames.insert(A->getValue(Args))) |
| 615 | Archs.push_back(A->getValue(Args)); |
Daniel Dunbar | 2fe63e6 | 2009-03-12 18:40:18 +0000 | [diff] [blame] | 616 | } |
| 617 | } |
| 618 | |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 619 | // When there is no explicit arch for this platform, make sure we still bind |
| 620 | // the architecture (to the default) so that -Xarch_ is handled correctly. |
Daniel Dunbar | 10ffa9a | 2009-03-18 03:13:20 +0000 | [diff] [blame] | 621 | if (!Archs.size()) |
| 622 | Archs.push_back(0); |
Daniel Dunbar | 2fe63e6 | 2009-03-12 18:40:18 +0000 | [diff] [blame] | 623 | |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 624 | // FIXME: We killed off some others but these aren't yet detected in a |
| 625 | // functional manner. If we added information to jobs about which "auxiliary" |
| 626 | // files they wrote then we could detect the conflict these cause downstream. |
Daniel Dunbar | 2fe63e6 | 2009-03-12 18:40:18 +0000 | [diff] [blame] | 627 | if (Archs.size() > 1) { |
| 628 | // No recovery needed, the point of this is just to prevent |
| 629 | // overwriting the same files. |
Daniel Dunbar | 2fe63e6 | 2009-03-12 18:40:18 +0000 | [diff] [blame] | 630 | if (const Arg *A = Args.getLastArg(options::OPT_save_temps)) |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 631 | Diag(clang::diag::err_drv_invalid_opt_with_multiple_archs) |
Daniel Dunbar | 38dd3d5 | 2009-03-20 06:14:23 +0000 | [diff] [blame] | 632 | << A->getAsString(Args); |
Daniel Dunbar | 2fe63e6 | 2009-03-12 18:40:18 +0000 | [diff] [blame] | 633 | } |
| 634 | |
| 635 | ActionList SingleActions; |
| 636 | BuildActions(Args, SingleActions); |
| 637 | |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 638 | // Add in arch binding and lipo (if necessary) for every top level action. |
Daniel Dunbar | 2fe63e6 | 2009-03-12 18:40:18 +0000 | [diff] [blame] | 639 | for (unsigned i = 0, e = SingleActions.size(); i != e; ++i) { |
| 640 | Action *Act = SingleActions[i]; |
| 641 | |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 642 | // Make sure we can lipo this kind of output. If not (and it is an actual |
| 643 | // output) then we disallow, since we can't create an output file with the |
| 644 | // right name without overwriting it. We could remove this oddity by just |
| 645 | // changing the output names to include the arch, which would also fix |
Daniel Dunbar | 2fe63e6 | 2009-03-12 18:40:18 +0000 | [diff] [blame] | 646 | // -save-temps. Compatibility wins for now. |
| 647 | |
Daniel Dunbar | 3dbd6c5 | 2009-03-13 17:46:02 +0000 | [diff] [blame] | 648 | if (Archs.size() > 1 && !types::canLipoType(Act->getType())) |
Daniel Dunbar | 2fe63e6 | 2009-03-12 18:40:18 +0000 | [diff] [blame] | 649 | Diag(clang::diag::err_drv_invalid_output_with_multiple_archs) |
| 650 | << types::getTypeName(Act->getType()); |
| 651 | |
| 652 | ActionList Inputs; |
Daniel Dunbar | 7587719 | 2009-03-19 07:55:12 +0000 | [diff] [blame] | 653 | for (unsigned i = 0, e = Archs.size(); i != e; ++i) |
Daniel Dunbar | 1368954 | 2009-03-13 20:33:35 +0000 | [diff] [blame] | 654 | Inputs.push_back(new BindArchAction(Act, Archs[i])); |
Daniel Dunbar | 2fe63e6 | 2009-03-12 18:40:18 +0000 | [diff] [blame] | 655 | |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 656 | // Lipo if necessary, we do it this way because we need to set the arch flag |
| 657 | // so that -Xarch_ gets overwritten. |
Daniel Dunbar | 2fe63e6 | 2009-03-12 18:40:18 +0000 | [diff] [blame] | 658 | if (Inputs.size() == 1 || Act->getType() == types::TY_Nothing) |
| 659 | Actions.append(Inputs.begin(), Inputs.end()); |
| 660 | else |
| 661 | Actions.push_back(new LipoJobAction(Inputs, Act->getType())); |
| 662 | } |
Daniel Dunbar | 53ec552 | 2009-03-12 07:58:46 +0000 | [diff] [blame] | 663 | } |
| 664 | |
Daniel Dunbar | 2154923 | 2009-03-18 02:55:38 +0000 | [diff] [blame] | 665 | void Driver::BuildActions(const ArgList &Args, ActionList &Actions) const { |
Daniel Dunbar | 8f25c79 | 2009-03-18 01:38:48 +0000 | [diff] [blame] | 666 | llvm::PrettyStackTraceString CrashInfo("Building compilation actions"); |
Daniel Dunbar | af61c71 | 2009-03-12 23:55:14 +0000 | [diff] [blame] | 667 | // Start by constructing the list of inputs and their types. |
| 668 | |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 669 | // Track the current user specified (-x) input. We also explicitly track the |
| 670 | // argument used to set the type; we only want to claim the type when we |
| 671 | // actually use it, so we warn about unused -x arguments. |
Daniel Dunbar | 83dd21f | 2009-03-13 17:57:10 +0000 | [diff] [blame] | 672 | types::ID InputType = types::TY_Nothing; |
| 673 | Arg *InputTypeArg = 0; |
| 674 | |
Daniel Dunbar | 53ec552 | 2009-03-12 07:58:46 +0000 | [diff] [blame] | 675 | llvm::SmallVector<std::pair<types::ID, const Arg*>, 16> Inputs; |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 676 | for (ArgList::const_iterator it = Args.begin(), ie = Args.end(); |
Daniel Dunbar | 53ec552 | 2009-03-12 07:58:46 +0000 | [diff] [blame] | 677 | it != ie; ++it) { |
| 678 | Arg *A = *it; |
| 679 | |
| 680 | if (isa<InputOption>(A->getOption())) { |
| 681 | const char *Value = A->getValue(Args); |
| 682 | types::ID Ty = types::TY_INVALID; |
| 683 | |
| 684 | // Infer the input type if necessary. |
Daniel Dunbar | 83dd21f | 2009-03-13 17:57:10 +0000 | [diff] [blame] | 685 | if (InputType == types::TY_Nothing) { |
| 686 | // If there was an explicit arg for this, claim it. |
| 687 | if (InputTypeArg) |
| 688 | InputTypeArg->claim(); |
| 689 | |
Daniel Dunbar | 53ec552 | 2009-03-12 07:58:46 +0000 | [diff] [blame] | 690 | // stdin must be handled specially. |
| 691 | if (memcmp(Value, "-", 2) == 0) { |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 692 | // If running with -E, treat as a C input (this changes the builtin |
| 693 | // macros, for example). This may be overridden by -ObjC below. |
Daniel Dunbar | 53ec552 | 2009-03-12 07:58:46 +0000 | [diff] [blame] | 694 | // |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 695 | // Otherwise emit an error but still use a valid type to avoid |
| 696 | // spurious errors (e.g., no inputs). |
Daniel Dunbar | 8022fd4 | 2009-03-15 00:48:16 +0000 | [diff] [blame] | 697 | if (!Args.hasArg(options::OPT_E, false)) |
Daniel Dunbar | b897f5d | 2009-03-12 09:13:48 +0000 | [diff] [blame] | 698 | Diag(clang::diag::err_drv_unknown_stdin_type); |
Daniel Dunbar | 53ec552 | 2009-03-12 07:58:46 +0000 | [diff] [blame] | 699 | Ty = types::TY_C; |
| 700 | } else { |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 701 | // Otherwise lookup by extension, and fallback to ObjectType if not |
| 702 | // found. We use a host hook here because Darwin at least has its own |
| 703 | // idea of what .s is. |
Daniel Dunbar | 53ec552 | 2009-03-12 07:58:46 +0000 | [diff] [blame] | 704 | if (const char *Ext = strrchr(Value, '.')) |
Daniel Dunbar | e33bea4 | 2009-03-20 23:39:23 +0000 | [diff] [blame] | 705 | Ty = Host->lookupTypeForExtension(Ext + 1); |
| 706 | |
Daniel Dunbar | 53ec552 | 2009-03-12 07:58:46 +0000 | [diff] [blame] | 707 | if (Ty == types::TY_INVALID) |
| 708 | Ty = types::TY_Object; |
| 709 | } |
| 710 | |
Daniel Dunbar | 683ca38 | 2009-05-18 21:47:54 +0000 | [diff] [blame] | 711 | // -ObjC and -ObjC++ override the default language, but only for "source |
| 712 | // files". We just treat everything that isn't a linker input as a |
| 713 | // source file. |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 714 | // |
Daniel Dunbar | 683ca38 | 2009-05-18 21:47:54 +0000 | [diff] [blame] | 715 | // FIXME: Clean this up if we move the phase sequence into the type. |
Daniel Dunbar | 53ec552 | 2009-03-12 07:58:46 +0000 | [diff] [blame] | 716 | if (Ty != types::TY_Object) { |
| 717 | if (Args.hasArg(options::OPT_ObjC)) |
| 718 | Ty = types::TY_ObjC; |
| 719 | else if (Args.hasArg(options::OPT_ObjCXX)) |
| 720 | Ty = types::TY_ObjCXX; |
| 721 | } |
| 722 | } else { |
| 723 | assert(InputTypeArg && "InputType set w/o InputTypeArg"); |
| 724 | InputTypeArg->claim(); |
| 725 | Ty = InputType; |
| 726 | } |
| 727 | |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 728 | // Check that the file exists. It isn't clear this is worth doing, since |
| 729 | // the tool presumably does this anyway, and this just adds an extra stat |
| 730 | // to the equation, but this is gcc compatible. |
Daniel Dunbar | 53ec552 | 2009-03-12 07:58:46 +0000 | [diff] [blame] | 731 | if (memcmp(Value, "-", 2) != 0 && !llvm::sys::Path(Value).exists()) |
Daniel Dunbar | b897f5d | 2009-03-12 09:13:48 +0000 | [diff] [blame] | 732 | Diag(clang::diag::err_drv_no_such_file) << A->getValue(Args); |
Daniel Dunbar | 53ec552 | 2009-03-12 07:58:46 +0000 | [diff] [blame] | 733 | else |
| 734 | Inputs.push_back(std::make_pair(Ty, A)); |
| 735 | |
| 736 | } else if (A->getOption().isLinkerInput()) { |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 737 | // Just treat as object type, we could make a special type for this if |
| 738 | // necessary. |
Daniel Dunbar | 53ec552 | 2009-03-12 07:58:46 +0000 | [diff] [blame] | 739 | Inputs.push_back(std::make_pair(types::TY_Object, A)); |
| 740 | |
| 741 | } else if (A->getOption().getId() == options::OPT_x) { |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 742 | InputTypeArg = A; |
Daniel Dunbar | 53ec552 | 2009-03-12 07:58:46 +0000 | [diff] [blame] | 743 | InputType = types::lookupTypeForTypeSpecifier(A->getValue(Args)); |
| 744 | |
| 745 | // Follow gcc behavior and treat as linker input for invalid -x |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 746 | // options. Its not clear why we shouldn't just revert to unknown; but |
| 747 | // this isn't very important, we might as well be bug comatible. |
Daniel Dunbar | 53ec552 | 2009-03-12 07:58:46 +0000 | [diff] [blame] | 748 | if (!InputType) { |
Daniel Dunbar | b897f5d | 2009-03-12 09:13:48 +0000 | [diff] [blame] | 749 | Diag(clang::diag::err_drv_unknown_language) << A->getValue(Args); |
Daniel Dunbar | 53ec552 | 2009-03-12 07:58:46 +0000 | [diff] [blame] | 750 | InputType = types::TY_Object; |
| 751 | } |
| 752 | } |
| 753 | } |
| 754 | |
Daniel Dunbar | 8b1604e | 2009-03-13 00:17:48 +0000 | [diff] [blame] | 755 | if (!SuppressMissingInputWarning && Inputs.empty()) { |
Daniel Dunbar | af61c71 | 2009-03-12 23:55:14 +0000 | [diff] [blame] | 756 | Diag(clang::diag::err_drv_no_input_files); |
| 757 | return; |
| 758 | } |
| 759 | |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 760 | // Determine which compilation mode we are in. We look for options which |
| 761 | // affect the phase, starting with the earliest phases, and record which |
| 762 | // option we used to determine the final phase. |
Daniel Dunbar | ad2a9af | 2009-03-13 11:38:42 +0000 | [diff] [blame] | 763 | Arg *FinalPhaseArg = 0; |
| 764 | phases::ID FinalPhase; |
Daniel Dunbar | af61c71 | 2009-03-12 23:55:14 +0000 | [diff] [blame] | 765 | |
| 766 | // -{E,M,MM} only run the preprocessor. |
Daniel Dunbar | ad2a9af | 2009-03-13 11:38:42 +0000 | [diff] [blame] | 767 | if ((FinalPhaseArg = Args.getLastArg(options::OPT_E)) || |
| 768 | (FinalPhaseArg = Args.getLastArg(options::OPT_M)) || |
| 769 | (FinalPhaseArg = Args.getLastArg(options::OPT_MM))) { |
| 770 | FinalPhase = phases::Preprocess; |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 771 | |
Daniel Dunbar | 5915fbf | 2009-09-01 16:57:46 +0000 | [diff] [blame] | 772 | // -{fsyntax-only,-analyze,emit-ast,S} only run up to the compiler. |
Daniel Dunbar | 8022fd4 | 2009-03-15 00:48:16 +0000 | [diff] [blame] | 773 | } else if ((FinalPhaseArg = Args.getLastArg(options::OPT_fsyntax_only)) || |
Daniel Dunbar | 63be57a | 2009-05-06 02:12:32 +0000 | [diff] [blame] | 774 | (FinalPhaseArg = Args.getLastArg(options::OPT__analyze, |
| 775 | options::OPT__analyze_auto)) || |
Daniel Dunbar | 5915fbf | 2009-09-01 16:57:46 +0000 | [diff] [blame] | 776 | (FinalPhaseArg = Args.getLastArg(options::OPT_emit_ast)) || |
Daniel Dunbar | ad2a9af | 2009-03-13 11:38:42 +0000 | [diff] [blame] | 777 | (FinalPhaseArg = Args.getLastArg(options::OPT_S))) { |
| 778 | FinalPhase = phases::Compile; |
Daniel Dunbar | af61c71 | 2009-03-12 23:55:14 +0000 | [diff] [blame] | 779 | |
| 780 | // -c only runs up to the assembler. |
Daniel Dunbar | ad2a9af | 2009-03-13 11:38:42 +0000 | [diff] [blame] | 781 | } else if ((FinalPhaseArg = Args.getLastArg(options::OPT_c))) { |
| 782 | FinalPhase = phases::Assemble; |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 783 | |
Daniel Dunbar | af61c71 | 2009-03-12 23:55:14 +0000 | [diff] [blame] | 784 | // Otherwise do everything. |
| 785 | } else |
Daniel Dunbar | ad2a9af | 2009-03-13 11:38:42 +0000 | [diff] [blame] | 786 | FinalPhase = phases::Link; |
Daniel Dunbar | af61c71 | 2009-03-12 23:55:14 +0000 | [diff] [blame] | 787 | |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 788 | // Reject -Z* at the top level, these options should never have been exposed |
| 789 | // by gcc. |
Daniel Dunbar | d7b88c2 | 2009-03-26 16:12:09 +0000 | [diff] [blame] | 790 | if (Arg *A = Args.getLastArg(options::OPT_Z_Joined)) |
Daniel Dunbar | 38dd3d5 | 2009-03-20 06:14:23 +0000 | [diff] [blame] | 791 | Diag(clang::diag::err_drv_use_of_Z_option) << A->getAsString(Args); |
Daniel Dunbar | af61c71 | 2009-03-12 23:55:14 +0000 | [diff] [blame] | 792 | |
Daniel Dunbar | ad2a9af | 2009-03-13 11:38:42 +0000 | [diff] [blame] | 793 | // Construct the actions to perform. |
| 794 | ActionList LinkerInputs; |
Daniel Dunbar | 53ec552 | 2009-03-12 07:58:46 +0000 | [diff] [blame] | 795 | for (unsigned i = 0, e = Inputs.size(); i != e; ++i) { |
Daniel Dunbar | ad2a9af | 2009-03-13 11:38:42 +0000 | [diff] [blame] | 796 | types::ID InputType = Inputs[i].first; |
| 797 | const Arg *InputArg = Inputs[i].second; |
| 798 | |
| 799 | unsigned NumSteps = types::getNumCompilationPhases(InputType); |
| 800 | assert(NumSteps && "Invalid number of steps!"); |
| 801 | |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 802 | // If the first step comes after the final phase we are doing as part of |
| 803 | // this compilation, warn the user about it. |
Daniel Dunbar | ad2a9af | 2009-03-13 11:38:42 +0000 | [diff] [blame] | 804 | phases::ID InitialPhase = types::getCompilationPhase(InputType, 0); |
| 805 | if (InitialPhase > FinalPhase) { |
Daniel Dunbar | 05494a7 | 2009-03-19 07:57:08 +0000 | [diff] [blame] | 806 | // Claim here to avoid the more general unused warning. |
| 807 | InputArg->claim(); |
Daniel Dunbar | 634b245 | 2009-09-17 04:13:26 +0000 | [diff] [blame] | 808 | |
| 809 | // Special case '-E' warning on a previously preprocessed file to make |
| 810 | // more sense. |
| 811 | if (InitialPhase == phases::Compile && FinalPhase == phases::Preprocess && |
| 812 | getPreprocessedType(InputType) == types::TY_INVALID) |
| 813 | Diag(clang::diag::warn_drv_preprocessed_input_file_unused) |
| 814 | << InputArg->getAsString(Args) |
| 815 | << FinalPhaseArg->getOption().getName(); |
| 816 | else |
| 817 | Diag(clang::diag::warn_drv_input_file_unused) |
| 818 | << InputArg->getAsString(Args) |
| 819 | << getPhaseName(InitialPhase) |
| 820 | << FinalPhaseArg->getOption().getName(); |
Daniel Dunbar | ad2a9af | 2009-03-13 11:38:42 +0000 | [diff] [blame] | 821 | continue; |
| 822 | } |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 823 | |
Daniel Dunbar | ad2a9af | 2009-03-13 11:38:42 +0000 | [diff] [blame] | 824 | // Build the pipeline for this file. |
| 825 | Action *Current = new InputAction(*InputArg, InputType); |
| 826 | for (unsigned i = 0; i != NumSteps; ++i) { |
| 827 | phases::ID Phase = types::getCompilationPhase(InputType, i); |
| 828 | |
| 829 | // We are done if this step is past what the user requested. |
| 830 | if (Phase > FinalPhase) |
| 831 | break; |
| 832 | |
| 833 | // Queue linker inputs. |
| 834 | if (Phase == phases::Link) { |
| 835 | assert(i + 1 == NumSteps && "linking must be final compilation step."); |
| 836 | LinkerInputs.push_back(Current); |
| 837 | Current = 0; |
| 838 | break; |
| 839 | } |
| 840 | |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 841 | // Some types skip the assembler phase (e.g., llvm-bc), but we can't |
| 842 | // encode this in the steps because the intermediate type depends on |
| 843 | // arguments. Just special case here. |
Daniel Dunbar | 337a627 | 2009-03-24 20:17:30 +0000 | [diff] [blame] | 844 | if (Phase == phases::Assemble && Current->getType() != types::TY_PP_Asm) |
| 845 | continue; |
| 846 | |
Daniel Dunbar | ad2a9af | 2009-03-13 11:38:42 +0000 | [diff] [blame] | 847 | // Otherwise construct the appropriate action. |
| 848 | Current = ConstructPhaseAction(Args, Phase, Current); |
| 849 | if (Current->getType() == types::TY_Nothing) |
| 850 | break; |
| 851 | } |
| 852 | |
| 853 | // If we ended with something, add to the output list. |
| 854 | if (Current) |
| 855 | Actions.push_back(Current); |
Daniel Dunbar | 53ec552 | 2009-03-12 07:58:46 +0000 | [diff] [blame] | 856 | } |
Daniel Dunbar | ad2a9af | 2009-03-13 11:38:42 +0000 | [diff] [blame] | 857 | |
| 858 | // Add a link action if necessary. |
| 859 | if (!LinkerInputs.empty()) |
| 860 | Actions.push_back(new LinkJobAction(LinkerInputs, types::TY_Image)); |
| 861 | } |
| 862 | |
| 863 | Action *Driver::ConstructPhaseAction(const ArgList &Args, phases::ID Phase, |
| 864 | Action *Input) const { |
Daniel Dunbar | 8f25c79 | 2009-03-18 01:38:48 +0000 | [diff] [blame] | 865 | llvm::PrettyStackTraceString CrashInfo("Constructing phase actions"); |
Daniel Dunbar | ad2a9af | 2009-03-13 11:38:42 +0000 | [diff] [blame] | 866 | // Build the appropriate action. |
| 867 | switch (Phase) { |
| 868 | case phases::Link: assert(0 && "link action invalid here."); |
| 869 | case phases::Preprocess: { |
Daniel Dunbar | cd8e4c4 | 2009-03-30 06:36:42 +0000 | [diff] [blame] | 870 | types::ID OutputTy; |
| 871 | // -{M, MM} alter the output type. |
| 872 | if (Args.hasArg(options::OPT_M) || Args.hasArg(options::OPT_MM)) { |
| 873 | OutputTy = types::TY_Dependencies; |
| 874 | } else { |
| 875 | OutputTy = types::getPreprocessedType(Input->getType()); |
| 876 | assert(OutputTy != types::TY_INVALID && |
| 877 | "Cannot preprocess this input type!"); |
| 878 | } |
Daniel Dunbar | ad2a9af | 2009-03-13 11:38:42 +0000 | [diff] [blame] | 879 | return new PreprocessJobAction(Input, OutputTy); |
| 880 | } |
| 881 | case phases::Precompile: |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 882 | return new PrecompileJobAction(Input, types::TY_PCH); |
Daniel Dunbar | ad2a9af | 2009-03-13 11:38:42 +0000 | [diff] [blame] | 883 | case phases::Compile: { |
| 884 | if (Args.hasArg(options::OPT_fsyntax_only)) { |
| 885 | return new CompileJobAction(Input, types::TY_Nothing); |
Daniel Dunbar | 63be57a | 2009-05-06 02:12:32 +0000 | [diff] [blame] | 886 | } else if (Args.hasArg(options::OPT__analyze, options::OPT__analyze_auto)) { |
Daniel Dunbar | ad2a9af | 2009-03-13 11:38:42 +0000 | [diff] [blame] | 887 | return new AnalyzeJobAction(Input, types::TY_Plist); |
Daniel Dunbar | 5915fbf | 2009-09-01 16:57:46 +0000 | [diff] [blame] | 888 | } else if (Args.hasArg(options::OPT_emit_ast)) { |
| 889 | return new CompileJobAction(Input, types::TY_AST); |
Daniel Dunbar | 337a627 | 2009-03-24 20:17:30 +0000 | [diff] [blame] | 890 | } else if (Args.hasArg(options::OPT_emit_llvm) || |
| 891 | Args.hasArg(options::OPT_flto) || |
| 892 | Args.hasArg(options::OPT_O4)) { |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 893 | types::ID Output = |
Daniel Dunbar | ad2a9af | 2009-03-13 11:38:42 +0000 | [diff] [blame] | 894 | Args.hasArg(options::OPT_S) ? types::TY_LLVMAsm : types::TY_LLVMBC; |
| 895 | return new CompileJobAction(Input, Output); |
| 896 | } else { |
| 897 | return new CompileJobAction(Input, types::TY_PP_Asm); |
| 898 | } |
| 899 | } |
| 900 | case phases::Assemble: |
| 901 | return new AssembleJobAction(Input, types::TY_Object); |
| 902 | } |
| 903 | |
| 904 | assert(0 && "invalid phase in ConstructPhaseAction"); |
| 905 | return 0; |
Daniel Dunbar | 53ec552 | 2009-03-12 07:58:46 +0000 | [diff] [blame] | 906 | } |
| 907 | |
Daniel Dunbar | 2154923 | 2009-03-18 02:55:38 +0000 | [diff] [blame] | 908 | void Driver::BuildJobs(Compilation &C) const { |
Daniel Dunbar | 8f25c79 | 2009-03-18 01:38:48 +0000 | [diff] [blame] | 909 | llvm::PrettyStackTraceString CrashInfo("Building compilation jobs"); |
Daniel Dunbar | f353c8c | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 910 | bool SaveTemps = C.getArgs().hasArg(options::OPT_save_temps); |
| 911 | bool UsePipes = C.getArgs().hasArg(options::OPT_pipe); |
Daniel Dunbar | 60ccc76 | 2009-03-18 23:18:19 +0000 | [diff] [blame] | 912 | |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 913 | // FIXME: Pipes are forcibly disabled until we support executing them. |
Daniel Dunbar | 60ccc76 | 2009-03-18 23:18:19 +0000 | [diff] [blame] | 914 | if (!CCCPrintBindings) |
| 915 | UsePipes = false; |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 916 | |
Daniel Dunbar | f353c8c | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 917 | // -save-temps inhibits pipes. |
| 918 | if (SaveTemps && UsePipes) { |
| 919 | Diag(clang::diag::warn_drv_pipe_ignored_with_save_temps); |
| 920 | UsePipes = true; |
| 921 | } |
| 922 | |
| 923 | Arg *FinalOutput = C.getArgs().getLastArg(options::OPT_o); |
| 924 | |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 925 | // It is an error to provide a -o option if we are making multiple output |
| 926 | // files. |
Daniel Dunbar | f353c8c | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 927 | if (FinalOutput) { |
| 928 | unsigned NumOutputs = 0; |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 929 | for (ActionList::const_iterator it = C.getActions().begin(), |
Daniel Dunbar | 2154923 | 2009-03-18 02:55:38 +0000 | [diff] [blame] | 930 | ie = C.getActions().end(); it != ie; ++it) |
Daniel Dunbar | f353c8c | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 931 | if ((*it)->getType() != types::TY_Nothing) |
| 932 | ++NumOutputs; |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 933 | |
Daniel Dunbar | f353c8c | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 934 | if (NumOutputs > 1) { |
| 935 | Diag(clang::diag::err_drv_output_argument_with_multiple_files); |
| 936 | FinalOutput = 0; |
| 937 | } |
| 938 | } |
| 939 | |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 940 | for (ActionList::const_iterator it = C.getActions().begin(), |
Daniel Dunbar | 2154923 | 2009-03-18 02:55:38 +0000 | [diff] [blame] | 941 | ie = C.getActions().end(); it != ie; ++it) { |
Daniel Dunbar | f353c8c | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 942 | Action *A = *it; |
| 943 | |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 944 | // If we are linking an image for multiple archs then the linker wants |
| 945 | // -arch_multiple and -final_output <final image name>. Unfortunately, this |
| 946 | // doesn't fit in cleanly because we have to pass this information down. |
Daniel Dunbar | f353c8c | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 947 | // |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 948 | // FIXME: This is a hack; find a cleaner way to integrate this into the |
| 949 | // process. |
Daniel Dunbar | f353c8c | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 950 | const char *LinkingOutput = 0; |
Daniel Dunbar | d7b88c2 | 2009-03-26 16:12:09 +0000 | [diff] [blame] | 951 | if (isa<LipoJobAction>(A)) { |
Daniel Dunbar | f353c8c | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 952 | if (FinalOutput) |
| 953 | LinkingOutput = FinalOutput->getValue(C.getArgs()); |
| 954 | else |
| 955 | LinkingOutput = DefaultImageName.c_str(); |
| 956 | } |
| 957 | |
| 958 | InputInfo II; |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 959 | BuildJobsForAction(C, A, &C.getDefaultToolChain(), |
Daniel Dunbar | 4954018 | 2009-09-09 18:36:01 +0000 | [diff] [blame] | 960 | /*BoundArch*/0, |
Daniel Dunbar | f353c8c | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 961 | /*CanAcceptPipe*/ true, |
| 962 | /*AtTopLevel*/ true, |
| 963 | /*LinkingOutput*/ LinkingOutput, |
| 964 | II); |
| 965 | } |
Daniel Dunbar | 586dc23 | 2009-03-16 06:42:30 +0000 | [diff] [blame] | 966 | |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 967 | // If the user passed -Qunused-arguments or there were errors, don't warn |
| 968 | // about any unused arguments. |
| 969 | if (Diags.getNumErrors() || |
Daniel Dunbar | 1e23f5f | 2009-04-07 19:04:18 +0000 | [diff] [blame] | 970 | C.getArgs().hasArg(options::OPT_Qunused_arguments)) |
Daniel Dunbar | af2e4ba | 2009-03-18 18:03:46 +0000 | [diff] [blame] | 971 | return; |
| 972 | |
Daniel Dunbar | a2094e7 | 2009-03-29 22:24:54 +0000 | [diff] [blame] | 973 | // Claim -### here. |
| 974 | (void) C.getArgs().hasArg(options::OPT__HASH_HASH_HASH); |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 975 | |
Daniel Dunbar | 586dc23 | 2009-03-16 06:42:30 +0000 | [diff] [blame] | 976 | for (ArgList::const_iterator it = C.getArgs().begin(), ie = C.getArgs().end(); |
| 977 | it != ie; ++it) { |
| 978 | Arg *A = *it; |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 979 | |
Daniel Dunbar | 586dc23 | 2009-03-16 06:42:30 +0000 | [diff] [blame] | 980 | // FIXME: It would be nice to be able to send the argument to the |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 981 | // Diagnostic, so that extra values, position, and so on could be printed. |
Daniel Dunbar | 4f53b29 | 2009-04-04 00:52:26 +0000 | [diff] [blame] | 982 | if (!A->isClaimed()) { |
Daniel Dunbar | 1e23f5f | 2009-04-07 19:04:18 +0000 | [diff] [blame] | 983 | if (A->getOption().hasNoArgumentUnused()) |
| 984 | continue; |
| 985 | |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 986 | // Suppress the warning automatically if this is just a flag, and it is an |
| 987 | // instance of an argument we already claimed. |
Daniel Dunbar | 4f53b29 | 2009-04-04 00:52:26 +0000 | [diff] [blame] | 988 | const Option &Opt = A->getOption(); |
| 989 | if (isa<FlagOption>(Opt)) { |
| 990 | bool DuplicateClaimed = false; |
| 991 | |
| 992 | // FIXME: Use iterator. |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 993 | for (ArgList::const_iterator it = C.getArgs().begin(), |
Daniel Dunbar | 4f53b29 | 2009-04-04 00:52:26 +0000 | [diff] [blame] | 994 | ie = C.getArgs().end(); it != ie; ++it) { |
| 995 | if ((*it)->isClaimed() && (*it)->getOption().matches(Opt.getId())) { |
| 996 | DuplicateClaimed = true; |
| 997 | break; |
| 998 | } |
| 999 | } |
| 1000 | |
| 1001 | if (DuplicateClaimed) |
| 1002 | continue; |
| 1003 | } |
| 1004 | |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 1005 | Diag(clang::diag::warn_drv_unused_argument) |
Daniel Dunbar | 38dd3d5 | 2009-03-20 06:14:23 +0000 | [diff] [blame] | 1006 | << A->getAsString(C.getArgs()); |
Daniel Dunbar | 4f53b29 | 2009-04-04 00:52:26 +0000 | [diff] [blame] | 1007 | } |
Daniel Dunbar | 586dc23 | 2009-03-16 06:42:30 +0000 | [diff] [blame] | 1008 | } |
Daniel Dunbar | 57b704d | 2009-03-13 22:12:33 +0000 | [diff] [blame] | 1009 | } |
| 1010 | |
Daniel Dunbar | f353c8c | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 1011 | void Driver::BuildJobsForAction(Compilation &C, |
| 1012 | const Action *A, |
| 1013 | const ToolChain *TC, |
Daniel Dunbar | 4954018 | 2009-09-09 18:36:01 +0000 | [diff] [blame] | 1014 | const char *BoundArch, |
Daniel Dunbar | f353c8c | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 1015 | bool CanAcceptPipe, |
| 1016 | bool AtTopLevel, |
| 1017 | const char *LinkingOutput, |
| 1018 | InputInfo &Result) const { |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 1019 | llvm::PrettyStackTraceString CrashInfo("Building compilation jobs"); |
Daniel Dunbar | 60ccc76 | 2009-03-18 23:18:19 +0000 | [diff] [blame] | 1020 | |
| 1021 | bool UsePipes = C.getArgs().hasArg(options::OPT_pipe); |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 1022 | // FIXME: Pipes are forcibly disabled until we support executing them. |
Daniel Dunbar | 60ccc76 | 2009-03-18 23:18:19 +0000 | [diff] [blame] | 1023 | if (!CCCPrintBindings) |
| 1024 | UsePipes = false; |
| 1025 | |
Daniel Dunbar | f353c8c | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 1026 | if (const InputAction *IA = dyn_cast<InputAction>(A)) { |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 1027 | // FIXME: It would be nice to not claim this here; maybe the old scheme of |
| 1028 | // just using Args was better? |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 1029 | const Arg &Input = IA->getInputArg(); |
| 1030 | Input.claim(); |
| 1031 | if (isa<PositionalArg>(Input)) { |
| 1032 | const char *Name = Input.getValue(C.getArgs()); |
| 1033 | Result = InputInfo(Name, A->getType(), Name); |
| 1034 | } else |
| 1035 | Result = InputInfo(&Input, A->getType(), ""); |
Daniel Dunbar | f353c8c | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 1036 | return; |
| 1037 | } |
| 1038 | |
| 1039 | if (const BindArchAction *BAA = dyn_cast<BindArchAction>(A)) { |
Daniel Dunbar | d7502d0 | 2009-09-08 23:37:19 +0000 | [diff] [blame] | 1040 | const ToolChain *TC = &C.getDefaultToolChain(); |
| 1041 | |
Daniel Dunbar | cb8ab23 | 2009-05-22 02:53:45 +0000 | [diff] [blame] | 1042 | std::string Arch; |
Daniel Dunbar | d7502d0 | 2009-09-08 23:37:19 +0000 | [diff] [blame] | 1043 | if (BAA->getArchName()) |
| 1044 | TC = Host->CreateToolChain(C.getArgs(), BAA->getArchName()); |
| 1045 | |
Daniel Dunbar | 4954018 | 2009-09-09 18:36:01 +0000 | [diff] [blame] | 1046 | BuildJobsForAction(C, *BAA->begin(), TC, BAA->getArchName(), |
| 1047 | CanAcceptPipe, AtTopLevel, LinkingOutput, Result); |
Daniel Dunbar | f353c8c | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 1048 | return; |
| 1049 | } |
| 1050 | |
| 1051 | const JobAction *JA = cast<JobAction>(A); |
| 1052 | const Tool &T = TC->SelectTool(C, *JA); |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 1053 | |
| 1054 | // See if we should use an integrated preprocessor. We do so when we have |
| 1055 | // exactly one input, since this is the only use case we care about |
| 1056 | // (irrelevant since we don't support combine yet). |
Daniel Dunbar | f353c8c | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 1057 | bool UseIntegratedCPP = false; |
| 1058 | const ActionList *Inputs = &A->getInputs(); |
| 1059 | if (Inputs->size() == 1 && isa<PreprocessJobAction>(*Inputs->begin())) { |
| 1060 | if (!C.getArgs().hasArg(options::OPT_no_integrated_cpp) && |
| 1061 | !C.getArgs().hasArg(options::OPT_traditional_cpp) && |
| 1062 | !C.getArgs().hasArg(options::OPT_save_temps) && |
| 1063 | T.hasIntegratedCPP()) { |
| 1064 | UseIntegratedCPP = true; |
| 1065 | Inputs = &(*Inputs)[0]->getInputs(); |
| 1066 | } |
| 1067 | } |
| 1068 | |
| 1069 | // Only use pipes when there is exactly one input. |
| 1070 | bool TryToUsePipeInput = Inputs->size() == 1 && T.acceptsPipedInput(); |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 1071 | InputInfoList InputInfos; |
Daniel Dunbar | f353c8c | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 1072 | for (ActionList::const_iterator it = Inputs->begin(), ie = Inputs->end(); |
| 1073 | it != ie; ++it) { |
| 1074 | InputInfo II; |
Daniel Dunbar | 4954018 | 2009-09-09 18:36:01 +0000 | [diff] [blame] | 1075 | BuildJobsForAction(C, *it, TC, BoundArch, TryToUsePipeInput, |
| 1076 | /*AtTopLevel*/false, LinkingOutput, II); |
Daniel Dunbar | f353c8c | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 1077 | InputInfos.push_back(II); |
| 1078 | } |
| 1079 | |
| 1080 | // Determine if we should output to a pipe. |
| 1081 | bool OutputToPipe = false; |
| 1082 | if (CanAcceptPipe && T.canPipeOutput()) { |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 1083 | // Some actions default to writing to a pipe if they are the top level phase |
| 1084 | // and there was no user override. |
Daniel Dunbar | f353c8c | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 1085 | // |
| 1086 | // FIXME: Is there a better way to handle this? |
| 1087 | if (AtTopLevel) { |
| 1088 | if (isa<PreprocessJobAction>(A) && !C.getArgs().hasArg(options::OPT_o)) |
| 1089 | OutputToPipe = true; |
Daniel Dunbar | 60ccc76 | 2009-03-18 23:18:19 +0000 | [diff] [blame] | 1090 | } else if (UsePipes) |
Daniel Dunbar | f353c8c | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 1091 | OutputToPipe = true; |
| 1092 | } |
| 1093 | |
| 1094 | // Figure out where to put the job (pipes). |
| 1095 | Job *Dest = &C.getJobs(); |
| 1096 | if (InputInfos[0].isPipe()) { |
Daniel Dunbar | 441d060 | 2009-03-17 17:53:55 +0000 | [diff] [blame] | 1097 | assert(TryToUsePipeInput && "Unrequested pipe!"); |
Daniel Dunbar | f353c8c | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 1098 | assert(InputInfos.size() == 1 && "Unexpected pipe with multiple inputs."); |
| 1099 | Dest = &InputInfos[0].getPipe(); |
| 1100 | } |
| 1101 | |
| 1102 | // Always use the first input as the base input. |
| 1103 | const char *BaseInput = InputInfos[0].getBaseInput(); |
Daniel Dunbar | 441d060 | 2009-03-17 17:53:55 +0000 | [diff] [blame] | 1104 | |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 1105 | // Determine the place to write output to (nothing, pipe, or filename) and |
| 1106 | // where to put the new job. |
Daniel Dunbar | 441d060 | 2009-03-17 17:53:55 +0000 | [diff] [blame] | 1107 | if (JA->getType() == types::TY_Nothing) { |
Daniel Dunbar | 5c3c1d7 | 2009-03-17 22:47:06 +0000 | [diff] [blame] | 1108 | Result = InputInfo(A->getType(), BaseInput); |
Daniel Dunbar | 441d060 | 2009-03-17 17:53:55 +0000 | [diff] [blame] | 1109 | } else if (OutputToPipe) { |
| 1110 | // Append to current piped job or create a new one as appropriate. |
Daniel Dunbar | 5c3c1d7 | 2009-03-17 22:47:06 +0000 | [diff] [blame] | 1111 | PipedJob *PJ = dyn_cast<PipedJob>(Dest); |
| 1112 | if (!PJ) { |
| 1113 | PJ = new PipedJob(); |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 1114 | // FIXME: Temporary hack so that -ccc-print-bindings work until we have |
| 1115 | // pipe support. Please remove later. |
Daniel Dunbar | b7b61b2 | 2009-03-20 00:11:04 +0000 | [diff] [blame] | 1116 | if (!CCCPrintBindings) |
| 1117 | cast<JobList>(Dest)->addJob(PJ); |
Daniel Dunbar | 871adcf | 2009-03-18 07:06:02 +0000 | [diff] [blame] | 1118 | Dest = PJ; |
Daniel Dunbar | 441d060 | 2009-03-17 17:53:55 +0000 | [diff] [blame] | 1119 | } |
Daniel Dunbar | 5c3c1d7 | 2009-03-17 22:47:06 +0000 | [diff] [blame] | 1120 | Result = InputInfo(PJ, A->getType(), BaseInput); |
Daniel Dunbar | 441d060 | 2009-03-17 17:53:55 +0000 | [diff] [blame] | 1121 | } else { |
Daniel Dunbar | 5c3c1d7 | 2009-03-17 22:47:06 +0000 | [diff] [blame] | 1122 | Result = InputInfo(GetNamedOutputPath(C, *JA, BaseInput, AtTopLevel), |
| 1123 | A->getType(), BaseInput); |
Daniel Dunbar | 441d060 | 2009-03-17 17:53:55 +0000 | [diff] [blame] | 1124 | } |
| 1125 | |
Daniel Dunbar | 5c3c1d7 | 2009-03-17 22:47:06 +0000 | [diff] [blame] | 1126 | if (CCCPrintBindings) { |
Daniel Dunbar | cd8e4c4 | 2009-03-30 06:36:42 +0000 | [diff] [blame] | 1127 | llvm::errs() << "# \"" << T.getToolChain().getTripleString() << '"' |
| 1128 | << " - \"" << T.getName() << "\", inputs: ["; |
Daniel Dunbar | 5c3c1d7 | 2009-03-17 22:47:06 +0000 | [diff] [blame] | 1129 | for (unsigned i = 0, e = InputInfos.size(); i != e; ++i) { |
| 1130 | llvm::errs() << InputInfos[i].getAsString(); |
| 1131 | if (i + 1 != e) |
| 1132 | llvm::errs() << ", "; |
| 1133 | } |
| 1134 | llvm::errs() << "], output: " << Result.getAsString() << "\n"; |
| 1135 | } else { |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 1136 | T.ConstructJob(C, *JA, *Dest, Result, InputInfos, |
Daniel Dunbar | 4954018 | 2009-09-09 18:36:01 +0000 | [diff] [blame] | 1137 | C.getArgsForToolChain(TC, BoundArch), LinkingOutput); |
Daniel Dunbar | 5c3c1d7 | 2009-03-17 22:47:06 +0000 | [diff] [blame] | 1138 | } |
Daniel Dunbar | f353c8c | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 1139 | } |
| 1140 | |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 1141 | const char *Driver::GetNamedOutputPath(Compilation &C, |
Daniel Dunbar | 441d060 | 2009-03-17 17:53:55 +0000 | [diff] [blame] | 1142 | const JobAction &JA, |
| 1143 | const char *BaseInput, |
| 1144 | bool AtTopLevel) const { |
Daniel Dunbar | 8f25c79 | 2009-03-18 01:38:48 +0000 | [diff] [blame] | 1145 | llvm::PrettyStackTraceString CrashInfo("Computing output path"); |
Daniel Dunbar | 441d060 | 2009-03-17 17:53:55 +0000 | [diff] [blame] | 1146 | // Output to a user requested destination? |
| 1147 | if (AtTopLevel) { |
| 1148 | if (Arg *FinalOutput = C.getArgs().getLastArg(options::OPT_o)) |
| 1149 | return C.addResultFile(FinalOutput->getValue(C.getArgs())); |
| 1150 | } |
| 1151 | |
| 1152 | // Output to a temporary file? |
| 1153 | if (!AtTopLevel && !C.getArgs().hasArg(options::OPT_save_temps)) { |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 1154 | std::string TmpName = |
Daniel Dunbar | 214399e | 2009-03-18 19:34:39 +0000 | [diff] [blame] | 1155 | GetTemporaryPath(types::getTypeTempSuffix(JA.getType())); |
| 1156 | return C.addTempFile(C.getArgs().MakeArgString(TmpName.c_str())); |
Daniel Dunbar | 441d060 | 2009-03-17 17:53:55 +0000 | [diff] [blame] | 1157 | } |
| 1158 | |
| 1159 | llvm::sys::Path BasePath(BaseInput); |
Daniel Dunbar | 5796bf4 | 2009-03-18 02:00:31 +0000 | [diff] [blame] | 1160 | std::string BaseName(BasePath.getLast()); |
Daniel Dunbar | 441d060 | 2009-03-17 17:53:55 +0000 | [diff] [blame] | 1161 | |
| 1162 | // Determine what the derived output name should be. |
| 1163 | const char *NamedOutput; |
| 1164 | if (JA.getType() == types::TY_Image) { |
| 1165 | NamedOutput = DefaultImageName.c_str(); |
| 1166 | } else { |
| 1167 | const char *Suffix = types::getTypeTempSuffix(JA.getType()); |
| 1168 | assert(Suffix && "All types used for output should have a suffix."); |
| 1169 | |
| 1170 | std::string::size_type End = std::string::npos; |
| 1171 | if (!types::appendSuffixForType(JA.getType())) |
| 1172 | End = BaseName.rfind('.'); |
| 1173 | std::string Suffixed(BaseName.substr(0, End)); |
| 1174 | Suffixed += '.'; |
| 1175 | Suffixed += Suffix; |
| 1176 | NamedOutput = C.getArgs().MakeArgString(Suffixed.c_str()); |
| 1177 | } |
| 1178 | |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 1179 | // As an annoying special case, PCH generation doesn't strip the pathname. |
Daniel Dunbar | 441d060 | 2009-03-17 17:53:55 +0000 | [diff] [blame] | 1180 | if (JA.getType() == types::TY_PCH) { |
| 1181 | BasePath.eraseComponent(); |
Daniel Dunbar | 56c5594 | 2009-03-18 09:58:30 +0000 | [diff] [blame] | 1182 | if (BasePath.isEmpty()) |
| 1183 | BasePath = NamedOutput; |
| 1184 | else |
| 1185 | BasePath.appendComponent(NamedOutput); |
Daniel Dunbar | 441d060 | 2009-03-17 17:53:55 +0000 | [diff] [blame] | 1186 | return C.addResultFile(C.getArgs().MakeArgString(BasePath.c_str())); |
| 1187 | } else { |
| 1188 | return C.addResultFile(NamedOutput); |
| 1189 | } |
| 1190 | } |
| 1191 | |
Daniel Dunbar | 5ed34f4 | 2009-09-09 22:33:00 +0000 | [diff] [blame] | 1192 | std::string Driver::GetFilePath(const char *Name, const ToolChain &TC) const { |
Daniel Dunbar | 0edefeb | 2009-03-18 20:26:19 +0000 | [diff] [blame] | 1193 | const ToolChain::path_list &List = TC.getFilePaths(); |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 1194 | for (ToolChain::path_list::const_iterator |
Daniel Dunbar | 0edefeb | 2009-03-18 20:26:19 +0000 | [diff] [blame] | 1195 | it = List.begin(), ie = List.end(); it != ie; ++it) { |
| 1196 | llvm::sys::Path P(*it); |
| 1197 | P.appendComponent(Name); |
| 1198 | if (P.exists()) |
Daniel Dunbar | 5ed34f4 | 2009-09-09 22:33:00 +0000 | [diff] [blame] | 1199 | return P.str(); |
Daniel Dunbar | 0edefeb | 2009-03-18 20:26:19 +0000 | [diff] [blame] | 1200 | } |
| 1201 | |
Daniel Dunbar | 5ed34f4 | 2009-09-09 22:33:00 +0000 | [diff] [blame] | 1202 | return Name; |
Daniel Dunbar | cb88167 | 2009-03-13 00:51:18 +0000 | [diff] [blame] | 1203 | } |
| 1204 | |
Daniel Dunbar | 5ed34f4 | 2009-09-09 22:33:00 +0000 | [diff] [blame] | 1205 | std::string Driver::GetProgramPath(const char *Name, const ToolChain &TC, |
| 1206 | bool WantFile) const { |
Daniel Dunbar | 0edefeb | 2009-03-18 20:26:19 +0000 | [diff] [blame] | 1207 | const ToolChain::path_list &List = TC.getProgramPaths(); |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 1208 | for (ToolChain::path_list::const_iterator |
Daniel Dunbar | 0edefeb | 2009-03-18 20:26:19 +0000 | [diff] [blame] | 1209 | it = List.begin(), ie = List.end(); it != ie; ++it) { |
| 1210 | llvm::sys::Path P(*it); |
| 1211 | P.appendComponent(Name); |
Mike Stump | 950bedd | 2009-03-27 00:40:20 +0000 | [diff] [blame] | 1212 | if (WantFile ? P.exists() : P.canExecute()) |
Daniel Dunbar | 5ed34f4 | 2009-09-09 22:33:00 +0000 | [diff] [blame] | 1213 | return P.str(); |
Daniel Dunbar | 0edefeb | 2009-03-18 20:26:19 +0000 | [diff] [blame] | 1214 | } |
| 1215 | |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 1216 | // If all else failed, search the path. |
| 1217 | llvm::sys::Path P(llvm::sys::Program::FindProgramByName(Name)); |
Daniel Dunbar | 632f50e | 2009-03-18 21:34:08 +0000 | [diff] [blame] | 1218 | if (!P.empty()) |
Daniel Dunbar | 5ed34f4 | 2009-09-09 22:33:00 +0000 | [diff] [blame] | 1219 | return P.str(); |
Daniel Dunbar | 632f50e | 2009-03-18 21:34:08 +0000 | [diff] [blame] | 1220 | |
Daniel Dunbar | 5ed34f4 | 2009-09-09 22:33:00 +0000 | [diff] [blame] | 1221 | return Name; |
Daniel Dunbar | cb88167 | 2009-03-13 00:51:18 +0000 | [diff] [blame] | 1222 | } |
| 1223 | |
Daniel Dunbar | 214399e | 2009-03-18 19:34:39 +0000 | [diff] [blame] | 1224 | std::string Driver::GetTemporaryPath(const char *Suffix) const { |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 1225 | // FIXME: This is lame; sys::Path should provide this function (in particular, |
| 1226 | // it should know how to find the temporary files dir). |
Daniel Dunbar | 214399e | 2009-03-18 19:34:39 +0000 | [diff] [blame] | 1227 | std::string Error; |
Daniel Dunbar | b03417f | 2009-04-20 20:28:21 +0000 | [diff] [blame] | 1228 | const char *TmpDir = ::getenv("TMPDIR"); |
| 1229 | if (!TmpDir) |
| 1230 | TmpDir = ::getenv("TEMP"); |
| 1231 | if (!TmpDir) |
Daniel Dunbar | 3ca7ee9 | 2009-04-21 00:25:10 +0000 | [diff] [blame] | 1232 | TmpDir = ::getenv("TMP"); |
| 1233 | if (!TmpDir) |
Daniel Dunbar | b03417f | 2009-04-20 20:28:21 +0000 | [diff] [blame] | 1234 | TmpDir = "/tmp"; |
| 1235 | llvm::sys::Path P(TmpDir); |
Daniel Dunbar | f60c63a | 2009-04-20 17:32:49 +0000 | [diff] [blame] | 1236 | P.appendComponent("cc"); |
Daniel Dunbar | 214399e | 2009-03-18 19:34:39 +0000 | [diff] [blame] | 1237 | if (P.makeUnique(false, &Error)) { |
| 1238 | Diag(clang::diag::err_drv_unable_to_make_temp) << Error; |
| 1239 | return ""; |
| 1240 | } |
| 1241 | |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 1242 | // FIXME: Grumble, makeUnique sometimes leaves the file around!? PR3837. |
Daniel Dunbar | 84603bc | 2009-03-18 23:08:52 +0000 | [diff] [blame] | 1243 | P.eraseFromDisk(false, 0); |
| 1244 | |
Daniel Dunbar | 214399e | 2009-03-18 19:34:39 +0000 | [diff] [blame] | 1245 | P.appendSuffix(Suffix); |
Chris Lattner | d57a7ef | 2009-08-23 22:45:33 +0000 | [diff] [blame] | 1246 | return P.str(); |
Daniel Dunbar | 214399e | 2009-03-18 19:34:39 +0000 | [diff] [blame] | 1247 | } |
| 1248 | |
Daniel Dunbar | cb8ab23 | 2009-05-22 02:53:45 +0000 | [diff] [blame] | 1249 | const HostInfo *Driver::GetHostInfo(const char *TripleStr) const { |
Daniel Dunbar | 8f25c79 | 2009-03-18 01:38:48 +0000 | [diff] [blame] | 1250 | llvm::PrettyStackTraceString CrashInfo("Constructing host"); |
Daniel Dunbar | cb8ab23 | 2009-05-22 02:53:45 +0000 | [diff] [blame] | 1251 | llvm::Triple Triple(TripleStr); |
Daniel Dunbar | dd98e2c | 2009-03-10 23:41:59 +0000 | [diff] [blame] | 1252 | |
Daniel Dunbar | cb8ab23 | 2009-05-22 02:53:45 +0000 | [diff] [blame] | 1253 | switch (Triple.getOS()) { |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 1254 | case llvm::Triple::AuroraUX: |
| 1255 | return createAuroraUXHostInfo(*this, Triple); |
Daniel Dunbar | cb8ab23 | 2009-05-22 02:53:45 +0000 | [diff] [blame] | 1256 | case llvm::Triple::Darwin: |
| 1257 | return createDarwinHostInfo(*this, Triple); |
| 1258 | case llvm::Triple::DragonFly: |
| 1259 | return createDragonFlyHostInfo(*this, Triple); |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 1260 | case llvm::Triple::OpenBSD: |
| 1261 | return createOpenBSDHostInfo(*this, Triple); |
Daniel Dunbar | cb8ab23 | 2009-05-22 02:53:45 +0000 | [diff] [blame] | 1262 | case llvm::Triple::FreeBSD: |
| 1263 | return createFreeBSDHostInfo(*this, Triple); |
Eli Friedman | 6b3454a | 2009-05-26 07:52:18 +0000 | [diff] [blame] | 1264 | case llvm::Triple::Linux: |
| 1265 | return createLinuxHostInfo(*this, Triple); |
Daniel Dunbar | cb8ab23 | 2009-05-22 02:53:45 +0000 | [diff] [blame] | 1266 | default: |
| 1267 | return createUnknownHostInfo(*this, Triple); |
| 1268 | } |
Daniel Dunbar | dd98e2c | 2009-03-10 23:41:59 +0000 | [diff] [blame] | 1269 | } |
Daniel Dunbar | af80e1f | 2009-03-24 18:57:02 +0000 | [diff] [blame] | 1270 | |
| 1271 | bool Driver::ShouldUseClangCompiler(const Compilation &C, const JobAction &JA, |
Daniel Dunbar | a6046be | 2009-09-08 23:36:55 +0000 | [diff] [blame] | 1272 | const llvm::Triple &Triple) const { |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 1273 | // Check if user requested no clang, or clang doesn't understand this type (we |
| 1274 | // only handle single inputs for now). |
Daniel Dunbar | 5915fbf | 2009-09-01 16:57:46 +0000 | [diff] [blame] | 1275 | if (!CCCUseClang || JA.size() != 1 || |
Daniel Dunbar | af80e1f | 2009-03-24 18:57:02 +0000 | [diff] [blame] | 1276 | !types::isAcceptedByClang((*JA.begin())->getType())) |
| 1277 | return false; |
| 1278 | |
Daniel Dunbar | 0f99d2e | 2009-03-24 19:02:31 +0000 | [diff] [blame] | 1279 | // Otherwise make sure this is an action clang understands. |
Daniel Dunbar | af80e1f | 2009-03-24 18:57:02 +0000 | [diff] [blame] | 1280 | if (isa<PreprocessJobAction>(JA)) { |
Daniel Dunbar | 6256d36 | 2009-03-24 19:14:56 +0000 | [diff] [blame] | 1281 | if (!CCCUseClangCPP) { |
| 1282 | Diag(clang::diag::warn_drv_not_using_clang_cpp); |
Daniel Dunbar | af80e1f | 2009-03-24 18:57:02 +0000 | [diff] [blame] | 1283 | return false; |
Daniel Dunbar | 6256d36 | 2009-03-24 19:14:56 +0000 | [diff] [blame] | 1284 | } |
Daniel Dunbar | af80e1f | 2009-03-24 18:57:02 +0000 | [diff] [blame] | 1285 | } else if (!isa<PrecompileJobAction>(JA) && !isa<CompileJobAction>(JA)) |
| 1286 | return false; |
| 1287 | |
Daniel Dunbar | 0f99d2e | 2009-03-24 19:02:31 +0000 | [diff] [blame] | 1288 | // Use clang for C++? |
Daniel Dunbar | 6256d36 | 2009-03-24 19:14:56 +0000 | [diff] [blame] | 1289 | if (!CCCUseClangCXX && types::isCXX((*JA.begin())->getType())) { |
| 1290 | Diag(clang::diag::warn_drv_not_using_clang_cxx); |
Daniel Dunbar | af80e1f | 2009-03-24 18:57:02 +0000 | [diff] [blame] | 1291 | return false; |
Daniel Dunbar | 6256d36 | 2009-03-24 19:14:56 +0000 | [diff] [blame] | 1292 | } |
Daniel Dunbar | af80e1f | 2009-03-24 18:57:02 +0000 | [diff] [blame] | 1293 | |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 1294 | // Always use clang for precompiling and AST generation, regardless of archs. |
Daniel Dunbar | 5915fbf | 2009-09-01 16:57:46 +0000 | [diff] [blame] | 1295 | if (isa<PrecompileJobAction>(JA) || JA.getType() == types::TY_AST) |
Daniel Dunbar | fec26bd | 2009-04-16 23:10:13 +0000 | [diff] [blame] | 1296 | return true; |
| 1297 | |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 1298 | // Finally, don't use clang if this isn't one of the user specified archs to |
| 1299 | // build. |
Daniel Dunbar | a6046be | 2009-09-08 23:36:55 +0000 | [diff] [blame] | 1300 | if (!CCCClangArchs.empty() && !CCCClangArchs.count(Triple.getArch())) { |
| 1301 | Diag(clang::diag::warn_drv_not_using_clang_arch) << Triple.getArchName(); |
Daniel Dunbar | af80e1f | 2009-03-24 18:57:02 +0000 | [diff] [blame] | 1302 | return false; |
Daniel Dunbar | 6256d36 | 2009-03-24 19:14:56 +0000 | [diff] [blame] | 1303 | } |
Daniel Dunbar | af80e1f | 2009-03-24 18:57:02 +0000 | [diff] [blame] | 1304 | |
| 1305 | return true; |
| 1306 | } |
Daniel Dunbar | d73fe9b | 2009-03-26 15:58:36 +0000 | [diff] [blame] | 1307 | |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 1308 | /// GetReleaseVersion - Parse (([0-9]+)(.([0-9]+)(.([0-9]+)?))?)? and return the |
| 1309 | /// grouped values as integers. Numbers which are not provided are set to 0. |
Daniel Dunbar | d73fe9b | 2009-03-26 15:58:36 +0000 | [diff] [blame] | 1310 | /// |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 1311 | /// \return True if the entire string was parsed (9.2), or all groups were |
| 1312 | /// parsed (10.3.5extrastuff). |
| 1313 | bool Driver::GetReleaseVersion(const char *Str, unsigned &Major, |
Daniel Dunbar | d73fe9b | 2009-03-26 15:58:36 +0000 | [diff] [blame] | 1314 | unsigned &Minor, unsigned &Micro, |
| 1315 | bool &HadExtra) { |
| 1316 | HadExtra = false; |
| 1317 | |
| 1318 | Major = Minor = Micro = 0; |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 1319 | if (*Str == '\0') |
Daniel Dunbar | d73fe9b | 2009-03-26 15:58:36 +0000 | [diff] [blame] | 1320 | return true; |
| 1321 | |
| 1322 | char *End; |
| 1323 | Major = (unsigned) strtol(Str, &End, 10); |
| 1324 | if (*Str != '\0' && *End == '\0') |
| 1325 | return true; |
| 1326 | if (*End != '.') |
| 1327 | return false; |
Daniel Dunbar | a823183 | 2009-09-08 23:36:43 +0000 | [diff] [blame] | 1328 | |
Daniel Dunbar | d73fe9b | 2009-03-26 15:58:36 +0000 | [diff] [blame] | 1329 | Str = End+1; |
| 1330 | Minor = (unsigned) strtol(Str, &End, 10); |
| 1331 | if (*Str != '\0' && *End == '\0') |
| 1332 | return true; |
| 1333 | if (*End != '.') |
| 1334 | return false; |
| 1335 | |
| 1336 | Str = End+1; |
| 1337 | Micro = (unsigned) strtol(Str, &End, 10); |
| 1338 | if (*Str != '\0' && *End == '\0') |
| 1339 | return true; |
| 1340 | if (Str == End) |
| 1341 | return false; |
| 1342 | HadExtra = true; |
| 1343 | return true; |
| 1344 | } |