Move EmitValue to MCObjectStreamer.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120269 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola 2010-11-28 23:08:47 +00:00
parent 08d55342e3
commit 6f95023a7f
5 changed files with 20 additions and 65 deletions

View File

@ -61,6 +61,7 @@ public:
/// @{
virtual void EmitLabel(MCSymbol *Symbol);
virtual void EmitValue(const MCExpr *Value, unsigned Size,unsigned AddrSpace);
virtual void EmitULEB128Value(const MCExpr *Value, unsigned AddrSpace = 0);
virtual void EmitSLEB128Value(const MCExpr *Value, unsigned AddrSpace = 0);
virtual void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol);

View File

@ -124,7 +124,6 @@ public:
assert(0 && "ELF doesn't support this directive");
}
virtual void EmitBytes(StringRef Data, unsigned AddrSpace);
virtual void EmitValue(const MCExpr *Value, unsigned Size,unsigned AddrSpace);
virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0,
unsigned ValueSize = 1,
unsigned MaxBytesToEmit = 0);
@ -370,25 +369,6 @@ void MCELFStreamer::EmitBytes(StringRef Data, unsigned AddrSpace) {
getOrCreateDataFragment()->getContents().append(Data.begin(), Data.end());
}
void MCELFStreamer::EmitValue(const MCExpr *Value, unsigned Size,
unsigned AddrSpace) {
// TODO: This is exactly the same as WinCOFFStreamer. Consider merging into
// MCObjectStreamer.
MCDataFragment *DF = getOrCreateDataFragment();
// Avoid fixups when possible.
int64_t AbsValue;
if (AddValueSymbols(Value)->EvaluateAsAbsolute(AbsValue)) {
// FIXME: Endianness assumption.
for (unsigned i = 0; i != Size; ++i)
DF->getContents().push_back(uint8_t(AbsValue >> (i * 8)));
} else {
DF->addFixup(MCFixup::Create(DF->getContents().size(), AddValueSymbols(Value),
MCFixup::getKindForSize(Size, false)));
DF->getContents().resize(DF->getContents().size() + Size, 0);
}
}
void MCELFStreamer::EmitValueToAlignment(unsigned ByteAlignment,
int64_t Value, unsigned ValueSize,
unsigned MaxBytesToEmit) {

View File

@ -74,7 +74,6 @@ public:
virtual void EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol,
uint64_t Size, unsigned ByteAlignment = 0);
virtual void EmitBytes(StringRef Data, unsigned AddrSpace);
virtual void EmitValue(const MCExpr *Value, unsigned Size,unsigned AddrSpace);
virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0,
unsigned ValueSize = 1,
unsigned MaxBytesToEmit = 0);
@ -307,26 +306,6 @@ void MCMachOStreamer::EmitBytes(StringRef Data, unsigned AddrSpace) {
getOrCreateDataFragment()->getContents().append(Data.begin(), Data.end());
}
void MCMachOStreamer::EmitValue(const MCExpr *Value, unsigned Size,
unsigned AddrSpace) {
// TODO: This is exactly the same as WinCOFFStreamer. Consider merging into
// MCObjectStreamer.
MCDataFragment *DF = getOrCreateDataFragment();
// Avoid fixups when possible.
int64_t AbsValue;
if (AddValueSymbols(Value)->EvaluateAsAbsolute(AbsValue)) {
// FIXME: Endianness assumption.
for (unsigned i = 0; i != Size; ++i)
DF->getContents().push_back(uint8_t(AbsValue >> (i * 8)));
} else {
DF->addFixup(MCFixup::Create(DF->getContents().size(),
AddValueSymbols(Value),
MCFixup::getKindForSize(Size, false)));
DF->getContents().resize(DF->getContents().size() + Size, 0);
}
}
void MCMachOStreamer::EmitValueToAlignment(unsigned ByteAlignment,
int64_t Value, unsigned ValueSize,
unsigned MaxBytesToEmit) {

View File

@ -76,6 +76,25 @@ const MCExpr *MCObjectStreamer::AddValueSymbols(const MCExpr *Value) {
return Value;
}
void MCObjectStreamer::EmitValue(const MCExpr *Value, unsigned Size,
unsigned AddrSpace) {
assert(AddrSpace == 0 && "Address space must be 0!");
MCDataFragment *DF = getOrCreateDataFragment();
// Avoid fixups when possible.
int64_t AbsValue;
if (AddValueSymbols(Value)->EvaluateAsAbsolute(AbsValue)) {
// FIXME: Endianness assumption.
for (unsigned i = 0; i != Size; ++i)
DF->getContents().push_back(uint8_t(AbsValue >> (i * 8)));
} else {
DF->addFixup(MCFixup::Create(DF->getContents().size(),
AddValueSymbols(Value),
MCFixup::getKindForSize(Size, false)));
DF->getContents().resize(DF->getContents().size() + Size, 0);
}
}
void MCObjectStreamer::EmitLabel(MCSymbol *Symbol) {
assert(!Symbol->isVariable() && "Cannot emit a variable symbol!");
assert(CurSection && "Cannot emit before setting section!");

View File

@ -68,8 +68,6 @@ public:
virtual void EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol,
uint64_t Size, unsigned ByteAlignment);
virtual void EmitBytes(StringRef Data, unsigned AddrSpace);
virtual void EmitValue(const MCExpr *Value, unsigned Size,
unsigned AddrSpace);
virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value,
unsigned ValueSize, unsigned MaxBytesToEmit);
virtual void EmitCodeAlignment(unsigned ByteAlignment,
@ -328,28 +326,6 @@ void WinCOFFStreamer::EmitBytes(StringRef Data, unsigned AddrSpace) {
getOrCreateDataFragment()->getContents().append(Data.begin(), Data.end());
}
void WinCOFFStreamer::EmitValue(const MCExpr *Value, unsigned Size,
unsigned AddrSpace) {
assert(AddrSpace == 0 && "Address space must be 0!");
// TODO: This is copied exactly from the MachOStreamer. Consider merging into
// MCObjectStreamer?
MCDataFragment *DF = getOrCreateDataFragment();
// Avoid fixups when possible.
int64_t AbsValue;
if (AddValueSymbols(Value)->EvaluateAsAbsolute(AbsValue)) {
// FIXME: Endianness assumption.
for (unsigned i = 0; i != Size; ++i)
DF->getContents().push_back(uint8_t(AbsValue >> (i * 8)));
} else {
DF->addFixup(MCFixup::Create(DF->getContents().size(),
AddValueSymbols(Value),
MCFixup::getKindForSize(Size, false)));
DF->getContents().resize(DF->getContents().size() + Size, 0);
}
}
void WinCOFFStreamer::EmitValueToAlignment(unsigned ByteAlignment,
int64_t Value,
unsigned ValueSize,