projects
/
oota-llvm.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
fix crash in my previous patch
[oota-llvm.git]
/
lib
/
Support
/
CommandLine.cpp
diff --git
a/lib/Support/CommandLine.cpp
b/lib/Support/CommandLine.cpp
index 681bc1d911e5a033fb750fe13281f93d19b1a333..07900d8493655eb689cdcba5717f3663feb37cad 100644
(file)
--- a/
lib/Support/CommandLine.cpp
+++ b/
lib/Support/CommandLine.cpp
@@
-17,6
+17,7
@@
//===----------------------------------------------------------------------===//
#include "llvm/Support/CommandLine.h"
//===----------------------------------------------------------------------===//
#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/ManagedStatic.h"
@@
-28,7
+29,6
@@
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringMap.h"
-#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Config/config.h"
#include <cerrno>
#include "llvm/ADT/Twine.h"
#include "llvm/Config/config.h"
#include <cerrno>
@@
-106,10
+106,10
@@
void Option::addArgument() {
/// GetOptionInfo - Scan the list of registered options, turning them into data
/// structures that are easier to handle.
/// 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,
+static void GetOptionInfo(
SmallVectorImpl
<Option*> &PositionalOpts,
+
SmallVectorImpl
<Option*> &SinkOpts,
StringMap<Option*> &OptionsMap) {
StringMap<Option*> &OptionsMap) {
-
std::vector<const char*
> OptionNames;
+
SmallVector<const char*, 16
> OptionNames;
Option *CAOpt = 0; // The ConsumeAfter option if it exists.
for (Option *O = RegisteredOptionList; O; O = O->getNextRegisteredOption()) {
// If this option wants to handle multiple option names, get the full set.
Option *CAOpt = 0; // The ConsumeAfter option if it exists.
for (Option *O = RegisteredOptionList; O; O = O->getNextRegisteredOption()) {
// If this option wants to handle multiple option names, get the full set.
@@
-376,6
+376,8
@@
static void ParseCStringVector(std::vector<char *> &OutputVector,
memcpy(NewStr, WorkStr.data(), Pos);
NewStr[Pos] = 0;
OutputVector.push_back(NewStr);
memcpy(NewStr, WorkStr.data(), Pos);
NewStr[Pos] = 0;
OutputVector.push_back(NewStr);
+
+ WorkStr = WorkStr.substr(Pos);
}
}
}
}
@@
-454,8
+456,8
@@
static void ExpandResponseFiles(unsigned argc, char** argv,
void cl::ParseCommandLineOptions(int argc, char **argv,
const char *Overview, bool ReadResponseFiles) {
// Process all registered options.
void cl::ParseCommandLineOptions(int argc, char **argv,
const char *Overview, bool ReadResponseFiles) {
// Process all registered options.
-
std::vector<Option*
> PositionalOpts;
-
std::vector<Option*
> SinkOpts;
+
SmallVector<Option*, 4
> PositionalOpts;
+
SmallVector<Option*, 4
> SinkOpts;
StringMap<Option*> Opts;
GetOptionInfo(PositionalOpts, SinkOpts, Opts);
StringMap<Option*> Opts;
GetOptionInfo(PositionalOpts, SinkOpts, Opts);
@@
-618,7
+620,7
@@
void cl::ParseCommandLineOptions(int argc, char **argv,
<< argv[i] << "'. Try: '" << argv[0] << " --help'\n";
ErrorParsing = true;
} else {
<< argv[i] << "'. Try: '" << argv[0] << " --help'\n";
ErrorParsing = true;
} else {
- for (
std::vector
<Option*>::iterator I = SinkOpts.begin(),
+ for (
SmallVectorImpl
<Option*>::iterator I = SinkOpts.begin(),
E = SinkOpts.end(); I != E ; ++I)
(*I)->addOccurrence(i, "", argv[i]);
}
E = SinkOpts.end(); I != E ; ++I)
(*I)->addOccurrence(i, "", argv[i]);
}
@@
-642,6
+644,7
@@
void cl::ParseCommandLineOptions(int argc, char **argv,
// Check for another comma.
Pos = Val.find(',');
}
// Check for another comma.
Pos = Val.find(',');
}
+ Value = Val;
}
// If this is a named positional argument, just remember that it is the
}
// If this is a named positional argument, just remember that it is the
@@
-760,9
+763,14
@@
void cl::ParseCommandLineOptions(int argc, char **argv,
// Free all the strdup()ed strings.
for (std::vector<char*>::iterator i = newArgv.begin(), e = newArgv.end();
i != e; ++i)
// Free all the strdup()ed strings.
for (std::vector<char*>::iterator i = newArgv.begin(), e = newArgv.end();
i != e; ++i)
- free
(*i);
+ free(*i);
}
}
+ DEBUG(errs() << "\nArgs: ";
+ for (int i = 0; i < argc; ++i)
+ errs() << argv[i] << ' ';
+ );
+
// If we had an error processing our arguments, don't let the program execute
if (ErrorParsing) exit(1);
}
// If we had an error processing our arguments, don't let the program execute
if (ErrorParsing) exit(1);
}
@@
-1010,6
+1018,12
@@
void generic_parser_base::printOptionInfo(const Option &O,
// --help and --help-hidden option implementation
//
// --help and --help-hidden option implementation
//
+static int OptNameCompare(const void *LHS, const void *RHS) {
+ typedef std::pair<const char *, Option*> pair_ty;
+
+ return strcmp(((pair_ty*)LHS)->first, ((pair_ty*)RHS)->first);
+}
+
namespace {
class HelpPrinter {
namespace {
class HelpPrinter {
@@
-1026,13
+1040,13
@@
public:
if (Value == false) return;
// Get all the options.
if (Value == false) return;
// Get all the options.
-
std::vector<Option*
> PositionalOpts;
-
std::vector<Option*
> SinkOpts;
+
SmallVector<Option*, 4
> PositionalOpts;
+
SmallVector<Option*, 4
> SinkOpts;
StringMap<Option*> OptMap;
GetOptionInfo(PositionalOpts, SinkOpts, OptMap);
// Copy Options into a vector so we can sort them as we like.
StringMap<Option*> OptMap;
GetOptionInfo(PositionalOpts, SinkOpts, OptMap);
// Copy Options into a vector so we can sort them as we like.
-
std::vector<Option*
> Opts;
+
SmallVector<std::pair<const char *, Option*>, 128
> Opts;
SmallPtrSet<Option*, 128> OptionSet; // Duplicate option detection.
for (StringMap<Option*>::iterator I = OptMap.begin(), E = OptMap.end();
SmallPtrSet<Option*, 128> OptionSet; // Duplicate option detection.
for (StringMap<Option*>::iterator I = OptMap.begin(), E = OptMap.end();
@@
-1046,11
+1060,15
@@
public:
continue;
// If we've already seen this option, don't add it to the list again.
continue;
// If we've already seen this option, don't add it to the list again.
- if (OptionSet.insert(I->second))
+ if (
!
OptionSet.insert(I->second))
continue;
continue;
- Opts.push_back(I->second);
+ Opts.push_back(std::pair<const char *, Option*>(I->getKey().data(),
+ I->second));
}
}
+
+ // Sort the options list alphabetically.
+ qsort(Opts.data(), Opts.size(), sizeof(Opts[0]), OptNameCompare);
if (ProgramOverview)
outs() << "OVERVIEW: " << ProgramOverview << "\n";
if (ProgramOverview)
outs() << "OVERVIEW: " << ProgramOverview << "\n";
@@
-1077,11
+1095,11
@@
public:
// Compute the maximum argument length...
MaxArgLen = 0;
for (size_t i = 0, e = Opts.size(); i != e; ++i)
// Compute the maximum argument length...
MaxArgLen = 0;
for (size_t i = 0, e = Opts.size(); i != e; ++i)
- MaxArgLen = std::max(MaxArgLen, Opts[i]->getOptionWidth());
+ MaxArgLen = std::max(MaxArgLen, Opts[i]
.second
->getOptionWidth());
outs() << "OPTIONS:\n";
for (size_t i = 0, e = Opts.size(); i != e; ++i)
outs() << "OPTIONS:\n";
for (size_t i = 0, e = Opts.size(); i != e; ++i)
- Opts[i]->printOptionInfo(MaxArgLen);
+ Opts[i]
.second
->printOptionInfo(MaxArgLen);
// Print any extra help the user has declared.
for (std::vector<const char *>::iterator I = MoreHelp->begin(),
// Print any extra help the user has declared.
for (std::vector<const char *>::iterator I = MoreHelp->begin(),
@@
-1111,57
+1129,64
@@
HHOp("help-hidden", cl::desc("Display all available options"),
static void (*OverrideVersionPrinter)() = 0;
static void (*OverrideVersionPrinter)() = 0;
+static int TargetArraySortFn(const void *LHS, const void *RHS) {
+ typedef std::pair<const char *, const Target*> pair_ty;
+ return strcmp(((const pair_ty*)LHS)->first, ((const pair_ty*)RHS)->first);
+}
+
namespace {
class VersionPrinter {
public:
void print() {
namespace {
class VersionPrinter {
public:
void print() {
- outs() << "Low Level Virtual Machine (http://llvm.org/):\n"
- << " " << PACKAGE_NAME << " version " << PACKAGE_VERSION;
+ raw_ostream &OS = outs();
+ OS << "Low Level Virtual Machine (http://llvm.org/):\n"
+ << " " << PACKAGE_NAME << " version " << PACKAGE_VERSION;
#ifdef LLVM_VERSION_INFO
#ifdef LLVM_VERSION_INFO
-
outs()
<< LLVM_VERSION_INFO;
+
OS
<< LLVM_VERSION_INFO;
#endif
#endif
-
outs()
<< "\n ";
+
OS
<< "\n ";
#ifndef __OPTIMIZE__
#ifndef __OPTIMIZE__
-
outs()
<< "DEBUG build";
+
OS
<< "DEBUG build";
#else
#else
-
outs()
<< "Optimized build";
+
OS
<< "Optimized build";
#endif
#ifndef NDEBUG
#endif
#ifndef NDEBUG
-
outs()
<< " with assertions";
+
OS
<< " with assertions";
#endif
#endif
-
outs()
<< ".\n"
-
<< " Built " << __DATE__ << " (" << __TIME__ << ").\n"
-
<< " Host: " << sys::getHostTriple() << '\n'
- << "\n"
-
<< " Registered Targets:\n";
+
OS
<< ".\n"
+ << " Built " << __DATE__ << " (" << __TIME__ << ").\n"
+ << " Host: " << sys::getHostTriple() << '\n'
+ << '\n'
+ << " Registered Targets:\n";
- std::vector<std::pair<
std::string
, const Target*> > Targets;
+ std::vector<std::pair<
const char *
, const Target*> > Targets;
size_t Width = 0;
for (TargetRegistry::iterator it = TargetRegistry::begin(),
ie = TargetRegistry::end(); it != ie; ++it) {
Targets.push_back(std::make_pair(it->getName(), &*it));
size_t Width = 0;
for (TargetRegistry::iterator it = TargetRegistry::begin(),
ie = TargetRegistry::end(); it != ie; ++it) {
Targets.push_back(std::make_pair(it->getName(), &*it));
- Width = std::max(Width,
Targets.back().first.length(
));
+ Width = std::max(Width,
strlen(Targets.back().first
));
}
}
- array_pod_sort(Targets.begin(), Targets.end());
+ if (!Targets.empty())
+ qsort(&Targets[0], Targets.size(), sizeof(Targets[0]),
+ TargetArraySortFn);
for (unsigned i = 0, e = Targets.size(); i != e; ++i) {
for (unsigned i = 0, e = Targets.size(); i != e; ++i) {
-
outs()
<< " " << Targets[i].first;
-
outs().indent(Width - Targets[i].first.length(
)) << " - "
+
OS
<< " " << Targets[i].first;
+
OS.indent(Width - strlen(Targets[i].first
)) << " - "
<< Targets[i].second->getShortDescription() << '\n';
}
if (Targets.empty())
<< Targets[i].second->getShortDescription() << '\n';
}
if (Targets.empty())
-
outs()
<< " (none)\n";
+
OS
<< " (none)\n";
}
void operator=(bool OptionWasSpecified) {
}
void operator=(bool OptionWasSpecified) {
- if (OptionWasSpecified) {
- if (OverrideVersionPrinter == 0) {
- print();
- exit(1);
- } else {
- (*OverrideVersionPrinter)();
- exit(1);
- }
+ if (!OptionWasSpecified) return;
+
+ if (OverrideVersionPrinter == 0) {
+ print();
+ exit(1);
}
}
+ (*OverrideVersionPrinter)();
+ exit(1);
}
};
} // End anonymous namespace
}
};
} // End anonymous namespace