diff options
author | Mikhail Glushenkov <foldr@codedgers.com> | 2009-07-07 16:08:41 +0000 |
---|---|---|
committer | Mikhail Glushenkov <foldr@codedgers.com> | 2009-07-07 16:08:41 +0000 |
commit | 8fe4447a0f608a29541dd41aaab27077061d510f (patch) | |
tree | d39e2eb50eba8ef73b1f252386b7f4fa8a549118 /utils/TableGen | |
parent | cbc360d56721347f077fd887314623d8725fd597 (diff) | |
download | external_llvm-8fe4447a0f608a29541dd41aaab27077061d510f.zip external_llvm-8fe4447a0f608a29541dd41aaab27077061d510f.tar.gz external_llvm-8fe4447a0f608a29541dd41aaab27077061d510f.tar.bz2 |
Add an 'init' option property.
Makes possible to provide default values for options defined in plugins (same as
cl::init).
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@74905 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils/TableGen')
-rw-r--r-- | utils/TableGen/LLVMCConfigurationEmitter.cpp | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/utils/TableGen/LLVMCConfigurationEmitter.cpp b/utils/TableGen/LLVMCConfigurationEmitter.cpp index b1fdc4f..b27ac43 100644 --- a/utils/TableGen/LLVMCConfigurationEmitter.cpp +++ b/utils/TableGen/LLVMCConfigurationEmitter.cpp @@ -187,11 +187,12 @@ struct OptionDescription { unsigned Flags; std::string Help; unsigned MultiVal; + Init* InitVal; OptionDescription(OptionType::OptionType t = OptionType::Switch, const std::string& n = "", const std::string& h = DefaultHelpString) - : Type(t), Name(n), Flags(0x0), Help(h), MultiVal(1) + : Type(t), Name(n), Flags(0x0), Help(h), MultiVal(1), InitVal(0) {} /// GenTypeDeclaration - Returns the C++ variable type of this @@ -447,6 +448,7 @@ public: AddHandler("extern", &CollectOptionProperties::onExtern); AddHandler("help", &CollectOptionProperties::onHelp); AddHandler("hidden", &CollectOptionProperties::onHidden); + AddHandler("init", &CollectOptionProperties::onInit); AddHandler("multi_val", &CollectOptionProperties::onMultiVal); AddHandler("one_or_more", &CollectOptionProperties::onOneOrMore); AddHandler("really_hidden", &CollectOptionProperties::onReallyHidden); @@ -490,6 +492,20 @@ private: optDesc_.setRequired(); } + void onInit (const DagInit* d) { + checkNumberOfArguments(d, 1); + Init* i = d->getArg(0); + const std::string& str = i->getAsString(); + + bool correct = optDesc_.isParameter() && dynamic_cast<StringInit*>(i); + correct |= (optDesc_.isSwitch() && (str == "true" || str == "false")); + + if (!correct) + throw std::string("Incorrect usage of the 'init' option property!"); + + optDesc_.InitVal = i; + } + void onOneOrMore (const DagInit* d) { checkNumberOfArguments(d, 0); if (optDesc_.isRequired() || optDesc_.isZeroOrOne()) @@ -1716,7 +1732,12 @@ void EmitOptionDefinitions (const OptionDescriptions& descs, } if (val.MultiVal > 1) - O << ", cl::multi_val(" << val.MultiVal << ")"; + O << ", cl::multi_val(" << val.MultiVal << ')'; + + if (val.InitVal) { + const std::string& str = val.InitVal->getAsString(); + O << ", cl::init(" << str << ')'; + } if (!val.Help.empty()) O << ", cl::desc(\"" << val.Help << "\")"; |