virtual void startBasicBlock(MachineBasicBlock &BB) {}
virtual void emitByte(unsigned char B);
virtual void emitPCRelativeDisp(Value *V);
+ virtual void emitGlobalAddress(GlobalValue *V);
};
}
void Emitter::startFunction(MachineFunction &F) {
CurBlock = (unsigned char *)getMemory();
CurByte = CurBlock; // Start writing at the beginning of the fn.
+ TheVM.addGlobalMapping(F.getFunction(), CurBlock);
}
#include <iostream>
std::cerr << "Finished Code Generation of Function: "
<< F.getFunction()->getName() << ": " << CurByte-CurBlock
<< " bytes of text\n";
- TheVM.addGlobalMapping(F.getFunction(), CurBlock);
}
*(unsigned*)CurByte = ZeroAddr; // 4 byte offset
CurByte += 4;
}
+
+void Emitter::emitGlobalAddress(GlobalValue *V) {
+ *(void**)CurByte = TheVM.getPointerToGlobal(V);
+ CurByte += 4;
+}
return FunctionRefs[RefAddr]->getName();
}
+// getPointerToGlobal - This returns the address of the specified global
+// value. This may involve code generation if it's a function.
+//
+void *VM::getPointerToGlobal(GlobalValue *GV) {
+ if (Function *F = dyn_cast<Function>(GV))
+ return getPointerToFunction(F);
+
+ assert(GlobalAddress[GV] && "Global hasn't had an address allocated yet?");
+ return GlobalAddress[GV];
+}
+
+
static void NoopFn() {}
/// getPointerToFunction - This method is used to get the address of the
void *resolveFunctionReference(void *RefAddr);
+ // getPointerToGlobal - This returns the address of the specified global
+ // value. This may involve code generation if it's a function.
+ //
+ void *getPointerToGlobal(GlobalValue *GV);
+
private:
static MachineCodeEmitter *createEmitter(VM &V);
void setupPassManager();