-//===-- Emitter.cpp - Write machine code to executable memory -------------===//
+//===-- JITEmitter.cpp - Write machine code to executable memory ----------===//
//
// The LLVM Compiler Infrastructure
//
//===----------------------------------------------------------------------===//
-// JIT MachineCodeEmitter code.
+// JITEmitter code.
//
namespace {
- /// Emitter - The JIT implementation of the MachineCodeEmitter, which is used
- /// to output functions to memory for execution.
- class Emitter : public MachineCodeEmitter {
+ /// JITEmitter - The JIT implementation of the MachineCodeEmitter, which is
+ /// used to output functions to memory for execution.
+ class JITEmitter : public MachineCodeEmitter {
JITMemoryManager MemMgr;
// CurBlock - The start of the current block of memory. CurByte - The
/// emitted.
std::vector<MachineRelocation> Relocations;
public:
- Emitter(JIT &jit) { TheJIT = &jit; }
+ JITEmitter(JIT &jit) { TheJIT = &jit; }
virtual void startFunction(MachineFunction &F);
virtual void finishFunction(MachineFunction &F);
}
MachineCodeEmitter *JIT::createEmitter(JIT &jit) {
- return new Emitter(jit);
+ return new JITEmitter(jit);
}
-void *Emitter::getPointerToGlobal(GlobalValue *V, void *Reference,
- bool DoesntNeedStub) {
+void *JITEmitter::getPointerToGlobal(GlobalValue *V, void *Reference,
+ bool DoesntNeedStub) {
if (GlobalVariable *GV = dyn_cast<GlobalVariable>(V)) {
/// FIXME: If we straightened things out, this could actually emit the
/// global immediately instead of queuing it for codegen later!
return getJITResolver(this).getFunctionStub(F);
}
-void Emitter::startFunction(MachineFunction &F) {
+void JITEmitter::startFunction(MachineFunction &F) {
CurByte = CurBlock = MemMgr.startFunctionBody();
TheJIT->addGlobalMapping(F.getFunction(), CurBlock);
}
-void Emitter::finishFunction(MachineFunction &F) {
+void JITEmitter::finishFunction(MachineFunction &F) {
MemMgr.endFunctionBody(CurByte);
ConstantPoolAddresses.clear();
NumBytes += CurByte-CurBlock;
Relocations.clear();
}
-void Emitter::emitConstantPool(MachineConstantPool *MCP) {
+void JITEmitter::emitConstantPool(MachineConstantPool *MCP) {
const std::vector<Constant*> &Constants = MCP->getConstants();
if (Constants.empty()) return;
}
}
-void Emitter::startFunctionStub(unsigned StubSize) {
+void JITEmitter::startFunctionStub(unsigned StubSize) {
SavedCurBlock = CurBlock; SavedCurByte = CurByte;
CurByte = CurBlock = MemMgr.allocateStub(StubSize);
}
-void *Emitter::finishFunctionStub(const Function *F) {
+void *JITEmitter::finishFunctionStub(const Function *F) {
NumBytes += CurByte-CurBlock;
std::swap(CurBlock, SavedCurBlock);
CurByte = SavedCurByte;
return SavedCurBlock;
}
-void Emitter::emitByte(unsigned char B) {
+void JITEmitter::emitByte(unsigned char B) {
*CurByte++ = B; // Write the byte to memory
}
-void Emitter::emitWord(unsigned W) {
+void JITEmitter::emitWord(unsigned W) {
// This won't work if the endianness of the host and target don't agree! (For
// a JIT this can't happen though. :)
*(unsigned*)CurByte = W;
CurByte += sizeof(unsigned);
}
-void Emitter::emitWordAt(unsigned W, unsigned *Ptr) {
+void JITEmitter::emitWordAt(unsigned W, unsigned *Ptr) {
*Ptr = W;
}
// in the constant pool that was last emitted with the 'emitConstantPool'
// method.
//
-uint64_t Emitter::getConstantPoolEntryAddress(unsigned ConstantNum) {
+uint64_t JITEmitter::getConstantPoolEntryAddress(unsigned ConstantNum) {
assert(ConstantNum < ConstantPoolAddresses.size() &&
"Invalid ConstantPoolIndex!");
return (intptr_t)ConstantPoolAddresses[ConstantNum];
// getCurrentPCValue - This returns the address that the next emitted byte
// will be output to.
//
-uint64_t Emitter::getCurrentPCValue() {
+uint64_t JITEmitter::getCurrentPCValue() {
return (intptr_t)CurByte;
}
-uint64_t Emitter::getCurrentPCOffset() {
+uint64_t JITEmitter::getCurrentPCOffset() {
return (intptr_t)CurByte-(intptr_t)CurBlock;
}