How to emit LLVM-IR from Cargo

我的未来我决定 提交于 2019-12-05 01:05:00
Jacob

There is cargo rustc to pass arbitrary compiler flags through Cargo to rustc. So I think:

cargo rustc -- --emit=llvm-ir

is what you want!

EDIT: You should use Jacob's answer instead; a lot easier and less hacky.

Build the project with cargo normally but add on the -v flag to show verbose output. The command will have a result like this:

casey@casey-ubuntu:~/Documents/project$ cargo build -v
   Fresh aster v0.22.1
   Fresh num-traits v0.1.34
   Fresh itoa v0.1.1
   ...
Compiling project v0.1.0 (file:///home/casey/Documents/project)
 Running `rustc src/main.rs --crate-name ...`
Finished debug [unoptimized + debuginfo] target(s) in 3.54 secs

If the command produces no output, make a change somewhere in your project code to trick the compiler into rebuilding it, since it will only rebuild if it detects a change in one of the files.

Copy the rustc command from inside the ` markers on the line starting with "Running `rustc..." and append --emit=llvm-ir to it.

This will produce a .ll file in your /target/debug folder.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!