Reputation: 3053
I am writing some C code using the LLVM C api. I need to check if an instruction value is of type int
or is a pointer. What I have tried to do is use LLVMTypeOf(LLVMValueRef val)
and just see if it equals ALL of the different types of int
: LLVMInt1Type()
, LLVMInt8Type()
, LLVMInt16Type()
, etc. I did not know how to figure out if it is a pointer type or not though and I think the method I was using to see if it was a integer is not working either.
Here is the API I have been referencing: http://llvm.org/doxygen/modules.html
Upvotes: 3
Views: 2008
Reputation: 41
In c you can use LLVMGetTypeKind and LLVMTypeOf to determine what type it is.
For integer type, you can check with:
if(LLVMGetTypeKind(LLVMTypeOf(LLVMValueRef val))==LLVMIntegerTypeKind)
For pointer type, you can check with:
if(LLVMGetTypeKind(LLVMTypeOf(LLVMValueRef val))==LLVMPointerTypeKind)
Enum reference: LLVMTypeKind
Upvotes: 4
Reputation: 848
The C API is very limited.
I think you have to use C++ API or wrap the C++ API to C API by yourself.
For example,
extern "C" int LLVMTypeIsPointerTy(LLVMTypeRef ty){
return ((llvm::Type*)ty)->isPointerTy();
}
Upvotes: 1