summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/AsmPrinter.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2005-11-10 18:06:33 +0000
committerChris Lattner <sabre@nondot.org>2005-11-10 18:06:33 +0000
commit55a6d9067b26a6c559b067e672cd60ee0420d68c (patch)
tree9609a74a9bea8482b7a4f79cd9bb01c2e22a80a4 /llvm/lib/CodeGen/AsmPrinter.cpp
parente039210a5b8b525a35a61f22ea1fbc70a7969ea8 (diff)
downloadbcm5719-llvm-55a6d9067b26a6c559b067e672cd60ee0420d68c.tar.gz
bcm5719-llvm-55a6d9067b26a6c559b067e672cd60ee0420d68c.zip
add support for .asciz, and enable it by default. If your target assemblerdoesn't support .asciz, just set AscizDirective to null in your asmprinter.
This compiles C strings to: l1__2E_str_1: ; '.str_1' .asciz "foo" instead of: l1__2E_str_1: ; '.str_1' .ascii "foo\000" llvm-svn: 24272
Diffstat (limited to 'llvm/lib/CodeGen/AsmPrinter.cpp')
-rw-r--r--llvm/lib/CodeGen/AsmPrinter.cpp18
1 files changed, 13 insertions, 5 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter.cpp
index d907d67b5a2..ae569bd15ae 100644
--- a/llvm/lib/CodeGen/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter.cpp
@@ -141,14 +141,15 @@ static inline char toOctal(int X) {
return (X&7)+'0';
}
-/// getAsCString - Return the specified array as a C compatible string, only if
+/// printAsCString - Print the specified array as a C compatible string, only if
/// the predicate isString is true.
///
-static void printAsCString(std::ostream &O, const ConstantArray *CVA) {
+static void printAsCString(std::ostream &O, const ConstantArray *CVA,
+ unsigned LastElt) {
assert(CVA->isString() && "Array is not string compatible!");
O << "\"";
- for (unsigned i = 0; i != CVA->getNumOperands(); ++i) {
+ for (unsigned i = 0; i != LastElt; ++i) {
unsigned char C =
(unsigned char)cast<ConstantInt>(CVA->getOperand(i))->getRawValue();
@@ -187,8 +188,15 @@ void AsmPrinter::emitGlobalConstant(const Constant *CV) {
return;
} else if (const ConstantArray *CVA = dyn_cast<ConstantArray>(CV)) {
if (CVA->isString()) {
- O << AsciiDirective;
- printAsCString(O, CVA);
+ unsigned NumElts = CVA->getNumOperands();
+ if (AscizDirective && NumElts &&
+ cast<ConstantInt>(CVA->getOperand(NumElts-1))->getRawValue() == 0) {
+ O << AscizDirective;
+ printAsCString(O, CVA, NumElts-1);
+ } else {
+ O << AsciiDirective;
+ printAsCString(O, CVA, NumElts);
+ }
O << "\n";
} else { // Not a string. Print the values in successive locations
for (unsigned i = 0, e = CVA->getNumOperands(); i != e; ++i)
OpenPOWER on IntegriCloud