Many years ago I decided that I liked the idea of UML. The main drawback was that it imposed some pretty strict restraints when you were only trying to get the initial ideas presented. It failed for what I was trying to accomplish, namely loose specification of a piece of software before I began writing it. I tried to use it as a sort of "scratch pad" to flesh out my ideas so I could come up with the general approach. While it did not fit this role very well, the documentation it presented made it easy to refer to when looking back on things I had done. There was no denying the benefits of good documentation.
There are several tools out there that will automatically generate documentation about your code for you. Doxygen is one of my personal favorites, generating multiple diagrams as well as the full documentation you add alongside your code. However, it only provides a limited set of diagrams and graphs (dependency graphs, inheritance diagrams and collaboration diagrams). It is designed around the idea of extracting limited information from the code and creating useful documentation based on that information.
One of the often overlooked UML diagrams is the Activity Diagram. The usefulness of activity diagrams is quickly lost if they are not constantly maintained with every code change. They describe the actual behavior of a system, easily representing complex behaviors in a straightforward manner. While it would be great if they could be generated by Doxygen, it requires semantic knowledge of language internals to be able to automatically generate the diagrams. Doxygen does not have the framework in place for the level of analysis required.
Introducing RocketShip
RocketShip was created as a way to extract more useful documentation from the actual code that has been written. It will currently generate a directed graph that is very similar to UML activity diagrams from the code itself. It is implemented as an analysis pass for LLVM's optimizer. This allows it to be used to automatically generate the corresponding graphs every time the code is compiled (providing you load the RocketShip module and pass the -rocketship flag to the optimizer).
Key Features
Language Independent - RocketShip operates on the LLVM bitcode passed to the optimizer, so any language that targets LLVM is supported.
Simple Output Format - RocketShip outputs dot files suitable for use with Graphviz, not some custom format that requires a special tool to use.
Fast - RocketShip processes each instruction in the bitcode only once, and requires only one pass to output the dot files.
Useful Diagrams - Rather than simply provide the full graph of the instructions and opcodes present in the bitcode, RocketShip combines instructions and condenses the graph to closely mimic the structure of the original source code automatically.
Current Limitations
C++ Support - Due to the way in which names are mangled in C++, RocketShip does not generate useful graphs for code that was originally in C++. This is at the top of the todo list.
Labels - LLVM bitcode uses labels to indicate jumps between blocks. These labels don't exist within the code but are currently used within the graph.
Variable Names - Variable names are not fully resolved, occasionally having _addr or an integer appended to them. This is due to how they are represented in the bitcode but is on the priority todo list.
Output - The dot files are output in the directory the optimizer is invoked from and only indicate the name of the function. They should be placed somewhere more meaningful instead.
Only tested against C and C++ - I have not tested against other languages that target LLVM, but nearly all languages should result in bitcode that is similar to C or C++.
Release
RocketShip is available at http://github.com/ismarc/RocketShip. As I have not decided on a license yet, you are free to download and use the software for evaluation, but please refrain from distribution. Once I have decided on a license, the repository will be updated (and the license will be an Open Source license, I just wanted to make sure the source was available before I finished weighing the pros of each one).
Example
What new product would be complete without a demonstration of capabilities? Rather than a contrived set of code to generate a graph that looks wonderful, I have been testing RocketShip against code I had laying around from working on Project Euler problems. Below is the source code for the function, the assembly representation of the bitcode and the subsequent graph that was generated automatically.