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 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 /// NameNeedsQuoting - Return true if the identifier \p Str needs quotes to be
30 /// syntactically correct.
31 static bool NameNeedsQuoting(StringRef Str) {
32 assert(!Str.empty() && "Cannot create an empty MCSymbol");
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)
37 if (!isAcceptableChar(Str[i]))
42 void MCSymbol::setVariableValue(const MCExpr *Value) {
43 assert(!IsUsed && "Cannot set a variable that has already been used.");
44 assert(Value && "Invalid variable value!");
46 this->Section = nullptr;
49 void MCSymbol::print(raw_ostream &OS) const {
50 // The name for this MCSymbol is required to be a valid target name. However,
51 // some targets support quoting names with funny characters. If the name
52 // contains a funny character, then print it quoted.
53 StringRef Name = getName();
54 if (!NameNeedsQuoting(Name)) {
60 for (unsigned I = 0, E = Name.size(); I != E; ++I) {
72 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
73 void MCSymbol::dump() const {