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 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140627/c49bdb2a/attachment.html>
Hi Eric, On 27 June 2014 03:25, Eric Lu <eirc.lew at gmail.com> wrote:> 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 -- View this message in context: http://llvm.1065342.n5.nabble.com/how-create-a-pointer-to-FILE-tp69982p69987.html Sent from the LLVM - Dev mailing list archive at Nabble.com.
Possibly Parallel Threads
- [LLVMdev] Assertion `castIsValid(getOpcode(), S, Ty) && "Illegal BitCast"' failed.
- [LLVMdev] Assertion `InReg && "Value not in map!"' failed
- [LLVMdev] Assertion `InReg && "Value not in map!"' failed
- [LLVMdev] How to unroll reduction loop with caching accumulator on register?
- [LLVMdev] How to unroll reduction loop with caching accumulator on register?