[llvm-commits] CVS: llvm/tools/jello/Emitter.cpp VM.cpp VM.h
Chris Lattner
lattner at cs.uiuc.edu
Wed Dec 4 00:46:08 PST 2002
Changes in directory llvm/tools/jello:
Emitter.cpp updated: 1.2 -> 1.3
VM.cpp updated: 1.3 -> 1.4
VM.h updated: 1.3 -> 1.4
---
Log message:
Add support for global value references
---
Diffs of the changes:
Index: llvm/tools/jello/Emitter.cpp
diff -u llvm/tools/jello/Emitter.cpp:1.2 llvm/tools/jello/Emitter.cpp:1.3
--- llvm/tools/jello/Emitter.cpp:1.2 Tue Dec 3 22:47:34 2002
+++ llvm/tools/jello/Emitter.cpp Wed Dec 4 00:45:40 2002
@@ -23,6 +23,7 @@
virtual void startBasicBlock(MachineBasicBlock &BB) {}
virtual void emitByte(unsigned char B);
virtual void emitPCRelativeDisp(Value *V);
+ virtual void emitGlobalAddress(GlobalValue *V);
};
}
@@ -44,6 +45,7 @@
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>
@@ -53,7 +55,6 @@
std::cerr << "Finished Code Generation of Function: "
<< F.getFunction()->getName() << ": " << CurByte-CurBlock
<< " bytes of text\n";
- TheVM.addGlobalMapping(F.getFunction(), CurBlock);
}
@@ -72,5 +73,10 @@
unsigned ZeroAddr = -(unsigned)CurByte-4; // Calculate displacement to null
*(unsigned*)CurByte = ZeroAddr; // 4 byte offset
+ CurByte += 4;
+}
+
+void Emitter::emitGlobalAddress(GlobalValue *V) {
+ *(void**)CurByte = TheVM.getPointerToGlobal(V);
CurByte += 4;
}
Index: llvm/tools/jello/VM.cpp
diff -u llvm/tools/jello/VM.cpp:1.3 llvm/tools/jello/VM.cpp:1.4
--- llvm/tools/jello/VM.cpp:1.3 Wed Dec 4 00:04:07 2002
+++ llvm/tools/jello/VM.cpp Wed Dec 4 00:45:40 2002
@@ -59,6 +59,18 @@
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
Index: llvm/tools/jello/VM.h
diff -u llvm/tools/jello/VM.h:1.3 llvm/tools/jello/VM.h:1.4
--- llvm/tools/jello/VM.h:1.3 Wed Dec 4 00:04:17 2002
+++ llvm/tools/jello/VM.h Wed Dec 4 00:45:40 2002
@@ -61,6 +61,11 @@
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();
More information about the llvm-commits
mailing list