C++ to C?

What command and options should be used to convert C++ to C?

Thanks

This works usually:
llvm-g++ -O2 -c x.cpp -emit-llvm -o - | llc -march=c

Or:
llvm-g++ -O2 -c x.cpp -emit-llvm -o x.bc
llc x.bc -march=c -o x.cbe.c

However the resulting C file is not meant to be human-readable (or
understandable).
What do you need the C++ -> C conversion for?

Best regards,
--Edwin

Try this:

llvm-gcc -c -O3 -emit-llvm file.cpp -o - | llc -march=c -o -

It should spray C code to standard out.

Ciao,

Duncan.

Bear in mind that if you use features from the C++ library, you are still going to need a C++ library.
llvm does not try to translate iostream into stdio calls or anything like that.


Hi Dale,

Thank you for your comments. (BTW, I’m here in San Jose - I see you’re at Apple).

I’m simply looking for tool that will accept C/C++ source and generate machine code for a virtual machine, the ultimate goal being to use the system as a teaching tool.

Any suggestions would be appreciated.

Thanks,
M. McDonnell


— On Sat, 10/11/08, Dale Johannesen dalej@apple.com wrote:



> From: Dale Johannesen dalej@apple.com
> Subject: Re: [LLVMdev] C++ to C?
> To: “LLVM Developers Mailing List” llvmdev@cs.uiuc.edu
> Cc: “Dale Johannesen” dalej@apple.com, “Michael” MichaelDMcDonnell@yahoo.com
> Date: Saturday, October 11, 2008, 12:33 PM
>
> <br>> On Oct 11, 2008, at 12:49 AM, Duncan Sands wrote:<br>> <br>> > On Friday 10 October 2008 20:29:49 Michael wrote:<br>> >> What command and options should be used to convert C++ to C?<br>> ><br>> > Try this:<br>> ><br>> > llvm-gcc -c -O3 -emit-llvm file.cpp -o - | llc -march=c -o -<br>> ><br>> > It should spray C code to standard out.<br>> <br>> Bear in mind that if you use features from the C++ library, you are <br>> still going to need a C++ library.<br>> llvm does not try to translate iostream into stdio calls or anything <br>> like that.<br>> <br>>

|