summaryrefslogtreecommitdiff
path: root/lib/VMCore/AsmWriter.cpp
diff options
context:
space:
mode:
authorNick Lewycky <nicholas@mxc.ca>2011-06-15 06:37:58 +0000
committerNick Lewycky <nicholas@mxc.ca>2011-06-15 06:37:58 +0000
commit9100a78bce4e1d34d8ffd5efa2cc79ed864dd1c0 (patch)
treecdc744ac8a554e94e7e133a0d4aa4ba96f750052 /lib/VMCore/AsmWriter.cpp
parent7a10ab7d6f50b59580cc8ab1eb52d562e81f28d8 (diff)
downloadllvm-9100a78bce4e1d34d8ffd5efa2cc79ed864dd1c0.tar.gz
llvm-9100a78bce4e1d34d8ffd5efa2cc79ed864dd1c0.tar.bz2
llvm-9100a78bce4e1d34d8ffd5efa2cc79ed864dd1c0.tar.xz
Teach the .ll parser to handle named metadata with non-simple names.
Unfortunately we can't follow what the rest of the language does (wrapping it in double-quotes) because that would cause an ambiguity with metadata strings, so instead we escape any unusual characters with \xx escaping. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@133050 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/AsmWriter.cpp')
-rw-r--r--lib/VMCore/AsmWriter.cpp20
1 files changed, 19 insertions, 1 deletions
diff --git a/lib/VMCore/AsmWriter.cpp b/lib/VMCore/AsmWriter.cpp
index 844284d09c..cfcffebd0d 100644
--- a/lib/VMCore/AsmWriter.cpp
+++ b/lib/VMCore/AsmWriter.cpp
@@ -1401,7 +1401,25 @@ void AssemblyWriter::printModule(const Module *M) {
}
void AssemblyWriter::printNamedMDNode(const NamedMDNode *NMD) {
- Out << "!" << NMD->getName() << " = !{";
+ Out << '!';
+ StringRef Name = NMD->getName();
+ if (Name.empty()) {
+ Out << "<empty name> ";
+ } else {
+ if (isalpha(Name[0]) || Name[0] == '-' || Name[0] == '$' ||
+ Name[0] == '.' || Name[0] == '_')
+ Out << Name[0];
+ else
+ Out << '\\' << hexdigit(Name[0] >> 4) << hexdigit(Name[0] & 0x0F);
+ for (unsigned i = 1, e = Name.size(); i != e; ++i) {
+ unsigned char C = Name[i];
+ if (isalnum(C) || C == '-' || C == '$' || C == '.' || C == '_')
+ Out << C;
+ else
+ Out << '\\' << hexdigit(C >> 4) << hexdigit(C & 0x0F);
+ }
+ }
+ Out << " = !{";
for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) {
if (i) Out << ", ";
int Slot = Machine.getMetadataSlot(NMD->getOperand(i));