Notes on LLVM: getting started with generating Control Flow Graph using LLVM

This is a post with my notes on generating cfg for an input program using LLVM. It also provides basic instructions on using clang and opt to run an existing llvm pass.

  • As a start, install llvm following the detailed tutorial outlined here
  • To compile the code into llvm,  we need to use the compiler clang.
  • Run optimization passes on the code using “opt command”
    • I used the following command to generate the a cfg for the hello.c shown in the previous tutorial
      • clang -emit-llvm hello.c -c -o hello.bc
      • opt -dot-cfg-only hello.bc  (a cfg.main.dot file was generated)
      • use Graphviz ( http://www.graphviz.org) to show the graph of the output file
Advertisements
This entry was posted in Programming Language. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s