在 LLVM 中,如何 insert/declare 具有可变参数数量的函数?
In LLVM, how to insert/declare a function with variable number of arguments?
我正在尝试将调用的函数提取到另一个模块。如果函数有定义数量的参数,我就成功了。
// Create the arguments vector from the my argument list
SmallVector<Type *, sizeof(MyArgs)> ArgTys;
for (Value *V : MyArgs)
ArgTys.push_back(V->getType());
// Just get a void return type
Type *RetTy = Type::getVoidTy(TempContext);
// Create a new function with MyArgs as arguments
Constant *C = TempM->getOrInsertFunction(
"TempF", FunctionType::get(RetTy, ArgTys, false));
但是如果函数的参数数量可变,getOrInsertFunction
只会添加我能够在 ArgTys
.
中使用 MyArgs
捕获的参数
如何验证源函数是否具有可变数量的参数?
如何使用 getOrInserFunction 来声明参数数量可变的函数?
根据 documentation:
您可以通过
声明可变参数函数
FunctionType::get(RetTy, ArgTys, true);
(因此,在您的情况下,更改 "TempF" 函数的 false
参数。)
您可以通过方法
查询函数是否正在使用可变参数列表
bool isVarArg() const
我正在尝试将调用的函数提取到另一个模块。如果函数有定义数量的参数,我就成功了。
// Create the arguments vector from the my argument list
SmallVector<Type *, sizeof(MyArgs)> ArgTys;
for (Value *V : MyArgs)
ArgTys.push_back(V->getType());
// Just get a void return type
Type *RetTy = Type::getVoidTy(TempContext);
// Create a new function with MyArgs as arguments
Constant *C = TempM->getOrInsertFunction(
"TempF", FunctionType::get(RetTy, ArgTys, false));
但是如果函数的参数数量可变,getOrInsertFunction
只会添加我能够在 ArgTys
.
MyArgs
捕获的参数
如何验证源函数是否具有可变数量的参数?
如何使用 getOrInserFunction 来声明参数数量可变的函数?
根据 documentation:
您可以通过
声明可变参数函数FunctionType::get(RetTy, ArgTys, true);
(因此,在您的情况下,更改 "TempF" 函数的 false
参数。)
您可以通过方法
查询函数是否正在使用可变参数列表bool isVarArg() const