[LLVMdev] [LLVM-Clang CFG] - generating CFG of a C program and llvm iterators

Duncan Sands baldrick at free.fr
Fri Sep 28 08:45:23 PDT 2012


Hi Rajendra, you want to get hold of the LLVM IR produced by clang (use the
-flto option to have clang produce LLVM IR), and pipe it to the "opt" command
line tool, into which you will have loaded your logic as a plugin pass.  So I
suggest you read about writing plugins for opt.

Ciao, Duncan.

> Hi,
>
> I want to generate Control Flow Graph (in memory CFG object) of any
> given C program and then iterate over this CFG (all function, basic
> blocks and instructions) using llvm iterators.
>
> I can see text output of CFG on screen, using following command:
> `clang -cc1 -Idummyh -analyze -analyzer-checker=debug.DumpCFG hello/hello.c'
> where dummyh has en empty stdio.h to remove this error:
> `fatal error: 'stdio.h' file not found'
>
> I see CFG.h and CFG.cpp that clang uses and have seen some docs on
> ModulePass, FunctionPass, BasicBlockPass, etc. But I have not figured
> out how to put together things to generate CFG and then write iterators.
>
> All help is much appreciated.
>
> Thank you.
>
> Rajendra
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev




More information about the llvm-dev mailing list