MC: Use accessors for access to MCAsmFixup.

llvm-svn: 104697
This commit is contained in:
Daniel Dunbar 2010-05-26 15:18:31 +00:00
parent 3627af5da4
commit 353a91ff76
5 changed files with 38 additions and 27 deletions

View File

@ -42,7 +42,6 @@ class TargetAsmBackend;
//
// FIXME: This should probably just be merged with MCFixup.
class MCAsmFixup {
public:
/// Offset - The offset inside the fragment which needs to be rewritten.
uint64_t Offset;
@ -55,6 +54,13 @@ public:
public:
MCAsmFixup(uint64_t _Offset, const MCExpr &_Value, MCFixupKind _Kind)
: Offset(_Offset), Value(&_Value), Kind(_Kind) {}
MCFixupKind getKind() const { return MCFixupKind(Kind); }
uint64_t getOffset() const { return Offset; }
void setOffset(uint64_t Value) { Offset = Value; }
const MCExpr *getValue() const { return Value; }
};
class MCFragment : public ilist_node<MCFragment> {
@ -150,7 +156,7 @@ public:
void addFixup(MCAsmFixup Fixup) {
// Enforce invariant that fixups are in offset order.
assert((Fixups.empty() || Fixup.Offset > Fixups.back().Offset) &&
assert((Fixups.empty() || Fixup.getOffset() > Fixups.back().getOffset()) &&
"Fixups must be added in order!");
Fixups.push_back(Fixup);
}

View File

@ -347,7 +347,7 @@ bool MCAssembler::EvaluateFixup(const MCAsmLayout &Layout,
MCValue &Target, uint64_t &Value) const {
++stats::EvaluateFixup;
if (!Fixup.Value->EvaluateAsRelocatable(Target, &Layout))
if (!Fixup.getValue()->EvaluateAsRelocatable(Target, &Layout))
report_fatal_error("expected relocatable expression");
// FIXME: How do non-scattered symbols work in ELF? I presume the linker
@ -356,8 +356,8 @@ bool MCAssembler::EvaluateFixup(const MCAsmLayout &Layout,
Value = Target.getConstant();
bool IsPCRel =
Emitter.getFixupKindInfo(Fixup.Kind).Flags & MCFixupKindInfo::FKF_IsPCRel;
bool IsPCRel = Emitter.getFixupKindInfo(
Fixup.getKind()).Flags & MCFixupKindInfo::FKF_IsPCRel;
bool IsResolved = true;
if (const MCSymbolRefExpr *A = Target.getSymA()) {
if (A->getSymbol().isDefined())
@ -399,7 +399,7 @@ bool MCAssembler::EvaluateFixup(const MCAsmLayout &Layout,
}
if (IsPCRel)
Value -= Layout.getFragmentAddress(DF) + Fixup.Offset;
Value -= Layout.getFragmentAddress(DF) + Fixup.getOffset();
return IsResolved;
}
@ -905,8 +905,9 @@ void MCAssembler::FinishLayout(MCAsmLayout &Layout) {
namespace llvm {
raw_ostream &operator<<(raw_ostream &OS, const MCAsmFixup &AF) {
OS << "<MCAsmFixup" << " Offset:" << AF.Offset << " Value:" << *AF.Value
<< " Kind:" << AF.Kind << ">";
OS << "<MCAsmFixup" << " Offset:" << AF.getOffset()
<< " Value:" << *AF.getValue()
<< " Kind:" << AF.getKind() << ">";
return OS;
}

View File

@ -471,7 +471,7 @@ void MCMachOStreamer::EmitInstruction(const MCInst &Inst) {
// Add the fixups and data.
MCDataFragment *DF = getOrCreateDataFragment();
for (unsigned i = 0, e = AsmFixups.size(); i != e; ++i) {
AsmFixups[i].Offset += DF->getContents().size();
AsmFixups[i].setOffset(AsmFixups[i].getOffset() + DF->getContents().size());
DF->addFixup(AsmFixups[i]);
}
DF->getContents().append(Code.begin(), Code.end());

View File

@ -474,13 +474,15 @@ public:
const MCFragment *Fragment,
const MCAsmFixup &Fixup, MCValue Target,
uint64_t &FixedValue) {
unsigned IsPCRel = isFixupKindPCRel(Fixup.Kind);
unsigned IsRIPRel = isFixupKindRIPRel(Fixup.Kind);
unsigned Log2Size = getFixupKindLog2Size(Fixup.Kind);
unsigned IsPCRel = isFixupKindPCRel(Fixup.getKind());
unsigned IsRIPRel = isFixupKindRIPRel(Fixup.getKind());
unsigned Log2Size = getFixupKindLog2Size(Fixup.getKind());
// See <reloc.h>.
uint32_t FixupOffset = Layout.getFragmentOffset(Fragment) + Fixup.Offset;
uint32_t FixupAddress = Layout.getFragmentAddress(Fragment) + Fixup.Offset;
uint32_t FixupOffset =
Layout.getFragmentOffset(Fragment) + Fixup.getOffset();
uint32_t FixupAddress =
Layout.getFragmentAddress(Fragment) + Fixup.getOffset();
int64_t Value = 0;
unsigned Index = 0;
unsigned IsExtern = 0;
@ -606,7 +608,7 @@ public:
// x86_64 distinguishes movq foo@GOTPCREL so that the linker can
// rewrite the movq to an leaq at link time if the symbol ends up in
// the same linkage unit.
if (unsigned(Fixup.Kind) == X86::reloc_riprel_4byte_movq_load)
if (unsigned(Fixup.getKind()) == X86::reloc_riprel_4byte_movq_load)
Type = RIT_X86_64_GOTLoad;
else
Type = RIT_X86_64_GOT;
@ -682,9 +684,9 @@ public:
const MCFragment *Fragment,
const MCAsmFixup &Fixup, MCValue Target,
uint64_t &FixedValue) {
uint32_t FixupOffset = Layout.getFragmentOffset(Fragment) + Fixup.Offset;
unsigned IsPCRel = isFixupKindPCRel(Fixup.Kind);
unsigned Log2Size = getFixupKindLog2Size(Fixup.Kind);
uint32_t FixupOffset = Layout.getFragmentOffset(Fragment)+Fixup.getOffset();
unsigned IsPCRel = isFixupKindPCRel(Fixup.getKind());
unsigned Log2Size = getFixupKindLog2Size(Fixup.getKind());
unsigned Type = RIT_Vanilla;
// See <reloc.h>.
@ -744,8 +746,8 @@ public:
return;
}
unsigned IsPCRel = isFixupKindPCRel(Fixup.Kind);
unsigned Log2Size = getFixupKindLog2Size(Fixup.Kind);
unsigned IsPCRel = isFixupKindPCRel(Fixup.getKind());
unsigned Log2Size = getFixupKindLog2Size(Fixup.getKind());
// If this is a difference or a defined symbol plus an offset, then we need
// a scattered relocation entry.
@ -769,7 +771,7 @@ public:
Target, FixedValue);
// See <reloc.h>.
uint32_t FixupOffset = Layout.getFragmentOffset(Fragment) + Fixup.Offset;
uint32_t FixupOffset = Layout.getFragmentOffset(Fragment)+Fixup.getOffset();
uint32_t Value = 0;
unsigned Index = 0;
unsigned IsExtern = 0;

View File

@ -46,12 +46,12 @@ public:
void ApplyFixup(const MCAsmFixup &Fixup, MCDataFragment &DF,
uint64_t Value) const {
unsigned Size = 1 << getFixupKindLog2Size(Fixup.Kind);
unsigned Size = 1 << getFixupKindLog2Size(Fixup.getKind());
assert(Fixup.Offset + Size <= DF.getContents().size() &&
assert(Fixup.getOffset() + Size <= DF.getContents().size() &&
"Invalid fixup offset!");
for (unsigned i = 0; i != Size; ++i)
DF.getContents()[Fixup.Offset + i] = uint8_t(Value >> (i * 8));
DF.getContents()[Fixup.getOffset() + i] = uint8_t(Value >> (i * 8));
}
bool MayNeedRelaxation(const MCInst &Inst,
@ -91,6 +91,8 @@ static unsigned getRelaxedOpcode(unsigned Op) {
bool X86AsmBackend::MayNeedRelaxation(const MCInst &Inst,
const SmallVectorImpl<MCAsmFixup> &Fixups) const {
for (unsigned i = 0, e = Fixups.size(); i != e; ++i) {
const MCAsmFixup &F = Fixups[i];
// We don't support relaxing anything else currently. Make sure we error out
// if we see a non-constant 1 or 2 byte fixup.
//
@ -98,13 +100,13 @@ bool X86AsmBackend::MayNeedRelaxation(const MCInst &Inst,
// object writer which should be verifying that any final relocations match
// the expected fixup. However, that code is more complicated and hasn't
// been written yet. See the FIXMEs in MachObjectWriter.cpp.
if ((Fixups[i].Kind == FK_Data_1 || Fixups[i].Kind == FK_Data_2) &&
!isa<MCConstantExpr>(Fixups[i].Value))
if ((F.getKind() == FK_Data_1 || F.getKind() == FK_Data_2) &&
!isa<MCConstantExpr>(F.getValue()))
report_fatal_error("unexpected small fixup with a non-constant operand!");
// Check for a 1byte pcrel fixup, and enforce that we would know how to
// relax this instruction.
if (unsigned(Fixups[i].Kind) == X86::reloc_pcrel_1byte) {
if (unsigned(F.getKind()) == X86::reloc_pcrel_1byte) {
assert(getRelaxedOpcode(Inst.getOpcode()) != Inst.getOpcode());
return true;
}