diff options
author | Chris Lattner <sabre@nondot.org> | 2003-07-23 15:22:26 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2003-07-23 15:22:26 +0000 |
commit | c07736a397012499e337c994f7f952b07c709544 (patch) | |
tree | e7ff1fb8eee2ca15a8f6edd4e537aecf7fe6be56 /lib/VMCore | |
parent | c8bf87af3efe766440d0df259a038a0b6998e6e9 (diff) | |
download | llvm-c07736a397012499e337c994f7f952b07c709544.tar.gz llvm-c07736a397012499e337c994f7f952b07c709544.tar.bz2 llvm-c07736a397012499e337c994f7f952b07c709544.tar.xz |
Simplify code by using ConstantInt::getRawValue instead of checking to see
whether the constant is signed or unsigned, then casting
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@7252 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore')
-rw-r--r-- | lib/VMCore/AsmWriter.cpp | 4 | ||||
-rw-r--r-- | lib/VMCore/ConstantRange.cpp | 5 | ||||
-rw-r--r-- | lib/VMCore/Constants.cpp | 13 |
3 files changed, 7 insertions, 15 deletions
diff --git a/lib/VMCore/AsmWriter.cpp b/lib/VMCore/AsmWriter.cpp index 0c62d05d2b..545349a6f5 100644 --- a/lib/VMCore/AsmWriter.cpp +++ b/lib/VMCore/AsmWriter.cpp @@ -274,9 +274,7 @@ static void WriteConstantInt(std::ostream &Out, const Constant *CV, if (isString) { Out << "c\""; for (unsigned i = 0; i < CA->getNumOperands(); ++i) { - unsigned char C = (ETy == Type::SByteTy) ? - (unsigned char)cast<ConstantSInt>(CA->getOperand(i))->getValue() : - (unsigned char)cast<ConstantUInt>(CA->getOperand(i))->getValue(); + unsigned char C = cast<ConstantInt>(CA->getOperand(i))->getRawValue(); if (isprint(C) && C != '"' && C != '\\') { Out << C; diff --git a/lib/VMCore/ConstantRange.cpp b/lib/VMCore/ConstantRange.cpp index b7ef5e0511..c9d8ae6fbb 100644 --- a/lib/VMCore/ConstantRange.cpp +++ b/lib/VMCore/ConstantRange.cpp @@ -126,10 +126,7 @@ uint64_t ConstantRange::getSetSize() const { // Simply subtract the bounds... Constant *Result = *(Constant*)Upper - *(Constant*)Lower; assert(Result && "Subtraction of constant integers not implemented?"); - if (getType()->isSigned()) - return (uint64_t)cast<ConstantSInt>(Result)->getValue(); - else - return cast<ConstantUInt>(Result)->getValue(); + return cast<ConstantInt>(Result)->getRawValue(); } diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp index 935c2938c2..7bbbdb3202 100644 --- a/lib/VMCore/Constants.cpp +++ b/lib/VMCore/Constants.cpp @@ -601,15 +601,12 @@ ConstantArray *ConstantArray::get(const std::string &Str) { // Otherwise, it asserts out. // std::string ConstantArray::getAsString() const { + assert((getType()->getElementType() == Type::UByteTy || + getType()->getElementType() == Type::SByteTy) && "Not a string!"); + std::string Result; - if (getType()->getElementType() == Type::SByteTy) - for (unsigned i = 0, e = getNumOperands(); i != e; ++i) - Result += (char)cast<ConstantSInt>(getOperand(i))->getValue(); - else { - assert(getType()->getElementType() == Type::UByteTy && "Not a string!"); - for (unsigned i = 0, e = getNumOperands(); i != e; ++i) - Result += (char)cast<ConstantUInt>(getOperand(i))->getValue(); - } + for (unsigned i = 0, e = getNumOperands(); i != e; ++i) + Result += (char)cast<ConstantInt>(getOperand(i))->getRawValue(); return Result; } |