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