[llvm] r194496 - GraphViz CFGPrinter: wrap long lines.

Andrew Trick atrick at apple.com
Tue Nov 12 19:09:09 PST 2013


On Nov 12, 2013, at 6:26 PM, Sean Silva <silvas at purdue.edu> wrote:

> 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.

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.

If you’ll notice the existing comment on the loop is “Process string output to make it nicer…”

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.

-Andy

> On Tue, Nov 12, 2013 at 1:06 PM, Andrew Trick <atrick at apple.com> wrote:
> Author: atrick
> Date: Tue Nov 12 12:06:09 2013
> New Revision: 194496
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=194496&view=rev
> Log:
> GraphViz CFGPrinter: wrap long lines.
> 
> Modified:
>     llvm/trunk/include/llvm/Analysis/CFGPrinter.h
> 
> Modified: llvm/trunk/include/llvm/Analysis/CFGPrinter.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/CFGPrinter.h?rev=194496&r1=194495&r2=194496&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/Analysis/CFGPrinter.h (original)
> +++ llvm/trunk/include/llvm/Analysis/CFGPrinter.h Tue Nov 12 12:06:09 2013
> @@ -46,6 +46,7 @@ struct DOTGraphTraits<const Function*> :
> 
>    static std::string getCompleteNodeLabel(const BasicBlock *Node,
>                                            const Function *) {
> +    enum { MaxColumns = 80 };
>      std::string Str;
>      raw_string_ostream OS(Str);
> 
> @@ -59,16 +60,32 @@ struct DOTGraphTraits<const Function*> :
>      if (OutStr[0] == '\n') OutStr.erase(OutStr.begin());
> 
>      // Process string output to make it nicer...
> -    for (unsigned i = 0; i != OutStr.length(); ++i)
> +    unsigned ColNum = 0;
> +    unsigned LastSpace = 0;
> +    for (unsigned i = 0; i != OutStr.length(); ++i) {
>        if (OutStr[i] == '\n') {                            // Left justify
>          OutStr[i] = '\\';
>          OutStr.insert(OutStr.begin()+i+1, 'l');
> +        ColNum = 0;
> +        LastSpace = 0;
>        } else if (OutStr[i] == ';') {                      // Delete comments!
>          unsigned Idx = OutStr.find('\n', i+1);            // Find end of line
>          OutStr.erase(OutStr.begin()+i, OutStr.begin()+Idx);
>          --i;
> +      } else if (ColNum == MaxColumns) {                  // Wrap lines.
> +        if (LastSpace) {
> +          OutStr.insert(LastSpace, "\\l...");
> +          ColNum = i - LastSpace;
> +          LastSpace = 0;
> +          i += 3; // The loop will advance 'i' again.
> +        }
> +        // Else keep trying to find a space.
>        }
> -
> +      else
> +        ++ColNum;
> +      if (OutStr[i] == ' ')
> +        LastSpace = i;
> +    }
>      return OutStr;
>    }
> 
> 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20131112/47a1c757/attachment.html>


More information about the llvm-commits mailing list