diff options
author | Reid Spencer <rspencer@reidspencer.com> | 2006-12-05 03:28:26 +0000 |
---|---|---|
committer | Reid Spencer <rspencer@reidspencer.com> | 2006-12-05 03:28:26 +0000 |
commit | 330d86d7489a961d452e821a34dc6de3f19ae73a (patch) | |
tree | cdb1f954a8ffa984badb38503638a13e7f074987 | |
parent | c0459fb7f52ca1bcba977f3e72abc050af078aee (diff) |
Implement createPointerCast.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@32212 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/VMCore/Instructions.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/VMCore/Instructions.cpp b/lib/VMCore/Instructions.cpp index 8c1f47d8af..65a910b8e8 100644 --- a/lib/VMCore/Instructions.cpp +++ b/lib/VMCore/Instructions.cpp @@ -1548,6 +1548,31 @@ CastInst *CastInst::createTruncOrBitCast(Value *S, const Type *Ty, return create(Instruction::Trunc, S, Ty, Name, InsertAtEnd); } +CastInst *CastInst::createPointerCast(Value *S, const Type *Ty, + const std::string &Name, + BasicBlock *InsertAtEnd) { + assert(isa<PointerType>(S->getType()) && "Invalid cast"); + assert((Ty->isIntegral() || Ty->getTypeID() == Type::PointerTyID) && + "Invalid cast"); + + if (Ty->isIntegral()) + return create(Instruction::PtrToInt, S, Ty, Name, InsertAtEnd); + return create(Instruction::BitCast, S, Ty, Name, InsertAtEnd); +} + +/// @brief Create a BitCast or a PtrToInt cast instruction +CastInst *CastInst::createPointerCast(Value *S, const Type *Ty, + const std::string &Name, + Instruction *InsertBefore) { + assert(isa<PointerType>(S->getType()) && "Invalid cast"); + assert((Ty->isIntegral() || Ty->getTypeID() == Type::PointerTyID) && + "Invalid cast"); + + if (Ty->isIntegral()) + return create(Instruction::PtrToInt, S, Ty, Name, InsertBefore); + return create(Instruction::BitCast, S, Ty, Name, InsertBefore); +} + // Provide a way to get a "cast" where the cast opcode is inferred from the // types and size of the operand. This, basically, is a parallel of the // logic in the checkCast function below. This axiom should hold: |