aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2002-12-04 06:45:40 +0000
committerChris Lattner <sabre@nondot.org>2002-12-04 06:45:40 +0000
commit42aa3ae90b9af648d34854aff4db43041497994a (patch)
tree4aabb22d0b90669b85b83dfc4ae0baa9ecf91883 /tools
parentdbf30f7b02e23a19eaa4f7b437a1f5682e4ee74c (diff)
downloadexternal_llvm-42aa3ae90b9af648d34854aff4db43041497994a.zip
external_llvm-42aa3ae90b9af648d34854aff4db43041497994a.tar.gz
external_llvm-42aa3ae90b9af648d34854aff4db43041497994a.tar.bz2
Add support for global value references
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@4908 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools')
-rw-r--r--tools/jello/Emitter.cpp8
-rw-r--r--tools/jello/VM.cpp12
-rw-r--r--tools/jello/VM.h5
3 files changed, 24 insertions, 1 deletions
diff --git a/tools/jello/Emitter.cpp b/tools/jello/Emitter.cpp
index 0e54322..db83318 100644
--- a/tools/jello/Emitter.cpp
+++ b/tools/jello/Emitter.cpp
@@ -23,6 +23,7 @@ namespace {
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 @@ static void *getMemory() {
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 @@ void Emitter::finishFunction(MachineFunction &F) {
std::cerr << "Finished Code Generation of Function: "
<< F.getFunction()->getName() << ": " << CurByte-CurBlock
<< " bytes of text\n";
- TheVM.addGlobalMapping(F.getFunction(), CurBlock);
}
@@ -74,3 +75,8 @@ void Emitter::emitPCRelativeDisp(Value *V) {
*(unsigned*)CurByte = ZeroAddr; // 4 byte offset
CurByte += 4;
}
+
+void Emitter::emitGlobalAddress(GlobalValue *V) {
+ *(void**)CurByte = TheVM.getPointerToGlobal(V);
+ CurByte += 4;
+}
diff --git a/tools/jello/VM.cpp b/tools/jello/VM.cpp
index 85c1f2a..8d6172a 100644
--- a/tools/jello/VM.cpp
+++ b/tools/jello/VM.cpp
@@ -59,6 +59,18 @@ const std::string &VM::getFunctionReferencedName(void *RefAddr) {
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
diff --git a/tools/jello/VM.h b/tools/jello/VM.h
index 6445101..783b7dc 100644
--- a/tools/jello/VM.h
+++ b/tools/jello/VM.h
@@ -61,6 +61,11 @@ public:
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();