Automatically generate flowcharts out of C++ code
Solution 1
clang/llvm
can generate graphviz dot files.
Example:
clang -S -emit-llvm -o hello.ll hello.cpp
opt hello.ll -dot-cfg -o hello.dot
This will output several .dot
files, one for each function defined in hello.cpp
.
You can also generate dominance graph, post dominance graph and more (see here).
After you have your .dot
files you can use dot
to convert it to a .png
file.
The .dot
file itself contains only the structure of the graph, so the output of dot
should be highly configurable (but I am not really familiar with it).
Solution 2
Use Enterprise Architect tool.
You can generate sequence diagram while you debug the code.
Demonstration: Online Demo
Note:- This works with C++ code as well. Just use Native debugger.
Related videos on Youtube
Konstantin
Updated on July 12, 2022Comments
-
Konstantin almost 2 years
I need to automatically construct flowcharts out of C++ code, ideally one flowchart per source file. Is there any tool (preferably C++/Python and either open-sourced or highly configurable - so I may change the look) that I can use to create flowcharts?
-
user1I am aware of Enterprise Architect sparxsystems.com/enterprise_architect_user_guide/9.2/… can generate sequence diagrams in the background while you debug your code. Once you are finished debugging, it asks you save the generated diagram. All functions where you have set the break-points and those are actually hit during debugging session are covered in the generated sequence diagram.
-
-
Konstantin over 9 yearsThank you for the suggestion. Is it configurable, can I change the appearance of charts there? The resulting chart in demo you mentioned is kind of stange...
-
Konstantin over 9 yearsIt seems that cflow creates call graphs but I need flowcharts (how algorithm works)
-
JorenHeit over 9 yearsAh right. Yeah it's analyzing your source statically, so if you want to know how your program actually flows at runtime, it won't help you.
-
user1 over 9 yearsNo, those are sequence diagrams. Sequence diagrams or Activity diagrams are good for object oriented code base, and your question is on C++. If you want flowcharts specifically, then use Code rocket designer. rapidqualitysystems.com
-
Konstantin over 9 yearsThank you for the suggestion! .dot files are indeed great for the task I have.