mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-06 20:32:19 +00:00
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
This commit is contained in:
parent
581936a99c
commit
64683edb4d
@ -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
|
||||
|
||||
|
@ -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>
|
||||
|
@ -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")
|
||||
]>;
|
||||
|
@ -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";
|
||||
|
Loading…
Reference in New Issue
Block a user