Creating new types in LLVM (in particular, a pointer to a function type)

I would like to create the following type,

void (i8*)* 

I tried using the type class to create the type above, but I did not find a direct method for this.
Someone please suggest me a method to create the specified type.
Thanks in advance.

+4
source share
1 answer

If you mean i8** (pointer to a 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 that returns nothing and accepts 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: you can use the LLVM C ++ API backend to create the C ++ code needed to create any kind of IR. This can be done with the LLVM online demo - http://llvm.org/demo/ - this is how I created the code for this answer.

+4
source

Source: https://habr.com/ru/post/1398264/


All Articles