<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Nov 12, 2013 at 10:09 PM, Andrew Trick <span dir="ltr"><<a href="mailto:atrick@apple.com" target="_blank">atrick@apple.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><br><div><div class="im"><div>On Nov 12, 2013, at 6:26 PM, Sean Silva <<a href="mailto:silvas@purdue.edu" target="_blank">silvas@purdue.edu</a>> wrote:</div>
<br><blockquote type="cite"><div dir="ltr">Out of curiousity, what was the motivation for this? It seems to add a lot of (honestly pretty unmaintable) complexity, and isn't this output meant to be fed to another tool.</div>
</blockquote><div><br></div></div><div>We have about as different an idea of unmaintainable as I could imagine. This is a trivial bit of code completely confined to a single loop that hasn’t been touched since Chris wrote it in 2003.</div>
</div></div></blockquote><div><br></div><div>I'm not claiming that the previous code was a model of perfection, but this commit caused it to cross a mental "ad-hoc poorly specified loop"-complexity threshold of mine.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><div><br></div><div>If you’ll notice the existing comment on the loop is “Process string output to make it nicer…”</div>
<div><br></div><div><div>Very long lines make it impossible for GraphViz to layout the graph such the the CFG structure is evident.  That’s definitely not nice. I don’t like the DOT language or the tool, but I need to make it work for our purpose. I’d be happy with any alternate implementation that you provide.</div>
</div></div></div></blockquote><div><br></div><div>Oh, I see now. This is modifying the content of string literals, not tokens in the source language. Sorry. Yeah I can see that making sense now (I was thinking that this was just wrapping the actual .dot file code).</div>
<div><br></div><div>-- Sean Silva</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><div><br></div><div>-Andy</div>
<div><div class="h5"><div><br></div><blockquote type="cite"><div class="gmail_extra"><div class="gmail_quote">On Tue, Nov 12, 2013 at 1:06 PM, Andrew Trick <span dir="ltr"><<a href="mailto:atrick@apple.com" target="_blank">atrick@apple.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Author: atrick<br>
Date: Tue Nov 12 12:06:09 2013<br>
New Revision: 194496<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=194496&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=194496&view=rev</a><br>
Log:<br>
GraphViz CFGPrinter: wrap long lines.<br>
<br>
Modified:<br>
    llvm/trunk/include/llvm/Analysis/CFGPrinter.h<br>
<br>
Modified: llvm/trunk/include/llvm/Analysis/CFGPrinter.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/CFGPrinter.h?rev=194496&r1=194495&r2=194496&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/CFGPrinter.h?rev=194496&r1=194495&r2=194496&view=diff</a><br>


==============================================================================<br>
--- llvm/trunk/include/llvm/Analysis/CFGPrinter.h (original)<br>
+++ llvm/trunk/include/llvm/Analysis/CFGPrinter.h Tue Nov 12 12:06:09 2013<br>
@@ -46,6 +46,7 @@ struct DOTGraphTraits<const Function*> :<br>
<br>
   static std::string getCompleteNodeLabel(const BasicBlock *Node,<br>
                                           const Function *) {<br>
+    enum { MaxColumns = 80 };<br>
     std::string Str;<br>
     raw_string_ostream OS(Str);<br>
<br>
@@ -59,16 +60,32 @@ struct DOTGraphTraits<const Function*> :<br>
     if (OutStr[0] == '\n') OutStr.erase(OutStr.begin());<br>
<br>
     // Process string output to make it nicer...<br>
-    for (unsigned i = 0; i != OutStr.length(); ++i)<br>
+    unsigned ColNum = 0;<br>
+    unsigned LastSpace = 0;<br>
+    for (unsigned i = 0; i != OutStr.length(); ++i) {<br>
       if (OutStr[i] == '\n') {                            // Left justify<br>
         OutStr[i] = '\\';<br>
         OutStr.insert(OutStr.begin()+i+1, 'l');<br>
+        ColNum = 0;<br>
+        LastSpace = 0;<br>
       } else if (OutStr[i] == ';') {                      // Delete comments!<br>
         unsigned Idx = OutStr.find('\n', i+1);            // Find end of line<br>
         OutStr.erase(OutStr.begin()+i, OutStr.begin()+Idx);<br>
         --i;<br>
+      } else if (ColNum == MaxColumns) {                  // Wrap lines.<br>
+        if (LastSpace) {<br>
+          OutStr.insert(LastSpace, "<a>\\l</a>...");<br>
+          ColNum = i - LastSpace;<br>
+          LastSpace = 0;<br>
+          i += 3; // The loop will advance 'i' again.<br>
+        }<br>
+        // Else keep trying to find a space.<br>
       }<br>
-<br>
+      else<br>
+        ++ColNum;<br>
+      if (OutStr[i] == ' ')<br>
+        LastSpace = i;<br>
+    }<br>
     return OutStr;<br>
   }<br>
<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu" target="_blank">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div>
</blockquote></div></div></div><br></div></blockquote></div><br></div></div>