aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2006-05-02 19:14:47 +0000
committerChris Lattner <sabre@nondot.org>2006-05-02 19:14:47 +0000
commitd3f0aefc33965d3d0ca6f92af4ebaea354b063c4 (patch)
treea930b341d61cfa8a4c28505803970a2b270946a2
parent43b429b05989075b60693d57395c99b0ad789f8d (diff)
downloadexternal_llvm-d3f0aefc33965d3d0ca6f92af4ebaea354b063c4.zip
external_llvm-d3f0aefc33965d3d0ca6f92af4ebaea354b063c4.tar.gz
external_llvm-d3f0aefc33965d3d0ca6f92af4ebaea354b063c4.tar.bz2
Fix a purely hypothetical problem (for now): emitWord emits in the host
byte format. This doesn't work when using the code emitter in a cross target environment. Since the code emitter is only really used by the JIT, this isn't a current problem, but if we ever start emitting .o files, it would be. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@28060 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/CodeGen/MachineCodeEmitter.h27
-rw-r--r--lib/Target/Alpha/AlphaCodeEmitter.cpp6
-rw-r--r--lib/Target/Alpha/AlphaJITInfo.cpp2
-rw-r--r--lib/Target/PowerPC/PPCCodeEmitter.cpp6
-rw-r--r--lib/Target/PowerPC/PPCJITInfo.cpp22
-rw-r--r--lib/Target/X86/X86CodeEmitter.cpp10
-rw-r--r--lib/Target/X86/X86JITInfo.cpp4
7 files changed, 42 insertions, 35 deletions
diff --git a/include/llvm/CodeGen/MachineCodeEmitter.h b/include/llvm/CodeGen/MachineCodeEmitter.h
index 72002ef..7f171b6 100644
--- a/include/llvm/CodeGen/MachineCodeEmitter.h
+++ b/include/llvm/CodeGen/MachineCodeEmitter.h
@@ -112,14 +112,29 @@ public:
*CurBufferPtr++ = B;
}
- /// emitWord - This callback is invoked when a word needs to be written to the
- /// output stream.
+ /// emitWordLE - This callback is invoked when a 32-bit word needs to be
+ /// written to the output stream in little-endian format.
+ ///
+ void emitWordLE(unsigned W) {
+ if (CurBufferPtr+4 <= BufferEnd) {
+ *CurBufferPtr++ = (unsigned char)(W >> 0);
+ *CurBufferPtr++ = (unsigned char)(W >> 8);
+ *CurBufferPtr++ = (unsigned char)(W >> 16);
+ *CurBufferPtr++ = (unsigned char)(W >> 24);
+ } else {
+ CurBufferPtr = BufferEnd;
+ }
+ }
+
+ /// emitWordBE - This callback is invoked when a 32-bit word needs to be
+ /// written to the output stream in big-endian format.
///
- void emitWord(unsigned W) {
- // FIXME: handle endian mismatches for .o file emission.
+ void emitWordBE(unsigned W) {
if (CurBufferPtr+4 <= BufferEnd) {
- *(unsigned*)CurBufferPtr = W;
- CurBufferPtr += 4;
+ *CurBufferPtr++ = (unsigned char)(W >> 24);
+ *CurBufferPtr++ = (unsigned char)(W >> 16);
+ *CurBufferPtr++ = (unsigned char)(W >> 8);
+ *CurBufferPtr++ = (unsigned char)(W >> 0);
} else {
CurBufferPtr = BufferEnd;
}
diff --git a/lib/Target/Alpha/AlphaCodeEmitter.cpp b/lib/Target/Alpha/AlphaCodeEmitter.cpp
index dfb7820..a04cd37 100644
--- a/lib/Target/Alpha/AlphaCodeEmitter.cpp
+++ b/lib/Target/Alpha/AlphaCodeEmitter.cpp
@@ -55,10 +55,6 @@ namespace {
void emitInstruction(const MachineInstr &MI);
- /// emitWord - write a 32-bit word to memory at the current PC
- ///
- void emitWord(unsigned w) { MCE.emitWord(w); }
-
/// getBinaryCodeForInstr - This function, generated by the
/// CodeEmitterGenerator using TableGen, produces the binary encoding for
/// machine instructions.
@@ -117,7 +113,7 @@ void AlphaCodeEmitter::emitBasicBlock(MachineBasicBlock &MBB) {
unsigned Opcode = MI.getOpcode();
switch(MI.getOpcode()) {
default:
- emitWord(getBinaryCodeForInstr(*I));
+ MCE.emitWordLE(getBinaryCodeForInstr(*I));
break;
case Alpha::ALTENT:
case Alpha::PCLABEL:
diff --git a/lib/Target/Alpha/AlphaJITInfo.cpp b/lib/Target/Alpha/AlphaJITInfo.cpp
index 6d20ec3..81f5e74 100644
--- a/lib/Target/Alpha/AlphaJITInfo.cpp
+++ b/lib/Target/Alpha/AlphaJITInfo.cpp
@@ -197,7 +197,7 @@ void *AlphaJITInfo::emitFunctionStub(void *Fn, MachineCodeEmitter &MCE) {
MCE.startFunctionStub(19*4);
void* Addr = (void*)(intptr_t)MCE.getCurrentPCValue();
for (int x = 0; x < 19; ++ x)
- MCE.emitWord(0);
+ MCE.emitWordLE(0);
EmitBranchToAt(Addr, Fn);
DEBUG(std::cerr << "Emitting Stub to " << Fn << " at [" << Addr << "]\n");
return MCE.finishFunctionStub(0);
diff --git a/lib/Target/PowerPC/PPCCodeEmitter.cpp b/lib/Target/PowerPC/PPCCodeEmitter.cpp
index 1b305f4..6fe6829 100644
--- a/lib/Target/PowerPC/PPCCodeEmitter.cpp
+++ b/lib/Target/PowerPC/PPCCodeEmitter.cpp
@@ -54,10 +54,6 @@ namespace {
///
void emitBasicBlock(MachineBasicBlock &MBB);
- /// emitWord - write a 32-bit word to memory at the current PC
- ///
- void emitWord(unsigned w) { MCE.emitWord(w); }
-
/// getValueBit - return the particular bit of Val
///
unsigned getValueBit(int64_t Val, unsigned bit) { return (Val >> bit) & 1; }
@@ -133,7 +129,7 @@ void PPCCodeEmitter::emitBasicBlock(MachineBasicBlock &MBB) {
unsigned Opcode = MI.getOpcode();
switch (MI.getOpcode()) {
default:
- emitWord(getBinaryCodeForInstr(*I));
+ MCE.emitWordBE(getBinaryCodeForInstr(*I));
break;
case PPC::IMPLICIT_DEF_GPR:
case PPC::IMPLICIT_DEF_F8:
diff --git a/lib/Target/PowerPC/PPCJITInfo.cpp b/lib/Target/PowerPC/PPCJITInfo.cpp
index 9329b38..a6d630e 100644
--- a/lib/Target/PowerPC/PPCJITInfo.cpp
+++ b/lib/Target/PowerPC/PPCJITInfo.cpp
@@ -168,23 +168,23 @@ void *PPCJITInfo::emitFunctionStub(void *Fn, MachineCodeEmitter &MCE) {
if (Fn != PPC32CompilationCallback) {
MCE.startFunctionStub(4*4);
void *Addr = (void*)(intptr_t)MCE.getCurrentPCValue();
- MCE.emitWord(0);
- MCE.emitWord(0);
- MCE.emitWord(0);
- MCE.emitWord(0);
+ MCE.emitWordBE(0);
+ MCE.emitWordBE(0);
+ MCE.emitWordBE(0);
+ MCE.emitWordBE(0);
EmitBranchToAt(Addr, Fn, false);
return MCE.finishFunctionStub(0);
}
MCE.startFunctionStub(4*7);
- MCE.emitWord(0x9421ffe0); // stwu r1,-32(r1)
- MCE.emitWord(0x7d6802a6); // mflr r11
- MCE.emitWord(0x91610028); // stw r11, 40(r1)
+ MCE.emitWordBE(0x9421ffe0); // stwu r1,-32(r1)
+ MCE.emitWordBE(0x7d6802a6); // mflr r11
+ MCE.emitWordBE(0x91610028); // stw r11, 40(r1)
void *Addr = (void*)(intptr_t)MCE.getCurrentPCValue();
- MCE.emitWord(0);
- MCE.emitWord(0);
- MCE.emitWord(0);
- MCE.emitWord(0);
+ MCE.emitWordBE(0);
+ MCE.emitWordBE(0);
+ MCE.emitWordBE(0);
+ MCE.emitWordBE(0);
EmitBranchToAt(Addr, Fn, true/*is call*/);
return MCE.finishFunctionStub(0);
}
diff --git a/lib/Target/X86/X86CodeEmitter.cpp b/lib/Target/X86/X86CodeEmitter.cpp
index a278fd5..175dae5 100644
--- a/lib/Target/X86/X86CodeEmitter.cpp
+++ b/lib/Target/X86/X86CodeEmitter.cpp
@@ -116,7 +116,7 @@ void Emitter::emitBasicBlock(MachineBasicBlock &MBB) {
/// emitPCRelativeValue - Emit a 32-bit PC relative address.
///
void Emitter::emitPCRelativeValue(unsigned Address) {
- MCE.emitWord(Address-MCE.getCurrentPCValue()-4);
+ MCE.emitWordLE(Address-MCE.getCurrentPCValue()-4);
}
/// emitPCRelativeBlockAddress - This method emits the PC relative address of
@@ -134,7 +134,7 @@ void Emitter::emitPCRelativeBlockAddress(MachineBasicBlock *MBB) {
// Otherwise, remember where this reference was and where it is to so we can
// deal with it later.
BBRefs.push_back(std::make_pair(MBB, MCE.getCurrentPCValue()));
- MCE.emitWord(0);
+ MCE.emitWordLE(0);
}
}
@@ -145,7 +145,7 @@ void Emitter::emitGlobalAddressForCall(GlobalValue *GV, bool isTailCall) {
MCE.addRelocation(MachineRelocation(MCE.getCurrentPCOffset(),
X86::reloc_pcrel_word, GV, 0,
!isTailCall /*Doesn'tNeedStub*/));
- MCE.emitWord(0);
+ MCE.emitWordLE(0);
}
/// emitGlobalAddress - Emit the specified address to the code stream assuming
@@ -155,7 +155,7 @@ void Emitter::emitGlobalAddressForCall(GlobalValue *GV, bool isTailCall) {
void Emitter::emitGlobalAddressForPtr(GlobalValue *GV, int Disp /* = 0 */) {
MCE.addRelocation(MachineRelocation(MCE.getCurrentPCOffset(),
X86::reloc_absolute_word, GV));
- MCE.emitWord(Disp); // The relocated value will be added to the displacement
+ MCE.emitWordLE(Disp); // The relocated value will be added to the displacement
}
/// emitExternalSymbolAddress - Arrange for the address of an external symbol to
@@ -165,7 +165,7 @@ void Emitter::emitExternalSymbolAddress(const char *ES, bool isPCRelative,
bool isTailCall) {
MCE.addRelocation(MachineRelocation(MCE.getCurrentPCOffset(),
isPCRelative ? X86::reloc_pcrel_word : X86::reloc_absolute_word, ES));
- MCE.emitWord(0);
+ MCE.emitWordLE(0);
}
/// N86 namespace - Native X86 Register numbers... used by X86 backend.
diff --git a/lib/Target/X86/X86JITInfo.cpp b/lib/Target/X86/X86JITInfo.cpp
index 7f93895..3d12221 100644
--- a/lib/Target/X86/X86JITInfo.cpp
+++ b/lib/Target/X86/X86JITInfo.cpp
@@ -170,14 +170,14 @@ void *X86JITInfo::emitFunctionStub(void *Fn, MachineCodeEmitter &MCE) {
if (Fn != X86CompilationCallback) {
MCE.startFunctionStub(5);
MCE.emitByte(0xE9);
- MCE.emitWord((intptr_t)Fn-MCE.getCurrentPCValue()-4);
+ MCE.emitWordLE((intptr_t)Fn-MCE.getCurrentPCValue()-4);
return MCE.finishFunctionStub(0);
}
MCE.startFunctionStub(6);
MCE.emitByte(0xE8); // Call with 32 bit pc-rel destination...
- MCE.emitWord((intptr_t)Fn-MCE.getCurrentPCValue()-4);
+ MCE.emitWordLE((intptr_t)Fn-MCE.getCurrentPCValue()-4);
MCE.emitByte(0xCD); // Interrupt - Just a marker identifying the stub!
return MCE.finishFunctionStub(0);