我想创建一个以下类型,
void (i8*)*
Run Code Online (Sandbox Code Playgroud)
我尝试使用Type类来创建上述类型,但是我没有找到任何直接方法来执行相同操作。
有人请向我建议一种创建上述类型的方法。
提前致谢。
如果您的意思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);
Run Code Online (Sandbox Code Playgroud)
如果您需要一个指向不返回任何值并采用的函数的指针i8*,则:
// 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);
Run Code Online (Sandbox Code Playgroud)
一个更通用的答案是:您可以使用LLVM C ++ API后端生成创建任何类型的IR所需的C ++代码。可以通过在线LLVM演示-http : //llvm.org/demo/方便地完成此操作-这就是我为该答案生成代码的方式。
| 归档时间: |
|
| 查看次数: |
3305 次 |
| 最近记录: |