X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FSupport%2FCommandLine.cpp;h=486875210fd14735ae562996dd80b2e976dd4096;hb=e6be34a53ecbe8c2ff9f0793b13d847e94c0de91;hp=2b0798aa77053e618526e308379a27f9b8323217;hpb=69d6f1358ca8c442a65fd8d5900f7296fbb2762d;p=oota-llvm.git diff --git a/lib/Support/CommandLine.cpp b/lib/Support/CommandLine.cpp index 2b0798aa770..486875210fd 100644 --- a/lib/Support/CommandLine.cpp +++ b/lib/Support/CommandLine.cpp @@ -2,8 +2,8 @@ // // The LLVM Compiler Infrastructure // -// This file was developed by the LLVM research group and is distributed under -// the University of Illinois Open Source License. See LICENSE.TXT for details. +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// // @@ -29,6 +29,7 @@ #include #include #include +#include using namespace llvm; using namespace cl; @@ -36,6 +37,7 @@ using namespace cl; // Template instantiations and anchors. // TEMPLATE_INSTANTIATION(class basic_parser); +TEMPLATE_INSTANTIATION(class basic_parser); TEMPLATE_INSTANTIATION(class basic_parser); TEMPLATE_INSTANTIATION(class basic_parser); TEMPLATE_INSTANTIATION(class basic_parser); @@ -50,6 +52,7 @@ TEMPLATE_INSTANTIATION(class opt); void Option::anchor() {} void basic_parser_impl::anchor() {} void parser::anchor() {} +void parser::anchor() {} void parser::anchor() {} void parser::anchor() {} void parser::anchor() {} @@ -98,6 +101,7 @@ void Option::addArgument() { /// GetOptionInfo - Scan the list of registered options, turning them into data /// structures that are easier to handle. static void GetOptionInfo(std::vector &PositionalOpts, + std::vector &SinkOpts, std::map &OptionsMap) { std::vector OptionNames; Option *CAOpt = 0; // The ConsumeAfter option if it exists. @@ -123,6 +127,8 @@ static void GetOptionInfo(std::vector &PositionalOpts, // Remember information about positional options. if (O->getFormattingFlag() == cl::Positional) PositionalOpts.push_back(O); + else if (O->getMiscFlags() & cl::Sink) // Remember sink options + SinkOpts.push_back(O); else if (O->getNumOccurrencesFlag() == cl::ConsumeAfter) { if (CAOpt) O->error("Cannot specify more than one option with cl::ConsumeAfter!"); @@ -330,12 +336,13 @@ void cl::ParseEnvironmentOptions(const char *progName, const char *envVar, free (*i); } -void cl::ParseCommandLineOptions(int &argc, char **argv, +void cl::ParseCommandLineOptions(int argc, char **argv, const char *Overview) { // Process all registered options. std::vector PositionalOpts; + std::vector SinkOpts; std::map Opts; - GetOptionInfo(PositionalOpts, Opts); + GetOptionInfo(PositionalOpts, SinkOpts, Opts); assert((!Opts.empty() || !PositionalOpts.empty()) && "No options specified!"); @@ -415,8 +422,9 @@ void cl::ParseCommandLineOptions(int &argc, char **argv, // response to things like -load, etc. If this happens, rescan the options. if (OptionListChanged) { PositionalOpts.clear(); + SinkOpts.clear(); Opts.clear(); - GetOptionInfo(PositionalOpts, Opts); + GetOptionInfo(PositionalOpts, SinkOpts, Opts); OptionListChanged = false; } @@ -512,9 +520,15 @@ void cl::ParseCommandLineOptions(int &argc, char **argv, } if (Handler == 0) { - cerr << ProgramName << ": Unknown command line argument '" - << argv[i] << "'. Try: '" << argv[0] << " --help'\n"; - ErrorParsing = true; + if (SinkOpts.empty()) { + cerr << ProgramName << ": Unknown command line argument '" + << argv[i] << "'. Try: '" << argv[0] << " --help'\n"; + ErrorParsing = true; + } else { + for (std::vector::iterator I = SinkOpts.begin(), + E = SinkOpts.end(); I != E ; ++I) + (*I)->addOccurrence(i, "", argv[i]); + } continue; } @@ -767,6 +781,22 @@ bool parser::parse(Option &O, const char *ArgName, return false; } +// parser implementation +// +bool parser::parse(Option &O, const char *ArgName, + const std::string &Arg, boolOrDefault &Value) { + if (Arg == "" || Arg == "true" || Arg == "TRUE" || Arg == "True" || + Arg == "1") { + Value = BOU_TRUE; + } else if (Arg == "false" || Arg == "FALSE" || Arg == "False" || Arg == "0") { + Value = BOU_FALSE; + } else { + return O.error(": '" + Arg + + "' is invalid value for boolean argument! Try 0 or 1"); + } + return false; +} + // parser implementation // bool parser::parse(Option &O, const char *ArgName, @@ -910,8 +940,9 @@ public: // Get all the options. std::vector PositionalOpts; + std::vector SinkOpts; std::map OptMap; - GetOptionInfo(PositionalOpts, OptMap); + GetOptionInfo(PositionalOpts, SinkOpts, OptMap); // Copy Options into a vector so we can sort them as we like... std::vector > Opts; @@ -933,7 +964,7 @@ public: } if (ProgramOverview) - cout << "OVERVIEW:" << ProgramOverview << "\n"; + cout << "OVERVIEW: " << ProgramOverview << "\n"; cout << "USAGE: " << ProgramName << " [options]";