Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Can I use LLVM to convert C++ code to C code?

code convert llvm
0
Posted

Can I use LLVM to convert C++ code to C code?

0

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

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123