LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 801 - Should share code for viewing dot graphs
Summary: Should share code for viewing dot graphs
Status: RESOLVED FIXED
Alias: None
Product: libraries
Classification: Unclassified
Component: Support Libraries (show other bugs)
Version: trunk
Hardware: All All
: P enhancement
Assignee: Reid Spencer
URL:
Keywords: code-cleanup
Depends on:
Blocks:
 
Reported: 2006-06-05 12:22 PDT by Chris Lattner
Modified: 2010-02-22 12:51 PST (History)
2 users (show)

See Also:
Fixed By Commit(s):


Attachments
Code cleanup (17.72 KB, patch)
2006-06-05 13:23 PDT, Anton Korobeynikov
Details
Refactored code (19.53 KB, patch)
2006-06-10 13:13 PDT, Anton Korobeynikov
Details
Patch over latest CVS snapshot (18.84 KB, patch)
2006-06-27 03:08 PDT, Anton Korobeynikov
Details
cvs diff -u output (17 bytes, patch)
2006-06-27 10:24 PDT, Anton Korobeynikov
Details
cvs diff -u output (15.98 KB, patch)
2006-06-27 10:28 PDT, Anton Korobeynikov
Details
missed GraphWriter.cpp (2.44 KB, patch)
2006-06-27 10:29 PDT, Anton Korobeynikov
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Lattner 2006-06-05 12:22:41 PDT
There are now several copies of the code for viewing a dot graph with dot&gv/dotty/Graphviz.  This 
should all be shared in one place in libsupport.

-Chris
Comment 1 Chris Lattner 2006-06-05 12:23:36 PDT
Specifically, see all the files that implementing PR798 had to change :(
Comment 2 Reid Spencer 2006-06-05 12:28:09 PDT
We need to check to make sure all the usages are the same and if not make sure
the shared code can handle the variant usages via arguments to the function.
Comment 3 Anton Korobeynikov 2006-06-05 12:34:22 PDT
All files actually use WriteGraph() call to output graph to stream. I'll
refactor code.
Comment 4 Anton Korobeynikov 2006-06-05 13:23:09 PDT
Created attachment 336 [details]
Code cleanup

Moved graph printing to Support/GraphWriter.h, fixed the correspondent calls.
Comment 5 Reid Spencer 2006-06-05 13:48:11 PDT
Anton,

The patch looks fine, except: I don't like having ViewGraph implementation in a
header file. This is going to get replicated in all those other files which
doesn't buy us anything for code size.  I understand the need to put it in a .h
because of the template.  But, the template doesn't use GraphType& G except in
the call to WriteGraph.

So, could you please refactor this so that the common parts are put in separate
functions in a .cpp file. Here's what I'd like to see:

1. Make an overload of WriteGraph that takes the same arguments as the ViewGraph
   function (GraphType, Name, Title). This would create its own temporary file
   and return that file name as its result (sys::Path). This is the first part
   of your patch (up to the #ifdef).

2. Create a new function, DisplayGraph, which takes a sys::Path that is presumed
   to be the postscript file to view. This function incorporates the second 
   part of your patch (everything after #ifdef).

3. Reduce the ViewGraph template to just:

template<typename GraphType>
void ViewGraph(const GraphType& G, 
               const std::string& Name, 
               const std::string& Title = "") {
  sys::Path path = WriteGraph(G,Name,Title)
  if (path.empty())
    return;
  DisplayGraph(path)
}

Reid.
Comment 6 Chris Lattner 2006-06-05 14:12:44 PDT
Another cleanup that might be required before this can be done: we should make the GraphWriter 
interface not be a big template with traits to allow customization.  Instead we should use inheritance, and 
subclassing to customize writing.  This would allow the huge template to come out of the header, and 
would reduce code size.

-Chris
Comment 7 Anton Korobeynikov 2006-06-10 13:13:35 PDT
Created attachment 342 [details]
Refactored code

Reid, this patch implements the functionality you've mentioned.
Comment 8 Reid Spencer 2006-06-16 15:06:36 PDT
Mine.
Comment 9 Reid Spencer 2006-06-17 09:41:36 PDT
The patch did not apply correctly. In particular,
lib/Analysis/DataStructure/Pringer.cpp failed. It looks like this code has
changed since the patch. 

Could you update to CVS head, fix any merge/conflict problems and then provide a
new patch. I'll try to apply it as soon as possible to avoid this problem.

Thanks,

Reid.
Comment 10 Reid Spencer 2006-06-23 06:56:49 PDT
Anton,

Any updates on this bug?

Reid.
Comment 11 Anton Korobeynikov 2006-06-23 08:22:40 PDT
Reid!

As you know already,  I'm in the process of migration to new system. I'm
managing to start working on this issue on monday.
Comment 12 Anton Korobeynikov 2006-06-27 03:08:32 PDT
Created attachment 352 [details]
Patch over latest CVS snapshot

Reid, 

this is the updated patch. Hope it will apply fine.
Comment 13 Anton Korobeynikov 2006-06-27 10:24:00 PDT
Created attachment 353 [details]
cvs diff -u output

Due to unknown reason new file lib/Support/GraphWriter.cpp wasn't included to
cvs diff output ("-N" switch was used). I'll upload it separately.
Comment 14 Anton Korobeynikov 2006-06-27 10:28:18 PDT
Created attachment 354 [details]
cvs diff -u output
Comment 15 Anton Korobeynikov 2006-06-27 10:29:33 PDT
Created attachment 355 [details]
missed GraphWriter.cpp
Comment 16 Reid Spencer 2006-06-27 11:37:31 PDT
The new patches applied correctly. I'm building and checking to make sure it
breaks nothing. If that works, I'll commit the patches.

Thanks, Anton.