llvm.org GIT mirror llvm / 7555f0a
llvmc: Properly handle (error) in edge properties. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@111827 91177308-0d34-0410-b5e6-96231b3b80d8 Mikhail Glushenkov 9 years ago
4 changed file(s) with 21 addition(s) and 20 deletion(s). Raw diff Collapse all Expand all
9292 def set_option;
9393 def unset_option;
9494
95 // Increase/decrease the edge weight.
95 // Increase the edge weight.
9696 def inc_weight;
97 def dec_weight;
9897
9998 // Empty DAG marker.
10099 def empty_dag_marker;
4545 virtual ~Edge() {}
4646
4747 const std::string& ToolName() const { return ToolName_; }
48 virtual unsigned Weight(const InputLanguagesSet& InLangs) const = 0;
48 virtual int Weight(const InputLanguagesSet& InLangs) const = 0;
4949 private:
5050 std::string ToolName_;
5151 };
5454 class SimpleEdge : public Edge {
5555 public:
5656 SimpleEdge(const std::string& T) : Edge(T) {}
57 unsigned Weight(const InputLanguagesSet&) const { return 1; }
57 int Weight(const InputLanguagesSet&) const { return 1; }
5858 };
5959
6060 /// Node - A node (vertex) of the compilation graph.
4545
4646 namespace {
4747
48 /// ChooseEdge - Return the edge with the maximum weight.
48 /// ChooseEdge - Return the edge with the maximum weight. Returns 0 on error.
4949 template
5050 const Edge* ChooseEdge(const C& EdgesContainer,
5151 const InputLanguagesSet& InLangs,
5252 const std::string& NodeName = "root") {
5353 const Edge* MaxEdge = 0;
54 unsigned MaxWeight = 0;
54 int MaxWeight = 0;
5555 bool SingleMax = true;
5656
5757 for (typename C::const_iterator B = EdgesContainer.begin(),
5858 E = EdgesContainer.end(); B != E; ++B) {
5959 const Edge* e = B->getPtr();
60 unsigned EW = e->Weight(InLangs);
60 int EW = e->Weight(InLangs);
61 if (EW < 0) {
62 // (error) invocation in TableGen -> we don't need to print an error
63 // message.
64 return 0;
65 }
6166 if (EW > MaxWeight) {
6267 MaxEdge = e;
6368 MaxWeight = EW;
473478 for (const_nodes_iterator B = this->NodesMap.begin(),
474479 E = this->NodesMap.end(); B != E; ++B) {
475480 const Node& N = B->second;
476 unsigned MaxWeight = 0;
481 int MaxWeight = 0;
477482
478483 // Ignore the root node.
479484 if (!N.ToolPtr)
481486
482487 for (Node::const_iterator EB = N.EdgesBegin(), EE = N.EdgesEnd();
483488 EB != EE; ++EB) {
484 unsigned EdgeWeight = (*EB)->Weight(Dummy);
489 int EdgeWeight = (*EB)->Weight(Dummy);
485490 if (EdgeWeight > MaxWeight) {
486491 MaxWeight = EdgeWeight;
487492 }
19491949
19501950 /// EmitActionHandlersCallback - Emit code that handles actions. Used by
19511951 /// EmitGenerateActionMethod() as an argument to EmitCaseConstructHandler().
1952
19531952 class EmitActionHandlersCallback;
19541953
19551954 typedef void (EmitActionHandlersCallback::* EmitActionHandlersCallbackHandler)
26482647 O << "}\n\n";
26492648 }
26502649
2651 /// IncDecWeight - Helper function passed to EmitCaseConstructHandler()
2652 /// by EmitEdgeClass().
2653 void IncDecWeight (const Init* i, unsigned IndentLevel,
2654 raw_ostream& O) {
2650 /// EmitEdgePropertyHandlerCallback - Emits code that handles edge
2651 /// properties. Helper function passed to EmitCaseConstructHandler() by
2652 /// EmitEdgeClass().
2653 void EmitEdgePropertyHandlerCallback (const Init* i, unsigned IndentLevel,
2654 raw_ostream& O) {
26552655 const DagInit& d = InitPtrToDag(i);
26562656 const std::string& OpName = GetOperatorName(d);
26572657
26582658 if (OpName == "inc_weight") {
26592659 O.indent(IndentLevel) << "ret += ";
26602660 }
2661 else if (OpName == "dec_weight") {
2662 O.indent(IndentLevel) << "ret -= ";
2663 }
26642661 else if (OpName == "error") {
2665 // TODO: fix this
26662662 CheckNumberOfArguments(d, 1);
26672663 O.indent(IndentLevel) << "PrintError(\""
26682664 << InitPtrToString(d.getArg(0))
26952691
26962692 // Function Weight().
26972693 O.indent(Indent1)
2698 << "unsigned Weight(const InputLanguagesSet& InLangs) const {\n";
2694 << "int Weight(const InputLanguagesSet& InLangs) const {\n";
26992695 O.indent(Indent2) << "unsigned ret = 0;\n";
27002696
27012697 // Handle the 'case' construct.
2702 EmitCaseConstructHandler(Case, Indent2, IncDecWeight, false, OptDescs, O);
2698 EmitCaseConstructHandler(Case, Indent2, EmitEdgePropertyHandlerCallback,
2699 false, OptDescs, O);
27032700
27042701 O.indent(Indent2) << "return ret;\n";
27052702 O.indent(Indent1) << "}\n\n};\n\n";