使用 Clang 将 C++ 转换为 C 代码
我知道llvm
可以用来把c++转成c代码.我想知道 clang
是否可以做同样的事情(看到 clang
是从 llvm
派生的).
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
).
那么我可以使用clang
将c++代码转换成c代码吗?
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 是一家微控制器制造商,不生产 c++ 编译器,但为他们的大多数产品生产 c 编译器.我想用 c++ 编写,然后作为构建过程的一部分,将 c++ 代码转换为临时 c 文件,然后将其输入 PIC 编译器,中提琴我已经为 PIC micro 编写了 c++ 代码.
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.
推荐答案
Clang 可以读取 C++ 并发出 LLVM IR.您似乎知道 LLVM 可以读取 IR 并发出 C(来自您自己的链接:http://llvm.org/releases/3.1/docs/FAQ.html#translatecxx).所以 Clang 不能直接发出 C,但它可以发出 LLVM IR,然后你转身转换为 C.两步,Clang 就是其中之一.
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.
相关文章