While replacing an MDNode elment, properly update MDNode's operand list.
[oota-llvm.git] / lib / MC / MCSymbol.cpp
1 //===- lib/MC/MCSymbol.cpp - MCSymbol implementation ----------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include "llvm/MC/MCSymbol.h"
11 #include "llvm/MC/MCAsmInfo.h"
12 #include "llvm/Support/raw_ostream.h"
13 using namespace llvm;
14
15 // Sentinel value for the absolute pseudo section.
16 const MCSection *MCSymbol::AbsolutePseudoSection =
17   reinterpret_cast<const MCSection *>(1);
18
19 /// ShouldQuoteIdentifier - Return true if the identifier \arg Str needs quotes
20 /// for this assembler.
21 static bool ShouldQuoteIdentifier(const StringRef &Str, const MCAsmInfo &MAI) {
22   // If the assembler doesn't support quotes, never use them.
23   if (!MAI.doesAllowQuotesInName())
24     return false;
25   
26   // If empty, we need quotes.
27   if (Str.empty())
28     return true;
29   
30   // If the first character is a number, we need quotes.
31   if (Str[0] >= '0' && Str[0] <= '9')
32     return true;
33
34   // If any of the characters in the string is an unacceptable character, force
35   // quotes.
36   for (unsigned i = 0, e = Str.size(); i != e; ++i) {
37     char C = Str[i];
38   
39     if ((C < 'a' || C > 'z') &&
40         (C < 'A' || C > 'Z') &&
41         (C < '0' || C > '9') &&
42         C != '_' && C != '$' && C != '.')
43       return true;
44   }
45   return false;
46 }
47
48 void MCSymbol::print(raw_ostream &OS, const MCAsmInfo *MAI) const {
49   if (!MAI || ShouldQuoteIdentifier(getName(), *MAI))
50     OS << '"' << getName() << '"';
51   else
52     OS << getName();
53 }
54
55 void MCSymbol::dump() const {
56   print(errs(), 0);
57 }