[llvm] r212865 - Option: Propagate flags from groups to options in each group
Reid Kleckner
reid at kleckner.net
Fri Jul 11 17:18:58 PDT 2014
Author: rnk
Date: Fri Jul 11 19:18:58 2014
New Revision: 212865
URL: http://llvm.org/viewvc/llvm-project?rev=212865&view=rev
Log:
Option: Propagate flags from groups to options in each group
This should make it easy to set a flag for a whole group of clang driver
options.
Modified:
llvm/trunk/include/llvm/Option/OptParser.td
llvm/trunk/utils/TableGen/OptParserEmitter.cpp
Modified: llvm/trunk/include/llvm/Option/OptParser.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Option/OptParser.td?rev=212865&r1=212864&r2=212865&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Option/OptParser.td (original)
+++ llvm/trunk/include/llvm/Option/OptParser.td Fri Jul 11 19:18:58 2014
@@ -75,6 +75,7 @@ class OptionGroup<string name> {
string Name = name;
string HelpText = ?;
OptionGroup Group = ?;
+ list<OptionFlag> Flags = [];
}
// Define the option class.
Modified: llvm/trunk/utils/TableGen/OptParserEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/OptParserEmitter.cpp?rev=212865&r1=212864&r2=212865&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/OptParserEmitter.cpp (original)
+++ llvm/trunk/utils/TableGen/OptParserEmitter.cpp Fri Jul 11 19:18:58 2014
@@ -221,9 +221,11 @@ void EmitOptParser(RecordKeeper &Records
// The containing option group (if any).
OS << ", ";
- if (const DefInit *DI = dyn_cast<DefInit>(R.getValueInit("Group")))
+ const ListInit *GroupFlags = nullptr;
+ if (const DefInit *DI = dyn_cast<DefInit>(R.getValueInit("Group"))) {
+ GroupFlags = DI->getDef()->getValueAsListInit("Flags");
OS << getOptionName(*DI->getDef());
- else
+ } else
OS << "INVALID";
// The option alias (if any).
@@ -249,17 +251,19 @@ void EmitOptParser(RecordKeeper &Records
}
// The option flags.
+ OS << ", ";
+ int NumFlags = 0;
const ListInit *LI = R.getValueAsListInit("Flags");
- if (LI->empty()) {
- OS << ", 0";
- } else {
- OS << ", ";
- for (unsigned i = 0, e = LI->size(); i != e; ++i) {
- if (i)
- OS << " | ";
- OS << cast<DefInit>(LI->getElement(i))->getDef()->getName();
- }
+ for (Init *I : *LI)
+ OS << (NumFlags++ ? " | " : "")
+ << cast<DefInit>(I)->getDef()->getName();
+ if (GroupFlags) {
+ for (Init *I : *GroupFlags)
+ OS << (NumFlags++ ? " | " : "")
+ << cast<DefInit>(I)->getDef()->getName();
}
+ if (NumFlags == 0)
+ OS << '0';
// The option parameter field.
OS << ", " << R.getValueAsInt("NumArgs");
More information about the llvm-commits
mailing list