[llvm-commits] [llvm] r98947 - in /llvm/trunk: include/llvm/Target/TargetAsmBackend.h lib/MC/MCAssembler.cpp lib/Target/X86/X86AsmBackend.cpp
Daniel Dunbar
daniel at zuster.org
Fri Mar 19 02:28:12 PDT 2010
Author: ddunbar
Date: Fri Mar 19 04:28:12 2010
New Revision: 98947
URL: http://llvm.org/viewvc/llvm-project?rev=98947&view=rev
Log:
MCAssembler: Move ApplyFixup to the TargetAsmBackend, this is a target specific not object writer specific task.
Modified:
llvm/trunk/include/llvm/Target/TargetAsmBackend.h
llvm/trunk/lib/MC/MCAssembler.cpp
llvm/trunk/lib/Target/X86/X86AsmBackend.cpp
Modified: llvm/trunk/include/llvm/Target/TargetAsmBackend.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetAsmBackend.h?rev=98947&r1=98946&r2=98947&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Target/TargetAsmBackend.h (original)
+++ llvm/trunk/include/llvm/Target/TargetAsmBackend.h Fri Mar 19 04:28:12 2010
@@ -10,7 +10,11 @@
#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 @@
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
Modified: llvm/trunk/lib/MC/MCAssembler.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAssembler.cpp?rev=98947&r1=98946&r2=98947&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCAssembler.cpp (original)
+++ llvm/trunk/lib/MC/MCAssembler.cpp Fri Mar 19 04:28:12 2010
@@ -930,17 +930,6 @@
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 @@
MOW.RecordRelocation(*this, *DF, Fixup, Target, FixedValue);
}
- MOW.ApplyFixup(Fixup, *DF, FixedValue);
+ getBackend().ApplyFixup(Fixup, *DF, FixedValue);
}
}
}
Modified: llvm/trunk/lib/Target/X86/X86AsmBackend.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86AsmBackend.cpp?rev=98947&r1=98946&r2=98947&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86AsmBackend.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86AsmBackend.cpp Fri Mar 19 04:28:12 2010
@@ -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 @@
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 {
More information about the llvm-commits
mailing list