# HG changeset patch # User Tomas Lindquist Olsen # Date 1238227232 -3600 # Node ID ba9d6292572abec2080b1af95c7c8c4bcd3f18d2 # Parent 9279a9dc6df307139ec68dc943e92de7f5a5ec52 Fixed forward reference problem in struct methods on x86-64. diff -r 9279a9dc6df3 -r ba9d6292572a gen/functions.cpp --- 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(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; diff -r 9279a9dc6df3 -r ba9d6292572a gen/structs.cpp --- 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); diff -r 9279a9dc6df3 -r ba9d6292572a ir/irstruct.h --- 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 staticVars; + std::vector structFuncs; }; //////////////////////////////////////////////////////////////////////////////