使用Clang将C ++转换为C代码 [英] Use Clang to convert C++ to C code

查看:92
本文介绍了使用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.

这篇关于使用Clang将C ++转换为C代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