如何使铛编译成LLVM IR [英] How to make clang compile to llvm IR

查看:126
本文介绍了如何使铛编译成LLVM IR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要铛编译我的 C / C ++ code到 LLVM 字节code,而不是二进制可执行文件。我怎样才能做到这一点?如果我得到的 LLVM 字节code,我怎样才能把它进一步把它编译成二进制可执行文件。

I want clang to compile my C/C++ code to LLVM bytecode rather than binary executable. How can I achieve that? And if I get the LLVM bytecode, how can I take it to further compile it to binary executable.

基本上我想编译成二进制可执行文件之前加一些我自己的code到 LLVM 字节code的。

Basically I want to add some of my own code to the LLVM bytecode before compiling to binary executable.

推荐答案

由于一些C / C ++文件 foo.c的

Given some C/C++ file foo.c:

> clang -S -emit-llvm foo.c

生成 foo.ll 这是一个LLVM IR文件。

Produces foo.ll which is an LLVM IR file.

-emit-LLVM 选项也可以传递到编译器的前端直接,而不是驱动程序通过 -cc1 <手段/ code>:

The -emit-llvm option can also be passed to the compiler front-end directly, and not the driver by means of -cc1:

> clang -cc1 foo.c -emit-llvm

生成 foo.ll 通过IR。 -cc1 补充说像 -ast打印一些很酷的选项。看看 -cc1 --help 了解更多信息。

Produces foo.ll with the IR. -cc1 adds some cool options like -ast-print. Check out -cc1 --help for more details.

要进一步LLVM编译IR到装配,使用有限责任公司工具:

To compile LLVM IR further to assembly, use the llc tool:

> llc foo.ll

生成 foo.s 与组件(默认为你运行它的计算机体系结构)。 有限责任公司是LLVM工具之一 - 这里是它的文档

Produces foo.s with assembly (defaulting to the machine architecture you run it on). llc is one of the LLVM tools - here is its documentation.

这篇关于如何使铛编译成LLVM IR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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