Extracting Basic Blocks/CFG from LLVM/clang on the Backend
I've been beginning to work with LLVM and I'm interested to know if there is a programmatic way to extract the control flow graph and/or basic blocks from LLVM/clang in order to do some analysis on them. Is there a way to hook into the tool cha开发者_运维问答in and pull out this information instead of doing a straight compilation? If not, what are the alternatives?
LLVM supports plugin passes. It would be straight-forward to write a pass to emit whatever data you want in whatever format you want.
However, LLVM has a large suite of analysis and transform passes already. You may be able to use the existing LLVM framework to extract the data you want after running the analysis passes you want.
Take a look at the docs, the code, and then ask more specific questions on the LLVMdev list to get the best answers.
The CFG (Control Flow Graph) is purely part of CLang.
The CFG supports Visitors (see CFG.h) but you might want to ask on CLang dev list if there is a code sample available.
精彩评论