From 64683edb4d76a0b50a5558b0e6aa1c74bf96c7d5 Mon Sep 17 00:00:00 2001 From: Mikhail Glushenkov Date: Tue, 6 May 2008 17:22:47 +0000 Subject: [PATCH] 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 --- tools/llvmc2/Common.td | 2 +- tools/llvmc2/Example.td | 9 +- tools/llvmc2/Tools.td | 4 +- utils/TableGen/LLVMCCConfigurationEmitter.cpp | 93 ++++++++++++++----- 4 files changed, 80 insertions(+), 28 deletions(-) diff --git a/tools/llvmc2/Common.td b/tools/llvmc2/Common.td index 30905a47d21..5e25dcf2f99 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 79376efae68..4fa4978b067 100644 --- a/tools/llvmc2/Example.td +++ b/tools/llvmc2/Example.td @@ -26,10 +26,11 @@ def CompilationGraph : CompilationGraph<[ Edge, Edge, - OptionalEdge, - OptionalEdge, - OptionalEdge, - OptionalEdge, + OptionalEdge, + OptionalEdge, + OptionalEdge, + OptionalEdge, Edge, Edge diff --git a/tools/llvmc2/Tools.td b/tools/llvmc2/Tools.td index 67104ec2c73..f4c73cb735b 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 eb0755e3ddb..6892299e127 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(*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(*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";