MacHiry
MacHiry

Reputation: 13

Writing Complete analysis using llvm-clang


I have following tasks that I need to do as part of my research idea:
1. Parse the C file(s) at hand to get llvm-IR.
2. Do analysis on the IR. Possibly add and remove some instructions or BB
3. Emit either x86 executable or C (need to decide later)

I think this is quite common task for any one writing analysis on C, I want to do all these tasks in C/C++ (as most of our research code is in C/C++). I googled a lot, although lot of documentation is available on Tasks 2 and 3, but less is available on Task 1, any idea on this would be really helpful.

I want to hook these tasks as a pipe line, any suggestion for this are also welcome.

-Thanks

Upvotes: 0

Views: 256

Answers (1)

Oak
Oak

Reputation: 26898

(1) can be done by using Clang to emit LLVM IR.

(2) can be done by writing your own LLVM pass, and later invoking it (with any other passes you're interested in) via LLVM's opt tool.

(3) (to x86) can be done by LLVM's llc tool.

All of these are also accessible as APIs, not only command-line tools, making it possible to incorporate into your pipe.

Upvotes: 1

Related Questions