[llvm-commits] [llvm] r50730 - in /llvm/trunk: tools/llvmc2/Common.td tools/llvmc2/Example.td tools/llvmc2/Tools.td utils/TableGen/LLVMCCConfigurationEmitter.cpp
Mikhail Glushenkov
foldr at codedgers.com
Tue May 6 10:22:48 PDT 2008
Author: foldr
Date: Tue May 6 12:22:47 2008
New Revision: 50730
URL: http://llvm.org/viewvc/llvm-project?rev=50730&view=rev
Log:
Add new edge properties: parameter_equals, element_in_list, and.
Modified:
llvm/trunk/tools/llvmc2/Common.td
llvm/trunk/tools/llvmc2/Example.td
llvm/trunk/tools/llvmc2/Tools.td
llvm/trunk/utils/TableGen/LLVMCCConfigurationEmitter.cpp
Modified: llvm/trunk/tools/llvmc2/Common.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvmc2/Common.td?rev=50730&r1=50729&r2=50730&view=diff
==============================================================================
--- llvm/trunk/tools/llvmc2/Common.td (original)
+++ llvm/trunk/tools/llvmc2/Common.td Tue May 6 12:22:47 2008
@@ -50,7 +50,7 @@
def switch_on;
def parameter_equals;
def element_in_list;
-def or;
+def and;
// Map from suffixes to language names
Modified: llvm/trunk/tools/llvmc2/Example.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvmc2/Example.td?rev=50730&r1=50729&r2=50730&view=diff
==============================================================================
--- llvm/trunk/tools/llvmc2/Example.td (original)
+++ llvm/trunk/tools/llvmc2/Example.td Tue May 6 12:22:47 2008
@@ -26,10 +26,11 @@
Edge<llvm_gcc_cpp, llc>,
Edge<llvm_as, llc>,
- OptionalEdge<llvm_gcc_c, opt, [(switch_on "opt")]>,
- OptionalEdge<llvm_gcc_cpp, opt, [(switch_on "opt")]>,
- OptionalEdge<llvm_as, opt, [(switch_on "opt")]>,
- OptionalEdge<opt, llc, [(switch_on "opt")]>,
+ OptionalEdge<llvm_gcc_c, opt, [(switch_on "S")]>,
+ OptionalEdge<llvm_gcc_cpp, opt, [(switch_on "S")]>,
+ OptionalEdge<llvm_as, opt, [(switch_on "S")]>,
+ OptionalEdge<opt, llc, [(and (switch_on "S"), (parameter_equals "O", "V")),
+ (element_in_list "P", "E")]>,
Edge<llc, llvm_gcc_assembler>,
Edge<llvm_gcc_assembler, llvm_gcc_linker>
Modified: llvm/trunk/tools/llvmc2/Tools.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvmc2/Tools.td?rev=50730&r1=50729&r2=50730&view=diff
==============================================================================
--- llvm/trunk/tools/llvmc2/Tools.td (original)
+++ llvm/trunk/tools/llvmc2/Tools.td Tue May 6 12:22:47 2008
@@ -38,7 +38,9 @@
def opt : Tool<
[(in_language "llvm-bitcode"),
(out_language "llvm-bitcode"),
- (switch_option "opt", (help "Enable opt")),
+ (switch_option "S", (help "Test switch")),
+ (parameter_option "O", (help "Test Parameter")),
+ (prefix_list_option "P", (help "Test Parameter List")),
(output_suffix "bc"),
(cmd_line "opt $INFILE -o $OUTFILE")
]>;
Modified: llvm/trunk/utils/TableGen/LLVMCCConfigurationEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/LLVMCCConfigurationEmitter.cpp?rev=50730&r1=50729&r2=50730&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/LLVMCCConfigurationEmitter.cpp (original)
+++ llvm/trunk/utils/TableGen/LLVMCCConfigurationEmitter.cpp Tue May 6 12:22:47 2008
@@ -905,6 +905,58 @@
}
}
+// Helper function used by EmitEdgePropertyTest.
+void EmitEdgePropertyTest1Arg(const DagInit& Prop,
+ const GlobalOptionDescriptions& OptDescs,
+ std::ostream& O) {
+ checkNumberOfArguments(&Prop, 1);
+ const std::string& OptName = InitPtrToString(Prop.getArg(0));
+ const GlobalOptionDescription& OptDesc = OptDescs.FindOption(OptName);
+ if (OptDesc.Type != OptionType::Switch)
+ throw OptName + ": incorrect option type!";
+ O << OptDesc.GenVariableName();
+}
+
+// Helper function used by EmitEdgePropertyTest.
+void EmitEdgePropertyTest2Args(const std::string& PropName,
+ const DagInit& Prop,
+ const GlobalOptionDescriptions& OptDescs,
+ std::ostream& O) {
+ checkNumberOfArguments(&Prop, 2);
+ const std::string& OptName = InitPtrToString(Prop.getArg(0));
+ const std::string& OptArg = InitPtrToString(Prop.getArg(1));
+ const GlobalOptionDescription& OptDesc = OptDescs.FindOption(OptName);
+
+ if (PropName == "parameter_equals") {
+ if (OptDesc.Type != OptionType::Parameter
+ && OptDesc.Type != OptionType::Prefix)
+ throw OptName + ": incorrect option type!";
+ O << OptDesc.GenVariableName() << " == \"" << OptArg << "\"";
+ }
+ else if (PropName == "element_in_list") {
+ if (OptDesc.Type != OptionType::ParameterList
+ && OptDesc.Type != OptionType::PrefixList)
+ throw OptName + ": incorrect option type!";
+ const std::string& VarName = OptDesc.GenVariableName();
+ O << "std::find(" << VarName << ".begin(),\n"
+ << Indent3 << VarName << ".end(), \""
+ << OptArg << "\") != " << VarName << ".end()";
+ }
+ else
+ throw PropName + ": unknown edge property!";
+}
+
+// Helper function used by EmitEdgeClasses.
+void EmitEdgePropertyTest(const std::string& PropName,
+ const DagInit& Prop,
+ const GlobalOptionDescriptions& OptDescs,
+ std::ostream& O) {
+ if (PropName == "switch_on")
+ EmitEdgePropertyTest1Arg(Prop, OptDescs, O);
+ else
+ EmitEdgePropertyTest2Args(PropName, Prop, OptDescs, O);
+}
+
// Emit Edge* classes that represent edges in the graph.
void EmitEdgeClasses (Record* CompilationGraph,
const GlobalOptionDescriptions& OptDescs,
@@ -923,38 +975,35 @@
<< "public:\n"
<< Indent1 << "Edge" << i << "() : Edge(\"" << B->getName()
<< "\") {}\n\n"
- << Indent1 << "bool isEnabled() const {\n";
+ << Indent1 << "bool isEnabled() const {\n"
+ << Indent2 << "bool ret = false;\n";
for (unsigned i = 0; i < Props->size(); ++i) {
const DagInit& Prop = dynamic_cast<DagInit&>(*Props->getElement(i));
const std::string& PropName = Prop.getOperator()->getAsString();
- if (PropName == "switch_on") {
- checkNumberOfArguments(&Prop, 1);
- const std::string& OptName = InitPtrToString(Prop.getArg(0));
- const GlobalOptionDescription& OptDesc = OptDescs.FindOption(OptName);
- if (OptDesc.Type != OptionType::Switch)
- throw OptName + ": incorrect option type!";
- O << Indent2 << "if (" << OptDesc.GenVariableName() << ")\n"
- << Indent3 << "return true;\n";
- }
- else if (PropName == "parameter_equals") {
- checkNumberOfArguments(&Prop, 2);
- throw PropName + ": not implemented!";
- }
- else if (PropName == "element_in_list") {
- checkNumberOfArguments(&Prop, 2);
- throw PropName + ": not implemented!";
- }
- else if (PropName == "or") {
- throw PropName + ": not implemented!";
+ O << Indent2 << "if (ret || (";
+ if (PropName == "and") {
+ const unsigned NumArgs = Prop.getNumArgs();
+ O << '(';
+ for (unsigned j = 0; j < NumArgs; ++j) {
+ const DagInit& InnerProp = dynamic_cast<DagInit&>(*Prop.getArg(j));
+ const std::string& InnerPropName =
+ InnerProp.getOperator()->getAsString();
+ EmitEdgePropertyTest(InnerPropName, InnerProp, OptDescs, O);
+ if (j != NumArgs - 1)
+ O << ")\n" << Indent3 << " && (";
+ else
+ O << ')';
+ }
}
else {
- throw "No such edge property: " + PropName;
+ EmitEdgePropertyTest(PropName, Prop, OptDescs, O);
}
+ O << "))\n" << Indent3 << "ret = true;\n";
}
- O << Indent2 << "return false;\n"
+ O << Indent2 << "return ret;\n"
<< Indent1 << "};\n\n"
<< Indent1 << "bool isDefault() const { return false; }\n"
<< "};\n\n";
More information about the llvm-commits
mailing list