Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display CFG from llvm in xvcg

There is -view-cfg option (doc) in llvm's opt program, which enables me to view the Control Flow Graph via dot program. But the CFG in too big to be rendered as postscript from dot. I know that there is the xvcg utiity capable of displaying complex graphs, including CFG (and its man says "VCG tool - visualization of compiler graphs").

So, how can I output llvm's CFG in xvcg format?

like image 432
osgx Avatar asked Jun 12 '13 09:06

osgx


1 Answers

Directly generating .vcg files from LLVM will require heavy modifications to GraphWriter, which is very GraphViz-specific. Instead, it seems to me that the most straightforward solution will be to save a dot file (via -dot-cfg instead of -view-cfg) and then convert it, using something like Graph-Easy. From its documentation (emphasis mine):

It understands the following formats as input:

  • Graph::Easy http://bloodgate.com/perl/graph/manual/
  • DOT http://www.graphviz.org/
  • VCG http://rw4.cs.uni-sb.de/~sander/html/gsvcg1.html
  • GDL http://www.aisee.com/

The output can be a dump of the graph in one of the following formats:

  • Graph::Easy http://bloodgate.com/perl/graph/manual/
  • DOT http://www.graphviz.org/
  • VCG http://rw4.cs.uni-sb.de/~sander/html/gsvcg1.html
  • GDL http://www.aisee.com/
  • GraphML http://graphml.graphdrawing.org/

By the way, if you want to get a lot of graphs and prefer to see them before generating a lot of dot files, consider using a dot viewer which also allows you to save the file, such as my fork of xdot.py - or better yet, modify xdot.py so that it knows how to save in .vcg format itself, using Graph-Easy.

Another alternative to Graph-Easy appears to be dot2gdl.

like image 154
Oak Avatar answered Sep 23 '22 05:09

Oak