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/MCExpr.h"
12 #include "llvm/Support/Debug.h"
13 #include "llvm/Support/raw_ostream.h"
16 // Sentinel value for the absolute pseudo section.
17 MCSection *MCSymbol::AbsolutePseudoSection = reinterpret_cast<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 \p 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::setVariableValue(const MCExpr *Value) {
42 assert(!IsUsed && "Cannot set a variable that has already been used.");
43 assert(Value && "Invalid variable value!");
45 this->Section = nullptr;
48 void MCSymbol::print(raw_ostream &OS) const {
49 // The name for this MCSymbol is required to be a valid target name. However,
50 // some targets support quoting names with funny characters. If the name
51 // contains a funny character, then print it quoted.
52 StringRef Name = getName();
57 if (!NameNeedsQuoting(Name)) {
63 for (unsigned I = 0, E = Name.size(); I != E; ++I) {
75 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
76 void MCSymbol::dump() const { dbgs() << *this; }