mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-08 20:06:03 +03:00
Fixed forward reference problem in struct methods on x86-64.
This commit is contained in:
parent
e61562033d
commit
740cdaa588
3 changed files with 27 additions and 0 deletions
|
@ -303,6 +303,16 @@ void DtoResolveFunction(FuncDeclaration* fdecl)
|
||||||
return; // ignore declaration completely
|
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());
|
//printf("resolve function: %s\n", fdecl->toPrettyChars());
|
||||||
|
|
||||||
if (fdecl->parent)
|
if (fdecl->parent)
|
||||||
|
@ -434,6 +444,8 @@ static void set_param_attrs(TypeFunction* f, llvm::Function* func, FuncDeclarati
|
||||||
|
|
||||||
void DtoDeclareFunction(FuncDeclaration* fdecl)
|
void DtoDeclareFunction(FuncDeclaration* fdecl)
|
||||||
{
|
{
|
||||||
|
DtoResolveFunction(fdecl);
|
||||||
|
|
||||||
if (fdecl->ir.declared) return;
|
if (fdecl->ir.declared) return;
|
||||||
fdecl->ir.declared = true;
|
fdecl->ir.declared = true;
|
||||||
|
|
||||||
|
@ -478,6 +490,9 @@ void DtoDeclareFunction(FuncDeclaration* fdecl)
|
||||||
if (!func)
|
if (!func)
|
||||||
func = llvm::Function::Create(functype, DtoLinkage(fdecl), mangled_name, gIR->module);
|
func = llvm::Function::Create(functype, DtoLinkage(fdecl), mangled_name, gIR->module);
|
||||||
|
|
||||||
|
if (Logger::enabled())
|
||||||
|
Logger::cout() << "func = " << *func << std::endl;
|
||||||
|
|
||||||
// add func to IRFunc
|
// add func to IRFunc
|
||||||
fdecl->ir.irFunc->func = func;
|
fdecl->ir.irFunc->func = func;
|
||||||
|
|
||||||
|
@ -594,6 +609,8 @@ void DtoDeclareFunction(FuncDeclaration* fdecl)
|
||||||
|
|
||||||
void DtoDefineFunction(FuncDeclaration* fd)
|
void DtoDefineFunction(FuncDeclaration* fd)
|
||||||
{
|
{
|
||||||
|
DtoDeclareFunction(fd);
|
||||||
|
|
||||||
if (fd->ir.defined) return;
|
if (fd->ir.defined) return;
|
||||||
fd->ir.defined = true;
|
fd->ir.defined = true;
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#include "gen/logger.h"
|
#include "gen/logger.h"
|
||||||
#include "gen/structs.h"
|
#include "gen/structs.h"
|
||||||
#include "gen/dvalue.h"
|
#include "gen/dvalue.h"
|
||||||
|
#include "gen/functions.h"
|
||||||
|
|
||||||
#include "ir/irstruct.h"
|
#include "ir/irstruct.h"
|
||||||
|
|
||||||
|
@ -583,6 +584,14 @@ void DtoResolveStruct(StructDeclaration* sd)
|
||||||
gIR->module->addTypeName(sd->mangle(),ST);
|
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();
|
gIR->structs.pop_back();
|
||||||
|
|
||||||
DtoDeclareStruct(sd);
|
DtoDeclareStruct(sd);
|
||||||
|
|
|
@ -152,6 +152,7 @@ struct IrStruct : IrBase
|
||||||
llvm::DICompositeType diCompositeType;
|
llvm::DICompositeType diCompositeType;
|
||||||
|
|
||||||
std::vector<VarDeclaration*> staticVars;
|
std::vector<VarDeclaration*> staticVars;
|
||||||
|
std::vector<FuncDeclaration*> structFuncs;
|
||||||
};
|
};
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue