MCAssembler: Move ApplyFixup to the TargetAsmBackend, this is a target specific not...
authorDaniel Dunbar <daniel@zuster.org>
Fri, 19 Mar 2010 09:28:12 +0000 (09:28 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Fri, 19 Mar 2010 09:28:12 +0000 (09:28 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@98947 91177308-0d34-0410-b5e6-96231b3b80d8

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

index faf91c4e3a09ba75fe3bd3e867aebf1cde9d27b7..cada3e4479f0744ad3e8d06d5901dfbf561c8a3d 100644 (file)
 #ifndef LLVM_TARGET_TARGETASMBACKEND_H
 #define LLVM_TARGET_TARGETASMBACKEND_H
 
+#include "llvm/System/DataTypes.h"
+
 namespace llvm {
+class MCAsmFixup;
+class MCDataFragment;
 class MCSection;
 class Target;
 
@@ -75,6 +79,12 @@ public:
   virtual bool doesSectionRequireSymbols(const MCSection &Section) const {
     return false;
   }
+
+  /// ApplyFixup - Apply the \arg Value for given \arg Fixup into the provided
+  /// data fragment, at the offset specified by the fixup and following the
+  /// fixup kind as appropriate.
+  virtual void ApplyFixup(const MCAsmFixup &Fixup, MCDataFragment &Fragment,
+                          uint64_t Value) const = 0;
 };
 
 } // End llvm namespace
index 500f23f6909d35d487d32736a143b4d25c21127d..c4c3a8a4f85658b7e07edf5f52f6fbdb031745a6 100644 (file)
@@ -930,17 +930,6 @@ public:
       OS << StringTable.str();
     }
   }
-
-  void ApplyFixup(const MCAsmFixup &Fixup, MCDataFragment &DF,
-                  uint64_t FixedValue) {
-    unsigned Size = 1 << getFixupKindLog2Size(Fixup.Kind);
-
-    // FIXME: Endianness assumption.
-    assert(Fixup.Offset + Size <= DF.getContents().size() &&
-           "Invalid fixup offset!");
-    for (unsigned i = 0; i != Size; ++i)
-      DF.getContents()[Fixup.Offset + i] = uint8_t(FixedValue >> (i * 8));
-  }
 };
 
 /* *** */
@@ -1475,7 +1464,7 @@ void MCAssembler::Finish() {
           MOW.RecordRelocation(*this, *DF, Fixup, Target, FixedValue);
         }
 
-        MOW.ApplyFixup(Fixup, *DF, FixedValue);
+        getBackend().ApplyFixup(Fixup, *DF, FixedValue);
       }
     }
   }
index d7a9e1a96535cfd83072161c85f277346c663e73..fec563817e6c31489f02ebe85d2896ef60449b82 100644 (file)
@@ -9,6 +9,8 @@
 
 #include "llvm/Target/TargetAsmBackend.h"
 #include "X86.h"
+#include "X86FixupKinds.h"
+#include "llvm/MC/MCAssembler.h"
 #include "llvm/MC/MCSectionMachO.h"
 #include "llvm/Target/TargetRegistry.h"
 #include "llvm/Target/TargetAsmBackend.h"
@@ -16,10 +18,34 @@ using namespace llvm;
 
 namespace {
 
+static unsigned getFixupKindLog2Size(unsigned Kind) {
+  switch (Kind) {
+  default: assert(0 && "invalid fixup kind!");
+  case X86::reloc_pcrel_1byte:
+  case FK_Data_1: return 0;
+  case FK_Data_2: return 1;
+  case X86::reloc_pcrel_4byte:
+  case X86::reloc_riprel_4byte:
+  case X86::reloc_riprel_4byte_movq_load:
+  case FK_Data_4: return 2;
+  case FK_Data_8: return 3;
+  }
+}
+
 class X86AsmBackend : public TargetAsmBackend {
 public:
   X86AsmBackend(const Target &T)
     : TargetAsmBackend(T) {}
+
+  void ApplyFixup(const MCAsmFixup &Fixup, MCDataFragment &DF,
+                  uint64_t Value) const {
+    unsigned Size = 1 << getFixupKindLog2Size(Fixup.Kind);
+
+    assert(Fixup.Offset + Size <= DF.getContents().size() &&
+           "Invalid fixup offset!");
+    for (unsigned i = 0; i != Size; ++i)
+      DF.getContents()[Fixup.Offset + i] = uint8_t(Value >> (i * 8));
+  }
 };
 
 class DarwinX86AsmBackend : public X86AsmBackend {