diff gen/functions.cpp @ 1364:46f6365a50d7

Added IrTypeFunction and IrTypeDelegate and eliminated IrDType. This means the Type::ir field can be removed. It's the final part needed for the move to a slightly more sane type system. Now the whole thing just needs to be cleaned up :P Added -v-cg switch, which right now just prints "codegen: module.name (module/name.d)" to stdout, this can really help figuring out where, in some complex build command, things go wrong.
author Tomas Lindquist Olsen <tomas.l.olsen gmail com>
date Sat, 16 May 2009 18:19:52 +0200
parents 34f2fd925de3
children 9a049fd1a014
line wrap: on
line diff
--- a/gen/functions.cpp	Sat May 16 14:22:23 2009 +0200
+++ b/gen/functions.cpp	Sat May 16 18:19:52 2009 +0200
@@ -27,15 +27,10 @@
 
 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
+
     // sanity check
     assert(type->ty == Tfunction);
     TypeFunction* f = (TypeFunction*)type;
@@ -165,27 +160,6 @@
         lidx++;
     }
 
-    // If the function type was forward referenced by one of the parameter types,
-    // it has now been set.
-    if (f->ir.type) {
-        // Notify ABI that we won't be needing it for this function type anymore.
-        abi->doneWithFunctionType();
-        
-        // Some cleanup of memory we won't use
-        delete fty.ret;
-        delete fty.arg_sret;
-        delete fty.arg_this;
-        delete fty.arg_nest;
-        delete fty.arg_arguments;
-        delete fty.arg_argptr;
-        for (IrFuncTy::ArgIter It = fty.args.begin(), E = fty.args.end(); It != E; ++It) {
-            delete *It;
-        }
-
-        Logger::cout() << "Final function type: " << **f->ir.type << '\n';
-        return llvm::cast<LLFunctionType>(*f->ir.type);
-    }
-
     // Now we can modify f->fty safely.
     f->fty = fty;
 
@@ -219,7 +193,6 @@
     }
 
     llvm::FunctionType* functype = llvm::FunctionType::get(f->fty.ret->ltype, argtypes, f->fty.c_vararg);
-    f->ir.type = new llvm::PATypeHolder(functype);
 
 #if 0
     Logger::cout() << "Final function type: " << *functype << "\n";
@@ -232,11 +205,6 @@
 
 static const llvm::FunctionType* DtoVaFunctionType(FuncDeclaration* fdecl)
 {
-    // type has already been resolved
-    if (fdecl->type->ir.type != 0) {
-        return llvm::cast<llvm::FunctionType>(fdecl->type->ir.type->get());
-    }
-
     TypeFunction* f = (TypeFunction*)fdecl->type;
     const llvm::FunctionType* fty = 0;
 
@@ -256,7 +224,6 @@
         fty = GET_INTRINSIC_DECL(vaend)->getFunctionType();
     assert(fty);
 
-    f->ir.type = new llvm::PATypeHolder(fty);
     return fty;
 }
 
@@ -264,10 +231,6 @@
 
 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);
@@ -280,7 +243,7 @@
             dthis = ad->type;
             const LLType* thisty = DtoType(dthis);
             //Logger::cout() << "this llvm type: " << *thisty << '\n';
-            if (isaStruct(thisty) || (!gIR->structs.empty() && thisty == gIR->topstruct()->type->ir.type->get()))
+            if (ad->isStructDeclaration())
                 thisty = getPtrToType(thisty);
         }
         else {
@@ -326,6 +289,9 @@
         return; // ignore declaration completely
     }
 
+    if (fdecl->ir.resolved) return;
+    fdecl->ir.resolved = true;
+
     //printf("resolve function: %s\n", fdecl->toPrettyChars());
 
     if (fdecl->parent)
@@ -373,10 +339,7 @@
         }
     }
 
-    DtoFunctionType(fdecl);
-
-    if (fdecl->ir.resolved) return;
-    fdecl->ir.resolved = true;
+    DtoType(fdecl->type);
 
     Logger::println("DtoResolveFunction(%s): %s", fdecl->toPrettyChars(), fdecl->loc.toChars());
     LOG_SCOPE;
@@ -515,7 +478,6 @@
         func->setCallingConv(llvm::CallingConv::C);
 
     fdecl->ir.irFunc->func = func;
-    assert(llvm::isa<llvm::FunctionType>(f->ir.type->get()));
 
     // parameter attributes
     if (!fdecl->isIntrinsic()) {
@@ -646,7 +608,7 @@
 
     Type* t = fd->type->toBasetype();
     TypeFunction* f = (TypeFunction*)t;
-    assert(f->ir.type);
+    assert(f->irtype);
 
     llvm::Function* func = fd->ir.irFunc->func;
     const llvm::FunctionType* functype = func->getFunctionType();