llvm.org GIT mirror llvm / 8c67e4c
llvmc: Improve error handling in EmitEdgeClasses(). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@111886 91177308-0d34-0410-b5e6-96231b3b80d8 Mikhail Glushenkov 9 years ago
1 changed file(s) with 25 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
12421242 }
12431243 };
12441244
1245 /// IsOptionalEdge - Validate that the 'optional_edge' has proper structure.
1246 bool IsOptionalEdge (const DagInit& Edg) {
1247 return (GetOperatorName(Edg) == "optional_edge") && (Edg.getNumArgs() > 2);
1248 }
1249
12451250 /// CheckForSuperfluousOptions - Check that there are no side
12461251 /// effect-free options (specified only in the OptionList). Otherwise,
12471252 /// output a warning.
12651270 // non-superfluous options.
12661271 for (DagVector::const_iterator B = EdgeVector.begin(),
12671272 E = EdgeVector.end(); B != E; ++B) {
1268 const DagInit* Edge = *B;
1269 if (Edge->getNumArgs() > 2) {
1270 const DagInit& Weight = InitPtrToDag(Edge->getArg(2));
1273 const DagInit& Edge = **B;
1274 if (IsOptionalEdge(Edge)) {
1275 const DagInit& Weight = InitPtrToDag(Edge.getArg(2));
12711276 WalkCase(&Weight, ExtractOptionNames(nonSuperfluousOptions), Id());
12721277 }
12731278 }
27172722
27182723 /// EmitEdgeClass - Emit a single Edge# class.
27192724 void EmitEdgeClass (unsigned N, const std::string& Target,
2720 const DagInit* Case, const OptionDescriptions& OptDescs,
2725 const DagInit& Case, const OptionDescriptions& OptDescs,
27212726 raw_ostream& O) {
27222727
27232728 // Class constructor.
27322737 O.indent(Indent2) << "unsigned ret = 0;\n";
27332738
27342739 // Handle the 'case' construct.
2735 EmitCaseConstructHandler(Case, Indent2, EmitEdgePropertyHandlerCallback,
2740 EmitCaseConstructHandler(&Case, Indent2, EmitEdgePropertyHandlerCallback,
27362741 false, OptDescs, O);
27372742
27382743 O.indent(Indent2) << "return ret;\n";
27462751 int i = 0;
27472752 for (DagVector::const_iterator B = EdgeVector.begin(),
27482753 E = EdgeVector.end(); B != E; ++B) {
2749 const DagInit* Edge = *B;
2750 const std::string& NodeB = InitPtrToString(Edge->getArg(1));
2751
2752 if (Edge->getNumArgs() > 2) {
2753 const DagInit* Weight = &InitPtrToDag(Edge->getArg(2));
2754 const DagInit& Edge = **B;
2755 const std::string& Name = GetOperatorName(Edge);
2756
2757 if (Name == "optional_edge") {
2758 assert(IsOptionalEdge(Edge));
2759 const std::string& NodeB = InitPtrToString(Edge.getArg(1));
2760
2761 const DagInit& Weight = InitPtrToDag(Edge.getArg(2));
27542762 EmitEdgeClass(i, NodeB, Weight, OptDescs, O);
2763 }
2764 else if (Name != "edge") {
2765 throw "Unknown edge class: '" + Name + "'!";
27552766 }
27562767
27572768 ++i;
27762787 int i = 0;
27772788 for (DagVector::const_iterator B = EdgeVector.begin(),
27782789 E = EdgeVector.end(); B != E; ++B) {
2779 const DagInit* Edge = *B;
2780 const std::string& NodeA = InitPtrToString(Edge->getArg(0));
2781 const std::string& NodeB = InitPtrToString(Edge->getArg(1));
2790 const DagInit& Edge = **B;
2791 const std::string& NodeA = InitPtrToString(Edge.getArg(0));
2792 const std::string& NodeB = InitPtrToString(Edge.getArg(1));
27822793
27832794 O.indent(Indent1) << "if (int ret = G.insertEdge(\"" << NodeA << "\", ";
27842795
2785 if (Edge->getNumArgs() > 2)
2796 if (IsOptionalEdge(Edge))
27862797 O << "new Edge" << i << "()";
27872798 else
27882799 O << "new SimpleEdge(\"" << NodeB << "\")";
30703081 EmitToolClassDefinition(*(*B), Data.OptDescs, O);
30713082
30723083 // Emit Edge# classes.
3073 // TODO: check for edge/optional_edge dag markers.
30743084 EmitEdgeClasses(Data.Edges, Data.OptDescs, O);
30753085
30763086 O << "} // End anonymous namespace.\n\n";