changeset 1155:ba9d6292572a

Fixed forward reference problem in struct methods on x86-64.
author Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
date Sat, 28 Mar 2009 09:00:32 +0100
parents 9279a9dc6df3
children 19d4ded7204a
files gen/functions.cpp gen/structs.cpp ir/irstruct.h
diffstat 3 files changed, 27 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/gen/functions.cpp	Sat Mar 28 08:25:58 2009 +0100
+++ b/gen/functions.cpp	Sat Mar 28 09:00:32 2009 +0100
@@ -303,6 +303,16 @@
         return; // ignore declaration completely
     }
 
+    if (AggregateDeclaration* ad = fdecl->isMember())
+    {
+        ad->codegen(Type::sir);
+        if (ad->isStructDeclaration() && llvm::isa<llvm::OpaqueType>(DtoType(ad->type)))
+        {
+            ad->ir.irStruct->structFuncs.push_back(fdecl);
+            return;
+        }
+    }
+
     //printf("resolve function: %s\n", fdecl->toPrettyChars());
 
     if (fdecl->parent)
@@ -434,6 +444,8 @@
 
 void DtoDeclareFunction(FuncDeclaration* fdecl)
 {
+    DtoResolveFunction(fdecl);
+
     if (fdecl->ir.declared) return;
     fdecl->ir.declared = true;
 
@@ -478,6 +490,9 @@
     if (!func)
         func = llvm::Function::Create(functype, DtoLinkage(fdecl), mangled_name, gIR->module);
 
+    if (Logger::enabled())
+        Logger::cout() << "func = " << *func << std::endl;
+
     // add func to IRFunc
     fdecl->ir.irFunc->func = func;
 
@@ -594,6 +609,8 @@
 
 void DtoDefineFunction(FuncDeclaration* fd)
 {
+    DtoDeclareFunction(fd);
+
     if (fd->ir.defined) return;
     fd->ir.defined = true;
 
--- a/gen/structs.cpp	Sat Mar 28 08:25:58 2009 +0100
+++ b/gen/structs.cpp	Sat Mar 28 09:00:32 2009 +0100
@@ -14,6 +14,7 @@
 #include "gen/logger.h"
 #include "gen/structs.h"
 #include "gen/dvalue.h"
+#include "gen/functions.h"
 
 #include "ir/irstruct.h"
 
@@ -583,6 +584,14 @@
         gIR->module->addTypeName(sd->mangle(),ST);
     }
 
+    // emit functions
+    size_t n = irstruct->structFuncs.size();
+    for (size_t i = 0; i < n; ++i)
+    {
+        DtoResolveFunction(irstruct->structFuncs[i]);
+    }
+    irstruct->structFuncs.clear();
+
     gIR->structs.pop_back();
 
     DtoDeclareStruct(sd);
--- a/ir/irstruct.h	Sat Mar 28 08:25:58 2009 +0100
+++ b/ir/irstruct.h	Sat Mar 28 09:00:32 2009 +0100
@@ -152,6 +152,7 @@
     llvm::DICompositeType diCompositeType;
 
     std::vector<VarDeclaration*> staticVars;
+    std::vector<FuncDeclaration*> structFuncs;
 };
 
 //////////////////////////////////////////////////////////////////////////////