[LLVMdev] Re: C to C++
Chris Lattner
sabre at nondot.org
Mon Jun 28 15:25:01 PDT 2004
On Mon, 28 Jun 2004, Surupa Biswas wrote:
> I am at the University of Maryland, College Park, working with Prof.
> Rajeev Barua. Someone just told me that LLVM includes a C++ to C
> source-to-source compiler. I was hoping you could tell me something about
> that - I am trying to run some C++ benchmarks on the Motorola Mcore
> simulator and my compiler only has a C front-end.
Yup, LLVM can do that and more. Use commands like this:
#1. Compile your program as normal with llvmg++
$ llvmg++ x.cpp -o program
or:
llvmg++ a.cpp -c
llvmg++ b.cpp -c
llvmg++ a.o b.o -o program
This will generate program and program.bc. The .bc file is the LLVM
version of the program all linked together.
#2. Convert the LLVM code to C code, using the LLC tool with the C
backend:
$ llc -march=c program.bc -o program.c
#3. Then compile the c file:
$ cc x.c
Note that, by default, the C backend does not support exception handling.
If you want/need it for a certain program, you can enable it by passing
"-enable-correct-eh-support" to the llc program. The resultant code will
use setjmp/longjmp to implement exception support that is correct but
relatively slow.
LLVM will eventually also have Java and other front-ends, which will allow
you to convert java code to C as well.
-Chris
--
http://llvm.cs.uiuc.edu/
http://www.nondot.org/~sabre/Projects/
More information about the llvm-dev
mailing list