forked from OSchip/llvm-project
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
This commit is contained in:
parent
ac2b198ec5
commit
93cd755c05
|
@ -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,8 +227,8 @@ 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)) {
|
||||
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";
|
||||
|
@ -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)) {
|
||||
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 if (CVA) {
|
||||
} 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 =
|
||||
|
|
Loading…
Reference in New Issue