Fix PR4948 (and a leak): by not destroying the DwarfException
[llvm/avr.git] / lib / MC / MCSymbol.cpp
blobef58aecf33cd7f832f9c09b21dc6b4126eb92a0b
1 //===- lib/MC/MCSymbol.cpp - MCSymbol implementation ----------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
10 #include "llvm/MC/MCSymbol.h"
11 #include "llvm/MC/MCAsmInfo.h"
12 #include "llvm/Support/raw_ostream.h"
13 using namespace llvm;
15 // Sentinel value for the absolute pseudo section.
16 const MCSection *MCSymbol::AbsolutePseudoSection =
17 reinterpret_cast<const MCSection *>(1);
19 /// ShouldQuoteIdentifier - Return true if the identifier \arg Str needs quotes
20 /// for this assembler.
21 static bool ShouldQuoteIdentifier(const StringRef &Str, const MCAsmInfo &MAI) {
22 // If the assembler doesn't support quotes, never use them.
23 if (!MAI.doesAllowQuotesInName())
24 return false;
26 // If empty, we need quotes.
27 if (Str.empty())
28 return true;
30 // If the first character is a number, we need quotes.
31 if (Str[0] >= '0' && Str[0] <= '9')
32 return true;
34 // If any of the characters in the string is an unacceptable character, force
35 // quotes.
36 for (unsigned i = 0, e = Str.size(); i != e; ++i) {
37 char C = Str[i];
39 if ((C < 'a' || C > 'z') &&
40 (C < 'A' || C > 'Z') &&
41 (C < '0' || C > '9') &&
42 C != '_' && C != '$' && C != '.' && C != '@')
43 return true;
45 return false;
48 void MCSymbol::print(raw_ostream &OS, const MCAsmInfo *MAI) const {
49 if (!MAI || ShouldQuoteIdentifier(getName(), *MAI))
50 OS << '"' << getName() << '"';
51 else
52 OS << getName();
55 void MCSymbol::dump() const {
56 print(errs(), 0);