diff gen/functions.cpp @ 1148:3d1b16dabd25

Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
author Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
date Fri, 27 Mar 2009 21:50:32 +0100
parents 4c20fcc4252b
children 5ebe8224988b
line wrap: on
line diff
--- a/gen/functions.cpp	Fri Mar 27 17:54:27 2009 +0100
+++ b/gen/functions.cpp	Fri Mar 27 21:50:32 2009 +0100
@@ -26,6 +26,12 @@
 
 const llvm::FunctionType* DtoFunctionType(Type* type, Type* thistype, Type* nesttype, bool ismain)
 {
+    // already built ?
+    if (type->ir.type != NULL) {
+        //assert(f->fty != NULL);
+        return llvm::cast<llvm::FunctionType>(type->ir.type->get());
+    }
+
     if (Logger::enabled())
         Logger::println("DtoFunctionType(%s)", type->toChars());
     LOG_SCOPE
@@ -33,12 +39,6 @@
     assert(type->ty == Tfunction);
     TypeFunction* f = (TypeFunction*)type;
 
-    // already built ?
-    if (type->ir.type != NULL) {
-        //assert(f->fty != NULL);
-        return llvm::cast<llvm::FunctionType>(type->ir.type->get());
-    }
-
     if (f->linkage != LINKintrinsic) {
         // Tell the ABI we're resolving a new function type
         gABI->newFunctionType(f);
@@ -241,14 +241,14 @@
 
 const llvm::FunctionType* DtoFunctionType(FuncDeclaration* fdecl)
 {
+    // type has already been resolved
+    if (fdecl->type->ir.type != 0)
+        return llvm::cast<llvm::FunctionType>(fdecl->type->ir.type->get());
+
     // handle for C vararg intrinsics
     if (fdecl->isVaIntrinsic())
         return DtoVaFunctionType(fdecl);
 
-    // type has already been resolved
-    if (fdecl->type->ir.type != 0)
-        return llvm::cast<llvm::FunctionType>(fdecl->type->ir.type->get());
-
     Type *dthis=0, *dnest=0;
 
     if (fdecl->needThis()) {
@@ -299,6 +299,7 @@
 void DtoResolveFunction(FuncDeclaration* fdecl)
 {
     if (!global.params.useUnitTests && fdecl->isUnitTestDeclaration()) {
+        Logger::println("Ignoring unittest %s", fdecl->toPrettyChars());
         return; // ignore declaration completely
     }
 
@@ -306,15 +307,12 @@
     if (fdecl->getModule() != gIR->dmodule)
     {
         if (fdecl->prot() == PROTprivate)
+        {
+            Logger::println("Ignoring private imported function %s", fdecl->toPrettyChars());
             return;
+        }
     }
 
-    if (fdecl->ir.resolved) return;
-    fdecl->ir.resolved = true;
-
-    Logger::println("DtoResolveFunction(%s): %s", fdecl->toPrettyChars(), fdecl->loc.toChars());
-    LOG_SCOPE;
-
     //printf("resolve function: %s\n", fdecl->toPrettyChars());
 
     if (fdecl->parent)
@@ -325,6 +323,7 @@
         {
             Logger::println("magic va_arg found");
             fdecl->llvmInternal = LLVMva_arg;
+            fdecl->ir.resolved = true;
             fdecl->ir.declared = true;
             fdecl->ir.initialized = true;
             fdecl->ir.defined = true;
@@ -347,9 +346,18 @@
 
     DtoFunctionType(fdecl);
 
+    if (fdecl->ir.resolved) return;
+    fdecl->ir.resolved = true;
+
+    Logger::println("DtoResolveFunction(%s): %s", fdecl->toPrettyChars(), fdecl->loc.toChars());
+    LOG_SCOPE;
+
     // queue declaration
     if (!fdecl->isAbstract())
-        gIR->declareList.push_back(fdecl);
+    {
+        Logger::println("Ignoring declaration of abstract function %s", fdecl->toPrettyChars());
+        DtoDeclareFunction(fdecl);
+    }
 }
 
 //////////////////////////////////////////////////////////////////////////////////////////
@@ -569,12 +577,9 @@
         gIR->unitTests.push_back(fdecl);
 
     if (!declareOnly)
-        gIR->defineList.push_back(fdecl);
+        Type::sir->addFunctionBody(fdecl->ir.irFunc);
     else
         assert(func->getLinkage() != llvm::GlobalValue::InternalLinkage);
-
-    if (Logger::enabled())
-        Logger::cout() << "func decl: " << *func << '\n';
 }
 
 //////////////////////////////////////////////////////////////////////////////////////////