* Pass the DSGraph around instead of the Function to printing fns
[oota-llvm.git] / lib / Analysis / DataStructure / Printer.cpp
index c0caaa07d751e8e1ba614ff93d2a3a83eedcd02f..ecd5486602fc700883bd5b55c47259c881eeeaca 100644 (file)
 
 void DSNode::dump() const { print(std::cerr, 0); }
 
-std::string DSNode::getCaption(Function *F) const {
+std::string DSNode::getCaption(const DSGraph *G) const {
   std::stringstream OS;
-  WriteTypeSymbolic(OS, getType(), F ? F->getParent() : 0);
+  Module *M = G ? G->getFunction().getParent() : 0;
+  WriteTypeSymbolic(OS, getType(), M);
 
   OS << " ";
   if (NodeType & ScalarNode) OS << "S";
@@ -24,6 +25,21 @@ std::string DSNode::getCaption(Function *F) const {
   if (NodeType & SubElement) OS << "E";
   if (NodeType & CastNode  ) OS << "C";
 
+  for (unsigned i = 0, e = Globals.size(); i != e; ++i) {
+    OS << "\n";
+    WriteAsOperand(OS, Globals[i], false, true, M);
+  }
+
+  if ((NodeType & ScalarNode) && G) {
+    const std::map<Value*, DSNodeHandle> &VM = G->getValueMap();
+    for (std::map<Value*, DSNodeHandle>::const_iterator I = VM.begin(),
+           E = VM.end(); I != E; ++I)
+      if (I->second == this) {
+        OS << "\n";
+        WriteAsOperand(OS, I->first, false, true, M);
+      }
+  }
+
   return OS.str();
 }
 
@@ -49,6 +65,7 @@ static void replaceIn(std::string &S, char From, const std::string &To) {
 static string escapeLabel(const string &In) {
   string Label(In);
   replaceIn(Label, '\\', "\\\\");  // Escape caption...
+  replaceIn(Label, '\n', "\\n");
   replaceIn(Label, ' ', "\\ ");
   replaceIn(Label, '{', "\\{");
   replaceIn(Label, '}', "\\}");
@@ -67,8 +84,8 @@ static void writeEdge(std::ostream &O, const void *SrcNode,
   O << ";\n";
 }
 
-void DSNode::print(std::ostream &O, Function *F) const {
-  string Caption = escapeLabel(getCaption(F));
+void DSNode::print(std::ostream &O, const DSGraph *G) const {
+  string Caption = escapeLabel(getCaption(G));
 
   O << "\tNode" << (void*)this << " [ label =\"{" << Caption;
 
@@ -97,22 +114,15 @@ void DSGraph::print(std::ostream &O) const {
 
   // Output all of the nodes...
   for (unsigned i = 0, e = Nodes.size(); i != e; ++i)
-    Nodes[i]->print(O, &Func);
+    Nodes[i]->print(O, this);
 
   O << "\n";
-  // Output all of the nodes edges for scalar labels
-  for (std::map<Value*, DSNodeHandle>::const_iterator I = ValueMap.begin(),
-         E = ValueMap.end(); I != E; ++I) {
-    O << "\tNode" << (void*)I->first << "[ shape=circle, label =\""
-      << escapeLabel(getValueName(I->first, Func)) << "\",style=dotted];\n";
-    writeEdge(O, I->first, "",-1, I->second.get(),"arrowtail=tee,style=dotted");
-  }
 
   // Output the returned value pointer...
   if (RetNode != 0) {
-    O << "\tNode0x1" << "[ shape=circle, label =\""
-      << escapeLabel("Return") << "\"];\n";
-    writeEdge(O, (void*)1, "", -1, RetNode, "arrowtail=tee,style=dotted");
+    O << "\tNode0x1" << "[ plaintext=circle, label =\""
+      << escapeLabel("returning") << "\"];\n";
+    writeEdge(O, (void*)1, "", -1, RetNode, "arrowtail=tee,color=gray63");
   }    
 
   // Output all of the call nodes...
@@ -127,7 +137,7 @@ void DSGraph::print(std::ostream &O) const {
 
     for (unsigned j = 0, e = Call.size(); j != e; ++j)
       if (Call[j])
-        writeEdge(O, &Call, ":g", j, Call[j]);
+        writeEdge(O, &Call, ":g", j, Call[j], "color=gray63");
   }