From 93cd755c05c3a56da03e54567a0531deb6263740 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Wed, 14 Jan 2004 17:15:17 +0000 Subject: [PATCH] Eliminate the isStringCompatible function, using ConstantArray::isString. It's not clear why the code was looking for signed chars < 0, but it can't matter to the assembler anyway, so the check goes away. This also fixes compatibility with arrays of [us]byte that have constantexprs in them. Also slightly restructure some code to be cleaner. llvm-svn: 10854 --- llvm/lib/Target/Sparc/EmitAssembly.cpp | 62 +++++++++----------------- 1 file changed, 22 insertions(+), 40 deletions(-) diff --git a/llvm/lib/Target/Sparc/EmitAssembly.cpp b/llvm/lib/Target/Sparc/EmitAssembly.cpp index 36da80bb2d56..a202ffab06b0 100644 --- a/llvm/lib/Target/Sparc/EmitAssembly.cpp +++ b/llvm/lib/Target/Sparc/EmitAssembly.cpp @@ -53,31 +53,14 @@ namespace { //===--------------------------------------------------------------------===// // Utility functions - /// Can we treat the specified array as a string? Only if it is an array of - /// ubytes or non-negative sbytes. - /// - bool isStringCompatible(const ConstantArray *CVA) { - const Type *ETy = cast(CVA->getType())->getElementType(); - if (ETy == Type::UByteTy) return true; - if (ETy != Type::SByteTy) return false; - - for (unsigned i = 0; i < CVA->getNumOperands(); ++i) - if (cast(CVA->getOperand(i))->getValue() < 0) - return false; - - return true; - } - /// getAsCString - Return the specified array as a C compatible string, only - /// if the predicate isStringCompatible is true. + /// if the predicate isString() is true. /// std::string getAsCString(const ConstantArray *CVA) { - assert(isStringCompatible(CVA) && "Array is not string compatible!"); + assert(CVA->isString() && "Array is not string compatible!"); - std::string Result; - const Type *ETy = cast(CVA->getType())->getElementType(); - Result = "\""; - for (unsigned i = 0; i < CVA->getNumOperands(); ++i) { + std::string Result = "\""; + for (unsigned i = 0; i != CVA->getNumOperands(); ++i) { unsigned char C = cast(CVA->getOperand(i))->getRawValue(); if (C == '"') { @@ -244,13 +227,13 @@ namespace { toAsm << "\t.align\t" << ConstantToAlignment(CV, Target) << "\n"; // Print .size and .type only if it is not a string. - const ConstantArray *CVA = dyn_cast(CV); - if (CVA && isStringCompatible(CVA)) { - // print it as a string and return - toAsm << valID << ":\n"; - toAsm << "\t" << ".ascii" << "\t" << getAsCString(CVA) << "\n"; - return; - } + if (const ConstantArray *CVA = dyn_cast(CV)) + if (CVA->isString()) { + // print it as a string and return + toAsm << valID << ":\n"; + toAsm << "\t" << ".ascii" << "\t" << getAsCString(CVA) << "\n"; + return; + } toAsm << "\t.type" << "\t" << valID << ",#object\n"; @@ -431,18 +414,17 @@ void AsmPrinter::printSingleConstantValue(const Constant* CV) { /// Uses printSingleConstantValue() to print each individual value. /// void AsmPrinter::printConstantValueOnly(const Constant* CV, - int numPadBytesAfter) -{ - const ConstantArray *CVA = dyn_cast(CV); - - if (CVA && isStringCompatible(CVA)) { - // print the string alone and return - toAsm << "\t" << ".ascii" << "\t" << getAsCString(CVA) << "\n"; - } else if (CVA) { - // Not a string. Print the values in successive locations - const std::vector &constValues = CVA->getValues(); - for (unsigned i=0; i < constValues.size(); i++) - printConstantValueOnly(cast(constValues[i].get())); + int numPadBytesAfter) { + if (const ConstantArray *CVA = dyn_cast(CV)) { + if (CVA->isString()) { + // print the string alone and return + toAsm << "\t" << ".ascii" << "\t" << getAsCString(CVA) << "\n"; + } else { + // Not a string. Print the values in successive locations + const std::vector &constValues = CVA->getValues(); + for (unsigned i=0; i < constValues.size(); i++) + printConstantValueOnly(cast(constValues[i].get())); + } } else if (const ConstantStruct *CVS = dyn_cast(CV)) { // Print the fields in successive locations. Pad to align if needed! const StructLayout *cvsLayout =