[llvm-commits] CVS: llvm/lib/CodeGen/AsmPrinter.cpp
Chris Lattner
lattner at cs.uiuc.edu
Thu Nov 10 10:06:45 PST 2005
Changes in directory llvm/lib/CodeGen:
AsmPrinter.cpp updated: 1.20 -> 1.21
---
Log message:
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"
---
Diffs of the changes: (+13 -5)
AsmPrinter.cpp | 18 +++++++++++++-----
1 files changed, 13 insertions(+), 5 deletions(-)
Index: llvm/lib/CodeGen/AsmPrinter.cpp
diff -u llvm/lib/CodeGen/AsmPrinter.cpp:1.20 llvm/lib/CodeGen/AsmPrinter.cpp:1.21
--- llvm/lib/CodeGen/AsmPrinter.cpp:1.20 Wed Aug 17 14:24:40 2005
+++ llvm/lib/CodeGen/AsmPrinter.cpp Thu Nov 10 12:06:33 2005
@@ -141,14 +141,15 @@
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 @@
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)
More information about the llvm-commits
mailing list