[llvm-commits] [llvm] r60667 - in /llvm/trunk: include/llvm/CompilerDriver/Common.td test/LLVMC/ExternOptions.td tools/llvmc/plugins/Clang/Clang.td utils/TableGen/LLVMCConfigurationEmitter.cpp
Mikhail Glushenkov
foldr at codedgers.com
Sun Dec 7 08:47:12 PST 2008
Author: foldr
Date: Sun Dec 7 10:47:12 2008
New Revision: 60667
URL: http://llvm.org/viewvc/llvm-project?rev=60667&view=rev
Log:
Make 'extern' an option property.
Makes (forward) work better.
Modified:
llvm/trunk/include/llvm/CompilerDriver/Common.td
llvm/trunk/test/LLVMC/ExternOptions.td
llvm/trunk/tools/llvmc/plugins/Clang/Clang.td
llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp
Modified: llvm/trunk/include/llvm/CompilerDriver/Common.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CompilerDriver/Common.td?rev=60667&r1=60666&r2=60667&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CompilerDriver/Common.td (original)
+++ llvm/trunk/include/llvm/CompilerDriver/Common.td Sun Dec 7 10:47:12 2008
@@ -34,16 +34,13 @@
def prefix_option;
def prefix_list_option;
-def extern_switch;
-def extern_parameter;
-def extern_list;
-
// Possible option properties.
def help;
def hidden;
def really_hidden;
def required;
+def extern;
// Empty DAG marker.
def empty;
Modified: llvm/trunk/test/LLVMC/ExternOptions.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/LLVMC/ExternOptions.td?rev=60667&r1=60666&r2=60667&view=diff
==============================================================================
--- llvm/trunk/test/LLVMC/ExternOptions.td (original)
+++ llvm/trunk/test/LLVMC/ExternOptions.td Sun Dec 7 10:47:12 2008
@@ -1,11 +1,12 @@
// Check that extern options work.
// The dummy tool and graph are required to silence warnings.
-// RUN: tblgen -I $srcroot/include --gen-llvmc %s | grep extern
+// RUN: tblgen -I $srcroot/include --gen-llvmc %s | grep {extern .* AutoGeneratedSwitch_Wall}
include "llvm/CompilerDriver/Common.td"
-def OptList : OptionList<[(extern_switch "Wall"),
- (extern_parameter "std"), (extern_list "L")]>;
+def OptList : OptionList<[(switch_option "Wall", (extern)),
+ (parameter_option "std", (extern)),
+ (prefix_list_option "L", (extern))]>;
def dummy_tool : Tool<[
(cmd_line "dummy_cmd"),
Modified: llvm/trunk/tools/llvmc/plugins/Clang/Clang.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvmc/plugins/Clang/Clang.td?rev=60667&r1=60666&r2=60667&view=diff
==============================================================================
--- llvm/trunk/tools/llvmc/plugins/Clang/Clang.td (original)
+++ llvm/trunk/tools/llvmc/plugins/Clang/Clang.td Sun Dec 7 10:47:12 2008
@@ -9,17 +9,17 @@
def Priority : PluginPriority<1>;
def Options : OptionList<[
-(extern_switch "E"),
-(extern_switch "c"),
-(extern_switch "fsyntax-only"),
-(extern_switch "emit-llvm"),
-(extern_switch "pthread"),
-(extern_list "I"),
-(extern_list "include"),
-(extern_list "L"),
-(extern_list "l"),
-(extern_list "Wa,"),
-(extern_list "Wl,"),
+(switch_option "E", (extern)),
+(switch_option "c", (extern)),
+(switch_option "fsyntax-only", (extern)),
+(switch_option "emit-llvm", (extern)),
+(switch_option "pthread", (extern)),
+(parameter_list_option "I", (extern)),
+(parameter_list_option "include", (extern)),
+(parameter_list_option "L", (extern)),
+(parameter_list_option "l", (extern)),
+(prefix_list_option "Wa,", (extern)),
+(prefix_list_option "Wl,", (extern)),
(switch_option "clang", (help "Use Clang instead of llvm-gcc"))
]>;
Modified: llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp?rev=60667&r1=60666&r2=60667&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp (original)
+++ llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp Sun Dec 7 10:47:12 2008
@@ -85,7 +85,7 @@
// checkNumberOfArguments - Ensure that the number of args in d is
// less than or equal to min_arguments, otherwise throw an exception.
void checkNumberOfArguments (const DagInit* d, unsigned min_arguments) {
- if (d->getNumArgs() < min_arguments)
+ if (!d || d->getNumArgs() < min_arguments)
throw "Property " + d->getOperator()->getAsString()
+ " has too few arguments!";
}
@@ -127,19 +127,18 @@
/// Extern* options are those that are defined in some other plugin.
namespace OptionType {
enum OptionType { Alias, Switch, Parameter, ParameterList,
- Prefix, PrefixList,
- ExternSwitch, ExternParameter, ExternList };
+ Prefix, PrefixList};
bool IsList (OptionType t) {
- return (t == ParameterList || t == PrefixList || t == ExternList);
+ return (t == ParameterList || t == PrefixList);
}
bool IsSwitch (OptionType t) {
- return (t == Switch || t == ExternSwitch);
+ return (t == Switch);
}
bool IsParameter (OptionType t) {
- return (t == Parameter || t == Prefix || t == ExternParameter);
+ return (t == Parameter || t == Prefix);
}
}
@@ -157,19 +156,13 @@
return OptionType::Prefix;
else if (T == "prefix_list_option")
return OptionType::PrefixList;
- else if (T == "extern_switch")
- return OptionType::ExternSwitch;
- else if (T == "extern_parameter")
- return OptionType::ExternParameter;
- else if (T == "extern_list")
- return OptionType::ExternList;
else
throw "Unknown option type: " + T + '!';
}
namespace OptionDescriptionFlags {
enum OptionDescriptionFlags { Required = 0x1, Hidden = 0x2,
- ReallyHidden = 0x4 };
+ ReallyHidden = 0x4, Extern = 0x8 };
}
/// OptionDescription - Represents data contained in a single
@@ -200,7 +193,9 @@
// Misc convenient getters/setters.
bool isAlias() const;
+
bool isExtern() const;
+ void setExtern();
bool isRequired() const;
void setRequired();
@@ -232,8 +227,10 @@
}
bool OptionDescription::isExtern() const {
- return (Type == OptionType::ExternList || Type == OptionType::ExternParameter
- || Type == OptionType::ExternSwitch);
+ return Flags & OptionDescriptionFlags::Extern;
+}
+void OptionDescription::setExtern() {
+ Flags |= OptionDescriptionFlags::Extern;
}
bool OptionDescription::isRequired() const {
@@ -261,14 +258,11 @@
switch (Type) {
case OptionType::Alias:
return "cl::alias";
- case OptionType::ExternList:
case OptionType::PrefixList:
case OptionType::ParameterList:
return "cl::list<std::string>";
case OptionType::Switch:
- case OptionType::ExternSwitch:
return "cl::opt<bool>";
- case OptionType::ExternParameter:
case OptionType::Parameter:
case OptionType::Prefix:
default:
@@ -283,12 +277,9 @@
return "AutoGeneratedAlias_" + EscapedName;
case OptionType::PrefixList:
case OptionType::ParameterList:
- case OptionType::ExternList:
return "AutoGeneratedList_" + EscapedName;
- case OptionType::ExternSwitch:
case OptionType::Switch:
return "AutoGeneratedSwitch_" + EscapedName;
- case OptionType::ExternParameter:
case OptionType::Prefix:
case OptionType::Parameter:
default:
@@ -402,6 +393,7 @@
: HandlerTable<CollectOptionProperties>(this), optDesc_(OD)
{
if (!staticMembersInitialized_) {
+ AddHandler("extern", &CollectOptionProperties::onExtern);
AddHandler("help", &CollectOptionProperties::onHelp);
AddHandler("hidden", &CollectOptionProperties::onHidden);
AddHandler("really_hidden", &CollectOptionProperties::onReallyHidden);
@@ -416,39 +408,31 @@
/// Option property handlers --
/// Methods that handle option properties such as (help) or (hidden).
+ void onExtern (const DagInit* d) {
+ checkNumberOfArguments(d, 0);
+ optDesc_.setExtern();
+ }
+
void onHelp (const DagInit* d) {
checkNumberOfArguments(d, 1);
- const std::string& help_message = InitPtrToString(d->getArg(0));
- optDesc_.Help = help_message;
+ optDesc_.Help = InitPtrToString(d->getArg(0));
}
void onHidden (const DagInit* d) {
checkNumberOfArguments(d, 0);
- checkToolProps(d);
optDesc_.setHidden();
}
void onReallyHidden (const DagInit* d) {
checkNumberOfArguments(d, 0);
- checkToolProps(d);
optDesc_.setReallyHidden();
}
void onRequired (const DagInit* d) {
checkNumberOfArguments(d, 0);
- checkToolProps(d);
optDesc_.setRequired();
}
- // Helper functions
-
- /// checkToolProps - Throw an error if toolProps_ == 0.
- void checkToolProps(const DagInit* d) {
- if (!d)
- throw "Option property " + d->getOperator()->getAsString()
- + " can't be used in this context";
- }
-
};
/// AddOption - A function object that is applied to every option
@@ -1163,11 +1147,9 @@
switch (D.Type) {
case OptionType::Switch:
- case OptionType::ExternSwitch:
O << Indent << "vec.push_back(\"" << Name << "\");\n";
break;
case OptionType::Parameter:
- case OptionType::ExternParameter:
O << Indent << "vec.push_back(\"" << Name << "\");\n";
O << Indent << "vec.push_back(" << D.GenVariableName() << ");\n";
break;
@@ -1183,7 +1165,6 @@
<< "*B);\n";
break;
case OptionType::ParameterList:
- case OptionType::ExternList:
O << Indent << "for (" << D.GenTypeDeclaration()
<< "::iterator B = " << D.GenVariableName() << ".begin(),\n"
<< Indent << "E = " << D.GenVariableName()
More information about the llvm-commits
mailing list