summaryrefslogtreecommitdiffstats
path: root/llvm/utils/TableGen/OptParserEmitter.cpp
diff options
context:
space:
mode:
authorHans Wennborg <hans@hanshq.net>2013-07-31 22:44:41 +0000
committerHans Wennborg <hans@hanshq.net>2013-07-31 22:44:41 +0000
commit5fdcf86861170e948ae577b4e931bdf98e7dfc35 (patch)
tree378c98a7a85d6315bd64e1b8913698b12d4bafcd /llvm/utils/TableGen/OptParserEmitter.cpp
parent97dd3d207a957e81885ddacae19a0abb3fc4faa8 (diff)
downloadbcm5719-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/utils/TableGen/OptParserEmitter.cpp')
-rw-r--r--llvm/utils/TableGen/OptParserEmitter.cpp33
1 files changed, 30 insertions, 3 deletions
diff --git a/llvm/utils/TableGen/OptParserEmitter.cpp b/llvm/utils/TableGen/OptParserEmitter.cpp
index 0c1f6236e05..d37939f635d 100644
--- a/llvm/utils/TableGen/OptParserEmitter.cpp
+++ b/llvm/utils/TableGen/OptParserEmitter.cpp
@@ -152,11 +152,22 @@ void EmitOptParser(RecordKeeper &Records, raw_ostream &OS) {
OS << "/////////\n";
OS << "// Groups\n\n";
OS << "#ifdef OPTION\n";
+
+ // FIXME: Remove when option parsing clients are updated.
+ OS << "#ifdef SUPPORT_ALIASARGS\n";
+ OS << "#define OPTIONX OPTION\n";
+ OS << "#else\n";
+ OS << "#define OPTIONX(prefix, name, id, kind, group, alias, aliasargs, "
+ << "flags, param, helptext, metavar) "
+ << "OPTION(prefix, name, id, kind, "
+ << "group, alias, flags, param, helptext, metavar)\n";
+ OS << "#endif\n";
+
for (unsigned i = 0, e = Groups.size(); i != e; ++i) {
const Record &R = *Groups[i];
// Start a single option entry.
- OS << "OPTION(";
+ OS << "OPTIONX(";
// The option prefix;
OS << "0";
@@ -178,7 +189,7 @@ void EmitOptParser(RecordKeeper &Records, raw_ostream &OS) {
OS << "INVALID";
// The other option arguments (unused for groups).
- OS << ", INVALID, 0, 0";
+ OS << ", INVALID, 0, 0, 0";
// The option help text.
if (!isa<UnsetInit>(R.getValueInit("HelpText"))) {
@@ -199,7 +210,7 @@ void EmitOptParser(RecordKeeper &Records, raw_ostream &OS) {
const Record &R = *Opts[i];
// Start a single option entry.
- OS << "OPTION(";
+ OS << "OPTIONX(";
// The option prefix;
std::vector<std::string> prf = R.getValueAsListOfStrings("Prefixes");
@@ -228,6 +239,21 @@ void EmitOptParser(RecordKeeper &Records, raw_ostream &OS) {
else
OS << "INVALID";
+ // The option alias arguments (if any).
+ // Emitted as a \0 separated list in a string, e.g. ["foo", "bar"]
+ // would become "foo\0bar\0". Note that the compiler adds an implicit
+ // terminating \0 at the end.
+ OS << ", ";
+ std::vector<std::string> AliasArgs = R.getValueAsListOfStrings("AliasArgs");
+ if (AliasArgs.size() == 0) {
+ OS << "0";
+ } else {
+ OS << "\"";
+ for (size_t i = 0, e = AliasArgs.size(); i != e; ++i)
+ OS << AliasArgs[i] << "\\0";
+ OS << "\"";
+ }
+
// The option flags.
const ListInit *LI = R.getValueAsListInit("Flags");
if (LI->empty()) {
@@ -261,6 +287,7 @@ void EmitOptParser(RecordKeeper &Records, raw_ostream &OS) {
OS << ")\n";
}
+ OS << "#undef OPTIONX\n"; // FIXME: Remove when option clients are updated.
OS << "#endif\n";
}
} // end namespace llvm
OpenPOWER on IntegriCloud