在 LLVM 中,如何插入/声明具有可变参数数量的函数

In LLVM, how to insert/declare a function with variable number of arguments?

本文关键字:声明 变参 数数 函数 LLVM 何插入 插入      更新时间:2023-10-16

我正在尝试将调用的函数提取到另一个模块。如果函数具有定义数量的参数,我就成功了。

    // 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声明具有可变参数数量的函数?

根据文档:

  1. 您可以通过以下方式声明变量参数函数

    FunctionType::get(RetTy, ArgTys, true);

(因此,在您的情况下,请更改"TempF"函数的false参数。

  1. 您可以查询函数是否正在使用带有该方法的变量参数列表

    bool isVarArg() const