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:
Mikhail Glushenkov 2010-08-23 19:24:08 +00:00
parent c712edc785
commit 7555f0a2bc
4 changed files with 21 additions and 20 deletions

View File

@ -93,9 +93,8 @@ def error;
def set_option;
def unset_option;
// Increase/decrease the edge weight.
// Increase the edge weight.
def inc_weight;
def dec_weight;
// Empty DAG marker.
def empty_dag_marker;

View File

@ -46,7 +46,7 @@ namespace llvmc {
virtual ~Edge() {}
const std::string& ToolName() const { return ToolName_; }
virtual unsigned Weight(const InputLanguagesSet& InLangs) const = 0;
virtual int Weight(const InputLanguagesSet& InLangs) const = 0;
private:
std::string ToolName_;
};
@ -55,7 +55,7 @@ namespace llvmc {
class SimpleEdge : public Edge {
public:
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.

View File

@ -46,19 +46,24 @@ namespace llvmc {
namespace {
/// ChooseEdge - Return the edge with the maximum weight.
/// ChooseEdge - Return the edge with the maximum weight. Returns 0 on error.
template <class C>
const Edge* ChooseEdge(const C& EdgesContainer,
const InputLanguagesSet& InLangs,
const std::string& NodeName = "root") {
const Edge* MaxEdge = 0;
unsigned MaxWeight = 0;
int MaxWeight = 0;
bool SingleMax = true;
for (typename C::const_iterator B = EdgesContainer.begin(),
E = EdgesContainer.end(); B != E; ++B) {
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) {
MaxEdge = e;
MaxWeight = EW;
@ -474,7 +479,7 @@ int CompilationGraph::CheckMultipleDefaultEdges() const {
for (const_nodes_iterator B = this->NodesMap.begin(),
E = this->NodesMap.end(); B != E; ++B) {
const Node& N = B->second;
unsigned MaxWeight = 0;
int MaxWeight = 0;
// Ignore the root node.
if (!N.ToolPtr)
@ -482,7 +487,7 @@ int CompilationGraph::CheckMultipleDefaultEdges() const {
for (Node::const_iterator EB = N.EdgesBegin(), EE = N.EdgesEnd();
EB != EE; ++EB) {
unsigned EdgeWeight = (*EB)->Weight(Dummy);
int EdgeWeight = (*EB)->Weight(Dummy);
if (EdgeWeight > MaxWeight) {
MaxWeight = EdgeWeight;
}

View File

@ -1950,7 +1950,6 @@ struct ActionHandlingCallbackBase
/// EmitActionHandlersCallback - Emit code that handles actions. Used by
/// EmitGenerateActionMethod() as an argument to EmitCaseConstructHandler().
class EmitActionHandlersCallback;
typedef void (EmitActionHandlersCallback::* EmitActionHandlersCallbackHandler)
@ -2649,21 +2648,18 @@ void EmitPopulateLanguageMap (const RecordKeeper& Records, raw_ostream& O)
O << "}\n\n";
}
/// IncDecWeight - Helper function passed to EmitCaseConstructHandler()
/// by EmitEdgeClass().
void IncDecWeight (const Init* i, unsigned IndentLevel,
raw_ostream& O) {
/// EmitEdgePropertyHandlerCallback - Emits code that handles edge
/// properties. Helper function passed to EmitCaseConstructHandler() by
/// EmitEdgeClass().
void EmitEdgePropertyHandlerCallback (const Init* i, unsigned IndentLevel,
raw_ostream& O) {
const DagInit& d = InitPtrToDag(i);
const std::string& OpName = GetOperatorName(d);
if (OpName == "inc_weight") {
O.indent(IndentLevel) << "ret += ";
}
else if (OpName == "dec_weight") {
O.indent(IndentLevel) << "ret -= ";
}
else if (OpName == "error") {
// TODO: fix this
CheckNumberOfArguments(d, 1);
O.indent(IndentLevel) << "PrintError(\""
<< InitPtrToString(d.getArg(0))
@ -2696,11 +2692,12 @@ void EmitEdgeClass (unsigned N, const std::string& Target,
// Function Weight().
O.indent(Indent1)
<< "unsigned Weight(const InputLanguagesSet& InLangs) const {\n";
<< "int Weight(const InputLanguagesSet& InLangs) const {\n";
O.indent(Indent2) << "unsigned ret = 0;\n";
// 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(Indent1) << "}\n\n};\n\n";