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

Sean Silva silvas at purdue.edu
Tue Nov 12 18:26:34 PST 2013


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.


-- Sean Silva


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/332c6a48/attachment.html>


More information about the llvm-commits mailing list