//===----------------------------------------------------------------------===//
#include "llvm/MC/MCSymbol.h"
-#include "llvm/MC/MCAsmInfo.h"
+#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
using namespace llvm;
const MCSection *MCSymbol::AbsolutePseudoSection =
reinterpret_cast<const MCSection *>(1);
-/// ShouldQuoteIdentifier - Return true if the identifier \arg Str needs quotes
-/// for this assembler.
-static bool ShouldQuoteIdentifier(const StringRef &Str, const MCAsmInfo &MAI) {
- // If the assembler doesn't support quotes, never use them.
- if (!MAI.doesAllowQuotesInName())
+static bool isAcceptableChar(char C) {
+ if ((C < 'a' || C > 'z') &&
+ (C < 'A' || C > 'Z') &&
+ (C < '0' || C > '9') &&
+ C != '_' && C != '$' && C != '.' && C != '@')
return false;
-
- // If empty, we need quotes.
- if (Str.empty())
- return true;
-
- // If the first character is a number, we need quotes.
- if (Str[0] >= '0' && Str[0] <= '9')
- return true;
+ return true;
+}
+/// NameNeedsQuoting - Return true if the identifier \arg Str needs quotes to be
+/// syntactically correct.
+static bool NameNeedsQuoting(StringRef Str) {
+ assert(!Str.empty() && "Cannot create an empty MCSymbol");
+
// If any of the characters in the string is an unacceptable character, force
// quotes.
- for (unsigned i = 0, e = Str.size(); i != e; ++i) {
- char C = Str[i];
-
- if ((C < 'a' || C > 'z') &&
- (C < 'A' || C > 'Z') &&
- (C < '0' || C > '9') &&
- C != '_' && C != '$' && C != '.' && C != '@')
+ for (unsigned i = 0, e = Str.size(); i != e; ++i)
+ if (!isAcceptableChar(Str[i]))
return true;
- }
return false;
}
-void MCSymbol::print(raw_ostream &OS, const MCAsmInfo *MAI) const {
- if (!MAI || ShouldQuoteIdentifier(getName(), *MAI))
- OS << '"' << getName() << '"';
- else
+void MCSymbol::print(raw_ostream &OS) const {
+ // The name for this MCSymbol is required to be a valid target name. However,
+ // some targets support quoting names with funny characters. If the name
+ // contains a funny character, then print it quoted.
+ if (!NameNeedsQuoting(getName())) {
OS << getName();
+ return;
+ }
+
+ OS << '"' << getName() << '"';
}
void MCSymbol::dump() const {
- print(errs(), 0);
+ print(dbgs());
}