diff options
author | Hans Wennborg <hans@hanshq.net> | 2013-07-31 22:44:41 +0000 |
---|---|---|
committer | Hans Wennborg <hans@hanshq.net> | 2013-07-31 22:44:41 +0000 |
commit | 5fdcf86861170e948ae577b4e931bdf98e7dfc35 (patch) | |
tree | 378c98a7a85d6315bd64e1b8913698b12d4bafcd /llvm/include | |
parent | 97dd3d207a957e81885ddacae19a0abb3fc4faa8 (diff) | |
download | bcm5719-llvm-5fdcf86861170e948ae577b4e931bdf98e7dfc35.tar.gz bcm5719-llvm-5fdcf86861170e948ae577b4e931bdf98e7dfc35.zip |
Option parsing: add support for alias arguments.
This makes option aliases more powerful by enabling them to
pass along arguments to the option they're aliasing.
For example, if we have a joined option "-foo=", we can now
specify a flag option "-bar" to be an alias of that, with the
argument "baz".
This is especially useful for the cl.exe compatible clang driver,
where many options are aliases. For example, this patch enables
us to alias "/Ox" to "-O3" (-O is a joined option), and "/WX" to
"-Werror" (again, -W is a joined option).
Differential Revision: http://llvm-reviews.chandlerc.com/D1245
llvm-svn: 187537
Diffstat (limited to 'llvm/include')
-rw-r--r-- | llvm/include/llvm/Option/OptParser.td | 2 | ||||
-rw-r--r-- | llvm/include/llvm/Option/OptTable.h | 1 | ||||
-rw-r--r-- | llvm/include/llvm/Option/Option.h | 10 |
3 files changed, 13 insertions, 0 deletions
diff --git a/llvm/include/llvm/Option/OptParser.td b/llvm/include/llvm/Option/OptParser.td index 394e0b6a4b0..32cc2c0cd5b 100644 --- a/llvm/include/llvm/Option/OptParser.td +++ b/llvm/include/llvm/Option/OptParser.td @@ -89,6 +89,7 @@ class Option<list<string> prefixes, string name, OptionKind kind> { list<OptionFlag> Flags = []; OptionGroup Group = ?; Option Alias = ?; + list<string> AliasArgs = []; } // Helpers for defining options. @@ -113,6 +114,7 @@ class JoinedAndSeparate<list<string> prefixes, string name> // Mix-ins for adding optional attributes. class Alias<Option alias> { Option Alias = alias; } +class AliasArgs<list<string> aliasargs> { list<string> AliasArgs = aliasargs; } class EnumName<string name> { string EnumName = name; } class Flags<list<OptionFlag> flags> { list<OptionFlag> Flags = flags; } class Group<OptionGroup group> { OptionGroup Group = group; } diff --git a/llvm/include/llvm/Option/OptTable.h b/llvm/include/llvm/Option/OptTable.h index 8ee219d37b8..a5b59cea3f6 100644 --- a/llvm/include/llvm/Option/OptTable.h +++ b/llvm/include/llvm/Option/OptTable.h @@ -44,6 +44,7 @@ public: unsigned short Flags; unsigned short GroupID; unsigned short AliasID; + const char *AliasArgs; }; private: diff --git a/llvm/include/llvm/Option/Option.h b/llvm/include/llvm/Option/Option.h index 4861b597260..47fd8174c5a 100644 --- a/llvm/include/llvm/Option/Option.h +++ b/llvm/include/llvm/Option/Option.h @@ -103,6 +103,16 @@ public: return Owner->getOption(Info->AliasID); } + /// \brief Get the alias arguments as a \0 separated list. + /// E.g. ["foo", "bar"] would be returned as "foo\0bar\0". + const char *getAliasArgs() const { + assert(Info && "Must have a valid info!"); + assert((!Info->AliasArgs || Info->AliasArgs[0] != 0) && + "AliasArgs should be either 0 or non-empty."); + + return Info->AliasArgs; + } + /// \brief Get the default prefix for this option. StringRef getPrefix() const { const char *Prefix = *Info->Prefixes; |