diff options
author | Chris Lattner <sabre@nondot.org> | 2004-01-14 17:15:17 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2004-01-14 17:15:17 +0000 |
commit | 07ad64231f76bf78ab2887235f3656dc40ff98d8 (patch) | |
tree | 0fd389fcd6149e15d772d558688df578f1e3d762 /lib/Target/SparcV9 | |
parent | aa06d0439ec183c2a7546c38ff50dbcfb285261b (diff) | |
download | external_llvm-07ad64231f76bf78ab2887235f3656dc40ff98d8.zip external_llvm-07ad64231f76bf78ab2887235f3656dc40ff98d8.tar.gz external_llvm-07ad64231f76bf78ab2887235f3656dc40ff98d8.tar.bz2 |
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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@10854 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Target/SparcV9')
-rw-r--r-- | lib/Target/SparcV9/SparcV9AsmPrinter.cpp | 62 |
1 files changed, 22 insertions, 40 deletions
diff --git a/lib/Target/SparcV9/SparcV9AsmPrinter.cpp b/lib/Target/SparcV9/SparcV9AsmPrinter.cpp index 36da80b..a202ffa 100644 --- a/lib/Target/SparcV9/SparcV9AsmPrinter.cpp +++ b/lib/Target/SparcV9/SparcV9AsmPrinter.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<ArrayType>(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<ConstantSInt>(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<ArrayType>(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<ConstantInt>(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<ConstantArray>(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<ConstantArray>(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<ConstantArray>(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<Use> &constValues = CVA->getValues(); - for (unsigned i=0; i < constValues.size(); i++) - printConstantValueOnly(cast<Constant>(constValues[i].get())); + int numPadBytesAfter) { + if (const ConstantArray *CVA = dyn_cast<ConstantArray>(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<Use> &constValues = CVA->getValues(); + for (unsigned i=0; i < constValues.size(); i++) + printConstantValueOnly(cast<Constant>(constValues[i].get())); + } } else if (const ConstantStruct *CVS = dyn_cast<ConstantStruct>(CV)) { // Print the fields in successive locations. Pad to align if needed! const StructLayout *cvsLayout = |