[llvm-commits] CVS: llvm/tools/jello/Emitter.cpp VM.cpp VM.h
Chris Lattner
lattner at cs.uiuc.edu
Tue Dec 3 22:48:01 PST 2002
Changes in directory llvm/tools/jello:
Emitter.cpp updated: 1.1 -> 1.2
VM.cpp updated: 1.1 -> 1.2
VM.h updated: 1.1 -> 1.2
---
Log message:
Implement lazy resolution of function calls
---
Diffs of the changes:
Index: llvm/tools/jello/Emitter.cpp
diff -u llvm/tools/jello/Emitter.cpp:1.1 llvm/tools/jello/Emitter.cpp:1.2
--- llvm/tools/jello/Emitter.cpp:1.1 Tue Dec 3 16:48:59 2002
+++ llvm/tools/jello/Emitter.cpp Tue Dec 3 22:47:34 2002
@@ -68,7 +68,9 @@
// resolved on demand. Keep track of these markers.
//
void Emitter::emitPCRelativeDisp(Value *V) {
- unsigned ZeroAddr = -(unsigned)CurByte; // Calculate displacement to null
+ TheVM.addFunctionRef(CurByte, cast<Function>(V));
+
+ unsigned ZeroAddr = -(unsigned)CurByte-4; // Calculate displacement to null
*(unsigned*)CurByte = ZeroAddr; // 4 byte offset
CurByte += 4;
}
Index: llvm/tools/jello/VM.cpp
diff -u llvm/tools/jello/VM.cpp:1.1 llvm/tools/jello/VM.cpp:1.2
--- llvm/tools/jello/VM.cpp:1.1 Tue Dec 3 16:48:59 2002
+++ llvm/tools/jello/VM.cpp Tue Dec 3 22:47:34 2002
@@ -43,6 +43,21 @@
return PF();
}
+void *VM::resolveFunctionReference(void *RefAddr) {
+ Function *F = FunctionRefs[RefAddr];
+ assert(F && "Reference address not known!");
+
+ void *Addr = getPointerToFunction(F);
+ assert(Addr && "Pointer to function unknown!");
+
+ FunctionRefs.erase(RefAddr);
+ return Addr;
+}
+
+const std::string &VM::getFunctionReferencedName(void *RefAddr) {
+ return FunctionRefs[RefAddr]->getName();
+}
+
/// getPointerToFunction - This method is used to get the address of the
/// specified function, compiling it if neccesary.
Index: llvm/tools/jello/VM.h
diff -u llvm/tools/jello/VM.h:1.1 llvm/tools/jello/VM.h:1.2
--- llvm/tools/jello/VM.h:1.1 Tue Dec 3 16:48:59 2002
+++ llvm/tools/jello/VM.h Tue Dec 3 22:47:34 2002
@@ -10,6 +10,7 @@
#include "llvm/PassManager.h"
#include <string>
#include <map>
+#include <vector>
class TargetMachine;
class Function;
@@ -23,12 +24,21 @@
PassManager PM; // Passes to compile a function
MachineCodeEmitter *MCE; // MCE object
+ // GlobalAddress - A mapping between LLVM values and their native code
+ // generated versions...
std::map<const GlobalValue*, void *> GlobalAddress;
+
+ // FunctionRefs - A mapping between addresses that refer to unresolved
+ // functions and the LLVM function object itself. This is used by the fault
+ // handler to lazily patch up references...
+ //
+ std::map<void*, Function*> FunctionRefs;
public:
VM(const std::string &name, Module &m, TargetMachine &tm)
: ExeName(name), M(m), TM(tm) {
MCE = createEmitter(*this); // Initialize MCE
setupPassManager();
+ registerCallback();
}
~VM();
@@ -41,10 +51,19 @@
CurVal = Addr;
}
+ void addFunctionRef(void *Ref, Function *F) {
+ FunctionRefs[Ref] = F;
+ }
+
+ const std::string &getFunctionReferencedName(void *RefAddr);
+
+ void *resolveFunctionReference(void *RefAddr);
+
private:
static MachineCodeEmitter *createEmitter(VM &V);
void setupPassManager();
void *getPointerToFunction(Function *F);
+ void registerCallback();
};
#endif
More information about the llvm-commits
mailing list