Deleted Added
full compact
Driver.cpp (198092) Driver.cpp (199512)
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"
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/OptTable.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 "clang/Basic/Version.h"
26

--- 12 unchanged lines hidden (view full) ---

39
40// Used to set values for "production" clang, for releases.
41// #define USE_PRODUCTION_CLANG
42
43Driver::Driver(const char *_Name, const char *_Dir,
44 const char *_DefaultHostTriple,
45 const char *_DefaultImageName,
46 bool IsProduction, Diagnostic &_Diags)
20#include "clang/Driver/Option.h"
21#include "clang/Driver/Options.h"
22#include "clang/Driver/Tool.h"
23#include "clang/Driver/ToolChain.h"
24#include "clang/Driver/Types.h"
25
26#include "clang/Basic/Version.h"
27

--- 12 unchanged lines hidden (view full) ---

40
41// Used to set values for "production" clang, for releases.
42// #define USE_PRODUCTION_CLANG
43
44Driver::Driver(const char *_Name, const char *_Dir,
45 const char *_DefaultHostTriple,
46 const char *_DefaultImageName,
47 bool IsProduction, Diagnostic &_Diags)
47 : Opts(new OptTable()), Diags(_Diags),
48 : Opts(createDriverOptTable()), Diags(_Diags),
48 Name(_Name), Dir(_Dir), DefaultHostTriple(_DefaultHostTriple),
49 DefaultImageName(_DefaultImageName),
50 Host(0),
51 CCCIsCXX(false), CCCEcho(false), CCCPrintBindings(false),
52 CCCGenericGCCName("gcc"), CCCUseClang(true),
53 CCCUseClangCXX(true), CCCUseClangCPP(true), CCCUsePCH(true),
54 SuppressMissingInputWarning(false) {
55 if (IsProduction) {

--- 14 unchanged lines hidden (view full) ---

70Driver::~Driver() {
71 delete Opts;
72 delete Host;
73}
74
75InputArgList *Driver::ParseArgStrings(const char **ArgBegin,
76 const char **ArgEnd) {
77 llvm::PrettyStackTraceString CrashInfo("Command line argument parsing");
49 Name(_Name), Dir(_Dir), DefaultHostTriple(_DefaultHostTriple),
50 DefaultImageName(_DefaultImageName),
51 Host(0),
52 CCCIsCXX(false), CCCEcho(false), CCCPrintBindings(false),
53 CCCGenericGCCName("gcc"), CCCUseClang(true),
54 CCCUseClangCXX(true), CCCUseClangCPP(true), CCCUsePCH(true),
55 SuppressMissingInputWarning(false) {
56 if (IsProduction) {

--- 14 unchanged lines hidden (view full) ---

71Driver::~Driver() {
72 delete Opts;
73 delete Host;
74}
75
76InputArgList *Driver::ParseArgStrings(const char **ArgBegin,
77 const char **ArgEnd) {
78 llvm::PrettyStackTraceString CrashInfo("Command line argument parsing");
78 InputArgList *Args = new InputArgList(ArgBegin, ArgEnd);
79 unsigned MissingArgIndex, MissingArgCount;
80 InputArgList *Args = getOpts().ParseArgs(ArgBegin, ArgEnd,
81 MissingArgIndex, MissingArgCount);
79
82
80 // FIXME: Handle '@' args (or at least error on them).
83 // Check for missing argument error.
84 if (MissingArgCount)
85 Diag(clang::diag::err_drv_missing_argument)
86 << Args->getArgString(MissingArgIndex) << MissingArgCount;
81
87
82 unsigned Index = 0, End = ArgEnd - ArgBegin;
83 while (Index < End) {
84 // gcc's handling of empty arguments doesn't make sense, but this is not a
85 // common use case. :)
86 //
87 // We just ignore them here (note that other things may still take them as
88 // arguments).
89 if (Args->getArgString(Index)[0] == '\0') {
90 ++Index;
91 continue;
92 }
93
94 unsigned Prev = Index;
95 Arg *A = getOpts().ParseOneArg(*Args, Index);
96 assert(Index > Prev && "Parser failed to consume argument.");
97
98 // Check for missing argument error.
99 if (!A) {
100 assert(Index >= End && "Unexpected parser error.");
101 Diag(clang::diag::err_drv_missing_argument)
102 << Args->getArgString(Prev)
103 << (Index - Prev - 1);
104 break;
105 }
106
88 // Check for unsupported options.
89 for (ArgList::const_iterator it = Args->begin(), ie = Args->end();
90 it != ie; ++it) {
91 Arg *A = *it;
107 if (A->getOption().isUnsupported()) {
108 Diag(clang::diag::err_drv_unsupported_opt) << A->getAsString(*Args);
109 continue;
110 }
92 if (A->getOption().isUnsupported()) {
93 Diag(clang::diag::err_drv_unsupported_opt) << A->getAsString(*Args);
94 continue;
95 }
111 Args->append(A);
112 }
113
114 return Args;
115}
116
117Compilation *Driver::BuildCompilation(int argc, const char **argv) {
118 llvm::PrettyStackTraceString CrashInfo("Compilation construction");
119

--- 215 unchanged lines hidden (view full) ---

335 OS << '\n';
336 OS << "USAGE: " << Name << " [options] <input files>\n";
337 OS << '\n';
338 OS << "OPTIONS:\n";
339
340 // Render help text into (option, help) pairs.
341 std::vector< std::pair<std::string, const char*> > OptionHelp;
342
96 }
97
98 return Args;
99}
100
101Compilation *Driver::BuildCompilation(int argc, const char **argv) {
102 llvm::PrettyStackTraceString CrashInfo("Compilation construction");
103

--- 215 unchanged lines hidden (view full) ---

319 OS << '\n';
320 OS << "USAGE: " << Name << " [options] <input files>\n";
321 OS << '\n';
322 OS << "OPTIONS:\n";
323
324 // Render help text into (option, help) pairs.
325 std::vector< std::pair<std::string, const char*> > OptionHelp;
326
343 for (unsigned i = options::OPT_INPUT, e = options::LastOption; i != e; ++i) {
344 options::ID Id = (options::ID) i;
327 for (unsigned i = 0, e = getOpts().getNumOptions(); i != e; ++i) {
328 options::ID Id = (options::ID) (i + 1);
345 if (const char *Text = getOpts().getOptionHelpText(Id))
346 OptionHelp.push_back(std::make_pair(getOptionHelpName(getOpts(), Id),
347 Text));
348 }
349
350 if (ShowHidden) {
351 OptionHelp.push_back(std::make_pair("\nDRIVER OPTIONS:",""));
352 OptionHelp.push_back(std::make_pair("-ccc-cxx",

--- 233 unchanged lines hidden (view full) ---

586 // Collect the list of architectures. Duplicates are allowed, but should only
587 // be handled once (in the order seen).
588 llvm::StringSet<> ArchNames;
589 llvm::SmallVector<const char *, 4> Archs;
590 for (ArgList::const_iterator it = Args.begin(), ie = Args.end();
591 it != ie; ++it) {
592 Arg *A = *it;
593
329 if (const char *Text = getOpts().getOptionHelpText(Id))
330 OptionHelp.push_back(std::make_pair(getOptionHelpName(getOpts(), Id),
331 Text));
332 }
333
334 if (ShowHidden) {
335 OptionHelp.push_back(std::make_pair("\nDRIVER OPTIONS:",""));
336 OptionHelp.push_back(std::make_pair("-ccc-cxx",

--- 233 unchanged lines hidden (view full) ---

570 // Collect the list of architectures. Duplicates are allowed, but should only
571 // be handled once (in the order seen).
572 llvm::StringSet<> ArchNames;
573 llvm::SmallVector<const char *, 4> Archs;
574 for (ArgList::const_iterator it = Args.begin(), ie = Args.end();
575 it != ie; ++it) {
576 Arg *A = *it;
577
594 if (A->getOption().getId() == options::OPT_arch) {
578 if (A->getOption().matches(options::OPT_arch)) {
595 // Validate the option here; we don't save the type here because its
596 // particular spelling may participate in other driver choices.
597 llvm::Triple::ArchType Arch =
598 llvm::Triple::getArchTypeForDarwinArchName(A->getValue(Args));
599 if (Arch == llvm::Triple::UnknownArch) {
600 Diag(clang::diag::err_drv_invalid_arch_name)
601 << A->getAsString(Args);
602 continue;

--- 78 unchanged lines hidden (view full) ---

681
682 // stdin must be handled specially.
683 if (memcmp(Value, "-", 2) == 0) {
684 // If running with -E, treat as a C input (this changes the builtin
685 // macros, for example). This may be overridden by -ObjC below.
686 //
687 // Otherwise emit an error but still use a valid type to avoid
688 // spurious errors (e.g., no inputs).
579 // Validate the option here; we don't save the type here because its
580 // particular spelling may participate in other driver choices.
581 llvm::Triple::ArchType Arch =
582 llvm::Triple::getArchTypeForDarwinArchName(A->getValue(Args));
583 if (Arch == llvm::Triple::UnknownArch) {
584 Diag(clang::diag::err_drv_invalid_arch_name)
585 << A->getAsString(Args);
586 continue;

--- 78 unchanged lines hidden (view full) ---

665
666 // stdin must be handled specially.
667 if (memcmp(Value, "-", 2) == 0) {
668 // If running with -E, treat as a C input (this changes the builtin
669 // macros, for example). This may be overridden by -ObjC below.
670 //
671 // Otherwise emit an error but still use a valid type to avoid
672 // spurious errors (e.g., no inputs).
689 if (!Args.hasArg(options::OPT_E, false))
673 if (!Args.hasArgNoClaim(options::OPT_E))
690 Diag(clang::diag::err_drv_unknown_stdin_type);
691 Ty = types::TY_C;
692 } else {
693 // Otherwise lookup by extension, and fallback to ObjectType if not
694 // found. We use a host hook here because Darwin at least has its own
695 // idea of what .s is.
696 if (const char *Ext = strrchr(Value, '.'))
697 Ty = Host->lookupTypeForExtension(Ext + 1);

--- 27 unchanged lines hidden (view full) ---

725 else
726 Inputs.push_back(std::make_pair(Ty, A));
727
728 } else if (A->getOption().isLinkerInput()) {
729 // Just treat as object type, we could make a special type for this if
730 // necessary.
731 Inputs.push_back(std::make_pair(types::TY_Object, A));
732
674 Diag(clang::diag::err_drv_unknown_stdin_type);
675 Ty = types::TY_C;
676 } else {
677 // Otherwise lookup by extension, and fallback to ObjectType if not
678 // found. We use a host hook here because Darwin at least has its own
679 // idea of what .s is.
680 if (const char *Ext = strrchr(Value, '.'))
681 Ty = Host->lookupTypeForExtension(Ext + 1);

--- 27 unchanged lines hidden (view full) ---

709 else
710 Inputs.push_back(std::make_pair(Ty, A));
711
712 } else if (A->getOption().isLinkerInput()) {
713 // Just treat as object type, we could make a special type for this if
714 // necessary.
715 Inputs.push_back(std::make_pair(types::TY_Object, A));
716
733 } else if (A->getOption().getId() == options::OPT_x) {
717 } else if (A->getOption().matches(options::OPT_x)) {
734 InputTypeArg = A;
735 InputType = types::lookupTypeForTypeSpecifier(A->getValue(Args));
736
737 // Follow gcc behavior and treat as linker input for invalid -x
738 // options. Its not clear why we shouldn't just revert to unknown; but
739 // this isn't very important, we might as well be bug comatible.
740 if (!InputType) {
741 Diag(clang::diag::err_drv_unknown_language) << A->getValue(Args);

--- 237 unchanged lines hidden (view full) ---

979 // instance of an argument we already claimed.
980 const Option &Opt = A->getOption();
981 if (isa<FlagOption>(Opt)) {
982 bool DuplicateClaimed = false;
983
984 // FIXME: Use iterator.
985 for (ArgList::const_iterator it = C.getArgs().begin(),
986 ie = C.getArgs().end(); it != ie; ++it) {
718 InputTypeArg = A;
719 InputType = types::lookupTypeForTypeSpecifier(A->getValue(Args));
720
721 // Follow gcc behavior and treat as linker input for invalid -x
722 // options. Its not clear why we shouldn't just revert to unknown; but
723 // this isn't very important, we might as well be bug comatible.
724 if (!InputType) {
725 Diag(clang::diag::err_drv_unknown_language) << A->getValue(Args);

--- 237 unchanged lines hidden (view full) ---

963 // instance of an argument we already claimed.
964 const Option &Opt = A->getOption();
965 if (isa<FlagOption>(Opt)) {
966 bool DuplicateClaimed = false;
967
968 // FIXME: Use iterator.
969 for (ArgList::const_iterator it = C.getArgs().begin(),
970 ie = C.getArgs().end(); it != ie; ++it) {
987 if ((*it)->isClaimed() && (*it)->getOption().matches(Opt.getId())) {
971 if ((*it)->isClaimed() && (*it)->getOption().matches(&Opt)) {
988 DuplicateClaimed = true;
989 break;
990 }
991 }
992
993 if (DuplicateClaimed)
994 continue;
995 }

--- 341 unchanged lines hidden ---
972 DuplicateClaimed = true;
973 break;
974 }
975 }
976
977 if (DuplicateClaimed)
978 continue;
979 }

--- 341 unchanged lines hidden ---