summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorMikhail Glushenkov <foldr@codedgers.com>2008-05-06 17:23:14 +0000
committerMikhail Glushenkov <foldr@codedgers.com>2008-05-06 17:23:14 +0000
commit9ef501b12012cee34fa1a1bf2599457d5701c498 (patch)
tree3c97d94a6cff803884bc6738ea394396a966023f /utils
parent64683edb4d76a0b50a5558b0e6aa1c74bf96c7d5 (diff)
downloadllvm-9ef501b12012cee34fa1a1bf2599457d5701c498.tar.gz
llvm-9ef501b12012cee34fa1a1bf2599457d5701c498.tar.bz2
llvm-9ef501b12012cee34fa1a1bf2599457d5701c498.tar.xz
Refactoring: extract method.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@50731 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils')
-rw-r--r--utils/TableGen/LLVMCCConfigurationEmitter.cpp96
1 files changed, 58 insertions, 38 deletions
diff --git a/utils/TableGen/LLVMCCConfigurationEmitter.cpp b/utils/TableGen/LLVMCCConfigurationEmitter.cpp
index 6892299e12..48008f1065 100644
--- a/utils/TableGen/LLVMCCConfigurationEmitter.cpp
+++ b/utils/TableGen/LLVMCCConfigurationEmitter.cpp
@@ -946,7 +946,7 @@ void EmitEdgePropertyTest2Args(const std::string& PropName,
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 @@ void EmitEdgePropertyTest(const std::string& PropName,
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 @@ void EmitEdgeClasses (Record* CompilationGraph,
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);
}
}