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/MCAsmInfo.h"
12 #include "llvm/MC/MCContext.h"
13 #include "llvm/MC/MCExpr.h"
14 #include "llvm/Support/Debug.h"
15 #include "llvm/Support/ErrorHandling.h"
16 #include "llvm/Support/raw_ostream.h"
19 // Sentinel value for the absolute pseudo section.
20 MCSection *MCSymbol::AbsolutePseudoSection = reinterpret_cast<MCSection *>(1);
22 void *MCSymbol::operator new(size_t s, const StringMapEntry<bool> *Name,
24 // We may need more space for a Name to account for alignment. So allocate
25 // space for the storage type and not the name pointer.
26 size_t Size = s + (Name ? sizeof(NameEntryStorageTy) : 0);
28 // For safety, ensure that the alignment of a pointer is enough for an
29 // MCSymbol. This also ensures we don't need padding between the name and
31 assert(alignOf<MCSymbol>() <= alignOf<NameEntryStorageTy>() &&
32 "Bad alignment of MCSymbol");
33 void *Storage = Ctx.allocate(Size, alignOf<NameEntryStorageTy>());
34 NameEntryStorageTy *Start = static_cast<NameEntryStorageTy*>(Storage);
35 NameEntryStorageTy *End = Start + (Name ? 1 : 0);
39 void MCSymbol::setVariableValue(const MCExpr *Value) {
40 assert(!IsUsed && "Cannot set a variable that has already been used.");
41 assert(Value && "Invalid variable value!");
43 SectionOrFragment = nullptr;
46 void MCSymbol::print(raw_ostream &OS, const MCAsmInfo *MAI) const {
47 // The name for this MCSymbol is required to be a valid target name. However,
48 // some targets support quoting names with funny characters. If the name
49 // contains a funny character, then print it quoted.
50 StringRef Name = getName();
51 if (!MAI || MAI->isValidUnquotedName(Name)) {
56 if (MAI && !MAI->supportsNameQuoting())
57 report_fatal_error("Symbol name with unsupported characters");
71 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
72 void MCSymbol::dump() const { dbgs() << *this; }