I have LLVM IR code in text format. What I wanna do is to be able to parse it and modify that code. Is there an API which can help in parsing the LLVM IR code? What libraries should I have in my system? At this moment I have clang
compiler installed as well LLVM, as I can use commands such as llc
, opt
and llvm-link
.
Asked
Active
Viewed 3,133 times
5

Anton Korobeynikov
- 9,074
- 25
- 28

pythonic
- 20,589
- 43
- 136
- 219
1 Answers
6
LLVM is primarily a C++ library. It has all the tools you can imagine to parse, manipulate and produce IR in both textual and bitcode (binary) formats.
To get started, take a look at the llvm::ParseIRFile
function, defined in header include/llvm/Support/IRReader.h
.
The best way to proceed would be to download the LLVM source code and build it, following these instructions. It's then easy to write your own code that uses the LLVM libraries.

Eli Bendersky
- 263,248
- 89
- 350
- 412
-
I have llvm 2.7. I can use clang but there is no clang++. Any idea how to add clang++ so I can start using the C++ libraries that you mention? – pythonic Feb 06 '12 at 13:09
-
@user1018562: you can build LLVM with `gcc`, no real need to have `clang` installed. However, you can also install clang 3.0 which is able to build LLVM itself. See http://clang.llvm.org/get_started.html – Eli Bendersky Feb 06 '12 at 13:10
-
@user1018562: and by the way, `clang++` is usually just a soft link to `clang` – Eli Bendersky Feb 06 '12 at 13:12
-
@user1018562: see also my answer here - http://stackoverflow.com/questions/9167347/parsing-and-modifying-llvm-ir-code – Eli Bendersky Feb 07 '12 at 06:13