如何将IR保存到文件并将其构建为可执行文件? [英] How to save IR to a file and build it to an executable file?
问题描述
现在我使用clang将.c文件构建为.s文件。而且我已经用llvm API修改了IR。但是,现在我无法将修改后的IR保存到文件中。我想使用 LLVMWriteBitcodeToFile,但是找不到 LLVMOpaqueModule的结构;我想使用 WriteBitcodeToFile,它总是显示类型不匹配。而且我还想知道如何将IR文件构建为可执行文件。
Now I use clang build my .c file to .s file. And I have used the llvm API modify the IR. However, now I can't save my modified IR to a file. I want to use "LLVMWriteBitcodeToFile", but I can't find the struct of "LLVMOpaqueModule"; I want to use "WriteBitcodeToFile", it always show me "type mismatch". And I also want to know how to build an IR file to a executable file.
接下来是保存模块的两种方法:
Next are two methods I use to save a module:
1,首先使用WriteBitcodeToFile
1、First use WriteBitcodeToFile
bool unbuffered = false;
llvm::raw_ostream ro(unbuffered);
WriteBitcodeToFile(m, ro);
2,第二次使用LLVMWriteBitcodeToFile
2、Second use LLVMWriteBitcodeToFile
const char *Path = "hello2.s";
int ans = LLVMWriteBitcodeToFile(m, Path);
注意:m是模块实例的一个点
note: m is a point of Module instance
推荐答案
- 要将IR保存到文件中,请参见以下问题的答案:将模块写入.bc位代码文件
- 要将IR编译为目标文件,请查看
llc
工具,并遵循其main
函数的作用。
- For saving the IR into a file, see the answer to this question: writing module to .bc bitcode file
- For compiling IR to an object file, look at the
llc
tool and follow what itsmain
function does.
这篇关于如何将IR保存到文件并将其构建为可执行文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!