1 //===- lib/MC/MCSymbol.cpp - MCSymbol implementation ----------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm/MC/MCSymbol.h"
11 #include "llvm/MC/MCAsmInfo.h"
12 #include "llvm/Support/raw_ostream.h"
15 // Sentinel value for the absolute pseudo section.
16 const MCSection *MCSymbol::AbsolutePseudoSection =
17 reinterpret_cast<const MCSection *>(1);
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())
26 // If empty, we need quotes.
30 // If the first character is a number, we need quotes.
31 if (Str[0] >= '0' && Str[0] <= '9')
34 // If any of the characters in the string is an unacceptable character, force
36 for (unsigned i = 0, e = Str.size(); i != e; ++i) {
39 if ((C < 'a' || C > 'z') &&
40 (C < 'A' || C > 'Z') &&
41 (C < '0' || C > '9') &&
42 C != '_' && C != '$' && C != '.')
48 void MCSymbol::print(raw_ostream &OS, const MCAsmInfo *MAI) const {
49 if (!MAI || ShouldQuoteIdentifier(getName(), *MAI))
50 OS << '"' << getName() << '"';
55 void MCSymbol::dump() const {