Automatically generate flowcharts out of C++ code

10,027

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

Solution 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.

Share:
10,027

Related videos on Youtube

Konstantin
Author by

Konstantin

Updated on July 12, 2022

Comments

  • Konstantin
    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?

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

    • user1
      user1
      I 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
    Konstantin over 9 years
    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
    Konstantin over 9 years
    It seems that cflow creates call graphs but I need flowcharts (how algorithm works)
  • JorenHeit
    JorenHeit over 9 years
    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.
  • user1
    user1 over 9 years
    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. rapidqualitysystems.com
  • Konstantin
    Konstantin over 9 years
    Thank you for the suggestion! .dot files are indeed great for the task I have.