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"
|
2015-06-09 00:31:39 +00:00
|
|
|
#include "llvm/MC/MCAsmInfo.h"
|
2015-06-09 18:36:13 +00:00
|
|
|
#include "llvm/MC/MCContext.h"
|
2010-05-05 19:00:56 +00:00
|
|
|
#include "llvm/MC/MCExpr.h"
|
2010-01-05 01:28:10 +00:00
|
|
|
#include "llvm/Support/Debug.h"
|
2015-06-09 00:31:39 +00:00
|
|
|
#include "llvm/Support/ErrorHandling.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.
|
2015-05-21 19:20:38 +00:00
|
|
|
MCSection *MCSymbol::AbsolutePseudoSection = reinterpret_cast<MCSection *>(1);
|
2009-08-22 07:22:36 +00:00
|
|
|
|
2015-06-09 19:56:05 +00: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-09 18:36:13 +00: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-09 23:33:35 +00:00
|
|
|
static_assert((unsigned)AlignOf<MCSymbol>::Alignment <=
|
2015-06-09 20:58:03 +00:00
|
|
|
AlignOf<NameEntryStorageTy>::Alignment,
|
|
|
|
"Bad alignment of MCSymbol");
|
2015-06-09 19:56:05 +00:00
|
|
|
void *Storage = Ctx.allocate(Size, alignOf<NameEntryStorageTy>());
|
|
|
|
NameEntryStorageTy *Start = static_cast<NameEntryStorageTy*>(Storage);
|
|
|
|
NameEntryStorageTy *End = Start + (Name ? 1 : 0);
|
2015-06-09 18:36:13 +00:00
|
|
|
return End;
|
|
|
|
}
|
|
|
|
|
2010-05-05 19:00:56 +00:00
|
|
|
void MCSymbol::setVariableValue(const MCExpr *Value) {
|
2010-11-15 14:40:36 +00:00
|
|
|
assert(!IsUsed && "Cannot set a variable that has already been used.");
|
2010-05-05 19:00:56 +00:00
|
|
|
assert(Value && "Invalid variable value!");
|
2015-06-22 19:57:33 +00:00
|
|
|
assert((SymbolContents == SymContentsUnset ||
|
|
|
|
SymbolContents == SymContentsVariable) &&
|
|
|
|
"Cannot give common/offset symbol a variable value");
|
2010-05-05 19:00:56 +00:00
|
|
|
this->Value = Value;
|
2015-06-22 19:57:33 +00:00
|
|
|
SymbolContents = SymContentsVariable;
|
2015-06-30 20:54:21 +00:00
|
|
|
setUndefined();
|
2010-05-05 19:00:56 +00:00
|
|
|
}
|
|
|
|
|
2015-06-09 00:31:39 +00:00
|
|
|
void MCSymbol::print(raw_ostream &OS, const MCAsmInfo *MAI) const {
|
2010-01-17 19:23:46 +00: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 06:05:49 +00:00
|
|
|
StringRef Name = getName();
|
2015-06-09 00:31:39 +00:00
|
|
|
if (!MAI || MAI->isValidUnquotedName(Name)) {
|
2013-11-14 06:05:49 +00:00
|
|
|
OS << Name;
|
2009-09-13 18:04:46 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-05-11 01:41:30 +00:00
|
|
|
|
2015-06-09 00:31:39 +00:00
|
|
|
if (MAI && !MAI->supportsNameQuoting())
|
|
|
|
report_fatal_error("Symbol name with unsupported characters");
|
|
|
|
|
2013-11-14 06:05:49 +00:00
|
|
|
OS << '"';
|
2015-06-09 00:31:39 +00:00
|
|
|
for (char C : Name) {
|
2013-11-14 06:05:49 +00:00
|
|
|
if (C == '\n')
|
|
|
|
OS << "\\n";
|
|
|
|
else if (C == '"')
|
|
|
|
OS << "\\\"";
|
|
|
|
else
|
|
|
|
OS << C;
|
|
|
|
}
|
|
|
|
OS << '"';
|
2009-08-14 03:41:23 +00:00
|
|
|
}
|
|
|
|
|
2012-09-12 05:06:18 +00:00
|
|
|
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
|
2015-05-27 13:05:42 +00:00
|
|
|
void MCSymbol::dump() const { dbgs() << *this; }
|
2012-09-06 19:55:56 +00:00
|
|
|
#endif
|