I'm trying to create a TruncInst
with an i8
destination type.
However, I can't seem to find an appropriate type constructor
when I look here. I expected it should be something simple like:
if (val->getType()->isIntegerTy(32))
{
TruncInst *ti = new TruncInst(val,new IntegerType(8));
}
But apparently it's not. I'm probably over looking something in the API. Any help is very much appreciated, thanks!
Type::getInt8Ty(getContext());
will get a type for you, assuming that you have a way to get the relevant context.
You cannot create an IntegerType yourself because LLVM's design says that if two types t1 and t2 are the same (e.g. both are 8-bit integer types) and exist in the same context, then t1==t2
. Much LLVM code expects to test for equality using ==
.