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/Debug.h"
13 #include "llvm/Support/raw_ostream.h"
16 // Sentinel value for the absolute pseudo section.
17 const MCSection *MCSymbol::AbsolutePseudoSection =
18 reinterpret_cast<const MCSection *>(1);
20 static bool isAcceptableChar(char C) {
21 if ((C < 'a' || C > 'z') &&
22 (C < 'A' || C > 'Z') &&
23 (C < '0' || C > '9') &&
24 C != '_' && C != '$' && C != '.' && C != '@')
29 /// NameNeedsEscaping - Return true if the identifier \arg Str needs quotes
30 /// for this assembler.
31 static bool NameNeedsEscaping(StringRef Str, const MCAsmInfo &MAI) {
32 assert(!Str.empty() && "Cannot create an empty MCSymbol");
34 // If the first character is a number and the target does not allow this, we
36 if (!MAI.doesAllowNameToStartWithDigit() && Str[0] >= '0' && Str[0] <= '9')
39 // If any of the characters in the string is an unacceptable character, force
41 for (unsigned i = 0, e = Str.size(); i != e; ++i)
42 if (!isAcceptableChar(Str[i]))
47 void MCSymbol::print(raw_ostream &OS, const MCAsmInfo *MAI) const {
48 // The name for this MCSymbol is required to be a valid target name. However,
49 // some targets support quoting names with funny characters. If the name
50 // contains a funny character, then print it quoted.
51 if (MAI == 0 || !NameNeedsEscaping(getName(), *MAI)) {
56 OS << '"' << getName() << '"';
59 void MCSymbol::dump() const {