mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-23 01:24:30 +00:00
Implemented switch_on edge property.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@50729 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -38,6 +38,7 @@ def llvm_gcc_cpp : Tool<
|
|||||||
def opt : Tool<
|
def opt : Tool<
|
||||||
[(in_language "llvm-bitcode"),
|
[(in_language "llvm-bitcode"),
|
||||||
(out_language "llvm-bitcode"),
|
(out_language "llvm-bitcode"),
|
||||||
|
(switch_option "opt", (help "Enable opt")),
|
||||||
(output_suffix "bc"),
|
(output_suffix "bc"),
|
||||||
(cmd_line "opt $INFILE -o $OUTFILE")
|
(cmd_line "opt $INFILE -o $OUTFILE")
|
||||||
]>;
|
]>;
|
||||||
|
@ -58,6 +58,15 @@ std::string InitPtrToString(Init* ptr) {
|
|||||||
return val.getValue();
|
return val.getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ensure that the number of args in d is <= min_arguments,
|
||||||
|
// throw exception otherwise
|
||||||
|
void checkNumberOfArguments (const DagInit* d, unsigned min_arguments) {
|
||||||
|
if (d->getNumArgs() < min_arguments)
|
||||||
|
throw "Property " + d->getOperator()->getAsString()
|
||||||
|
+ " has too few arguments!";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
/// Back-end specific code
|
/// Back-end specific code
|
||||||
|
|
||||||
@ -187,6 +196,14 @@ struct GlobalOptionDescriptions {
|
|||||||
// Should the emitter generate a "cl::sink" option?
|
// Should the emitter generate a "cl::sink" option?
|
||||||
bool HasSink;
|
bool HasSink;
|
||||||
|
|
||||||
|
const GlobalOptionDescription& FindOption(const std::string& OptName) const {
|
||||||
|
const_iterator I = Descriptions.find(OptName);
|
||||||
|
if (I != Descriptions.end())
|
||||||
|
return I->second;
|
||||||
|
else
|
||||||
|
throw OptName + ": no such option!";
|
||||||
|
}
|
||||||
|
|
||||||
// Support for STL-style iteration
|
// Support for STL-style iteration
|
||||||
const_iterator begin() const { return Descriptions.begin(); }
|
const_iterator begin() const { return Descriptions.begin(); }
|
||||||
const_iterator end() const { return Descriptions.end(); }
|
const_iterator end() const { return Descriptions.end(); }
|
||||||
@ -358,7 +375,7 @@ public:
|
|||||||
// Just forwards to the corresponding property handler.
|
// Just forwards to the corresponding property handler.
|
||||||
void operator() (Init* i) {
|
void operator() (Init* i) {
|
||||||
DagInit& d = dynamic_cast<DagInit&>(*i);
|
DagInit& d = dynamic_cast<DagInit&>(*i);
|
||||||
std::string property_name = d.getOperator()->getAsString();
|
const std::string& property_name = d.getOperator()->getAsString();
|
||||||
PropertyHandlerMap::iterator method
|
PropertyHandlerMap::iterator method
|
||||||
= propertyHandlers_.find(property_name);
|
= propertyHandlers_.find(property_name);
|
||||||
|
|
||||||
@ -470,14 +487,6 @@ private:
|
|||||||
insertDescription(o);
|
insertDescription(o);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure that the number of args in d is <= min_arguments,
|
|
||||||
// throw exception otherwise
|
|
||||||
void checkNumberOfArguments (DagInit* d, unsigned min_arguments) {
|
|
||||||
if (d->getNumArgs() < min_arguments)
|
|
||||||
throw "Property " + d->getOperator()->getAsString()
|
|
||||||
+ " has too few arguments!";
|
|
||||||
}
|
|
||||||
|
|
||||||
// Insert new GlobalOptionDescription into GlobalOptionDescriptions list
|
// Insert new GlobalOptionDescription into GlobalOptionDescriptions list
|
||||||
void insertDescription (const GlobalOptionDescription& o)
|
void insertDescription (const GlobalOptionDescription& o)
|
||||||
{
|
{
|
||||||
@ -897,7 +906,6 @@ void TypecheckGraph (Record* CompilationGraph,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Emit Edge* classes that represent edges in the graph.
|
// Emit Edge* classes that represent edges in the graph.
|
||||||
// TOFIX: add edge properties.
|
|
||||||
void EmitEdgeClasses (Record* CompilationGraph,
|
void EmitEdgeClasses (Record* CompilationGraph,
|
||||||
const GlobalOptionDescriptions& OptDescs,
|
const GlobalOptionDescriptions& OptDescs,
|
||||||
std::ostream& O) {
|
std::ostream& O) {
|
||||||
@ -914,13 +922,42 @@ void EmitEdgeClasses (Record* CompilationGraph,
|
|||||||
O << "class Edge" << i << ": public Edge {\n"
|
O << "class Edge" << i << ": public Edge {\n"
|
||||||
<< "public:\n"
|
<< "public:\n"
|
||||||
<< Indent1 << "Edge" << i << "() : Edge(\"" << B->getName()
|
<< Indent1 << "Edge" << i << "() : Edge(\"" << B->getName()
|
||||||
<< "\") {}\n";
|
<< "\") {}\n\n"
|
||||||
|
<< Indent1 << "bool isEnabled() const {\n";
|
||||||
|
|
||||||
O << Indent1 << "bool isEnabled() const { return true; }\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 << Indent1 << "bool isDefault() const { return false; }\n";
|
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!";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw "No such edge property: " + PropName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
O << "};\n\n";
|
O << Indent2 << "return false;\n"
|
||||||
|
<< Indent1 << "};\n\n"
|
||||||
|
<< Indent1 << "bool isDefault() const { return false; }\n"
|
||||||
|
<< "};\n\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user