Is there a FunctionType with named arguments in LLVM?

允我心安 提交于 2020-01-25 08:11:17

问题


In LLVM, a function looks like this:

define i32 @foo(i32, i32)

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.

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).


回答1:


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.



来源:https://stackoverflow.com/questions/58956530/is-there-a-functiontype-with-named-arguments-in-llvm

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