summaryrefslogtreecommitdiffstats
path: root/lib/MC/MCAsmStreamer.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2010-01-23 00:15:00 +0000
committerChris Lattner <sabre@nondot.org>2010-01-23 00:15:00 +0000
commit12e555c36ce11c39ce15cd0b27bf7b02a068beb2 (patch)
tree5ace870a46c820714ceb3f895b5a955c3e67a0a0 /lib/MC/MCAsmStreamer.cpp
parent06203127a7815df8aa63849995536fa467aeba93 (diff)
downloadexternal_llvm-12e555c36ce11c39ce15cd0b27bf7b02a068beb2.zip
external_llvm-12e555c36ce11c39ce15cd0b27bf7b02a068beb2.tar.gz
external_llvm-12e555c36ce11c39ce15cd0b27bf7b02a068beb2.tar.bz2
teach MCAsmStreamer::EmitBytes to use .ascii and .asciz
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@94259 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/MC/MCAsmStreamer.cpp')
-rw-r--r--lib/MC/MCAsmStreamer.cpp50
1 files changed, 47 insertions, 3 deletions
diff --git a/lib/MC/MCAsmStreamer.cpp b/lib/MC/MCAsmStreamer.cpp
index d4ef3ca..75903aa 100644
--- a/lib/MC/MCAsmStreamer.cpp
+++ b/lib/MC/MCAsmStreamer.cpp
@@ -271,13 +271,57 @@ void MCAsmStreamer::EmitZerofill(const MCSection *Section, MCSymbol *Symbol,
EmitEOL();
}
+static inline char toOctal(int X) { return (X&7)+'0'; }
+
void MCAsmStreamer::EmitBytes(StringRef Data, unsigned AddrSpace) {
assert(CurSection && "Cannot emit contents before setting section!");
- const char *Directive = MAI.getData8bitsDirective(AddrSpace);
- for (unsigned i = 0, e = Data.size(); i != e; ++i) {
- OS << Directive << (unsigned)(unsigned char)Data[i];
+ if (Data.empty()) return;
+
+ if (Data.size() == 1) {
+ OS << MAI.getData8bitsDirective(AddrSpace);
+ OS << (unsigned)(unsigned char)Data[0];
EmitEOL();
+ return;
}
+
+ // If the data ends with 0 and the target supports .asciz, use it, otherwise
+ // use .ascii
+ if (MAI.getAscizDirective() && Data.back() == 0) {
+ OS << MAI.getAscizDirective();
+ Data = Data.substr(0, Data.size()-1);
+ } else {
+ OS << MAI.getAsciiDirective();
+ }
+
+ OS << " \"";
+ for (unsigned i = 0, e = Data.size(); i != e; ++i) {
+ unsigned char C = Data[i];
+ if (C == '"' || C == '\\') {
+ OS << '\\' << (char)C;
+ continue;
+ }
+
+ if (isprint((unsigned char)C)) {
+ OS << (char)C;
+ continue;
+ }
+
+ switch (C) {
+ case '\b': OS << "\\b"; break;
+ case '\f': OS << "\\f"; break;
+ case '\n': OS << "\\n"; break;
+ case '\r': OS << "\\r"; break;
+ case '\t': OS << "\\t"; break;
+ default:
+ OS << '\\';
+ OS << toOctal(C >> 6);
+ OS << toOctal(C >> 3);
+ OS << toOctal(C >> 0);
+ break;
+ }
+ }
+ OS << '"';
+ EmitEOL();
}
/// EmitIntValue - Special case of EmitValue that avoids the client having