[LLVMdev] Creating Pointer Constants
Nyx
mcheva at cs.mcgill.ca
Sun Mar 8 11:46:05 PDT 2009
Hello,
I am writing a JIT compiler for a subset of the Matlab language and as a
part of my implementation, I would like to be able to pass a constant
pointer to a native function I'm calling.
Right now, this is what I do:
llvm::Constant* constInt = llvm::ConstantInt::get(llvm::Type::Int64Ty,
(int64)thePointer);
llvm::Value* constPtr = llvm::ConstantExpr::getIntToPtr(constInt,
llvm::PointerType::getUnqual(llvm::Type::Int32Ty));
builder.CreateCall(my_function, constPtr);
The resulting IR call looks like this:
call void @nativeFunc(i32* inttoptr (i64 146876396 to i32*))
I'm just wondering if there is a better way to approach this. Casting a
pointer to a signed integer and back to a pointer looks both hack-ish, and
potentially risky (what happens if the address falls in the negative range
of the signed integer?). Unfortunately, I couldn't call a pointer constant
type in the LLVM doxygen documentation.
Thank you for your time,
- Maxime
--
View this message in context: http://www.nabble.com/Creating-Pointer-Constants-tp22401381p22401381.html
Sent from the LLVM - Dev mailing list archive at Nabble.com.
More information about the llvm-dev
mailing list