Can I use LLVM to convert C++ code to C code?
Yes, you can use LLVM to convert code from any language LLVM supports to C. Note that the generated C code will be very low level (all loops are lowered to gotos, etc) and not very pretty (comments are stripped, original source formatting is totally lost, variables are renamed, expressions are regrouped), so this may not be what you’re looking for. Also, there are several limitations noted below. Use commands like this: • Compile your program as normal with llvm-g++: % llvm-g++ x.cpp -o program or: % llvm-g++ a.cpp -c % llvm-g++ b.cpp -c % llvm-g++ a.o b.o -o program With llvm-gcc3, this will generate program and program.bc. The .bc file is the LLVM version of the program all linked together. • Convert the LLVM code to C code, using the LLC tool with the C backend: % llc -march=c program.bc -o program.c • Finally, compile the C file: % cc x.c Using LLVM does not eliminate the need for C++ library support. If you use the llvm-g++ front-end, the generated code will depend on g++’s C++ su