I'd like to create a following Type,
void (i8*)*
I tried using Type class to create above type, But I did't find any direct method to do the same.
Someone Please suggest me a method to create the above type.
Thanks in advance.
If you mean i8**
(pointer to pointer to i8
), then:
// 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);
If you need a pointer to a function returning nothing and taking i8*
, then:
// 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);
A more general answer would be: you can use the LLVM C++ API backend to generate the C++ code needed to create any kind of IR. This can be conveniently done with the online LLVM demo - http://llvm.org/demo/ - this is how I generated the code for this answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With