LLVM中是否有带有命名参数的FunctionType? [英] Is there a FunctionType with named arguments in LLVM?

查看:276
本文介绍了LLVM中是否有带有命名参数的FunctionType?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在LLVM中,函数如下所示:

In LLVM, a function looks like this:

define i32 @foo(i32, i32)

lli时,我注意到这也被接受:

By playing with lli, I noticed that this is also accepted:

define i32 @foo(i32 %first-arg, i32 %second-arg)

,然后可以从给定名称访问参数.

and then the arguments are accessible from the given names.

我应该如何使用C ++ API生成具有命名参数的函数?我检查了文档,似乎没有办法为FunctionType::get提供名称,因为它的第二个参数的类型为ArrayRef<Type *>,其中没有名称字段(或Twine).

How should I generate such a function with named arguments using the C++ API? I checked the documentation and it seems that there's no way to supply names to FunctionType::get as its second argument is of type ArrayRef<Type *> where there isn't a field for name (or Twine).

推荐答案

名称不是该类型的一部分.就类型而言,每个i32都是相同的.但是,就像可以设置函数名称一样,您可以在不影响类型的情况下设置函数参数的名称.我从LLVM的生代版本抄写了一个for循环,并添加了setName()调用,该方法有效:

The names aren't part of the type. In terms of types, each and every i32 is the same. However, you can set a function argument's name without affecting the type, just like you can set the function's name. I cribbed a for loop from an mezozoic version of LLVM and added a setName() call, and that worked:

for (Function::arg_iterator a = foo->arg_begin(), ae = foo->arg_end();
     a != ae;
     ++a) {
  …
  a->setName(bar->name);
  …
}

我认为现在有一种更漂亮的方式来编写该循环.

I assume there's a prettier way to write that loop now.

这篇关于LLVM中是否有带有命名参数的FunctionType?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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