diff gen/functions.cpp @ 117:56a21f3e5d3e trunk

[svn r121] Finished ModuleInfo implementation. Static ctors/dtors now work according to spec. Changed class vtable types slightly in some cases. Overridden functions now always take the the type of the first class declaring the method as this parameter. This helps when using headers (w. implementation somewhere else)
author lindquist
date Mon, 26 Nov 2007 04:49:23 +0100
parents fd7ad91fd713
children 79c9ac745fbc
line wrap: on
line diff
--- a/gen/functions.cpp	Sun Nov 25 18:55:52 2007 +0100
+++ b/gen/functions.cpp	Mon Nov 26 04:49:23 2007 +0100
@@ -468,23 +468,6 @@
     {
         fd->llvmDModule = gIR->dmodule;
 
-        // handle static constructor / destructor
-        if (fd->isStaticCtorDeclaration() || fd->isStaticDtorDeclaration()) {
-            const llvm::ArrayType* sctor_type = llvm::ArrayType::get(llvm::PointerType::get(functype),1);
-            //Logger::cout() << "static ctor type: " << *sctor_type << '\n';
-
-            llvm::Constant* sctor_func = llvm::cast<llvm::Constant>(fd->llvmValue);
-            //Logger::cout() << "static ctor func: " << *sctor_func << '\n';
-
-            llvm::Constant* sctor_init = llvm::ConstantArray::get(sctor_type,&sctor_func,1);
-
-            //Logger::cout() << "static ctor init: " << *sctor_init << '\n';
-
-            // output the llvm.global_ctors array
-            const char* varname = fd->isStaticCtorDeclaration() ? "_d_module_ctor_array" : "_d_module_dtor_array";
-            llvm::GlobalVariable* sctor_arr = new llvm::GlobalVariable(sctor_type, false, llvm::GlobalValue::AppendingLinkage, sctor_init, varname, gIR->module);
-        }
-
         // function definition
         if (fd->fbody != 0)
         {
@@ -492,18 +475,6 @@
             assert(fd->llvmIRFunc);
             gIR->functions.push_back(fd->llvmIRFunc);
 
-            /* // moved to declaration
-            // this handling
-            if (f->llvmUsesThis) {
-                Logger::println("uses this");
-                if (f->llvmRetInPtr)
-                    fd->llvmThisVar = ++func->arg_begin();
-                else
-                    fd->llvmThisVar = func->arg_begin();
-                assert(fd->llvmThisVar != 0);
-            }
-            */
-
             if (fd->isMain())
                 gIR->emitMain = true;
 
@@ -681,7 +652,7 @@
     llvm::BasicBlock* bb = new llvm::BasicBlock("entry",func);
 
     // call static ctors
-    llvm::Function* fn = LLVM_D_GetRuntimeFunction(ir.module,"_d_run_module_ctors");
+    llvm::Function* fn = LLVM_D_GetRuntimeFunction(ir.module,"_moduleCtor");
     llvm::Instruction* apt = new llvm::CallInst(fn,"",bb);
 
     // call user main function
@@ -720,7 +691,7 @@
     call->setCallingConv(ir.mainFunc->getCallingConv());
 
     // call static dtors
-    fn = LLVM_D_GetRuntimeFunction(ir.module,"_d_run_module_dtors");
+    fn = LLVM_D_GetRuntimeFunction(ir.module,"_moduleDtor");
     new llvm::CallInst(fn,"",bb);
 
     // return
@@ -728,3 +699,31 @@
 }
 
 //////////////////////////////////////////////////////////////////////////////////////////
+
+const llvm::FunctionType* DtoBaseFunctionType(FuncDeclaration* fdecl)
+{
+    Dsymbol* parent = fdecl->toParent();
+    ClassDeclaration* cd = parent->isClassDeclaration();
+    assert(cd);
+
+    FuncDeclaration* f = fdecl;
+
+    while (cd)
+    {
+        ClassDeclaration* base = cd->baseClass;
+        if (!base)
+            break;
+        FuncDeclaration* f2 = base->findFunc(fdecl->ident, (TypeFunction*)fdecl->type);
+        if (f2) {
+            f = f2;
+            cd = base;
+        }
+        else
+            break;
+    }
+
+    DtoResolveDsymbol(f);
+    return llvm::cast<llvm::FunctionType>(DtoType(f->type));
+}
+
+//////////////////////////////////////////////////////////////////////////////////////////