diff options
| author | Chris Lattner <sabre@nondot.org> | 2009-09-13 18:11:09 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2009-09-13 18:11:09 +0000 |
| commit | de79e4fc2eb0c89cab6af356f350ca2e1ff6653d (patch) | |
| tree | ea855a32e8cd671c9736f6449722a8286bc43a8b /llvm/lib/MC | |
| parent | 3d6c8ebb584375d01b1acead4c2056b3f0c501fc (diff) | |
| download | bcm5719-llvm-de79e4fc2eb0c89cab6af356f350ca2e1ff6653d.tar.gz bcm5719-llvm-de79e4fc2eb0c89cab6af356f350ca2e1ff6653d.zip | |
fix MCSymbol printing on darwin to exactly match the mangler (handling of \n and " in a symbol name).
llvm-svn: 81683
Diffstat (limited to 'llvm/lib/MC')
| -rw-r--r-- | llvm/lib/MC/MCSymbol.cpp | 36 |
1 files changed, 28 insertions, 8 deletions
diff --git a/llvm/lib/MC/MCSymbol.cpp b/llvm/lib/MC/MCSymbol.cpp index 64cc15af1b1..832f8fbcbb4 100644 --- a/llvm/lib/MC/MCSymbol.cpp +++ b/llvm/lib/MC/MCSymbol.cpp @@ -65,6 +65,23 @@ static void PrintMangledName(raw_ostream &OS, StringRef Str) { } } +/// PrintMangledQuotedName - On systems that support quoted symbols, we still +/// have to escape some (obscure) characters like " and \n which would break the +/// assembler's lexing. +static void PrintMangledQuotedName(raw_ostream &OS, StringRef Str) { + OS << '"'; + + for (unsigned i = 0, e = Str.size(); i != e; ++i) { + if (Str[i] == '"') + OS << "_QQ_"; + else if (Str[i] == '\n') + OS << "_NL_"; + else + OS << Str[i]; + } + OS << '"'; +} + void MCSymbol::print(raw_ostream &OS, const MCAsmInfo *MAI) const { if (MAI == 0 || !NameNeedsEscaping(getName(), *MAI)) { @@ -72,14 +89,17 @@ void MCSymbol::print(raw_ostream &OS, const MCAsmInfo *MAI) const { return; } - // On darwin and other systems that allow quoted names, just do that. - if (MAI->doesAllowQuotesInName()) { - OS << '"' << getName() << '"'; - return; - } - - // Otherwise, we have to mangle the name. - PrintMangledName(OS, getName()); + // On systems that do not allow quoted names, print with mangling. + if (!MAI->doesAllowQuotesInName()) + return PrintMangledName(OS, getName()); + + // If the string contains a double quote or newline, we still have to mangle + // it. + if (getName().find('"') != std::string::npos || + getName().find('\n') != std::string::npos) + return PrintMangledQuotedName(OS, getName()); + + OS << '"' << getName() << '"'; } void MCSymbol::dump() const { |

