Eliminated the need for resolve, declare, const-init and define lists to drive code generation.

This commit is contained in:
Tomas Lindquist Olsen 2009-03-27 21:50:32 +01:00
parent daef67acc3
commit ec986231e5
14 changed files with 198 additions and 402 deletions

View file

@ -288,7 +288,7 @@ struct VarDeclaration : Declaration
#if IN_LLVM
/// Codegen traversal
void codegen(Ir* ir);
virtual void codegen(Ir* ir);
// LDC
AnonDeclaration* anonDecl;
@ -368,7 +368,6 @@ struct TypeInfoDeclaration : VarDeclaration
#if IN_LLVM
/// Codegen traversal
void codegen(Ir* ir);
virtual void llvmDeclare();
virtual void llvmDefine();
#endif
};
@ -382,7 +381,6 @@ struct TypeInfoStructDeclaration : TypeInfoDeclaration
#endif
#if IN_LLVM
void llvmDeclare();
void llvmDefine();
#endif
};
@ -396,7 +394,6 @@ struct TypeInfoClassDeclaration : TypeInfoDeclaration
#endif
#if IN_LLVM
void llvmDeclare();
void llvmDefine();
#endif
};
@ -410,7 +407,6 @@ struct TypeInfoInterfaceDeclaration : TypeInfoDeclaration
#endif
#if IN_LLVM
void llvmDeclare();
void llvmDefine();
#endif
};
@ -424,7 +420,6 @@ struct TypeInfoTypedefDeclaration : TypeInfoDeclaration
#endif
#if IN_LLVM
void llvmDeclare();
void llvmDefine();
#endif
};
@ -438,7 +433,6 @@ struct TypeInfoPointerDeclaration : TypeInfoDeclaration
#endif
#if IN_LLVM
void llvmDeclare();
void llvmDefine();
#endif
};
@ -452,7 +446,6 @@ struct TypeInfoArrayDeclaration : TypeInfoDeclaration
#endif
#if IN_LLVM
void llvmDeclare();
void llvmDefine();
#endif
};
@ -466,7 +459,6 @@ struct TypeInfoStaticArrayDeclaration : TypeInfoDeclaration
#endif
#if IN_LLVM
void llvmDeclare();
void llvmDefine();
#endif
};
@ -480,7 +472,6 @@ struct TypeInfoAssociativeArrayDeclaration : TypeInfoDeclaration
#endif
#if IN_LLVM
void llvmDeclare();
void llvmDefine();
#endif
};
@ -494,7 +485,6 @@ struct TypeInfoEnumDeclaration : TypeInfoDeclaration
#endif
#if IN_LLVM
void llvmDeclare();
void llvmDefine();
#endif
};
@ -508,7 +498,6 @@ struct TypeInfoFunctionDeclaration : TypeInfoDeclaration
#endif
#if IN_LLVM
void llvmDeclare();
void llvmDefine();
#endif
};
@ -522,7 +511,6 @@ struct TypeInfoDelegateDeclaration : TypeInfoDeclaration
#endif
#if IN_LLVM
void llvmDeclare();
void llvmDefine();
#endif
};
@ -536,7 +524,6 @@ struct TypeInfoTupleDeclaration : TypeInfoDeclaration
#endif
#if IN_LLVM
void llvmDeclare();
void llvmDefine();
#endif
};
@ -551,7 +538,6 @@ struct TypeInfoConstDeclaration : TypeInfoDeclaration
#endif
#if IN_LLVM
void llvmDeclare();
void llvmDefine();
#endif
};
@ -565,7 +551,6 @@ struct TypeInfoInvariantDeclaration : TypeInfoDeclaration
#endif
#if IN_LLVM
void llvmDeclare();
void llvmDefine();
#endif
};

View file

