"...lib/CodeGen/git@repo.hca.bsc.es:rferrer/llvm-epi-0.8.git" did not exist on "322f41d09546bd50134e705f8db15c9768a97c01"
Newer
Older
//===-- CommandLine.cpp - Command line parser implementation --------------===//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//===----------------------------------------------------------------------===//
//
// This class implements a command line argument processor that is useful when
// creating a tool. It provides a simple, minimalistic interface that is easily
// extensible and supports nonlocal (library) command line options.
//
// Note that rather than trying to figure out what this code does, you could try
// reading the library documentation located in docs/CommandLine.html
//
//===----------------------------------------------------------------------===//
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Target/TargetRegistry.h"
#include "llvm/System/Path.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/Twine.h"
//===----------------------------------------------------------------------===//
// Template instantiations and anchors.
//
TEMPLATE_INSTANTIATION(class basic_parser<bool>);
TEMPLATE_INSTANTIATION(class basic_parser<boolOrDefault>);
TEMPLATE_INSTANTIATION(class basic_parser<int>);
TEMPLATE_INSTANTIATION(class basic_parser<unsigned>);
TEMPLATE_INSTANTIATION(class basic_parser<double>);
TEMPLATE_INSTANTIATION(class basic_parser<float>);
TEMPLATE_INSTANTIATION(class basic_parser<std::string>);
TEMPLATE_INSTANTIATION(class basic_parser<char>);
TEMPLATE_INSTANTIATION(class opt<unsigned>);
TEMPLATE_INSTANTIATION(class opt<int>);
TEMPLATE_INSTANTIATION(class opt<std::string>);
TEMPLATE_INSTANTIATION(class opt<char>);
TEMPLATE_INSTANTIATION(class opt<bool>);
void Option::anchor() {}
void basic_parser_impl::anchor() {}
void parser<bool>::anchor() {}
void parser<boolOrDefault>::anchor() {}
void parser<int>::anchor() {}
void parser<unsigned>::anchor() {}
void parser<double>::anchor() {}
void parser<float>::anchor() {}
void parser<std::string>::anchor() {}
void parser<char>::anchor() {}
//===----------------------------------------------------------------------===//
// Globals for name and overview of program. Program name is not a string to
// avoid static ctor/dtor issues.
static char ProgramName[80] = "<premain>";
static const char *ProgramOverview = 0;
// This collects additional help to be printed.
static ManagedStatic<std::vector<const char*> > MoreHelp;
: morehelp(Help) {
}
static bool OptionListChanged = false;
// MarkOptionsChanged - Internal helper function.
void cl::MarkOptionsChanged() {
OptionListChanged = true;
}
Chris Lattner
committed
/// RegisteredOptionList - This is the list of the command line options that
/// have statically constructed themselves.
static Option *RegisteredOptionList = 0;
void Option::addArgument() {
assert(NextRegistered == 0 && "argument multiply registered!");
Chris Lattner
committed
NextRegistered = RegisteredOptionList;
RegisteredOptionList = this;
MarkOptionsChanged();
Chris Lattner
committed
}
//===----------------------------------------------------------------------===//
// Basic, shared command line option processing machinery.
Chris Lattner
committed
/// GetOptionInfo - Scan the list of registered options, turning them into data
/// structures that are easier to handle.
static void GetOptionInfo(std::vector<Option*> &PositionalOpts,
std::vector<Option*> &SinkOpts,
StringMap<Option*> &OptionsMap) {
Chris Lattner
committed
std::vector<const char*> OptionNames;
Option *CAOpt = 0; // The ConsumeAfter option if it exists.
Chris Lattner
committed
for (Option *O = RegisteredOptionList; O; O = O->getNextRegisteredOption()) {
// If this option wants to handle multiple option names, get the full set.
// This handles enum options like "-O1 -O2" etc.
O->getExtraOptionNames(OptionNames);
if (O->ArgStr[0])
OptionNames.push_back(O->ArgStr);
Chris Lattner
committed
// Handle named options.
for (size_t i = 0, e = OptionNames.size(); i != e; ++i) {
Chris Lattner
committed
// Add argument to the argument map!
if (OptionsMap.GetOrCreateValue(OptionNames[i], O).second != O) {
Benjamin Kramer
committed
errs() << ProgramName << ": CommandLine Error: Argument '"
Matthijs Kooijman
committed
<< OptionNames[i] << "' defined more than once!\n";
Chris Lattner
committed
}
}
Chris Lattner
committed
OptionNames.clear();
Chris Lattner
committed
// 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);
Chris Lattner
committed
else if (O->getNumOccurrencesFlag() == cl::ConsumeAfter) {
if (CAOpt)
Chris Lattner
committed
O->error("Cannot specify more than one option with cl::ConsumeAfter!");
CAOpt = O;
Chris Lattner
committed
}
Chris Lattner
committed
}
if (CAOpt)
PositionalOpts.push_back(CAOpt);
// Make sure that they are in order of registration not backwards.
std::reverse(PositionalOpts.begin(), PositionalOpts.end());
Chris Lattner
committed
}
Chris Lattner
committed
/// LookupOption - Lookup the option specified by the specified option on the
/// command line. If there is a value specified (after an equal sign) return
/// that as well.
Chris Lattner
committed
static Option *LookupOption(const char *&Arg, const char *&Value,
StringMap<Option*> &OptionsMap) {
while (*Arg == '-') ++Arg; // Eat leading dashes
const char *ArgEnd = Arg;
while (*ArgEnd && *ArgEnd != '=')
++ArgEnd; // Scan till end of argument name.
if (*ArgEnd == '=') // If we have an equals sign...
Value = ArgEnd+1; // Get the value, not the equals
if (*Arg == 0) return 0;
// Look up the option.
StringMap<Option*>::iterator I =
OptionsMap.find(llvm::StringRef(Arg, ArgEnd-Arg));
Chris Lattner
committed
return I != OptionsMap.end() ? I->second : 0;
static inline bool ProvideOption(Option *Handler, const char *ArgName,
const char *Value, int argc, char **argv,
int &i) {
// Is this a multi-argument option?
unsigned NumAdditionalVals = Handler->getNumAdditionalVals();
// Enforce value requirements
switch (Handler->getValueExpectedFlag()) {
case ValueRequired:
if (Value == 0) { // No value specified?
if (i+1 >= argc)
return Handler->error("requires a value!");
// Steal the next argument, like for '-o filename'
Value = argv[++i];
}
break;
case ValueDisallowed:
if (NumAdditionalVals > 0)
return Handler->error("multi-valued option specified"
" with ValueDisallowed modifier!");
if (Value)
return Handler->error("does not allow a value! '" +
Twine(Value) + "' specified.");
break;
Loading
Loading full blame...