diff gen/runtime.c @ 52:0c77619e803b trunk

[svn r56] Initial support for TypeInfo. Enums not work. Several other bugfixes.
author lindquist
date Tue, 23 Oct 2007 05:55:12 +0200
parents 8b0e809563df
children a9d29e9f1fed
line wrap: on
line diff
--- a/gen/runtime.c	Mon Oct 22 17:25:44 2007 +0200
+++ b/gen/runtime.c	Tue Oct 23 05:55:12 2007 +0200
@@ -1,5 +1,6 @@
 #include <cassert>
 
+#include "gen/llvm.h"
 #include "llvm/Module.h"
 #include "llvm/Bitcode/ReaderWriter.h"
 #include "llvm/Support/MemoryBuffer.h"
@@ -13,6 +14,8 @@
 static llvm::Module* M = NULL;
 static bool runtime_failed = false;
 
+//////////////////////////////////////////////////////////////////////////////////////////////////
+
 bool LLVM_D_InitRuntime()
 {
     Logger::println("*** Loading D runtime ***");
@@ -41,7 +44,7 @@
         Logger::println("Failed to load runtime: %s", errstr.c_str());
         runtime_failed = true;
     }
-    
+
     delete buffer;
     return retval;
 }
@@ -54,6 +57,8 @@
     }
 }
 
+//////////////////////////////////////////////////////////////////////////////////////////////////
+
 llvm::Function* LLVM_D_GetRuntimeFunction(llvm::Module* target, const char* name)
 {
     // TODO maybe check the target module first, to allow overriding the runtime on a pre module basis?
@@ -63,20 +68,47 @@
         error("No implicit runtime calls allowed with -noruntime option enabled");
         fatal();
     }
-    
+
     if (!M) {
         assert(!runtime_failed);
         LLVM_D_InitRuntime();
     }
-    
+
     llvm::Function* fn = M->getFunction(name);
     if (!fn) {
         error("Runtime function '%s' was not found", name);
         fatal();
         //return NULL;
     }
-    
+
     const llvm::FunctionType* fnty = fn->getFunctionType();
     return llvm::cast<llvm::Function>(target->getOrInsertFunction(name, fnty));
 }
 
+//////////////////////////////////////////////////////////////////////////////////////////////////
+
+llvm::GlobalVariable* LLVM_D_GetRuntimeGlobal(llvm::Module* target, const char* name)
+{
+    // TODO maybe check the target module first, to allow overriding the runtime on a pre module basis?
+    // could be done and seems like it could be neat too :)
+
+    if (global.params.noruntime) {
+        error("No implicit runtime calls allowed with -noruntime option enabled");
+        fatal();
+    }
+
+    if (!M) {
+        assert(!runtime_failed);
+        LLVM_D_InitRuntime();
+    }
+
+    llvm::GlobalVariable* g = M->getNamedGlobal(name);
+    if (!g) {
+        error("Runtime global '%s' was not found", name);
+        fatal();
+        //return NULL;
+    }
+
+    const llvm::PointerType* t = g->getType();
+    return new llvm::GlobalVariable(t->getElementType(),g->isConstant(),g->getLinkage(),NULL,g->getName(),target);
+}