[llvm-commits] [llvm] r50731 - /llvm/trunk/utils/TableGen/LLVMCCConfigurationEmitter.cpp
Mikhail Glushenkov
foldr at codedgers.com
Tue May 6 10:23:14 PDT 2008
Author: foldr
Date: Tue May 6 12:23:14 2008
New Revision: 50731
URL: http://llvm.org/viewvc/llvm-project?rev=50731&view=rev
Log:
Refactoring: extract method.
Modified:
llvm/trunk/utils/TableGen/LLVMCCConfigurationEmitter.cpp
Modified: llvm/trunk/utils/TableGen/LLVMCCConfigurationEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/LLVMCCConfigurationEmitter.cpp?rev=50731&r1=50730&r2=50731&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/LLVMCCConfigurationEmitter.cpp (original)
+++ llvm/trunk/utils/TableGen/LLVMCCConfigurationEmitter.cpp Tue May 6 12:23:14 2008
@@ -946,7 +946,7 @@
throw PropName + ": unknown edge property!";
}
-// Helper function used by EmitEdgeClasses.
+// Helper function used by EmitEdgeClass.
void EmitEdgePropertyTest(const std::string& PropName,
const DagInit& Prop,
const GlobalOptionDescriptions& OptDescs,
@@ -957,7 +957,62 @@
EmitEdgePropertyTest2Args(PropName, Prop, OptDescs, O);
}
-// Emit Edge* classes that represent edges in the graph.
+// Emit a single Edge* class.
+void EmitEdgeClass(unsigned N, const std::string& Target,
+ ListInit* Props, const GlobalOptionDescriptions& OptDescs,
+ std::ostream& O) {
+ bool IsDefault = false;
+
+ // Class constructor.
+ O << "class Edge" << N << ": public Edge {\n"
+ << "public:\n"
+ << Indent1 << "Edge" << N << "() : Edge(\"" << Target
+ << "\") {}\n\n"
+
+ // Function isEnabled().
+ << Indent1 << "bool isEnabled() const {\n"
+ << Indent2 << "bool ret = false;\n";
+
+ for (size_t i = 0, PropsSize = Props->size(); i < PropsSize; ++i) {
+ const DagInit& Prop = dynamic_cast<DagInit&>(*Props->getElement(i));
+ const std::string& PropName = Prop.getOperator()->getAsString();
+
+ if (PropName == "default")
+ IsDefault = true;
+
+ O << Indent2 << "if (ret || (";
+ if (PropName == "and") {
+ O << '(';
+ for (unsigned j = 0, NumArgs = Prop.getNumArgs(); 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 {
+ EmitEdgePropertyTest(PropName, Prop, OptDescs, O);
+ }
+ O << "))\n" << Indent3 << "ret = true;\n";
+ }
+
+ O << Indent2 << "return ret;\n"
+ << Indent1 << "};\n\n"
+
+ // Function isDefault().
+ << Indent1 << "bool isDefault() const { return ";
+ if (IsDefault)
+ O << "true";
+ else
+ O << "false";
+ O <<"; }\n};\n\n";
+}
+
+// Emit Edge* classes that represent graph edges.
void EmitEdgeClasses (Record* CompilationGraph,
const GlobalOptionDescriptions& OptDescs,
std::ostream& O) {
@@ -971,42 +1026,7 @@
if (Props->empty())
continue;
- O << "class Edge" << i << ": public Edge {\n"
- << "public:\n"
- << Indent1 << "Edge" << i << "() : Edge(\"" << B->getName()
- << "\") {}\n\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();
-
- 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 {
- EmitEdgePropertyTest(PropName, Prop, OptDescs, O);
- }
- O << "))\n" << Indent3 << "ret = true;\n";
- }
-
- O << Indent2 << "return ret;\n"
- << Indent1 << "};\n\n"
- << Indent1 << "bool isDefault() const { return false; }\n"
- << "};\n\n";
+ EmitEdgeClass(i, B->getName(), Props, OptDescs, O);
}
}
More information about the llvm-commits
mailing list