aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2002-04-18 18:15:38 +0000
committerChris Lattner <sabre@nondot.org>2002-04-18 18:15:38 +0000
commit4b1de8eb997798a48d8b8f6dfd50872ccc88e17f (patch)
tree03179c2c2b0dcac45f57ff3aadcfed883a1dcff4
parentccc259635ace985306115566d065919fae511370 (diff)
* getAsString requires that the input array is string compatible, so
assert it. * Use WriteAsOperand instead of getStringValue for constants git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2296 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Target/SparcV9/SparcV9AsmPrinter.cpp65
1 files changed, 32 insertions, 33 deletions
diff --git a/lib/Target/SparcV9/SparcV9AsmPrinter.cpp b/lib/Target/SparcV9/SparcV9AsmPrinter.cpp
index 79b7b003c7..a46f2ef729 100644
--- a/lib/Target/SparcV9/SparcV9AsmPrinter.cpp
+++ b/lib/Target/SparcV9/SparcV9AsmPrinter.cpp
@@ -22,6 +22,7 @@
#include "llvm/Function.h"
#include "llvm/Module.h"
#include "llvm/SlotCalculator.h"
+#include "llvm/Assembly/Writer.h"
#include "Support/StringExtras.h"
#include "Support/HashExtras.h"
#include <iostream>
@@ -472,41 +473,39 @@ static inline char toOctal(int X) {
// the predicate isStringCompatible is true.
//
static string getAsCString(ConstantArray *CPA) {
- if (isStringCompatible(CPA)) {
- string Result;
- const Type *ETy = cast<ArrayType>(CPA->getType())->getElementType();
- Result = "\"";
- for (unsigned i = 0; i < CPA->getNumOperands(); ++i) {
- unsigned char C = (ETy == Type::SByteTy) ?
- (unsigned char)cast<ConstantSInt>(CPA->getOperand(i))->getValue() :
- (unsigned char)cast<ConstantUInt>(CPA->getOperand(i))->getValue();
-
- if (isprint(C)) {
- Result += C;
- } else {
- switch(C) {
- case '\a': Result += "\\a"; break;
- case '\b': Result += "\\b"; break;
- case '\f': Result += "\\f"; break;
- case '\n': Result += "\\n"; break;
- case '\r': Result += "\\r"; break;
- case '\t': Result += "\\t"; break;
- case '\v': Result += "\\v"; break;
- default:
- Result += '\\';
- Result += toOctal(C >> 6);
- Result += toOctal(C >> 3);
- Result += toOctal(C >> 0);
- break;
- }
+ assert(isStringCompatible(CPA) && "Array is not string compatible!");
+
+ string Result;
+ const Type *ETy = cast<ArrayType>(CPA->getType())->getElementType();
+ Result = "\"";
+ for (unsigned i = 0; i < CPA->getNumOperands(); ++i) {
+ unsigned char C = (ETy == Type::SByteTy) ?
+ (unsigned char)cast<ConstantSInt>(CPA->getOperand(i))->getValue() :
+ (unsigned char)cast<ConstantUInt>(CPA->getOperand(i))->getValue();
+
+ if (isprint(C)) {
+ Result += C;
+ } else {
+ switch(C) {
+ case '\a': Result += "\\a"; break;
+ case '\b': Result += "\\b"; break;
+ case '\f': Result += "\\f"; break;
+ case '\n': Result += "\\n"; break;
+ case '\r': Result += "\\r"; break;
+ case '\t': Result += "\\t"; break;
+ case '\v': Result += "\\v"; break;
+ default:
+ Result += '\\';
+ Result += toOctal(C >> 6);
+ Result += toOctal(C >> 3);
+ Result += toOctal(C >> 0);
+ break;
}
}
- Result += "\"";
-
- return Result;
- } else {
- return CPA->getStrValue();
}
+ Result += "\"";
+
+ return Result;
}
inline bool
@@ -631,7 +630,7 @@ SparcModuleAsmPrinter::printSingleConstant(const Constant* CV)
toAsm << "\t! " << CV->getType()->getDescription()
<< " value: " << Val << "\n";
} else {
- toAsm << CV->getStrValue() << "\n";
+ WriteAsOperand(toAsm, CV, false, false) << "\n";
}
}
else if (ConstantPointer* CPP = dyn_cast<ConstantPointer>(CV))