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/Support/Debug.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 static bool isAcceptableChar(char C) {
20 if ((C < 'a' || C > 'z') &&
21 (C < 'A' || C > 'Z') &&
22 (C < '0' || C > '9') &&
23 C != '_' && C != '$' && C != '.' && C != '@')
28 /// NameNeedsQuoting - Return true if the identifier \arg Str needs quotes to be
29 /// syntactically correct.
30 static bool NameNeedsQuoting(StringRef Str) {
31 assert(!Str.empty() && "Cannot create an empty MCSymbol");
33 // If any of the characters in the string is an unacceptable character, force
35 for (unsigned i = 0, e = Str.size(); i != e; ++i)
36 if (!isAcceptableChar(Str[i]))
41 void MCSymbol::print(raw_ostream &OS) const {
42 // The name for this MCSymbol is required to be a valid target name. However,
43 // some targets support quoting names with funny characters. If the name
44 // contains a funny character, then print it quoted.
45 if (!NameNeedsQuoting(getName())) {
50 OS << '"' << getName() << '"';
53 void MCSymbol::dump() const {