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