From 895aef47207550668c0a4290d10ce1b2463f9776 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 2 Mar 2008 03:16:38 +0000 Subject: [PATCH] Print i32/i64 integer constants as 1u instead of ((unsigned int)1). Use dyn_cast better. llvm-svn: 47804 --- llvm/lib/Target/CBackend/CBackend.cpp | 43 ++++++++++++++------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/llvm/lib/Target/CBackend/CBackend.cpp b/llvm/lib/Target/CBackend/CBackend.cpp index 4816ba2682fb..c1a101475c7f 100644 --- a/llvm/lib/Target/CBackend/CBackend.cpp +++ b/llvm/lib/Target/CBackend/CBackend.cpp @@ -133,8 +133,8 @@ namespace { bool IgnoreName = false, const ParamAttrsList *PAL = 0); std::ostream &printSimpleType(std::ostream &Out, const Type *Ty, - bool isSigned, - const std::string &NameSoFar = ""); + bool isSigned, + const std::string &NameSoFar = ""); void printStructReturnPointerFunctionType(std::ostream &Out, const ParamAttrsList *PAL, @@ -888,7 +888,11 @@ void CWriter::printConstant(Constant *CPV) { if (ConstantInt *CI = dyn_cast(CPV)) { const Type* Ty = CI->getType(); if (Ty == Type::Int1Ty) - Out << (CI->getZExtValue() ? '1' : '0') ; + Out << (CI->getZExtValue() ? '1' : '0'); + else if (Ty == Type::Int32Ty) + Out << CI->getZExtValue() << 'u'; + else if (Ty->getPrimitiveSizeInBits() > 32) + Out << CI->getZExtValue() << "ull"; else { Out << "(("; printSimpleType(Out, Ty, false) << ')'; @@ -896,9 +900,7 @@ void CWriter::printConstant(Constant *CPV) { Out << CI->getZExtValue() << 'u'; else Out << CI->getSExtValue(); - if (Ty->getPrimitiveSizeInBits() > 32) - Out << "ll"; - Out << ')'; + Out << ')'; } return; } @@ -970,7 +972,10 @@ void CWriter::printConstant(Constant *CPV) { } case Type::ArrayTyID: - if (isa(CPV) || isa(CPV)) { + if (const ConstantArray *CA = cast(CPV)) { + printConstantVector(CA); + } else { + assert(isa(CPV) || isa(CPV)); const ArrayType *AT = cast(CPV->getType()); Out << '{'; if (AT->getNumElements()) { @@ -983,27 +988,23 @@ void CWriter::printConstant(Constant *CPV) { } } Out << " }"; - } else { - printConstantArray(cast(CPV)); } break; case Type::VectorTyID: - if (isa(CPV) || isa(CPV)) { - const VectorType *AT = cast(CPV->getType()); - Out << '{'; - if (AT->getNumElements()) { - Out << ' '; - Constant *CZ = Constant::getNullValue(AT->getElementType()); + if (const ConstantVector *CV = cast(CPV)) { + printConstantVector(CV); + } else { + assert(isa(CPV) || isa(CPV)); + const VectorType *VT = cast(CPV->getType()); + Out << "{ "; + Constant *CZ = Constant::getNullValue(VT->getElementType()); + printConstant(CZ); + for (unsigned i = 1, e = AT->getNumElements(); i != e; ++i) { + Out << ", "; printConstant(CZ); - for (unsigned i = 1, e = AT->getNumElements(); i != e; ++i) { - Out << ", "; - printConstant(CZ); - } } Out << " }"; - } else { - printConstantVector(cast(CPV)); } break;