How to parse LLVM IR

I have LLVM IR code in text format. I want to do this in order to parse it and change this code. Is there an API that can help in analyzing LLVM IR code? What libraries should I have in my system? At this point, I have the clang compiler as well as LLVM, as I can use commands like llc , opt and llvm-link .

+4
source share
1 answer

LLVM is primarily a C ++ library. It has all the tools that you can imagine to analyze, manipulate and create IR in both text and bit (binary) formats.

To get started, take a look at the llvm::ParseIRFile function defined in the include/llvm/Support/IRReader.h .

The best way to continue is to download the LLVM source code and create it by following these instructions . Then it's easy to write your own code that uses the LLVM libraries.

+5
source

Source: https://habr.com/ru/post/1395009/


All Articles