I have been trying to make clang 2.9 output an AST with graphviz using the following:
./clang -cc1 -ast-view smd.c
However it outputs the code on the console and complains that:
Stmt::viewAST is only available in debug builds on systems with Graphviz or gv!
At llvm documentation it is mentioned that /Applications/Graphviz.app/Contents/MacOS/
should be added to path. I did so using export PATH=$PATH:/Applications/Graphviz.app/Contents/MacOS/
but still does not work.
Also on the same documentation it is mentioned that:
Getting this to work requires a small amount of configuration. On Unix systems with X11, install the graphviz toolkit, and make sure 'dot' and 'gv' are in your path. If you are running on Mac OS/X, download and install the Mac OS/X Graphviz program, and add /Applications/Graphviz.app/Contents/MacOS/ (or wherever you install it) to your path. Once in your system and path are set up, rerun the LLVM configure script and rebuild LLVM to enable this functionality.
I am clueless on where is this configuration and rebuild LLVM (All I did was download the llvm+clang 2.9 package and run directly from the folder the commands.
In respect to my graphviz version:
$ dot -v
dot - graphviz version 2.28.0 (20111028.1807)
However the gv
command is not available and I can't seem to find on google where is it supposed to be located or to be obtained.
Any clue on this? The question itself is how to output clang 2.9 to graphviz. I just believe it has to do with this gv that cannot be found on my machine but I might be mislead.
Thank you.
Since I had to go thru some weird details to get this working and from what I saw its not a direct approach for a Mac OS Lion user, here is what I found in case anyone get stuck as much as I did for what seem a simple one line task.
First and before anything, you might want to check if you have graphviz and gv, as mentioned on my original question you will, if you fall under the same situation as I did, have clang complaining at you about graphviz or gv. While graphviz is relatively easy to find just using google, gv didn't seem to me because it was missing its first name on their official website, that is GNU gv.
You should get graphviz installed without much headache, but gv might not. It complains about a dependency called Xaw3d
. Their website contains a not so up to date version (2003) but thats what will do. If you are as unfortunate as me, you will find out the download is broken. Luckily enough a friend pointed me to this website from MIT of someone who had to deal with this so saved me a lot of time. It is very recent (may,2012) at the point I am answering this so it should work for you too. I am posting here what I actually used just in case that page goes down:
Avoid the pkg-config utility
by running:
$ ./configure X11_CFLAGS='-I/usr/X11/include/X11' X11_LIBS='-L/usr/X11/lib -lX11 -lXext -lXmu -lXt'
while inside the ibXaw3d-1.6
directory on your console.
Followed by:
make
sudo make install
make clean
With that done go back and install gv, if it doesnt works change their code that was also bugged for me (lacking few parameters on a line that makes it impossible to get the installation done) as the MIT page mentions:
Change on Scrollbar.c
:
(*swclass->threeD_class.shadowdraw) (w, event, region, FALSE);
to
(*swclass->threeD_class.shadowdraw) (w, event, region, sbw->threeD.relief, FALSE);
On MAC it will also complain about zombie process if the following is not run so just in case as the author also suggests get the configure done this way:
./configure --x-includes=/usr/X11/include/X11 --x-libraries=/usr/X11/lib --enable-SIGCHLD-fallback
And finally gv should be usable if you run $gb whatever.ps
. In case you are wondering, that is one of its use, open .ps if not all of it (I didn't bother looking much on it since it was not the original purpose).
Now if you are still unlucky as I am, running the same thing will not work.
Thanks to Joey (the person on the comment below) and the LLVM mailing list people I found out that I should run the build on debug mode.
Now it seems that if you are downloading the binaries like I originally did for MAC OS it will automatically comes on non debug mode for optimization reasons (10 times faster or so I got on one of the outputs on the console).
If you go to this page and follow 1. to 5. you will get the most recent version already on debug mode following the instructions on that page.
Make sure you open the LLVM/Debug+Accerts/bin/clang
and execute from that clang. The result should open a GUI on gv with the tree.
As you may notice I had to move on to the most recent version. There is a way to compile on debug mode on llvm compile according to llvm getting started. Basically this paragraph says it all:
These builds are enabled with the --enable-optimized option to configure or by specifying ENABLE_OPTIMIZED=1 on the gmake command line. For these builds, the build system will compile the tools and libraries with GCC optimizations enabled and strip debugging information from the libraries and executables it generates. Note that Release Builds are default when using an LLVM distribution.
Although I got some messages that seemed to confirm I successfully compiled 2.9 on debug mode such as:
llvm[0]: * Completed Debug Build
llvm[0]: * Note: Debug build can be 10 times slower than an
llvm[0]: * optimized build. Use make ENABLE_OPTIMIZED=1 to
llvm[0]: * make an optimized build. Alternatively you can
llvm[0]: * configure with --enable-optimized.
doing the same thing (in this case the folder was only called Debug
instead of Debug+Asserts
), however did not work for 2.9 going on the same process. If anyone know why please let me know as I am still interested on 2.9 but all in all, at last for seeing it visually this one works. I still have no clue why it only outputs on gv but not on graphviz as well.