Implement getPointerCast.
authorReid Spencer <rspencer@reidspencer.com>
Tue, 5 Dec 2006 03:25:26 +0000 (03:25 +0000)
committerReid Spencer <rspencer@reidspencer.com>
Tue, 5 Dec 2006 03:25:26 +0000 (03:25 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@32211 91177308-0d34-0410-b5e6-96231b3b80d8

lib/VMCore/Constants.cpp

index 3238ad0824ab83da58315334abfb8d7268464c48..dc3d9935d6922187e9ad5c2170c6a6d565d3d885 100644 (file)
@@ -1552,6 +1552,16 @@ Constant *ConstantExpr::getTruncOrBitCast(Constant *C, const Type *Ty) {
   return getCast(Instruction::Trunc, C, Ty);
 }
 
+Constant *ConstantExpr::getPointerCast(Constant *S, const Type *Ty) {
+  assert(isa<PointerType>(S->getType()) && "Invalid cast");
+  assert((Ty->isIntegral() || Ty->getTypeID() == Type::PointerTyID) &&
+         "Invalid cast");
+
+  if (Ty->isIntegral())
+    return getCast(Instruction::PtrToInt, S, Ty);
+  return getCast(Instruction::BitCast, S, Ty);
+}
+
 Constant *ConstantExpr::getTrunc(Constant *C, const Type *Ty) {
   assert(C->getType()->isInteger() && "Trunc operand must be integer");
   assert(Ty->isIntegral() && "Trunc produces only integral");