aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMikhail Glushenkov <foldr@codedgers.com>2008-05-06 17:22:47 +0000
committerMikhail Glushenkov <foldr@codedgers.com>2008-05-06 17:22:47 +0000
commit3f6743ec2bef7e60f38bb488ea4aa5fd336088ca (patch)
tree9a592b12d8997eac83b6f7eab7e0863ce5fbd8f6
parenta5922ccdafdffd382a4af62b3baf42e4fa52d350 (diff)
downloadexternal_llvm-3f6743ec2bef7e60f38bb488ea4aa5fd336088ca.zip
external_llvm-3f6743ec2bef7e60f38bb488ea4aa5fd336088ca.tar.gz
external_llvm-3f6743ec2bef7e60f38bb488ea4aa5fd336088ca.tar.bz2
Add new edge properties: parameter_equals, element_in_list, and.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@50730 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--tools/llvmc2/Common.td2
-rw-r--r--tools/llvmc2/Example.td9
-rw-r--r--tools/llvmc2/Tools.td4
-rw-r--r--utils/TableGen/LLVMCCConfigurationEmitter.cpp93
4 files changed, 80 insertions, 28 deletions
diff --git a/tools/llvmc2/Common.td b/tools/llvmc2/Common.td
index 30905a4..5e25dcf 100644
--- a/tools/llvmc2/Common.td
+++ b/tools/llvmc2/Common.td
@@ -50,7 +50,7 @@ def required;
def switch_on;
def parameter_equals;
def element_in_list;
-def or;
+def and;
// Map from suffixes to language names
diff --git a/tools/llvmc2/Example.td b/tools/llvmc2/Example.td
index 79376ef..4fa4978 100644
--- a/tools/llvmc2/Example.td
+++ b/tools/llvmc2/Example.td
@@ -26,10 +26,11 @@ def CompilationGraph : CompilationGraph<[
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>
diff --git a/tools/llvmc2/Tools.td b/tools/llvmc2/Tools.td
index 67104ec..f4c73cb 100644
--- a/tools/llvmc2/Tools.td
+++ b/tools/llvmc2/Tools.td
@@ -38,7 +38,9 @@ def llvm_gcc_cpp : Tool<
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")
]>;
diff --git a/utils/TableGen/LLVMCCConfigurationEmitter.cpp b/utils/TableGen/LLVMCCConfigurationEmitter.cpp
index eb0755e..6892299 100644
--- a/utils/TableGen/LLVMCCConfigurationEmitter.cpp
+++ b/utils/TableGen/LLVMCCConfigurationEmitter.cpp
@@ -905,6 +905,58 @@ void TypecheckGraph (Record* CompilationGraph,
}
}
+// 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 @@ void EmitEdgeClasses (Record* CompilationGraph,
<< "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";