MC: Use accessors for access to MCAsmFixup.
authorDaniel Dunbar <daniel@zuster.org>
Wed, 26 May 2010 15:18:31 +0000 (15:18 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Wed, 26 May 2010 15:18:31 +0000 (15:18 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@104697 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/MC/MCAssembler.h
lib/MC/MCAssembler.cpp
lib/MC/MCMachOStreamer.cpp
lib/MC/MachObjectWriter.cpp
lib/Target/X86/X86AsmBackend.cpp

index 7b2ce9c6f58f341b389fc5916fffd0e6141955c1..c34042bd5221f1712fee8025b5a69fbcd1e2526a 100644 (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);
   }
index 02b4a8d3c9dcf9d20c3986a31076a69875731d98..de04d2b553594a6639a734b6f5f569944cc286dc 100644 (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;
 }
 
index 660284ef00bf15991c087ba76b5e514b401ea73c..eaa89fac6495102bab4f50d0b462fcbb64cfd5ba 100644 (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());
index fc742e4aa5c13f03343ce7402dd2c5ea83845cda..464bf86a7287872ec6a7903addebd62375202b6b 100644 (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;
index e072392987c37517211f5ce598db94ee66f968ec..eec310b71a483cf669f4939bf59bf1189532c900 100644 (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;
     }