mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-17 20:23:59 +00:00
llvmc: Properly handle (error) in edge properties.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@111827 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -93,9 +93,8 @@ def error;
|
|||||||
def set_option;
|
def set_option;
|
||||||
def unset_option;
|
def unset_option;
|
||||||
|
|
||||||
// Increase/decrease the edge weight.
|
// Increase the edge weight.
|
||||||
def inc_weight;
|
def inc_weight;
|
||||||
def dec_weight;
|
|
||||||
|
|
||||||
// Empty DAG marker.
|
// Empty DAG marker.
|
||||||
def empty_dag_marker;
|
def empty_dag_marker;
|
||||||
|
@ -46,7 +46,7 @@ namespace llvmc {
|
|||||||
virtual ~Edge() {}
|
virtual ~Edge() {}
|
||||||
|
|
||||||
const std::string& ToolName() const { return ToolName_; }
|
const std::string& ToolName() const { return ToolName_; }
|
||||||
virtual unsigned Weight(const InputLanguagesSet& InLangs) const = 0;
|
virtual int Weight(const InputLanguagesSet& InLangs) const = 0;
|
||||||
private:
|
private:
|
||||||
std::string ToolName_;
|
std::string ToolName_;
|
||||||
};
|
};
|
||||||
@ -55,7 +55,7 @@ namespace llvmc {
|
|||||||
class SimpleEdge : public Edge {
|
class SimpleEdge : public Edge {
|
||||||
public:
|
public:
|
||||||
SimpleEdge(const std::string& T) : Edge(T) {}
|
SimpleEdge(const std::string& T) : Edge(T) {}
|
||||||
unsigned Weight(const InputLanguagesSet&) const { return 1; }
|
int Weight(const InputLanguagesSet&) const { return 1; }
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Node - A node (vertex) of the compilation graph.
|
/// Node - A node (vertex) of the compilation graph.
|
||||||
|
@ -46,19 +46,24 @@ namespace llvmc {
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
/// ChooseEdge - Return the edge with the maximum weight.
|
/// ChooseEdge - Return the edge with the maximum weight. Returns 0 on error.
|
||||||
template <class C>
|
template <class C>
|
||||||
const Edge* ChooseEdge(const C& EdgesContainer,
|
const Edge* ChooseEdge(const C& EdgesContainer,
|
||||||
const InputLanguagesSet& InLangs,
|
const InputLanguagesSet& InLangs,
|
||||||
const std::string& NodeName = "root") {
|
const std::string& NodeName = "root") {
|
||||||
const Edge* MaxEdge = 0;
|
const Edge* MaxEdge = 0;
|
||||||
unsigned MaxWeight = 0;
|
int MaxWeight = 0;
|
||||||
bool SingleMax = true;
|
bool SingleMax = true;
|
||||||
|
|
||||||
for (typename C::const_iterator B = EdgesContainer.begin(),
|
for (typename C::const_iterator B = EdgesContainer.begin(),
|
||||||
E = EdgesContainer.end(); B != E; ++B) {
|
E = EdgesContainer.end(); B != E; ++B) {
|
||||||
const Edge* e = B->getPtr();
|
const Edge* e = B->getPtr();
|
||||||
unsigned EW = e->Weight(InLangs);
|
int EW = e->Weight(InLangs);
|
||||||
|
if (EW < 0) {
|
||||||
|
// (error) invocation in TableGen -> we don't need to print an error
|
||||||
|
// message.
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
if (EW > MaxWeight) {
|
if (EW > MaxWeight) {
|
||||||
MaxEdge = e;
|
MaxEdge = e;
|
||||||
MaxWeight = EW;
|
MaxWeight = EW;
|
||||||
@ -474,7 +479,7 @@ int CompilationGraph::CheckMultipleDefaultEdges() const {
|
|||||||
for (const_nodes_iterator B = this->NodesMap.begin(),
|
for (const_nodes_iterator B = this->NodesMap.begin(),
|
||||||
E = this->NodesMap.end(); B != E; ++B) {
|
E = this->NodesMap.end(); B != E; ++B) {
|
||||||
const Node& N = B->second;
|
const Node& N = B->second;
|
||||||
unsigned MaxWeight = 0;
|
int MaxWeight = 0;
|
||||||
|
|
||||||
// Ignore the root node.
|
// Ignore the root node.
|
||||||
if (!N.ToolPtr)
|
if (!N.ToolPtr)
|
||||||
@ -482,7 +487,7 @@ int CompilationGraph::CheckMultipleDefaultEdges() const {
|
|||||||
|
|
||||||
for (Node::const_iterator EB = N.EdgesBegin(), EE = N.EdgesEnd();
|
for (Node::const_iterator EB = N.EdgesBegin(), EE = N.EdgesEnd();
|
||||||
EB != EE; ++EB) {
|
EB != EE; ++EB) {
|
||||||
unsigned EdgeWeight = (*EB)->Weight(Dummy);
|
int EdgeWeight = (*EB)->Weight(Dummy);
|
||||||
if (EdgeWeight > MaxWeight) {
|
if (EdgeWeight > MaxWeight) {
|
||||||
MaxWeight = EdgeWeight;
|
MaxWeight = EdgeWeight;
|
||||||
}
|
}
|
||||||
|
@ -1950,7 +1950,6 @@ struct ActionHandlingCallbackBase
|
|||||||
|
|
||||||
/// EmitActionHandlersCallback - Emit code that handles actions. Used by
|
/// EmitActionHandlersCallback - Emit code that handles actions. Used by
|
||||||
/// EmitGenerateActionMethod() as an argument to EmitCaseConstructHandler().
|
/// EmitGenerateActionMethod() as an argument to EmitCaseConstructHandler().
|
||||||
|
|
||||||
class EmitActionHandlersCallback;
|
class EmitActionHandlersCallback;
|
||||||
|
|
||||||
typedef void (EmitActionHandlersCallback::* EmitActionHandlersCallbackHandler)
|
typedef void (EmitActionHandlersCallback::* EmitActionHandlersCallbackHandler)
|
||||||
@ -2649,9 +2648,10 @@ void EmitPopulateLanguageMap (const RecordKeeper& Records, raw_ostream& O)
|
|||||||
O << "}\n\n";
|
O << "}\n\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
/// IncDecWeight - Helper function passed to EmitCaseConstructHandler()
|
/// EmitEdgePropertyHandlerCallback - Emits code that handles edge
|
||||||
/// by EmitEdgeClass().
|
/// properties. Helper function passed to EmitCaseConstructHandler() by
|
||||||
void IncDecWeight (const Init* i, unsigned IndentLevel,
|
/// EmitEdgeClass().
|
||||||
|
void EmitEdgePropertyHandlerCallback (const Init* i, unsigned IndentLevel,
|
||||||
raw_ostream& O) {
|
raw_ostream& O) {
|
||||||
const DagInit& d = InitPtrToDag(i);
|
const DagInit& d = InitPtrToDag(i);
|
||||||
const std::string& OpName = GetOperatorName(d);
|
const std::string& OpName = GetOperatorName(d);
|
||||||
@ -2659,11 +2659,7 @@ void IncDecWeight (const Init* i, unsigned IndentLevel,
|
|||||||
if (OpName == "inc_weight") {
|
if (OpName == "inc_weight") {
|
||||||
O.indent(IndentLevel) << "ret += ";
|
O.indent(IndentLevel) << "ret += ";
|
||||||
}
|
}
|
||||||
else if (OpName == "dec_weight") {
|
|
||||||
O.indent(IndentLevel) << "ret -= ";
|
|
||||||
}
|
|
||||||
else if (OpName == "error") {
|
else if (OpName == "error") {
|
||||||
// TODO: fix this
|
|
||||||
CheckNumberOfArguments(d, 1);
|
CheckNumberOfArguments(d, 1);
|
||||||
O.indent(IndentLevel) << "PrintError(\""
|
O.indent(IndentLevel) << "PrintError(\""
|
||||||
<< InitPtrToString(d.getArg(0))
|
<< InitPtrToString(d.getArg(0))
|
||||||
@ -2696,11 +2692,12 @@ void EmitEdgeClass (unsigned N, const std::string& Target,
|
|||||||
|
|
||||||
// Function Weight().
|
// Function Weight().
|
||||||
O.indent(Indent1)
|
O.indent(Indent1)
|
||||||
<< "unsigned Weight(const InputLanguagesSet& InLangs) const {\n";
|
<< "int Weight(const InputLanguagesSet& InLangs) const {\n";
|
||||||
O.indent(Indent2) << "unsigned ret = 0;\n";
|
O.indent(Indent2) << "unsigned ret = 0;\n";
|
||||||
|
|
||||||
// Handle the 'case' construct.
|
// Handle the 'case' construct.
|
||||||
EmitCaseConstructHandler(Case, Indent2, IncDecWeight, false, OptDescs, O);
|
EmitCaseConstructHandler(Case, Indent2, EmitEdgePropertyHandlerCallback,
|
||||||
|
false, OptDescs, O);
|
||||||
|
|
||||||
O.indent(Indent2) << "return ret;\n";
|
O.indent(Indent2) << "return ret;\n";
|
||||||
O.indent(Indent1) << "}\n\n};\n\n";
|
O.indent(Indent1) << "}\n\n};\n\n";
|
||||||
|
Reference in New Issue
Block a user