7

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?

http://www.faqs.org/patents/img/20110088010_08.png

Konstantin
  • 2,361
  • 3
  • 36
  • 51
  • 1
    I am aware of Enterprise Architect http://www.sparxsystems.com/enterprise_architect_user_guide/9.2/execution_analyzer/generating_sequence_diagram.html 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. – user1 Dec 05 '14 at 06:47
  • So EA gives a *dynamic* analysis, not a static analysis. – Ira Baxter Oct 07 '16 at 19:42

3 Answers3

4

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 .dotfiles 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).

sbabbi
  • 10,402
  • 2
  • 24
  • 51
2

Use Enterprise Architect tool.

http://www.sparxsystems.com/enterprise_architect_user_guide/9.2/execution_analyzer/generating_sequence_diagram.html

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.

user1
  • 3,763
  • 7
  • 29
  • 60
  • Thank 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 Dec 05 '14 at 08:25
  • No, 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. http://www.rapidqualitysystems.com/ – user1 Dec 05 '14 at 08:52
0

If you don't mind plaintext output, 'cflow' will do the job. It's in the repositories of at least Debian, and probably most Linux distro's.

JorenHeit
  • 3,335
  • 2
  • 16
  • 26
  • It seems that cflow creates call graphs but I need flowcharts (how algorithm works) – Konstantin Dec 05 '14 at 08:28
  • Ah 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. – JorenHeit Dec 05 '14 at 08:49