在LLVM中创建新类型(特别是指向函数类型的指针)

在LLVM中创建新类型(特别是指向函数类型的指针),llvm,Llvm,我想创建以下类型 void (i8*)* 我尝试使用Type类来创建上述类型,但没有找到任何直接方法来执行此操作。 有人请建议我创建上述类型的方法。 提前感谢。如果您的意思是i8**(指针指向i8),那么: 如果您需要一个指向函数的指针,该函数不返回任何内容,并接受i8*,则: // This creates the i8* type PointerType* PointerTy = PointerType::get(IntegerType::get(mod->getContext(

我想创建以下类型

  void (i8*)*
我尝试使用Type类来创建上述类型,但没有找到任何直接方法来执行此操作。
有人请建议我创建上述类型的方法。

提前感谢。

如果您的意思是
i8**
(指针指向
i8
),那么:

如果您需要一个指向函数的指针,该函数不返回任何内容,并接受
i8*
,则:

// This creates the i8* type
PointerType* PointerTy = PointerType::get(IntegerType::get(mod->getContext(), 8), 0);
// This creates the i8** type
PointerType* PointerPtrTy = PointerType::get(PointerTy, 0);
// This creates the i8* type
PointerType* PointerTy = PointerType::get(IntegerType::get(mod->getContext(), 8), 0);

// Create a function type. Its argument types are passed as a vector
std::vector<Type*>FuncTy_args;
FuncTy_args.push_back(PointerTy);                 // one argument: char*
FunctionType* FuncTy = FunctionType::get(
  /*Result=*/Type::getVoidTy(mod->getContext()),  // returning void
  /*Params=*/FuncTy_args,                         // taking those args
  /*isVarArg=*/false);

// Finally this is the pointer to the function type described above
PointerType* PtrToFuncTy = PointerType::get(FuncTy, 0);
//这将创建i8*类型
PointerType*PointerTy=PointerType::get(IntegerType::get(mod->getContext(),8),0);
//创建一个函数类型。它的参数类型作为向量传递
std::向量函数参数;
函数参数。向后推(指针);//一个参数:char*
FunctionType*Function=FunctionType::get(
/*Result=*/Type::getVoidTy(mod->getContext()),//返回void
/*Params=*/funcy_args,//获取这些args
/*isVarArg=*/false);
//最后,这是指向上述函数类型的指针
PointerType*ptrtofuncy=PointerType::get(FuncTy,0);

一个更一般的答案是:你可以使用LLVM C++ API后端来生成创建任何类型的IR所需的C++代码。这可以通过在线LLVM演示方便地完成——这就是我为这个答案生成代码的方式