2009-08-14 11:41:23 +08: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"
|
2015-06-09 08:31:39 +08:00
|
|
|
#include "llvm/MC/MCAsmInfo.h"
|
2015-06-10 02:36:13 +08:00
|
|
|
#include "llvm/MC/MCContext.h"
|
2010-05-06 03:00:56 +08:00
|
|
|
#include "llvm/MC/MCExpr.h"
|
2010-01-05 09:28:10 +08:00
|
|
|
#include "llvm/Support/Debug.h"
|
2015-06-09 08:31:39 +08:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2009-08-14 11:41:23 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
using namespace llvm;
|
|
|
|
|
2009-08-22 15:22:36 +08:00
|
|
|
// Sentinel value for the absolute pseudo section.
|
2015-05-22 03:20:38 +08:00
|
|
|
MCSection *MCSymbol::AbsolutePseudoSection = reinterpret_cast<MCSection *>(1);
|
2009-08-22 15:22:36 +08:00
|
|
|
|
2015-06-10 03:56:05 +08:00
|
|
|
void *MCSymbol::operator new(size_t s, const StringMapEntry<bool> *Name,
|
|
|
|
MCContext &Ctx) {
|
|
|
|
// We may need more space for a Name to account for alignment. So allocate
|
|
|
|
// space for the storage type and not the name pointer.
|
|
|
|
size_t Size = s + (Name ? sizeof(NameEntryStorageTy) : 0);
|
2015-06-10 02:36:13 +08:00
|
|
|
|
|
|
|
// For safety, ensure that the alignment of a pointer is enough for an
|
|
|
|
// MCSymbol. This also ensures we don't need padding between the name and
|
|
|
|
// symbol.
|
2015-06-10 04:41:08 +08:00
|
|
|
// FIXME: Use static_assert when constexpr is supported.
|
2015-06-10 03:56:05 +08:00
|
|
|
assert(alignOf<MCSymbol>() <= alignOf<NameEntryStorageTy>() &&
|
2015-06-10 02:36:13 +08:00
|
|
|
"Bad alignment of MCSymbol");
|
2015-06-10 03:56:05 +08:00
|
|
|
void *Storage = Ctx.allocate(Size, alignOf<NameEntryStorageTy>());
|
|
|
|
NameEntryStorageTy *Start = static_cast<NameEntryStorageTy*>(Storage);
|
|
|
|
NameEntryStorageTy *End = Start + (Name ? 1 : 0);
|
2015-06-10 02:36:13 +08:00
|
|
|
return End;
|
|
|
|
}
|
|
|
|
|
2010-05-06 03:00:56 +08:00
|
|
|
void MCSymbol::setVariableValue(const MCExpr *Value) {
|
2010-11-15 22:40:36 +08:00
|
|
|
assert(!IsUsed && "Cannot set a variable that has already been used.");
|
2010-05-06 03:00:56 +08:00
|
|
|
assert(Value && "Invalid variable value!");
|
|
|
|
this->Value = Value;
|
2015-06-09 02:41:57 +08:00
|
|
|
SectionOrFragment = nullptr;
|
2010-05-06 03:00:56 +08:00
|
|
|
}
|
|
|
|
|
2015-06-09 08:31:39 +08:00
|
|
|
void MCSymbol::print(raw_ostream &OS, const MCAsmInfo *MAI) const {
|
2010-01-18 03:23:46 +08: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.
|
2013-11-14 14:05:49 +08:00
|
|
|
StringRef Name = getName();
|
2015-06-09 08:31:39 +08:00
|
|
|
if (!MAI || MAI->isValidUnquotedName(Name)) {
|
2013-11-14 14:05:49 +08:00
|
|
|
OS << Name;
|
2009-09-14 02:04:46 +08:00
|
|
|
return;
|
|
|
|
}
|
2012-05-11 09:41:30 +08:00
|
|
|
|
2015-06-09 08:31:39 +08:00
|
|
|
if (MAI && !MAI->supportsNameQuoting())
|
|
|
|
report_fatal_error("Symbol name with unsupported characters");
|
|
|
|
|
2013-11-14 14:05:49 +08:00
|
|
|
OS << '"';
|
2015-06-09 08:31:39 +08:00
|
|
|
for (char C : Name) {
|
2013-11-14 14:05:49 +08:00
|
|
|
if (C == '\n')
|
|
|
|
OS << "\\n";
|
|
|
|
else if (C == '"')
|
|
|
|
OS << "\\\"";
|
|
|
|
else
|
|
|
|
OS << C;
|
|
|
|
}
|
|
|
|
OS << '"';
|
2009-08-14 11:41:23 +08:00
|
|
|
}
|
|
|
|
|
2012-09-12 13:06:18 +08:00
|
|
|
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
|
2015-05-27 21:05:42 +08:00
|
|
|
void MCSymbol::dump() const { dbgs() << *this; }
|
2012-09-07 03:55:56 +08:00
|
|
|
#endif
|