[llvm-commits] [llvm] r95924 - in /llvm/trunk: include/llvm/MC/MCCodeEmitter.h lib/MC/MCAsmStreamer.cpp lib/MC/MCCodeEmitter.cpp lib/Target/X86/X86MCCodeEmitter.cpp
Chris Lattner
sabre at nondot.org
Thu Feb 11 13:27:18 PST 2010
Author: lattner
Date: Thu Feb 11 15:27:18 2010
New Revision: 95924
URL: http://llvm.org/viewvc/llvm-project?rev=95924&view=rev
Log:
make getFixupKindInfo return a const reference, allowing
the tables to be const. Teach MCCodeEmitter to handle
the target-indep kinds so that we don't crash on them.
Modified:
llvm/trunk/include/llvm/MC/MCCodeEmitter.h
llvm/trunk/lib/MC/MCAsmStreamer.cpp
llvm/trunk/lib/MC/MCCodeEmitter.cpp
llvm/trunk/lib/Target/X86/X86MCCodeEmitter.cpp
Modified: llvm/trunk/include/llvm/MC/MCCodeEmitter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCCodeEmitter.h?rev=95924&r1=95923&r2=95924&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCCodeEmitter.h (original)
+++ llvm/trunk/include/llvm/MC/MCCodeEmitter.h Thu Feb 11 15:27:18 2010
@@ -56,7 +56,7 @@
virtual unsigned getNumFixupKinds() const = 0;
/// getFixupKindInfo - Get information on a fixup kind.
- virtual MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const = 0;
+ virtual const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const;
/// @}
Modified: llvm/trunk/lib/MC/MCAsmStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAsmStreamer.cpp?rev=95924&r1=95923&r2=95924&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCAsmStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCAsmStreamer.cpp Thu Feb 11 15:27:18 2010
@@ -552,7 +552,7 @@
for (unsigned i = 0, e = Fixups.size(); i != e; ++i) {
MCFixup &F = Fixups[i];
- MCFixupKindInfo &Info = Emitter->getFixupKindInfo(F.getKind());
+ const MCFixupKindInfo &Info = Emitter->getFixupKindInfo(F.getKind());
for (unsigned j = 0; j != Info.TargetSize; ++j) {
unsigned Index = F.getOffset() * 8 + Info.TargetOffset + j;
assert(Index < Code.size() * 8 && "Invalid offset in fixup!");
@@ -599,7 +599,7 @@
for (unsigned i = 0, e = Fixups.size(); i != e; ++i) {
MCFixup &F = Fixups[i];
- MCFixupKindInfo &Info = Emitter->getFixupKindInfo(F.getKind());
+ const MCFixupKindInfo &Info = Emitter->getFixupKindInfo(F.getKind());
OS << " fixup " << char('A' + i) << " - " << "offset: " << F.getOffset()
<< ", value: " << *F.getValue() << ", kind: " << Info.Name << "\n";
}
Modified: llvm/trunk/lib/MC/MCCodeEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCCodeEmitter.cpp?rev=95924&r1=95923&r2=95924&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCCodeEmitter.cpp (original)
+++ llvm/trunk/lib/MC/MCCodeEmitter.cpp Thu Feb 11 15:27:18 2010
@@ -16,3 +16,15 @@
MCCodeEmitter::~MCCodeEmitter() {
}
+
+const MCFixupKindInfo &MCCodeEmitter::getFixupKindInfo(MCFixupKind Kind) const {
+ static const MCFixupKindInfo Builtins[] = {
+ { "FK_Data_1", 0, 8 },
+ { "FK_Data_2", 0, 16 },
+ { "FK_Data_4", 0, 32 },
+ { "FK_Data_8", 0, 64 }
+ };
+
+ assert(Kind <= 3 && "Unknown fixup kind");
+ return Builtins[Kind];
+}
Modified: llvm/trunk/lib/Target/X86/X86MCCodeEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86MCCodeEmitter.cpp?rev=95924&r1=95923&r2=95924&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86MCCodeEmitter.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86MCCodeEmitter.cpp Thu Feb 11 15:27:18 2010
@@ -45,16 +45,19 @@
~X86MCCodeEmitter() {}
unsigned getNumFixupKinds() const {
- return 1;
+ return 2;
}
- MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const {
- static MCFixupKindInfo Infos[] = {
+ const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const {
+ const static MCFixupKindInfo Infos[] = {
{ "reloc_pcrel_4byte", 0, 4 * 8 },
{ "reloc_pcrel_1byte", 0, 1 * 8 }
};
+
+ if (Kind < FirstTargetFixupKind)
+ return MCCodeEmitter::getFixupKindInfo(Kind);
- assert(Kind >= FirstTargetFixupKind && Kind < MaxTargetFixupKind &&
+ assert(unsigned(Kind - FirstTargetFixupKind) < getNumFixupKinds() &&
"Invalid kind!");
return Infos[Kind - FirstTargetFixupKind];
}
More information about the llvm-commits
mailing list