2009-08-14 03:41:23 +00:00
|
|
|
//===- lib/MC/MCSymbol.cpp - MCSymbol implementation ----------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/MC/MCSymbol.h"
|
2009-09-03 05:57:47 +00:00
|
|
|
#include "llvm/MC/MCAsmInfo.h"
|
2009-08-14 03:41:23 +00:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
using namespace llvm;
|
|
|
|
|
2009-08-22 07:22:36 +00:00
|
|
|
// Sentinel value for the absolute pseudo section.
|
|
|
|
const MCSection *MCSymbol::AbsolutePseudoSection =
|
|
|
|
reinterpret_cast<const MCSection *>(1);
|
|
|
|
|
2009-09-03 05:57:47 +00:00
|
|
|
/// 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())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// If empty, we need quotes.
|
2009-08-14 03:41:23 +00:00
|
|
|
if (Str.empty())
|
|
|
|
return true;
|
2009-09-03 05:57:47 +00:00
|
|
|
|
|
|
|
// If the first character is a number, we need quotes.
|
|
|
|
if (Str[0] >= '0' && Str[0] <= '9')
|
2009-08-14 03:41:23 +00:00
|
|
|
return true;
|
|
|
|
|
2009-09-03 05:57:47 +00:00
|
|
|
// 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') &&
|
2009-09-09 00:14:09 +00:00
|
|
|
C != '_' && C != '$' && C != '.' && C != '@')
|
2009-08-14 03:41:23 +00:00
|
|
|
return true;
|
2009-09-03 05:57:47 +00:00
|
|
|
}
|
2009-08-14 03:41:23 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-09-03 05:46:51 +00:00
|
|
|
void MCSymbol::print(raw_ostream &OS, const MCAsmInfo *MAI) const {
|
2009-09-03 05:57:47 +00:00
|
|
|
if (!MAI || ShouldQuoteIdentifier(getName(), *MAI))
|
2009-08-14 03:41:23 +00:00
|
|
|
OS << '"' << getName() << '"';
|
|
|
|
else
|
|
|
|
OS << getName();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MCSymbol::dump() const {
|
2009-09-03 05:46:51 +00:00
|
|
|
print(errs(), 0);
|
2009-08-14 03:41:23 +00:00
|
|
|
}
|