Add support for global value references
authorChris Lattner <sabre@nondot.org>
Wed, 4 Dec 2002 06:45:40 +0000 (06:45 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 4 Dec 2002 06:45:40 +0000 (06:45 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@4908 91177308-0d34-0410-b5e6-96231b3b80d8

tools/jello/Emitter.cpp
tools/jello/VM.cpp
tools/jello/VM.h

index 0e54322ef9b40c6fc90aaf37c1bd3aa1ac39bd00..db83318cf2e9f12fe0ed3bb1bd7b860ce7546bb1 100644 (file)
@@ -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;
+}
index 85c1f2a1e1f635985feb00ce8ae8743d5daaba02..8d6172ad28642d18cbf13cdbe08185bc0ccfe2a4 100644 (file)
@@ -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
index 64451014c1690a571ee4238f2990becb4f9c4a8d..783b7dc12ebbe3b1937d2281c952649df16da79b 100644 (file)
@@ -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();