Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use Clang to convert C++ to C code

I know that llvm can be used to convert c++ into c code. I was wondering if clang could do the same thing (seeing as clang was derived from llvm).

So can I use clang to convert c++ code into c code?

If you want to know why I want to do this here is my scenario:

PIC, which is a micro controller manufacturer, does not make c++ compilers, but does make c compilers for most of their products. I want to write in c++ and then as part of my build process, convert the c++ code into a temporary c file, which is then fed into the PIC compiler, and viola I have written c++ code for a PIC micro.

like image 983
DarthRubik Avatar asked May 06 '16 22:05

DarthRubik


1 Answers

Clang can read C++ and emit LLVM IR. You seem to be aware that LLVM can read IR and emit C (from your own link: http://llvm.org/releases/3.1/docs/FAQ.html#translatecxx). So Clang cannot directly emit C, but it can emit LLVM IR which you then turn around and convert to C. Two steps, and Clang is one of them.

like image 66
John Zwinck Avatar answered Oct 01 '22 15:10

John Zwinck