LLVM IR:如何在另一个.ll文件中调用函数 [英] LLVM IR: How to call a function in another .ll file

查看:433
本文介绍了LLVM IR:如何在另一个.ll文件中调用函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写LLVM IR代码,可以在另一个.ll文件中调用一个函数吗?

I am writing LLVM IR code, can I call a function in another .ll file?

例如: 在一个.ll文件中,有一个函数foo();. 我可以在b.ll中使用此功能,就像调用foo一样吗?如果是这样,我如何添加a.ll

For example: In a.ll file, there is a function foo(); Can I use this function in b.ll, like just call foo? If so, how can I include a.ll

谢谢

推荐答案

您需要在调用它的ll文件中添加函数foo的声明,然后像往常一样转换链接ll文件以生成可执行文件

You need to add declaration of function foo in the ll file in which you are calling it, then as usual convert link ll files to generate executable

 llvm-link a.ll b.ll -o a.out

示例 a.ll

declare i32 @foo(i32)

define i32 @main() {
    start:
    %0 = call i32 @foo(i32 0)
    ret i32 %0
}

b.ll

define i32 @foo(i32) {
    start:
    ret i32 %0
}

这篇关于LLVM IR:如何在另一个.ll文件中调用函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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