Hi, all
I want to create a function in LLVM IR, whose type is:
void _to_prof( FILE* ptrF);
I do it within LLVM, but I don’t know how build the parameter type for FILE* ptrF.
Best Regards.
Eric Lu
Hi, all
I want to create a function in LLVM IR, whose type is:
void _to_prof( FILE* ptrF);
I do it within LLVM, but I don’t know how build the parameter type for FILE* ptrF.
Best Regards.
Eric Lu
Hi Eric,
void _to_prof( FILE* ptrF);
I do it within LLVM, but I don't know how build the parameter type for
FILE* ptrF.
The definition of the FILE type is handled by your platform's libc
implementation. It's not standardised in any way. That said, if all
you want to do is pass and return the "FILE *" (and not, say, allocate
one or inspect its internals) then passing an "i8*" works in all cases
I know about.
Strictly, it's undefined behaviour at the C level; but in practice all
CPUs and compilers make sure that kind of mismatch works, if only
because there's so much legacy code out there that does it.
Cheers.
Tim.
Thanks, Tim.
It works.
VoidPtrTy = Type::getInt8PtrTy(M.getContext());
M.getOrInsertFunction("__to_prof", VoidTy, VoidPtrTy, NULL);
==>
declare void @__to_prof(i8*)
CallInst *CallI;
Instruction *I = LoopHeader->begin();
Value * Null = (Value*) ConstantPointerNull::get(VoidPtrTy );
//Value * Null = (Value*) ConstantPointerNull::get( 0 );
Value *PtrNull = Builder->CreatePointerCast( Null, VoidPtrTy);
Builder->SetInsertPoint(I );
CallI = Builder->CreateCall( __TO_PROF_FUNCTION, PtrNull ); //
__to_prof(i8* null)
==>
call void @__to_prof(i8* null)
Eric