mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-07 19:36:06 +03:00
Fixed problems introduced by previous commits that prevented Tango from compiling.
This commit is contained in:
parent
ec986231e5
commit
be3bfbff5d
8 changed files with 63 additions and 44 deletions
|
@ -145,6 +145,19 @@ static void DtoResolveInterface(InterfaceDeclaration* cd)
|
|||
IrStruct* irstruct = new IrStruct(cd);
|
||||
cd->ir.irStruct = irstruct;
|
||||
|
||||
// create the type
|
||||
const LLType* t = LLArrayType::get(getVoidPtrType(), cd->vtbl.dim);
|
||||
assert(!ts->ir.type);
|
||||
ts->ir.type = new LLPATypeHolder(getPtrToType(t));
|
||||
|
||||
// ... and ClassInfo
|
||||
std::string varname("_D");
|
||||
varname.append(cd->mangle());
|
||||
varname.append("11__InterfaceZ");
|
||||
|
||||
// create global
|
||||
irstruct->classInfo = new llvm::GlobalVariable(irstruct->classInfoOpaque.get(), false, DtoLinkage(cd), NULL, varname, gIR->module);
|
||||
|
||||
// handle base interfaces
|
||||
if (cd->baseclasses.dim)
|
||||
{
|
||||
|
@ -168,11 +181,6 @@ static void DtoResolveInterface(InterfaceDeclaration* cd)
|
|||
}
|
||||
}
|
||||
|
||||
// create the type
|
||||
const LLType* t = LLArrayType::get(getVoidPtrType(), cd->vtbl.dim);
|
||||
assert(!ts->ir.type);
|
||||
ts->ir.type = new LLPATypeHolder(getPtrToType(t));
|
||||
|
||||
// request declaration
|
||||
DtoDeclareInterface(cd);
|
||||
|
||||
|
@ -238,10 +246,18 @@ void DtoResolveClass(ClassDeclaration* cd)
|
|||
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);
|
||||
varname = "_D";
|
||||
varname.append(cd->mangle());
|
||||
varname.append("6__initZ");
|
||||
irstruct->init = new llvm::GlobalVariable(irstruct->initOpaque.get(), true, _linkage, NULL, varname, gIR->module);
|
||||
|
||||
// ... and ClassInfo
|
||||
varname = "_D";
|
||||
varname.append(cd->mangle());
|
||||
varname.append("7__ClassZ");
|
||||
|
||||
// create global
|
||||
irstruct->classInfo = new llvm::GlobalVariable(irstruct->classInfoOpaque.get(), false, _linkage, NULL, varname, gIR->module);
|
||||
|
||||
// push state
|
||||
gIR->structs.push_back(irstruct);
|
||||
|
@ -778,6 +794,15 @@ void DtoConstInitClass(ClassDeclaration* cd)
|
|||
// refine __initZ global type to the one of the initializer
|
||||
llvm::cast<llvm::OpaqueType>(irstruct->initOpaque.get())->refineAbstractTypeTo(irstruct->constInit->getType());
|
||||
|
||||
// build initializers for static member variables
|
||||
size_t n = irstruct->staticVars.size();
|
||||
for (size_t i = 0; i < n; ++i)
|
||||
{
|
||||
DtoConstInitGlobal(irstruct->staticVars[i]);
|
||||
}
|
||||
// This is all we use it for. Clear the memory!
|
||||
irstruct->staticVars.clear();
|
||||
|
||||
// if (Logger::enabled())
|
||||
// {
|
||||
// Logger::cout() << "class " << cd->toChars() << std::endl;
|
||||
|
@ -1333,17 +1358,6 @@ void DtoDeclareClassInfo(ClassDeclaration* cd)
|
|||
// resovle ClassInfo
|
||||
ClassDeclaration* cinfo = ClassDeclaration::classinfo;
|
||||
DtoResolveClass(cinfo);
|
||||
|
||||
// do the mangle
|
||||
std::string gname("_D");
|
||||
gname.append(cd->mangle());
|
||||
if (!cd->isInterfaceDeclaration())
|
||||
gname.append("7__ClassZ");
|
||||
else
|
||||
gname.append("11__InterfaceZ");
|
||||
|
||||
// create global
|
||||
irstruct->classInfo = new llvm::GlobalVariable(irstruct->classInfoOpaque.get(), false, DtoLinkage(cd), NULL, gname, gIR->module);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -84,6 +84,9 @@ void VarDeclaration::codegen(Ir* p)
|
|||
return;
|
||||
}
|
||||
|
||||
if (AggregateDeclaration* ad = isMember())
|
||||
ad->codegen(p);
|
||||
|
||||
// global variable or magic
|
||||
#if DMDV2
|
||||
// taken from dmd2/structs
|
||||
|
@ -135,6 +138,11 @@ void VarDeclaration::codegen(Ir* p)
|
|||
if (nakedUse)
|
||||
gIR->usedArray.push_back(DtoBitCast(gvar, getVoidPtrType()));
|
||||
|
||||
// don't initialize static struct members yet, they might be of the struct type
|
||||
// which doesn't have a static initializer yet.
|
||||
if (AggregateDeclaration* ad = isMember())
|
||||
ad->ir.irStruct->staticVars.push_back(this);
|
||||
else
|
||||
DtoConstInitGlobal(this);
|
||||
}
|
||||
else
|
||||
|
|
|
@ -303,16 +303,6 @@ void DtoResolveFunction(FuncDeclaration* fdecl)
|
|||
return; // ignore declaration completely
|
||||
}
|
||||
|
||||
// is imported and we don't have access?
|
||||
if (fdecl->getModule() != gIR->dmodule)
|
||||
{
|
||||
if (fdecl->prot() == PROTprivate)
|
||||
{
|
||||
Logger::println("Ignoring private imported function %s", fdecl->toPrettyChars());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//printf("resolve function: %s\n", fdecl->toPrettyChars());
|
||||
|
||||
if (fdecl->parent)
|
||||
|
|
|
@ -4,11 +4,12 @@
|
|||
// which uses the llvm license
|
||||
|
||||
#include "gen/llvm.h"
|
||||
#include "llvm/LinkAllVMCore.h"
|
||||
#include "llvm/Linker.h"
|
||||
#include "llvm/System/Signals.h"
|
||||
#include "llvm/Target/SubtargetFeature.h"
|
||||
#include "llvm/Target/TargetMachine.h"
|
||||
#include "llvm/Target/TargetMachineRegistry.h"
|
||||
#include "llvm/LinkAllVMCore.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
@ -117,6 +118,9 @@ static void initFromString(char*& dest, const cl::opt<std::string>& src) {
|
|||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
// stack trace on signals
|
||||
llvm::sys::PrintStackTraceOnErrorSignal();
|
||||
|
||||
Array files;
|
||||
char *p, *ext;
|
||||
Module *m;
|
||||
|
|
|
@ -97,16 +97,7 @@ LLConstant* DtoConstStructInitializer(StructInitializer* si)
|
|||
TypeStruct* ts = (TypeStruct*)si->ad->type;
|
||||
|
||||
// force constant initialization of the symbol
|
||||
si->ad->codegen(Type::sir);;
|
||||
|
||||
// get formal type
|
||||
const llvm::StructType* structtype = isaStruct(ts->ir.type->get());
|
||||
|
||||
#if 0
|
||||
// log it
|
||||
if (Logger::enabled())
|
||||
Logger::cout() << "llvm struct type: " << *structtype << '\n';
|
||||
#endif
|
||||
si->ad->codegen(Type::sir);
|
||||
|
||||
// sanity check
|
||||
assert(si->value.dim > 0);
|
||||
|
@ -241,7 +232,7 @@ Lpadding:
|
|||
}
|
||||
|
||||
// there might still be padding after the last one, make sure that is defaulted/zeroed as well
|
||||
size_t structsize = getTypePaddedSize(structtype);
|
||||
size_t structsize = si->ad->structsize;
|
||||
|
||||
// if there is space before the next explicit initializer
|
||||
// FIXME: this should be handled in the loop above as well
|
||||
|
@ -645,6 +636,15 @@ void DtoConstInitStruct(StructDeclaration* sd)
|
|||
// refine __initZ global type to the one of the initializer
|
||||
llvm::cast<llvm::OpaqueType>(irstruct->initOpaque.get())->refineAbstractTypeTo(irstruct->constInit->getType());
|
||||
|
||||
// build initializers for static member variables
|
||||
size_t n = irstruct->staticVars.size();
|
||||
for (size_t i = 0; i < n; ++i)
|
||||
{
|
||||
DtoConstInitGlobal(irstruct->staticVars[i]);
|
||||
}
|
||||
// This is all we use it for. Clear the memory!
|
||||
irstruct->staticVars.clear();
|
||||
|
||||
gIR->structs.pop_back();
|
||||
|
||||
// emit typeinfo
|
||||
|
|
|
@ -326,7 +326,7 @@ DValue* DtoCallFunction(Loc& loc, Type* resulttype, DValue* fnval, Expressions*
|
|||
{
|
||||
ctxarg = gIR->ir->CreateExtractValue(fnval->getRVal(), 0, ".ptr");
|
||||
}
|
||||
assert(ctxarg->getType() == argiter->get());
|
||||
ctxarg = DtoBitCast(ctxarg, argiter->get());
|
||||
++argiter;
|
||||
args.push_back(ctxarg);
|
||||
}
|
||||
|
|
|
@ -969,6 +969,7 @@ LLConstant* AddrExp::toConstElem(IRState* p)
|
|||
// global variable
|
||||
if (VarDeclaration* vd = vexp->var->isVarDeclaration())
|
||||
{
|
||||
vd->codegen(Type::sir);
|
||||
LLConstant* llc = llvm::dyn_cast<LLConstant>(vd->ir.getIrValue());
|
||||
assert(llc);
|
||||
return llc;
|
||||
|
|
|
@ -150,6 +150,8 @@ struct IrStruct : IrBase
|
|||
|
||||
// composite type debug description
|
||||
llvm::DICompositeType diCompositeType;
|
||||
|
||||
std::vector<VarDeclaration*> staticVars;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue