aboutsummaryrefslogtreecommitdiff
path: root/include/llvm/Support/CommandLine.h
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-04-06 21:06:55 +0000
committerChris Lattner <sabre@nondot.org>2007-04-06 21:06:55 +0000
commit9878d6ae3a535e421f69e0c08e27b259ad1bdbdc (patch)
tree7b3c0449245f15e0eb329336c62e38ffe94816a8 /include/llvm/Support/CommandLine.h
parent4802d90ca8deabe490d7baa263609a514bc11c16 (diff)
rearchitect the registration mechanism used by the command line option stuff.
This dramatically reduce the amount of memory allocated by the commandline stuff at static init time, changing it to build local data structures when ParseCommandLineOptions is called. In a dummy empty program that links some llvm libraries, this reduces the number of malloc'd bytes from 4864 to 3360 on entry to main. Most of that memory is now allocated by non-commandline related stuff. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35701 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/Support/CommandLine.h')
-rw-r--r--include/llvm/Support/CommandLine.h56
1 files changed, 37 insertions, 19 deletions
diff --git a/include/llvm/Support/CommandLine.h b/include/llvm/Support/CommandLine.h
index 4758ff5b39..328aae1c98 100644
--- a/include/llvm/Support/CommandLine.h
+++ b/include/llvm/Support/CommandLine.h
@@ -142,16 +142,18 @@ class Option {
virtual enum ValueExpected getValueExpectedFlagDefault() const {
return ValueOptional;
}
+
// Out of line virtual function to provide home for the class.
virtual void anchor();
- int NumOccurrences; // The number of times specified
- int Flags; // Flags for the argument
- unsigned Position; // Position of last occurrence of the option
+ int NumOccurrences; // The number of times specified
+ int Flags; // Flags for the argument
+ unsigned Position; // Position of last occurrence of the option
+ Option *NextRegistered; // Singly linked list of registered options.
public:
- const char *ArgStr; // The argument string itself (ex: "help", "o")
- const char *HelpStr; // The descriptive text message for --help
- const char *ValueStr; // String describing what the value of this option is
+ const char *ArgStr; // The argument string itself (ex: "help", "o")
+ const char *HelpStr; // The descriptive text message for --help
+ const char *ValueStr; // String describing what the value of this option is
inline enum NumOccurrences getNumOccurrencesFlag() const {
return static_cast<enum NumOccurrences>(Flags & OccurrencesMask);
@@ -198,16 +200,17 @@ public:
protected:
Option(unsigned DefaultFlags)
: NumOccurrences(0), Flags(DefaultFlags | NormalFormatting), Position(0),
- ArgStr(""), HelpStr(""), ValueStr("") {
+ NextRegistered(0), ArgStr(""), HelpStr(""), ValueStr("") {
assert(getNumOccurrencesFlag() != 0 &&
getOptionHiddenFlag() != 0 && "Not all default flags specified!");
}
public:
- // addArgument - Tell the system that this Option subclass will handle all
- // occurrences of -ArgStr on the command line.
+ // addArgument - Register this argument with the commandline system.
//
- void addArgument(const char *ArgStr);
+ void addArgument();
+
+ Option *getNextRegisteredOption() const { return NextRegistered; }
// Return the width of the option tag for printing...
virtual unsigned getOptionWidth() const = 0;
@@ -217,6 +220,8 @@ public:
//
virtual void printOptionInfo(unsigned GlobalWidth) const = 0;
+ virtual void getExtraOptionNames(std::vector<const char*> &OptionNames) {}
+
// addOccurrence - Wrapper around handleOccurrence that enforces Flags
//
bool addOccurrence(unsigned pos, const char *ArgName,
@@ -379,16 +384,18 @@ struct generic_parser_base {
// argstr field should be stable, copy it down now.
//
hasArgStr = O.hasArgStr();
-
+ }
+
+ void getExtraOptionNames(std::vector<const char*> &OptionNames) {
// If there has been no argstr specified, that means that we need to add an
// argument for every possible option. This ensures that our options are
// vectored to us.
- //
if (!hasArgStr)
for (unsigned i = 0, e = getNumOptions(); i != e; ++i)
- O.addArgument(getOption(i));
+ OptionNames.push_back(getOption(i));
}
+
enum ValueExpected getValueExpectedFlagDefault() const {
// If there is an ArgStr specified, then we are of the form:
//
@@ -483,6 +490,8 @@ struct basic_parser_impl { // non-template implementation of basic_parser<t>
return ValueRequired;
}
+ void getExtraOptionNames(std::vector<const char*> &OptionNames) {}
+
void initialize(Option &O) {}
// Return the width of the option tag for printing...
@@ -772,6 +781,9 @@ class opt : public Option,
virtual enum ValueExpected getValueExpectedFlagDefault() const {
return Parser.getValueExpectedFlagDefault();
}
+ virtual void getExtraOptionNames(std::vector<const char*> &OptionNames) {
+ return Parser.getExtraOptionNames(OptionNames);
+ }
// Forward printing stuff to the parser...
virtual unsigned getOptionWidth() const {return Parser.getOptionWidth(*this);}
@@ -780,7 +792,7 @@ class opt : public Option,
}
void done() {
- addArgument(ArgStr);
+ addArgument();
Parser.initialize(*this);
}
public:
@@ -923,7 +935,10 @@ class list : public Option, public list_storage<DataType, Storage> {
virtual enum ValueExpected getValueExpectedFlagDefault() const {
return Parser.getValueExpectedFlagDefault();
}
-
+ virtual void getExtraOptionNames(std::vector<const char*> &OptionNames) {
+ return Parser.getExtraOptionNames(OptionNames);
+ }
+
virtual bool handleOccurrence(unsigned pos, const char *ArgName,
const std::string &Arg) {
typename ParserClass::parser_data_type Val =
@@ -943,7 +958,7 @@ class list : public Option, public list_storage<DataType, Storage> {
}
void done() {
- addArgument(ArgStr);
+ addArgument();
Parser.initialize(*this);
}
public:
@@ -1106,7 +1121,10 @@ class bits : public Option, public bits_storage<DataType, Storage> {
virtual enum ValueExpected getValueExpectedFlagDefault() const {
return Parser.getValueExpectedFlagDefault();
}
-
+ virtual void getExtraOptionNames(std::vector<const char*> &OptionNames) {
+ return Parser.getExtraOptionNames(OptionNames);
+ }
+
virtual bool handleOccurrence(unsigned pos, const char *ArgName,
const std::string &Arg) {
typename ParserClass::parser_data_type Val =
@@ -1126,7 +1144,7 @@ class bits : public Option, public bits_storage<DataType, Storage> {
}
void done() {
- addArgument(ArgStr);
+ addArgument();
Parser.initialize(*this);
}
public:
@@ -1221,7 +1239,7 @@ class alias : public Option {
error(": cl::alias must have argument name specified!");
if (AliasFor == 0)
error(": cl::alias must have an cl::aliasopt(option) specified!");
- addArgument(ArgStr);
+ addArgument();
}
public:
void setAliasFor(Option &O) {