Make error messages more useful than jsut an abort
[oota-llvm.git] / lib / Analysis / DataStructure / Printer.cpp
index d862264dcfc059b607c753f69b6c65c7f12065dd..7f0bf5a5120d6ae859a5b4d7660eead83813d9c1 100644 (file)
@@ -47,6 +47,7 @@ static std::string getCaption(const DSNode *N, const DSGraph *G) {
     if (N->NodeType & DSNode::Incomplete ) OS << "I";
     if (N->NodeType & DSNode::Modified   ) OS << "M";
     if (N->NodeType & DSNode::Read       ) OS << "R";
+    if (N->NodeType & DSNode::DEAD       ) OS << "<dead>";
     OS << "\n";
   }
 
@@ -64,12 +65,11 @@ struct DOTGraphTraits<const DSGraph*> : public DefaultDOTGraphTraits {
     if (G->hasFunction())
       return "Function " + G->getFunction().getName();
     else
-      return "Globals graph";
+      return "Global graph";
   }
 
   static const char *getGraphProperties(const DSGraph *G) {
-    return "\tedge [arrowtail=\"dot\"];\n"
-           "\tsize=\"10,7.5\";\n"
+    return "\tsize=\"10,7.5\";\n"
            "\trotate=\"90\";\n";
   }
 
@@ -127,6 +127,8 @@ struct DOTGraphTraits<const DSGraph*> : public DefaultDOTGraphTraits {
       EdgeSourceCaptions[0] = "r";
       if (Call.isDirectCall())
         EdgeSourceCaptions[1] = Call.getCalleeFunc()->getName();
+      else
+        EdgeSourceCaptions[1] = "f";
 
       GW.emitSimpleNode(&Call, "shape=record", "call", Call.getNumPtrArgs()+2,
                         &EdgeSourceCaptions);
@@ -134,21 +136,21 @@ struct DOTGraphTraits<const DSGraph*> : public DefaultDOTGraphTraits {
       if (DSNode *N = Call.getRetVal().getNode()) {
         int EdgeDest = Call.getRetVal().getOffset() >> DS::PointerShift;
         if (EdgeDest == 0) EdgeDest = -1;
-        GW.emitEdge(&Call, 0, N, EdgeDest, "color=gray63");
+        GW.emitEdge(&Call, 0, N, EdgeDest, "color=gray63,tailclip=false");
       }
 
       // Print out the callee...
       if (Call.isIndirectCall()) {
         DSNode *N = Call.getCalleeNode();
         assert(N && "Null call site callee node!");
-        GW.emitEdge(&Call, 1, N, -1, "color=gray63");
+        GW.emitEdge(&Call, 1, N, -1, "color=gray63,tailclip=false");
       }
 
       for (unsigned j = 0, e = Call.getNumPtrArgs(); j != e; ++j)
         if (DSNode *N = Call.getPtrArg(j).getNode()) {
           int EdgeDest = Call.getPtrArg(j).getOffset() >> DS::PointerShift;
           if (EdgeDest == 0) EdgeDest = -1;
-          GW.emitEdge(&Call, j+2, N, EdgeDest, "color=gray63");
+          GW.emitEdge(&Call, j+2, N, EdgeDest, "color=gray63,tailclip=false");
         }
     }
   }
@@ -179,6 +181,24 @@ void DSGraph::writeGraphToFile(std::ostream &O,
   }
 }
 
+/// viewGraph - Emit a dot graph, run 'dot', run gv on the postscript file,
+/// then cleanup.  For use from the debugger.
+///
+void DSGraph::viewGraph() const {
+  std::ofstream F("/tmp/tempgraph.dot");
+  if (!F.good()) {
+    std::cerr << "Error opening '/tmp/tempgraph.dot' for temporary graph!\n";
+    return;
+  }
+  print(F);
+  F.close();
+  if (system("dot -Tps /tmp/tempgraph.dot > /tmp/tempgraph.ps"))
+    std::cerr << "Error running dot: 'dot' not in path?\n";
+  system("gv /tmp/tempgraph.ps");
+  system("rm /tmp/tempgraph.dot /tmp/tempgraph.ps");
+}
+
+
 template <typename Collection>
 static void printCollection(const Collection &C, std::ostream &O,
                             const Module *M, const std::string &Prefix) {