2009-08-14 05:41:23 +02: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"
|
2010-01-05 02:28:10 +01:00
|
|
|
#include "llvm/Support/Debug.h"
|
2009-08-14 05:41:23 +02:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
using namespace llvm;
|
|
|
|
|
2009-08-22 09:22:36 +02:00
|
|
|
// Sentinel value for the absolute pseudo section.
|
|
|
|
const MCSection *MCSymbol::AbsolutePseudoSection =
|
|
|
|
reinterpret_cast<const MCSection *>(1);
|
|
|
|
|
2009-09-13 20:04:46 +02:00
|
|
|
static bool isAcceptableChar(char C) {
|
|
|
|
if ((C < 'a' || C > 'z') &&
|
|
|
|
(C < 'A' || C > 'Z') &&
|
|
|
|
(C < '0' || C > '9') &&
|
|
|
|
C != '_' && C != '$' && C != '.' && C != '@')
|
2009-09-03 07:57:47 +02:00
|
|
|
return false;
|
2009-09-13 20:04:46 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-01-17 21:11:03 +01:00
|
|
|
/// NameNeedsQuoting - Return true if the identifier \arg Str needs quotes to be
|
|
|
|
/// syntactically correct.
|
|
|
|
static bool NameNeedsQuoting(StringRef Str) {
|
2009-09-13 20:04:46 +02:00
|
|
|
assert(!Str.empty() && "Cannot create an empty MCSymbol");
|
2009-09-03 07:57:47 +02:00
|
|
|
|
|
|
|
// If any of the characters in the string is an unacceptable character, force
|
|
|
|
// quotes.
|
2009-09-13 20:04:46 +02:00
|
|
|
for (unsigned i = 0, e = Str.size(); i != e; ++i)
|
|
|
|
if (!isAcceptableChar(Str[i]))
|
2009-08-14 05:41:23 +02:00
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-01-17 22:43:43 +01:00
|
|
|
void MCSymbol::print(raw_ostream &OS) const {
|
2010-01-17 20:23:46 +01:00
|
|
|
// 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.
|
2010-01-17 21:11:03 +01:00
|
|
|
if (!NameNeedsQuoting(getName())) {
|
2009-08-14 05:41:23 +02:00
|
|
|
OS << getName();
|
2009-09-13 20:04:46 +02:00
|
|
|
return;
|
|
|
|
}
|
2009-09-13 20:11:09 +02:00
|
|
|
|
|
|
|
OS << '"' << getName() << '"';
|
2009-08-14 05:41:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void MCSymbol::dump() const {
|
2010-01-17 22:43:43 +01:00
|
|
|
print(dbgs());
|
2009-08-14 05:41:23 +02:00
|
|
|
}
|