@ -676,7 +676,7 @@ static LLValue* DtoArrayEqCmp_impl(Loc& loc, const char* func, DValue* l, DValue
Type* t = l->getType();
LLValue* tival = DtoTypeInfoOf(t);
// DtoTypeInfoOf only does declare, not enough in this case :/
DtoForceConstInitDsymbol(t->vtinfo);
t->vtinfo->codegen(Type::sir);
if (Logger::enabled())
Logger::cout() << "typeinfo decl: " << *tival << '\n';

View file

@ -124,6 +124,10 @@ static void add_class_data(ClassDeclaration* target, ClassDeclaration* cd)
//////////////////////////////////////////////////////////////////////////////////////////
static void DtoDeclareInterface(InterfaceDeclaration* cd);
static void DtoConstInitInterface(InterfaceDeclaration* cd);
static void DtoDefineInterface(InterfaceDeclaration* cd);
static void DtoResolveInterface(InterfaceDeclaration* cd)
{
if (cd->ir.resolved) return;
@ -170,7 +174,7 @@ static void DtoResolveInterface(InterfaceDeclaration* cd)
ts->ir.type = new LLPATypeHolder(getPtrToType(t));
// request declaration
gIR->declareList.push_back(cd);
DtoDeclareInterface(cd);
// handle members
// like "nested" interfaces
@ -193,14 +197,16 @@ void DtoResolveClass(ClassDeclaration* cd)
return;
}
// make sure the base classes are processed first
if (cd->baseClass)
cd->baseClass->codegen(Type::sir);
if (cd->ir.resolved) return;
cd->ir.resolved = true;
Logger::println("DtoResolveClass(%s): %s", cd->toPrettyChars(), cd->loc.toChars());
LOG_SCOPE;
//printf("resolve class: %s\n", cd->toPrettyChars());
// get the TypeClass
assert(cd->type->ty == Tclass);
TypeClass* ts = (TypeClass*)cd->type;
@ -221,10 +227,21 @@ void DtoResolveClass(ClassDeclaration* cd)
return;
}
// resolve the base class
if (cd->baseClass) {
DtoResolveClass(cd->baseClass);
}
// create the symbols we're going to need
// avoids chicken egg problems
llvm::GlobalValue::LinkageTypes _linkage = DtoLinkage(cd);
// there is always a vtbl symbol
std::string varname("_D");
varname.append(cd->mangle());
varname.append("6__vtblZ");
irstruct->vtbl = new llvm::GlobalVariable(irstruct->vtblInitTy.get(), true, _linkage, NULL, varname, gIR->module);
// ... and initZ
std::string initname("_D");
initname.append(cd->mangle());
initname.append("6__initZ");
irstruct->init = new llvm::GlobalVariable(irstruct->initOpaque.get(), true, _linkage, NULL, initname, gIR->module);
// push state
gIR->structs.push_back(irstruct);
@ -252,6 +269,7 @@ void DtoResolveClass(ClassDeclaration* cd)
llvm::PATypeHolder* spa = ts->ir.type;
llvm::cast<llvm::OpaqueType>(spa->get())->refineAbstractTypeTo(structtype);
structtype = isaStruct(spa->get());
assert(structtype);
// name the type
gIR->module->addTypeName(cd->mangle(), ts->ir.type->get());
@ -269,13 +287,15 @@ void DtoResolveClass(ClassDeclaration* cd)
gIR->structs.pop_back();
// queue declare
gIR->declareList.push_back(cd);
DtoDeclareClass(cd);
}
//////////////////////////////////////////////////////////////////////////////////////////
static void DtoDeclareInterface(InterfaceDeclaration* cd)
{
DtoResolveInterface(cd);
if (cd->ir.declared) return;
cd->ir.declared = true;
@ -321,12 +341,12 @@ static void DtoDeclareInterface(InterfaceDeclaration* cd)
DtoDeclareClassInfo(cd);
// request const init
gIR->constInitList.push_back(cd);
DtoConstInitInterface(cd);
// emit typeinfo and request definition
if (mustDefineSymbol(cd))
{
gIR->defineList.push_back(cd);
DtoDefineInterface(cd);
DtoTypeInfoOf(cd->type, false);
}
}
@ -343,6 +363,8 @@ void DtoDeclareClass(ClassDeclaration* cd)
return;
}
DtoResolveClass(cd);
if (cd->ir.declared) return;
cd->ir.declared = true;
@ -366,12 +388,6 @@ void DtoDeclareClass(ClassDeclaration* cd)
llvm::GlobalValue::LinkageTypes _linkage = DtoLinkage(cd);
// create vtbl symbol
std::string varname("_D");
varname.append(cd->mangle());
varname.append("6__vtblZ");
irstruct->vtbl = new llvm::GlobalVariable(irstruct->vtblInitTy.get(), true, _linkage, 0, varname, gIR->module);
// get interface info type
const llvm::StructType* infoTy = DtoInterfaceInfoType();
@ -410,23 +426,14 @@ void DtoDeclareClass(ClassDeclaration* cd)
idx++;
}
// initZ init
std::string initname("_D");
initname.append(cd->mangle());
initname.append("6__initZ");
// initZ global
llvm::GlobalVariable* initvar = new llvm::GlobalVariable(irstruct->initOpaque.get(), true, _linkage, NULL, initname, gIR->module);
irstruct->init = initvar;
gIR->structs.pop_back();
// request const init
gIR->constInitList.push_back(cd);
DtoConstInitClass(cd);
// define ? (set initializers)
if (needs_definition)
gIR->defineList.push_back(cd);
DtoDefineClass(cd);
// classinfo
DtoDeclareClassInfo(cd);
@ -544,6 +551,8 @@ static size_t init_class_initializer(std::vector<LLConstant*>& inits, ClassDecla
// build the vtable initializer for class cd
static void init_class_vtbl_initializer(ClassDeclaration* cd)
{
cd->codegen(Type::sir);
// generate vtable initializer
std::vector<LLConstant*> sinits(cd->vtbl.dim, NULL);
@ -551,6 +560,8 @@ static void init_class_vtbl_initializer(ClassDeclaration* cd)
assert(cd->vtbl.dim > 1);
DtoDeclareClassInfo(cd);
// first entry always classinfo
assert(irstruct->classInfo);
sinits[0] = DtoBitCast(irstruct->classInfo, DtoType(ClassDeclaration::classinfo->type));
@ -575,7 +586,9 @@ static void init_class_vtbl_initializer(ClassDeclaration* cd)
}
else
{
DtoForceDeclareDsymbol(fd);
fd->codegen(Type::sir);
Logger::println("F = %s", fd->toPrettyChars());
assert(fd->ir.irFunc);
assert(fd->ir.irFunc->func);
sinits[k] = fd->ir.irFunc->func;
}
@ -645,7 +658,7 @@ static void init_class_interface_vtbl_initializers(ClassDeclaration* cd)
inits[j] = getNullPtr(getVoidPtrType());
else
{
DtoForceDeclareDsymbol(fd);
fd->codegen(Type::sir);
assert(fd->ir.irFunc->func);
inits[j] = fd->ir.irFunc->func;
@ -662,7 +675,7 @@ static void init_class_interface_vtbl_initializers(ClassDeclaration* cd)
// build the interface info for ClassInfo
// generate interface info initializer
DtoForceDeclareDsymbol(iri->decl);
iri->decl->codegen(Type::sir);
// classinfo
IrStruct* iris = iri->decl->ir.irStruct;
@ -698,6 +711,8 @@ static void init_class_interface_vtbl_initializers(ClassDeclaration* cd)
static void DtoConstInitInterface(InterfaceDeclaration* cd)
{
DtoDeclareInterface(cd);
if (cd->ir.initialized) return;
cd->ir.initialized = true;
@ -717,18 +732,14 @@ void DtoConstInitClass(ClassDeclaration* cd)
return;
}
DtoDeclareClass(cd);
if (cd->ir.initialized) return;
cd->ir.initialized = true;
Logger::println("DtoConstInitClass(%s): %s", cd->toPrettyChars(), cd->loc.toChars());
LOG_SCOPE;
assert(!cd->isInterfaceDeclaration());
// make sure the baseclass is const initialized
if (cd->baseClass)
DtoForceConstInitDsymbol(cd->baseClass);
// get IrStruct
IrStruct* irstruct = cd->ir.irStruct;
gIR->structs.push_back(irstruct);
@ -811,6 +822,8 @@ static void DefineInterfaceInfos(IrStruct* irstruct)
static void DtoDefineInterface(InterfaceDeclaration* cd)
{
DtoConstInitInterface(cd);
if (cd->ir.defined) return;
cd->ir.defined = true;
@ -839,6 +852,8 @@ void DtoDefineClass(ClassDeclaration* cd)
return;
}
DtoConstInitClass(cd);
if (cd->ir.defined) return;
cd->ir.defined = true;
@ -898,7 +913,7 @@ void DtoDefineClass(ClassDeclaration* cd)
DValue* DtoNewClass(Loc loc, TypeClass* tc, NewExp* newexp)
{
// resolve type
DtoForceDeclareDsymbol(tc->sym);
tc->sym->codegen(Type::sir);
// allocate
LLValue* mem;
@ -909,7 +924,7 @@ DValue* DtoNewClass(Loc loc, TypeClass* tc, NewExp* newexp)
// custom allocator
else if (newexp->allocator)
{
DtoForceDeclareDsymbol(newexp->allocator);
newexp->allocator->codegen(Type::sir);
DFuncValue dfn(newexp->allocator, newexp->allocator->ir.irFunc->func);
DValue* res = DtoCallFunction(newexp->loc, NULL, &dfn, newexp->newargs);
mem = DtoBitCast(res->getRVal(), DtoType(tc), ".newclass_custom");
@ -959,7 +974,7 @@ DValue* DtoNewClass(Loc loc, TypeClass* tc, NewExp* newexp)
{
Logger::println("Calling constructor");
assert(newexp->arguments != NULL);
DtoForceDeclareDsymbol(newexp->member);
newexp->member->codegen(Type::sir);
DFuncValue dfn(newexp->member, newexp->member->ir.irFunc->func, mem);
return DtoCallFunction(newexp->loc, tc, &dfn, newexp->arguments);
}
@ -972,7 +987,7 @@ DValue* DtoNewClass(Loc loc, TypeClass* tc, NewExp* newexp)
void DtoInitClass(TypeClass* tc, LLValue* dst)
{
DtoForceConstInitDsymbol(tc->sym);
tc->sym->codegen(Type::sir);
size_t presz = 2*getTypePaddedSize(DtoSize_t());
uint64_t n = getTypePaddedSize(tc->ir.type->get()) - presz;
@ -1122,8 +1137,8 @@ DValue* DtoDynamicCastObject(DValue* val, Type* _to)
// call:
// Object _d_dynamic_cast(Object o, ClassInfo c)
DtoForceDeclareDsymbol(ClassDeclaration::object);
DtoForceDeclareDsymbol(ClassDeclaration::classinfo);
ClassDeclaration::object->codegen(Type::sir);
ClassDeclaration::classinfo->codegen(Type::sir);
llvm::Function* func = LLVM_D_GetRuntimeFunction(gIR->module, "_d_dynamic_cast");
const llvm::FunctionType* funcTy = func->getFunctionType();
@ -1137,7 +1152,7 @@ DValue* DtoDynamicCastObject(DValue* val, Type* _to)
// ClassInfo c
TypeClass* to = (TypeClass*)_to->toBasetype();
DtoForceDeclareDsymbol(to->sym);
to->sym->codegen(Type::sir);
assert(to->sym->ir.irStruct->classInfo);
LLValue* cinfo = to->sym->ir.irStruct->classInfo;
// unfortunately this is needed as the implementation of object differs somehow from the declaration
@ -1187,8 +1202,8 @@ DValue* DtoDynamicCastInterface(DValue* val, Type* _to)
// call:
// Object _d_interface_cast(void* p, ClassInfo c)
DtoForceDeclareDsymbol(ClassDeclaration::object);
DtoForceDeclareDsymbol(ClassDeclaration::classinfo);
ClassDeclaration::object->codegen(Type::sir);
ClassDeclaration::classinfo->codegen(Type::sir);
llvm::Function* func = LLVM_D_GetRuntimeFunction(gIR->module, "_d_interface_cast");
const llvm::FunctionType* funcTy = func->getFunctionType();
@ -1201,7 +1216,7 @@ DValue* DtoDynamicCastInterface(DValue* val, Type* _to)
// ClassInfo c
TypeClass* to = (TypeClass*)_to->toBasetype();
DtoForceDeclareDsymbol(to->sym);
to->sym->codegen(Type::sir);
assert(to->sym->ir.irStruct->classInfo);
LLValue* cinfo = to->sym->ir.irStruct->classInfo;
// unfortunately this is needed as the implementation of object differs somehow from the declaration
@ -1404,7 +1419,7 @@ static LLConstant* build_class_dtor(ClassDeclaration* cd)
if (!dtor)
return getNullPtr(getVoidPtrType());
DtoForceDeclareDsymbol(dtor);
dtor->codegen(Type::sir);
return llvm::ConstantExpr::getBitCast(dtor->ir.irFunc->func, getPtrToType(LLType::Int8Ty));
}
@ -1480,7 +1495,7 @@ void DtoDefineClassInfo(ClassDeclaration* cd)
std::vector<LLConstant*> inits;
ClassDeclaration* cinfo = ClassDeclaration::classinfo;
DtoForceConstInitDsymbol(cinfo);
cinfo->codegen(Type::sir);
LLConstant* c;
@ -1575,7 +1590,7 @@ void DtoDefineClassInfo(ClassDeclaration* cd)
const LLType* invTy = DtoType(invVar->type);
if (cd->inv)
{
DtoForceDeclareDsymbol(cd->inv);
cd->inv->codegen(Type::sir);
c = cd->inv->ir.irFunc->func;
c = DtoBitCast(c, invTy);
}
@ -1595,7 +1610,7 @@ void DtoDefineClassInfo(ClassDeclaration* cd)
// deallocator
if (cd->aggDelete)
{
DtoForceDeclareDsymbol(cd->aggDelete);
cd->aggDelete->codegen(Type::sir);
c = cd->aggDelete->ir.irFunc->func;
c = DtoBitCast(c, voidPtr);
}
@ -1625,7 +1640,7 @@ void DtoDefineClassInfo(ClassDeclaration* cd)
// default constructor
if (cd->defaultCtor)
{
DtoForceDeclareDsymbol(cd->defaultCtor);
cd->defaultCtor->codegen(Type::sir);
c = isaConstant(cd->defaultCtor->ir.irFunc->func);
c = DtoBitCast(c, voidPtr);
}

View file

@ -135,7 +135,7 @@ void VarDeclaration::codegen(Ir* p)
if (nakedUse)
gIR->usedArray.push_back(DtoBitCast(gvar, getVoidPtrType()));
gIR->constInitList.push_back(this);
DtoConstInitGlobal(this);
}
else
{

View file

@ -26,6 +26,12 @@ using namespace llvm::Attribute;
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 @@ const llvm::FunctionType* DtoFunctionType(Type* type, Type* thistype, Type* nest
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 @@ static const llvm::FunctionType* DtoVaFunctionType(FuncDeclaration* fdecl)
const llvm::FunctionType* DtoFunctionType(FuncDeclaration* fdecl)
{
// 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());
// handle for C vararg intrinsics
if (fdecl->isVaIntrinsic())
return DtoVaFunctionType(fdecl);
Type *dthis=0, *dnest=0;
if (fdecl->needThis()) {
@ -299,6 +299,7 @@ static llvm::Function* DtoDeclareVaFunction(FuncDeclaration* fdecl)
void DtoResolveFunction(FuncDeclaration* fdecl)
{
if (!global.params.useUnitTests && fdecl->isUnitTestDeclaration()) {
Logger::println("Ignoring unittest %s", fdecl->toPrettyChars());
return; // ignore declaration completely
}
@ -306,14 +307,11 @@ void DtoResolveFunction(FuncDeclaration* fdecl)
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());
@ -325,6 +323,7 @@ void DtoResolveFunction(FuncDeclaration* fdecl)
{
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 @@ void DtoResolveFunction(FuncDeclaration* fdecl)
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 @@ void DtoDeclareFunction(FuncDeclaration* fdecl)
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';
}
//////////////////////////////////////////////////////////////////////////////////////////

View file

@ -153,16 +153,6 @@ struct IRState
// debug info helper
llvm::DIFactory difactory;
typedef std::list<Dsymbol*> DsymbolList;
// dsymbols that need to be resolved
DsymbolList resolveList;
// dsymbols that need to be declared
DsymbolList declareList;
// dsymbols that need constant initializers constructed
DsymbolList constInitList;
// dsymbols that need definitions
DsymbolList defineList;
// static ctors/dtors/unittests
typedef std::vector<FuncDeclaration*> FuncDeclVector;
FuncDeclVector ctors;

View file

@ -866,6 +866,8 @@ void DtoResolveDsymbol(Dsymbol* dsym)
void DtoDeclareDsymbol(Dsymbol* dsym)
{
DtoResolveDsymbol(dsym);
if (StructDeclaration* sd = dsym->isStructDeclaration()) {
DtoDeclareStruct(sd);
}
@ -888,6 +890,8 @@ void DtoDeclareDsymbol(Dsymbol* dsym)
void DtoConstInitDsymbol(Dsymbol* dsym)
{
DtoDeclareDsymbol(dsym);
if (StructDeclaration* sd = dsym->isStructDeclaration()) {
DtoConstInitStruct(sd);
}
@ -910,6 +914,8 @@ void DtoConstInitDsymbol(Dsymbol* dsym)
void DtoDefineDsymbol(Dsymbol* dsym)
{
DtoConstInitDsymbol(dsym);
if (StructDeclaration* sd = dsym->isStructDeclaration()) {
DtoDefineStruct(sd);
}
@ -917,7 +923,7 @@ void DtoDefineDsymbol(Dsymbol* dsym)
DtoDefineClass(cd);
}
else if (FuncDeclaration* fd = dsym->isFuncDeclaration()) {
DtoDefineFunction(fd);
Type::sir->addFunctionBody(fd->ir.irFunc);
}
else if (TypeInfoDeclaration* fd = dsym->isTypeInfoDeclaration()) {
DtoDefineTypeInfo(fd);
@ -932,6 +938,8 @@ void DtoDefineDsymbol(Dsymbol* dsym)
void DtoConstInitGlobal(VarDeclaration* vd)
{
vd->codegen(Type::sir);
if (vd->ir.initialized) return;
vd->ir.initialized = gIR->dmodule;
@ -977,42 +985,6 @@ void DtoConstInitGlobal(VarDeclaration* vd)
}
}
//////////////////////////////////////////////////////////////////////////////////////////
void DtoForceDeclareDsymbol(Dsymbol* dsym)
{
if (dsym->ir.declared) return;
Logger::println("DtoForceDeclareDsymbol(%s)", dsym->toPrettyChars());
LOG_SCOPE;
DtoResolveDsymbol(dsym);
DtoDeclareDsymbol(dsym);
}
//////////////////////////////////////////////////////////////////////////////////////////
void DtoForceConstInitDsymbol(Dsymbol* dsym)
{
if (dsym->ir.initialized) return;
Logger::println("DtoForceConstInitDsymbol(%s)", dsym->toPrettyChars());
LOG_SCOPE;
DtoResolveDsymbol(dsym);
DtoDeclareDsymbol(dsym);
DtoConstInitDsymbol(dsym);
}
//////////////////////////////////////////////////////////////////////////////////////////
void DtoForceDefineDsymbol(Dsymbol* dsym)
{
if (dsym->ir.defined) return;
Logger::println("DtoForceDefineDsymbol(%s)", dsym->toPrettyChars());
LOG_SCOPE;
DtoResolveDsymbol(dsym);
DtoDeclareDsymbol(dsym);
DtoConstInitDsymbol(dsym);
DtoDefineDsymbol(dsym);
}
/****************************************************************************************/
/*////////////////////////////////////////////////////////////////////////////////////////
// DECLARATION EXP HELPER
@ -1106,13 +1078,13 @@ DValue* DtoDeclarationExp(Dsymbol* declaration)
else if (StructDeclaration* s = declaration->isStructDeclaration())
{
Logger::println("StructDeclaration");
DtoForceConstInitDsymbol(s);
s->codegen(Type::sir);
}
// function declaration
else if (FuncDeclaration* f = declaration->isFuncDeclaration())
{
Logger::println("FuncDeclaration");
DtoForceDeclareDsymbol(f);
f->codegen(Type::sir);
}
// alias declaration
else if (AliasDeclaration* a = declaration->isAliasDeclaration())
@ -1130,7 +1102,7 @@ DValue* DtoDeclarationExp(Dsymbol* declaration)
else if (ClassDeclaration* e = declaration->isClassDeclaration())
{
Logger::println("ClassDeclaration");
DtoForceConstInitDsymbol(e);
e->codegen(Type::sir);
}
// typedef
else if (TypedefDeclaration* tdef = declaration->isTypedefDeclaration())
@ -1392,8 +1364,9 @@ LLConstant* DtoTypeInfoOf(Type* type, bool base)
type->getTypeInfo(NULL);
TypeInfoDeclaration* tidecl = type->vtinfo;
assert(tidecl);
DtoForceDeclareDsymbol(tidecl);
tidecl->codegen(Type::sir);
assert(tidecl->ir.irGlobal != NULL);
assert(tidecl->ir.irGlobal->value != NULL);
LLConstant* c = isaConstant(tidecl->ir.irGlobal->value);
assert(c != NULL);
if (base)

View file

@ -94,9 +94,6 @@ void DtoDeclareDsymbol(Dsymbol* dsym);
void DtoDefineDsymbol(Dsymbol* dsym);
void DtoConstInitDsymbol(Dsymbol* dsym);
void DtoConstInitGlobal(VarDeclaration* vd);
void DtoForceDeclareDsymbol(Dsymbol* dsym);
void DtoForceConstInitDsymbol(Dsymbol* dsym);
void DtoForceDefineDsymbol(Dsymbol* dsym);
// declaration inside a declarationexp
DValue* DtoDeclarationExp(Dsymbol* declaration);

View file

@ -97,7 +97,7 @@ LLConstant* DtoConstStructInitializer(StructInitializer* si)
TypeStruct* ts = (TypeStruct*)si->ad->type;
// force constant initialization of the symbol
DtoForceConstInitDsymbol(si->ad);
si->ad->codegen(Type::sir);;
// get formal type
const llvm::StructType* structtype = isaStruct(ts->ir.type->get());
@ -517,6 +517,15 @@ void DtoResolveStruct(StructDeclaration* sd)
// create the type
ts->ir.type = new LLPATypeHolder(llvm::OpaqueType::get());
// create symbols we're going to need
// avoids chicken egg problems
std::string initname("_D");
initname.append(sd->mangle());
initname.append("6__initZ");
llvm::GlobalValue::LinkageTypes _linkage = DtoExternalLinkage(sd);
sd->ir.irStruct->init = new llvm::GlobalVariable(sd->ir.irStruct->initOpaque.get(), true, _linkage, NULL, initname, gIR->module);
// handle forward declaration structs (opaques)
// didn't even know D had those ...
if (sd->sizeok != 1)
@ -579,13 +588,15 @@ void DtoResolveStruct(StructDeclaration* sd)
gIR->structs.pop_back();
gIR->declareList.push_back(sd);
DtoDeclareStruct(sd);
}
//////////////////////////////////////////////////////////////////////////////////////////
void DtoDeclareStruct(StructDeclaration* sd)
{
DtoResolveStruct(sd);
if (sd->ir.declared) return;
sd->ir.declared = true;
@ -594,23 +605,17 @@ void DtoDeclareStruct(StructDeclaration* sd)
TypeStruct* ts = (TypeStruct*)sd->type->toBasetype();
std::string initname("_D");
initname.append(sd->mangle());
initname.append("6__initZ");
llvm::GlobalValue::LinkageTypes _linkage = DtoExternalLinkage(sd);
llvm::GlobalVariable* initvar = new llvm::GlobalVariable(sd->ir.irStruct->initOpaque.get(), true, _linkage, NULL, initname, gIR->module);
sd->ir.irStruct->init = initvar;
gIR->constInitList.push_back(sd);
DtoConstInitStruct(sd);
if (mustDefineSymbol(sd))
gIR->defineList.push_back(sd);
DtoDefineStruct(sd);
}
//////////////////////////////////////////////////////////////////////////////////////////
void DtoConstInitStruct(StructDeclaration* sd)
{
DtoDeclareStruct(sd);
if (sd->ir.initialized) return;
sd->ir.initialized = true;
@ -651,6 +656,8 @@ void DtoConstInitStruct(StructDeclaration* sd)
void DtoDefineStruct(StructDeclaration* sd)
{
DtoConstInitStruct(sd);
if (sd->ir.defined) return;
sd->ir.defined = true;

View file

@ -95,7 +95,7 @@ DValue* VarExp::toElem(IRState* p)
else if (TypeInfoDeclaration* tid = vd->isTypeInfoDeclaration())
{
Logger::println("TypeInfoDeclaration");
DtoForceDeclareDsymbol(tid);
tid->codegen(Type::sir);
assert(tid->ir.getIrValue());
const LLType* vartype = DtoType(type);
LLValue* m = tid->ir.getIrValue();
@ -107,7 +107,7 @@ DValue* VarExp::toElem(IRState* p)
else if (ClassInfoDeclaration* cid = vd->isClassInfoDeclaration())
{
Logger::println("ClassInfoDeclaration: %s", cid->cd->toChars());
DtoForceDeclareDsymbol(cid->cd);
cid->cd->codegen(Type::sir);;
assert(cid->cd->ir.irStruct->classInfo);
return new DVarValue(type, vd, cid->cd->ir.irStruct->classInfo);
}
@ -175,7 +175,7 @@ DValue* VarExp::toElem(IRState* p)
Logger::println("FuncDeclaration");
LLValue* func = 0;
if (fdecl->llvmInternal != LLVMva_arg) {
DtoForceDeclareDsymbol(fdecl);
fdecl->codegen(Type::sir);
func = fdecl->ir.irFunc->func;
}
return new DFuncValue(fdecl, func);
@ -188,7 +188,7 @@ DValue* VarExp::toElem(IRState* p)
assert(sdecltype->ty == Tstruct);
TypeStruct* ts = (TypeStruct*)sdecltype;
assert(ts->sym);
DtoForceConstInitDsymbol(ts->sym);
ts->sym->codegen(Type::sir);
assert(ts->sym->ir.irStruct->init);
return new DVarValue(type, ts->sym->ir.irStruct->init);
}
@ -214,7 +214,7 @@ LLConstant* VarExp::toConstElem(IRState* p)
Logger::print("Sym: type=%s\n", sdecltype->toChars());
assert(sdecltype->ty == Tstruct);
TypeStruct* ts = (TypeStruct*)sdecltype;
DtoForceConstInitDsymbol(ts->sym);
ts->sym->codegen(Type::sir);
assert(ts->sym->ir.irStruct->constInit);
return ts->sym->ir.irStruct->constInit;
}
@ -922,7 +922,7 @@ DValue* AddrExp::toElem(IRState* p)
//Logger::println("FuncDeclaration");
FuncDeclaration* fd = fv->func;
assert(fd);
DtoForceDeclareDsymbol(fd);
fd->codegen(Type::sir);
return new DFuncValue(fd, fd->ir.irFunc->func);
}
else if (DImValue* im = v->isIm()) {
@ -976,7 +976,7 @@ LLConstant* AddrExp::toConstElem(IRState* p)
// static function
else if (FuncDeclaration* fd = vexp->var->isFuncDeclaration())
{
DtoForceDeclareDsymbol(fd);
fd->codegen(Type::sir);
IrFunction* irfunc = fd->ir.irFunc;
return irfunc->func;
}
@ -1125,7 +1125,7 @@ DValue* DotVarExp::toElem(IRState* p)
// look up function
//
if (!vtbllookup) {
DtoForceDeclareDsymbol(fdecl);
fdecl->codegen(Type::sir);
funcval = fdecl->ir.irFunc->func;
assert(funcval);
}
@ -1634,7 +1634,7 @@ DValue* NewExp::toElem(IRState* p)
}
else {
assert(ts->sym);
DtoForceConstInitDsymbol(ts->sym);
ts->sym->codegen(Type::sir);
DtoAggrCopy(mem,ts->sym->ir.irStruct->init);
}
return new DImValue(type, mem);
@ -2027,7 +2027,7 @@ DValue* DelegateExp::toElem(IRState* p)
assert(0 && "TODO delegate to interface method");
else
{
DtoForceDeclareDsymbol(func);
func->codegen(Type::sir);
castfptr = func->ir.irFunc->func;
}
@ -2252,7 +2252,7 @@ DValue* FuncExp::toElem(IRState* p)
if (fd->isNested()) Logger::println("nested");
Logger::println("kind = %s\n", fd->kind());
DtoForceDefineDsymbol(fd);
fd->codegen(Type::sir);
assert(fd->ir.irFunc->func);
if(fd->tok == TOKdelegate) {
@ -2289,7 +2289,7 @@ LLConstant* FuncExp::toConstElem(IRState* p)
assert(fd);
assert(fd->tok == TOKfunction);
DtoForceDefineDsymbol(fd);
fd->codegen(Type::sir);
assert(fd->ir.irFunc->func);
return fd->ir.irFunc->func;

View file

@ -145,6 +145,9 @@ llvm::Module* Module::genLLVMModule(Ir* sir)
// generate ModuleInfo
genmoduleinfo();
// emit function bodies
sir->emitFunctionBodies();
// emit usedArray
if (!ir.usedArray.empty())
{
@ -599,7 +602,7 @@ void Module::genmoduleinfo()
fatal();
}
DtoForceConstInitDsymbol(moduleinfo);
moduleinfo->codegen(Type::sir);
// check for patch
if (moduleinfo->fields.dim != 9)

View file

@ -271,6 +271,15 @@ Expression *createTypeInfoArray(Scope *sc, Expression *exps[], int dim)
// MAGIC PLACE
//////////////////////////////////////////////////////////////////////////////
void DtoResolveTypeInfo(TypeInfoDeclaration* tid);
void DtoDeclareTypeInfo(TypeInfoDeclaration* tid);
void DtoConstInitTypeInfo(TypeInfoDeclaration* tid);
void TypeInfoDeclaration::codegen(Ir*)
{
DtoResolveTypeInfo(this);
}
void DtoResolveTypeInfo(TypeInfoDeclaration* tid)
{
if (tid->ir.resolved) return;
@ -279,57 +288,46 @@ void DtoResolveTypeInfo(TypeInfoDeclaration* tid)
Logger::println("DtoResolveTypeInfo(%s)", tid->toChars());
LOG_SCOPE;
tid->ir.irGlobal = new IrGlobal(tid);
IrGlobal* irg = new IrGlobal(tid);
irg->value = new llvm::GlobalVariable(irg->type.get(), true,
TYPEINFO_LINKAGE_TYPE, NULL, tid->mangle(), gIR->module);
gIR->declareList.push_back(tid);
}
tid->ir.irGlobal = irg;
void TypeInfoDeclaration::codegen(Ir*)
{
DtoResolveTypeInfo(this);
DtoDeclareTypeInfo(tid);
}
void DtoDeclareTypeInfo(TypeInfoDeclaration* tid)
{
DtoResolveTypeInfo(tid);
if (tid->ir.declared) return;
tid->ir.declared = true;
Logger::println("DtoDeclareTypeInfo(%s)", tid->toChars());
LOG_SCOPE;
IrGlobal* irg = tid->ir.irGlobal;
std::string mangled(tid->mangle());
Logger::println("type = '%s'", tid->tinfo->toChars());
Logger::println("typeinfo mangle: %s", mangled.c_str());
assert(irg->value != NULL);
// this is a declaration of a builtin __initZ var
if (tid->tinfo->builtinTypeInfo()) {
LLValue* found = gIR->module->getNamedGlobal(mangled);
if (!found)
{
const LLType* t = LLOpaqueType::get();
llvm::GlobalVariable* g = new llvm::GlobalVariable(t, true, llvm::GlobalValue::ExternalLinkage, NULL, mangled, gIR->module);
assert(g);
/*if (!tid->ir.irGlobal)
tid->ir.irGlobal = new IrGlobal(tid);*/
tid->ir.irGlobal->value = g;
mangled.append("__TYPE");
gIR->module->addTypeName(mangled, tid->ir.irGlobal->value->getType()->getContainedType(0));
Logger::println("Got typeinfo var: %s", tid->ir.irGlobal->value->getName().c_str());
tid->ir.initialized = true;
tid->ir.defined = true;
}
else if (!tid->ir.irGlobal->value) {
tid->ir.irGlobal->value = found;
tid->ir.initialized = true;
tid->ir.defined = true;
}
// fixup the global
const llvm::Type* rty = Type::typeinfo->type->ir.type->get();
llvm::cast<llvm::OpaqueType>(irg->type.get())->refineAbstractTypeTo(rty);
LLGlobalVariable* g = isaGlobalVar(irg->value);
g->setLinkage(llvm::GlobalValue::ExternalLinkage);
return;
}
// custom typedef
else {
tid->llvmDeclare();
gIR->constInitList.push_back(tid);
}
DtoConstInitTypeInfo(tid);
}
void DtoConstInitTypeInfo(TypeInfoDeclaration* tid)
@ -340,7 +338,7 @@ void DtoConstInitTypeInfo(TypeInfoDeclaration* tid)
Logger::println("DtoConstInitTypeInfo(%s)", tid->toChars());
LOG_SCOPE;
gIR->defineList.push_back(tid);
tid->llvmDefine();
}
void DtoDefineTypeInfo(TypeInfoDeclaration* tid)
@ -356,11 +354,6 @@ void DtoDefineTypeInfo(TypeInfoDeclaration* tid)
/* ========================================================================= */
void TypeInfoDeclaration::llvmDeclare()
{
assert(0 && "TypeInfoDeclaration::llvmDeclare");
}
void TypeInfoDeclaration::llvmDefine()
{
assert(0 && "TypeInfoDeclaration::llvmDeclare");
@ -368,27 +361,13 @@ void TypeInfoDeclaration::llvmDefine()
/* ========================================================================= */
void TypeInfoTypedefDeclaration::llvmDeclare()
{
Logger::println("TypeInfoTypedefDeclaration::llvmDeclare() %s", toChars());
LOG_SCOPE;
ClassDeclaration* base = Type::typeinfotypedef;
DtoResolveClass(base);
const LLStructType* stype = isaStruct(base->type->ir.type->get());
// create the symbol
ir.irGlobal->value = new llvm::GlobalVariable(ir.irGlobal->type.get(), true, TYPEINFO_LINKAGE_TYPE, NULL, toChars(), gIR->module);
}
void TypeInfoTypedefDeclaration::llvmDefine()
{
Logger::println("TypeInfoTypedefDeclaration::llvmDefine() %s", toChars());
LOG_SCOPE;
ClassDeclaration* base = Type::typeinfotypedef;
DtoForceConstInitDsymbol(base);
base->codegen(Type::sir);
// vtbl
std::vector<LLConstant*> sinits;
@ -439,25 +418,13 @@ void TypeInfoTypedefDeclaration::llvmDefine()
/* ========================================================================= */
void TypeInfoEnumDeclaration::llvmDeclare()
{
Logger::println("TypeInfoEnumDeclaration::llvmDeclare() %s", toChars());
LOG_SCOPE;
ClassDeclaration* base = Type::typeinfoenum;
DtoResolveClass(base);
// create the symbol
ir.irGlobal->value = new llvm::GlobalVariable(ir.irGlobal->type.get(), true, TYPEINFO_LINKAGE_TYPE, NULL, toChars(), gIR->module);
}
void TypeInfoEnumDeclaration::llvmDefine()
{
Logger::println("TypeInfoEnumDeclaration::llvmDefine() %s", toChars());
LOG_SCOPE;
ClassDeclaration* base = Type::typeinfoenum;
DtoForceConstInitDsymbol(base);
base->codegen(Type::sir);
// vtbl
std::vector<LLConstant*> sinits;
@ -512,19 +479,10 @@ void TypeInfoEnumDeclaration::llvmDefine()
/* ========================================================================= */
static void LLVM_D_Declare_TypeInfoBase(TypeInfoDeclaration* tid, ClassDeclaration* cd)
{
ClassDeclaration* base = cd;
DtoResolveClass(base);
// create the symbol
tid->ir.irGlobal->value = new llvm::GlobalVariable(tid->ir.irGlobal->type.get(), true, TYPEINFO_LINKAGE_TYPE, NULL, tid->toChars(), gIR->module);
}
static void LLVM_D_Define_TypeInfoBase(Type* basetype, TypeInfoDeclaration* tid, ClassDeclaration* cd)
{
ClassDeclaration* base = cd;
DtoForceConstInitDsymbol(base);
base->codegen(Type::sir);
// vtbl
std::vector<LLConstant*> sinits;
@ -549,17 +507,6 @@ static void LLVM_D_Define_TypeInfoBase(Type* basetype, TypeInfoDeclaration* tid,
/* ========================================================================= */
void TypeInfoPointerDeclaration::llvmDeclare()
{
Logger::println("TypeInfoPointerDeclaration::llvmDeclare() %s", toChars());
LOG_SCOPE;
assert(tinfo->ty == Tpointer);
TypePointer *tc = (TypePointer *)tinfo;
LLVM_D_Declare_TypeInfoBase(this, Type::typeinfopointer);
}
void TypeInfoPointerDeclaration::llvmDefine()
{
Logger::println("TypeInfoPointerDeclaration::llvmDefine() %s", toChars());
@ -573,17 +520,6 @@ void TypeInfoPointerDeclaration::llvmDefine()
/* ========================================================================= */
void TypeInfoArrayDeclaration::llvmDeclare()
{
Logger::println("TypeInfoArrayDeclaration::llvmDeclare() %s", toChars());
LOG_SCOPE;
assert(tinfo->ty == Tarray);
TypeDArray *tc = (TypeDArray *)tinfo;
LLVM_D_Declare_TypeInfoBase(this, Type::typeinfoarray);
}
void TypeInfoArrayDeclaration::llvmDefine()
{
Logger::println("TypeInfoArrayDeclaration::llvmDefine() %s", toChars());
@ -597,19 +533,6 @@ void TypeInfoArrayDeclaration::llvmDefine()
/* ========================================================================= */
void TypeInfoStaticArrayDeclaration::llvmDeclare()
{
Logger::println("TypeInfoStaticArrayDeclaration::llvmDeclare() %s", toChars());
LOG_SCOPE;
// init typeinfo class
ClassDeclaration* base = Type::typeinfostaticarray;
DtoResolveClass(base);
// create the symbol
ir.irGlobal->value = new llvm::GlobalVariable(ir.irGlobal->type.get(), true, TYPEINFO_LINKAGE_TYPE, NULL, toChars(), gIR->module);
}
void TypeInfoStaticArrayDeclaration::llvmDefine()
{
Logger::println("TypeInfoStaticArrayDeclaration::llvmDefine() %s", toChars());
@ -617,7 +540,7 @@ void TypeInfoStaticArrayDeclaration::llvmDefine()
// init typeinfo class
ClassDeclaration* base = Type::typeinfostaticarray;
DtoForceConstInitDsymbol(base);
base->codegen(Type::sir);
// get type of typeinfo class
const LLStructType* stype = isaStruct(base->type->ir.type->get());
@ -652,19 +575,6 @@ void TypeInfoStaticArrayDeclaration::llvmDefine()
/* ========================================================================= */
void TypeInfoAssociativeArrayDeclaration::llvmDeclare()
{
Logger::println("TypeInfoAssociativeArrayDeclaration::llvmDeclare() %s", toChars());
LOG_SCOPE;
// init typeinfo class
ClassDeclaration* base = Type::typeinfoassociativearray;
DtoResolveClass(base);
// create the symbol
ir.irGlobal->value = new llvm::GlobalVariable(ir.irGlobal->type.get(), true, TYPEINFO_LINKAGE_TYPE, NULL, toChars(), gIR->module);
}
void TypeInfoAssociativeArrayDeclaration::llvmDefine()
{
Logger::println("TypeInfoAssociativeArrayDeclaration::llvmDefine() %s", toChars());
@ -672,7 +582,7 @@ void TypeInfoAssociativeArrayDeclaration::llvmDefine()
// init typeinfo class
ClassDeclaration* base = Type::typeinfoassociativearray;
DtoForceConstInitDsymbol(base);
base->codegen(Type::sir);
// initializer vector
std::vector<LLConstant*> sinits;
@ -706,17 +616,6 @@ void TypeInfoAssociativeArrayDeclaration::llvmDefine()
/* ========================================================================= */
void TypeInfoFunctionDeclaration::llvmDeclare()
{
Logger::println("TypeInfoFunctionDeclaration::llvmDeclare() %s", toChars());
LOG_SCOPE;
assert(tinfo->ty == Tfunction);
TypeFunction *tc = (TypeFunction *)tinfo;
LLVM_D_Declare_TypeInfoBase(this, Type::typeinfofunction);
}
void TypeInfoFunctionDeclaration::llvmDefine()
{
Logger::println("TypeInfoFunctionDeclaration::llvmDefine() %s", toChars());
@ -730,17 +629,6 @@ void TypeInfoFunctionDeclaration::llvmDefine()
/* ========================================================================= */
void TypeInfoDelegateDeclaration::llvmDeclare()
{
Logger::println("TypeInfoDelegateDeclaration::llvmDeclare() %s", toChars());
LOG_SCOPE;
assert(tinfo->ty == Tdelegate);
TypeDelegate *tc = (TypeDelegate *)tinfo;
LLVM_D_Declare_TypeInfoBase(this, Type::typeinfodelegate);
}
void TypeInfoDelegateDeclaration::llvmDefine()
{
Logger::println("TypeInfoDelegateDeclaration::llvmDefine() %s", toChars());
@ -754,23 +642,6 @@ void TypeInfoDelegateDeclaration::llvmDefine()
/* ========================================================================= */
void TypeInfoStructDeclaration::llvmDeclare()
{
Logger::println("TypeInfoStructDeclaration::llvmDeclare() %s", toChars());
LOG_SCOPE;
assert(tinfo->ty == Tstruct);
TypeStruct *tc = (TypeStruct *)tinfo;
StructDeclaration *sd = tc->sym;
DtoResolveDsymbol(sd);
ClassDeclaration* base = Type::typeinfostruct;
DtoResolveClass(base);
// create the symbol
ir.irGlobal->value = new llvm::GlobalVariable(ir.irGlobal->type.get(), true, TYPEINFO_LINKAGE_TYPE, NULL, toChars(), gIR->module);
}
void TypeInfoStructDeclaration::llvmDefine()
{
Logger::println("TypeInfoStructDeclaration::llvmDefine() %s", toChars());
@ -779,10 +650,10 @@ void TypeInfoStructDeclaration::llvmDefine()
assert(tinfo->ty == Tstruct);
TypeStruct *tc = (TypeStruct *)tinfo;
StructDeclaration *sd = tc->sym;
DtoForceConstInitDsymbol(sd);
sd->codegen(Type::sir);
ClassDeclaration* base = Type::typeinfostruct;
DtoForceConstInitDsymbol(base);
base->codegen(Type::sir);
const LLStructType* stype = isaStruct(base->type->ir.type->get());
@ -870,7 +741,7 @@ void TypeInfoStructDeclaration::llvmDefine()
{
fd = fdx->overloadExactMatch(tftohash);
if (fd) {
DtoForceDeclareDsymbol(fd);
fd->codegen(Type::sir);
assert(fd->ir.irFunc->func != 0);
LLConstant* c = isaConstant(fd->ir.irFunc->func);
assert(c);
@ -896,7 +767,7 @@ void TypeInfoStructDeclaration::llvmDefine()
{
fd = fdx->overloadExactMatch(tfeqptr);
if (fd) {
DtoForceDeclareDsymbol(fd);
fd->codegen(Type::sir);
assert(fd->ir.irFunc->func != 0);
LLConstant* c = isaConstant(fd->ir.irFunc->func);
assert(c);
@ -924,7 +795,7 @@ void TypeInfoStructDeclaration::llvmDefine()
{
fd = fdx->overloadExactMatch(tftostring);
if (fd) {
DtoForceDeclareDsymbol(fd);
fd->codegen(Type::sir);
assert(fd->ir.irFunc->func != 0);
LLConstant* c = isaConstant(fd->ir.irFunc->func);
assert(c);
@ -968,20 +839,6 @@ void TypeInfoStructDeclaration::llvmDefine()
/* ========================================================================= */
void TypeInfoClassDeclaration::llvmDeclare()
{
Logger::println("TypeInfoClassDeclaration::llvmDeclare() %s", toChars());
LOG_SCOPE;
// init typeinfo class
ClassDeclaration* base = Type::typeinfoclass;
assert(base);
DtoResolveClass(base);
// create the symbol
ir.irGlobal->value = new llvm::GlobalVariable(ir.irGlobal->type.get(), true, TYPEINFO_LINKAGE_TYPE, NULL, toChars(), gIR->module);
}
void TypeInfoClassDeclaration::llvmDefine()
{
Logger::println("TypeInfoClassDeclaration::llvmDefine() %s", toChars());
@ -990,7 +847,7 @@ void TypeInfoClassDeclaration::llvmDefine()
// init typeinfo class
ClassDeclaration* base = Type::typeinfoclass;
assert(base);
DtoForceConstInitDsymbol(base);
base->codegen(Type::sir);
// initializer vector
std::vector<LLConstant*> sinits;
@ -1003,7 +860,7 @@ void TypeInfoClassDeclaration::llvmDefine()
// get classinfo
assert(tinfo->ty == Tclass);
TypeClass *tc = (TypeClass *)tinfo;
DtoForceDeclareDsymbol(tc->sym);
tc->sym->codegen(Type::sir);;
assert(tc->sym->ir.irStruct->classInfo);
sinits.push_back(tc->sym->ir.irStruct->classInfo);
@ -1019,20 +876,6 @@ void TypeInfoClassDeclaration::llvmDefine()
/* ========================================================================= */
void TypeInfoInterfaceDeclaration::llvmDeclare()
{
Logger::println("TypeInfoInterfaceDeclaration::llvmDeclare() %s", toChars());
LOG_SCOPE;
// init typeinfo class
ClassDeclaration* base = Type::typeinfointerface;
assert(base);
DtoResolveClass(base);
// create the symbol
ir.irGlobal->value = new llvm::GlobalVariable(ir.irGlobal->type.get(), true, TYPEINFO_LINKAGE_TYPE, NULL, toChars(), gIR->module);
}
void TypeInfoInterfaceDeclaration::llvmDefine()
{
Logger::println("TypeInfoInterfaceDeclaration::llvmDefine() %s", toChars());
@ -1041,7 +884,7 @@ void TypeInfoInterfaceDeclaration::llvmDefine()
// init typeinfo class
ClassDeclaration* base = Type::typeinfointerface;
assert(base);
DtoForceConstInitDsymbol(base);
base->codegen(Type::sir);
// get type of typeinfo class
const LLStructType* stype = isaStruct(base->type->ir.type->get());
@ -1072,20 +915,6 @@ void TypeInfoInterfaceDeclaration::llvmDefine()
/* ========================================================================= */
void TypeInfoTupleDeclaration::llvmDeclare()
{
Logger::println("TypeInfoTupleDeclaration::llvmDeclare() %s", toChars());
LOG_SCOPE;
// init typeinfo class
ClassDeclaration* base = Type::typeinfotypelist;
assert(base);
DtoResolveClass(base);
// create the symbol
ir.irGlobal->value = new llvm::GlobalVariable(ir.irGlobal->type.get(), true, TYPEINFO_LINKAGE_TYPE, NULL, toChars(), gIR->module);
}
void TypeInfoTupleDeclaration::llvmDefine()
{
Logger::println("TypeInfoTupleDeclaration::llvmDefine() %s", toChars());
@ -1094,7 +923,7 @@ void TypeInfoTupleDeclaration::llvmDefine()
// init typeinfo class
ClassDeclaration* base = Type::typeinfotypelist;
assert(base);
DtoForceConstInitDsymbol(base);
base->codegen(Type::sir);
// get type of typeinfo class
const LLStructType* stype = isaStruct(base->type->ir.type->get());
@ -1156,14 +985,6 @@ void TypeInfoTupleDeclaration::llvmDefine()
#if DMDV2
void TypeInfoConstDeclaration::llvmDeclare()
{
Logger::println("TypeInfoConstDeclaration::llvmDeclare() %s", toChars());
LOG_SCOPE;
LLVM_D_Declare_TypeInfoBase(this, Type::typeinfoconst);
}
void TypeInfoConstDeclaration::llvmDefine()
{
Logger::println("TypeInfoConstDeclaration::llvmDefine() %s", toChars());
@ -1177,14 +998,6 @@ void TypeInfoConstDeclaration::llvmDefine()
/* ========================================================================= */
void TypeInfoInvariantDeclaration::llvmDeclare()
{
Logger::println("TypeInfoInvariantDeclaration::llvmDeclare() %s", toChars());
LOG_SCOPE;
LLVM_D_Declare_TypeInfoBase(this, Type::typeinfoinvariant);
}
void TypeInfoInvariantDeclaration::llvmDefine()
{
Logger::println("TypeInfoInvariantDeclaration::llvmDefine() %s", toChars());

10
ir/ir.h
View file

@ -3,10 +3,13 @@
#ifndef LDC_IR_IR_H
#define LDC_IR_IR_H
#include <deque>
#include "ir/irforw.h"
#include "root.h"
struct IRState;
struct IrFunction;
struct IrBase : Object
{
@ -15,13 +18,18 @@ struct IrBase : Object
struct Ir
{
Ir() : irs(NULL) {}
Ir();
void setState(IRState* p) { irs = p; }
IRState* getState() { return irs; }
void addFunctionBody(IrFunction* f);
void emitFunctionBodies();
private:
IRState* irs;
std::deque<IrFunction*> functionbodies;
};
#endif

View file

@ -49,7 +49,7 @@ IRLandingPadInfo::IRLandingPadInfo(Catch* catchstmt, llvm::BasicBlock* end)
assert(catchstmt->type);
catchType = catchstmt->type->toBasetype()->isClassHandle();
assert(catchType);
DtoForceDeclareDsymbol(catchType);
catchType->codegen(Type::sir);
}
IRLandingPadInfo::IRLandingPadInfo(Statement* finallystmt)