mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-01-11 18:33:14 +01:00
[svn r189] moving IR data back into DMD frontend nodes
This commit is contained in:
@@ -82,7 +82,7 @@ llvm::Constant* DtoConstStructInitializer(StructInitializer* si)
|
||||
|
||||
TypeStruct* ts = (TypeStruct*)si->ad->type;
|
||||
|
||||
const llvm::StructType* structtype = isaStruct(gIR->irType[ts].type->get());
|
||||
const llvm::StructType* structtype = isaStruct(ts->ir.type->get());
|
||||
Logger::cout() << "llvm struct type: " << *structtype << '\n';
|
||||
|
||||
assert(si->value.dim == si->vars.dim);
|
||||
@@ -95,11 +95,11 @@ llvm::Constant* DtoConstStructInitializer(StructInitializer* si)
|
||||
VarDeclaration* vd = (VarDeclaration*)si->vars.data[i];
|
||||
assert(vd);
|
||||
llvm::Constant* v = DtoConstInitializer(vd->type, ini);
|
||||
inits.push_back(DUnionIdx(gIR->irDsymbol[vd].irField->index, gIR->irDsymbol[vd].irField->indexOffset, v));
|
||||
inits.push_back(DUnionIdx(vd->ir.irField->index, vd->ir.irField->indexOffset, v));
|
||||
}
|
||||
|
||||
DtoConstInitStruct((StructDeclaration*)si->ad);
|
||||
return gIR->irDsymbol[si->ad].irStruct->dunion->getConst(inits);
|
||||
return si->ad->ir.irStruct->dunion->getConst(inits);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -115,7 +115,7 @@ llvm::Value* DtoIndexStruct(llvm::Value* ptr, StructDeclaration* sd, Type* t, un
|
||||
const llvm::Type* llt = getPtrToType(DtoType(t));
|
||||
const llvm::Type* st = getPtrToType(DtoType(sd->type));
|
||||
if (ptr->getType() != st) {
|
||||
assert(gIR->irDsymbol[sd].irStruct->hasUnions);
|
||||
assert(sd->ir.irStruct->hasUnions);
|
||||
ptr = gIR->ir->CreateBitCast(ptr, st, "tmp");
|
||||
}
|
||||
|
||||
@@ -123,26 +123,26 @@ llvm::Value* DtoIndexStruct(llvm::Value* ptr, StructDeclaration* sd, Type* t, un
|
||||
VarDeclaration* vd = (VarDeclaration*)sd->fields.data[i];
|
||||
Type* vdtype = DtoDType(vd->type);
|
||||
//Logger::println("found %u type %s", vd->offset, vdtype->toChars());
|
||||
assert(gIR->irDsymbol[vd].irField->index >= 0);
|
||||
assert(vd->ir.irField->index >= 0);
|
||||
if (os == vd->offset && vdtype == t) {
|
||||
idxs.push_back(gIR->irDsymbol[vd].irField->index);
|
||||
idxs.push_back(vd->ir.irField->index);
|
||||
ptr = DtoGEP(ptr, idxs, "tmp");
|
||||
if (ptr->getType() != llt)
|
||||
ptr = gIR->ir->CreateBitCast(ptr, llt, "tmp");
|
||||
if (gIR->irDsymbol[vd].irField->indexOffset)
|
||||
ptr = new llvm::GetElementPtrInst(ptr, DtoConstUint(gIR->irDsymbol[vd].irField->indexOffset), "tmp", gIR->scopebb());
|
||||
if (vd->ir.irField->indexOffset)
|
||||
ptr = new llvm::GetElementPtrInst(ptr, DtoConstUint(vd->ir.irField->indexOffset), "tmp", gIR->scopebb());
|
||||
return ptr;
|
||||
}
|
||||
else if (vdtype->ty == Tstruct && (vd->offset + vdtype->size()) > os) {
|
||||
TypeStruct* ts = (TypeStruct*)vdtype;
|
||||
StructDeclaration* ssd = ts->sym;
|
||||
idxs.push_back(gIR->irDsymbol[vd].irField->index);
|
||||
if (gIR->irDsymbol[vd].irField->indexOffset) {
|
||||
idxs.push_back(vd->ir.irField->index);
|
||||
if (vd->ir.irField->indexOffset) {
|
||||
Logger::println("has union field offset");
|
||||
ptr = DtoGEP(ptr, idxs, "tmp");
|
||||
if (ptr->getType() != llt)
|
||||
ptr = DtoBitCast(ptr, llt);
|
||||
ptr = new llvm::GetElementPtrInst(ptr, DtoConstUint(gIR->irDsymbol[vd].irField->indexOffset), "tmp", gIR->scopebb());
|
||||
ptr = new llvm::GetElementPtrInst(ptr, DtoConstUint(vd->ir.irField->indexOffset), "tmp", gIR->scopebb());
|
||||
std::vector<unsigned> tmp;
|
||||
return DtoIndexStruct(ptr, ssd, t, os-vd->offset, tmp);
|
||||
}
|
||||
@@ -170,8 +170,8 @@ llvm::Value* DtoIndexStruct(llvm::Value* ptr, StructDeclaration* sd, Type* t, un
|
||||
|
||||
void DtoResolveStruct(StructDeclaration* sd)
|
||||
{
|
||||
if (gIR->irDsymbol[sd].resolved) return;
|
||||
gIR->irDsymbol[sd].resolved = true;
|
||||
if (sd->ir.resolved) return;
|
||||
sd->ir.resolved = true;
|
||||
|
||||
Logger::println("DtoResolveStruct(%s): %s", sd->toChars(), sd->loc.toChars());
|
||||
LOG_SCOPE;
|
||||
@@ -182,7 +182,7 @@ void DtoResolveStruct(StructDeclaration* sd)
|
||||
TypeStruct* ts = (TypeStruct*)DtoDType(sd->type);
|
||||
|
||||
IrStruct* irstruct = new IrStruct(ts);
|
||||
gIR->irDsymbol[sd].irStruct = irstruct;
|
||||
sd->ir.irStruct = irstruct;
|
||||
gIR->structs.push_back(irstruct);
|
||||
|
||||
// fields
|
||||
@@ -246,7 +246,7 @@ void DtoResolveStruct(StructDeclaration* sd)
|
||||
fieldtype = i->second.type;
|
||||
fieldinit = i->second.var;
|
||||
prevsize = getABITypeSize(fieldtype);
|
||||
gIR->irDsymbol[i->second.var].irField->index = idx;
|
||||
i->second.var->ir.irField->index = idx;
|
||||
}
|
||||
// colliding offset?
|
||||
else if (lastoffset == i->first) {
|
||||
@@ -255,16 +255,16 @@ void DtoResolveStruct(StructDeclaration* sd)
|
||||
fieldpad += s - prevsize;
|
||||
prevsize = s;
|
||||
}
|
||||
gIR->irDsymbol[sd].irStruct->hasUnions = true;
|
||||
gIR->irDsymbol[i->second.var].irField->index = idx;
|
||||
sd->ir.irStruct->hasUnions = true;
|
||||
i->second.var->ir.irField->index = idx;
|
||||
}
|
||||
// intersecting offset?
|
||||
else if (i->first < (lastoffset + prevsize)) {
|
||||
size_t s = getABITypeSize(i->second.type);
|
||||
assert((i->first + s) <= (lastoffset + prevsize)); // this holds because all types are aligned to their size
|
||||
gIR->irDsymbol[sd].irStruct->hasUnions = true;
|
||||
gIR->irDsymbol[i->second.var].irField->index = idx;
|
||||
gIR->irDsymbol[i->second.var].irField->indexOffset = (i->first - lastoffset) / s;
|
||||
sd->ir.irStruct->hasUnions = true;
|
||||
i->second.var->ir.irField->index = idx;
|
||||
i->second.var->ir.irField->indexOffset = (i->first - lastoffset) / s;
|
||||
}
|
||||
// fresh offset
|
||||
else {
|
||||
@@ -284,7 +284,7 @@ void DtoResolveStruct(StructDeclaration* sd)
|
||||
fieldtype = i->second.type;
|
||||
fieldinit = i->second.var;
|
||||
prevsize = getABITypeSize(fieldtype);
|
||||
gIR->irDsymbol[i->second.var].irField->index = idx;
|
||||
i->second.var->ir.irField->index = idx;
|
||||
fieldpad = 0;
|
||||
}
|
||||
}
|
||||
@@ -307,8 +307,8 @@ void DtoResolveStruct(StructDeclaration* sd)
|
||||
structtype = isaStruct(pa.get());
|
||||
}
|
||||
|
||||
assert(gIR->irType[ts].type == 0);
|
||||
gIR->irType[ts].type = new llvm::PATypeHolder(structtype);
|
||||
assert(ts->ir.type == 0);
|
||||
ts->ir.type = new llvm::PATypeHolder(structtype);
|
||||
|
||||
if (sd->parent->isModule()) {
|
||||
gIR->module->addTypeName(sd->mangle(),structtype);
|
||||
@@ -323,8 +323,8 @@ void DtoResolveStruct(StructDeclaration* sd)
|
||||
|
||||
void DtoDeclareStruct(StructDeclaration* sd)
|
||||
{
|
||||
if (gIR->irDsymbol[sd].declared) return;
|
||||
gIR->irDsymbol[sd].declared = true;
|
||||
if (sd->ir.declared) return;
|
||||
sd->ir.declared = true;
|
||||
|
||||
Logger::println("DtoDeclareStruct(%s): %s", sd->toChars(), sd->loc.toChars());
|
||||
LOG_SCOPE;
|
||||
@@ -336,8 +336,8 @@ void DtoDeclareStruct(StructDeclaration* sd)
|
||||
initname.append("6__initZ");
|
||||
|
||||
llvm::GlobalValue::LinkageTypes _linkage = DtoExternalLinkage(sd);
|
||||
llvm::GlobalVariable* initvar = new llvm::GlobalVariable(gIR->irType[ts].type->get(), true, _linkage, NULL, initname, gIR->module);
|
||||
gIR->irDsymbol[sd].irStruct->init = initvar;
|
||||
llvm::GlobalVariable* initvar = new llvm::GlobalVariable(ts->ir.type->get(), true, _linkage, NULL, initname, gIR->module);
|
||||
sd->ir.irStruct->init = initvar;
|
||||
|
||||
gIR->constInitList.push_back(sd);
|
||||
if (DtoIsTemplateInstance(sd) || sd->getModule() == gIR->dmodule)
|
||||
@@ -348,13 +348,13 @@ void DtoDeclareStruct(StructDeclaration* sd)
|
||||
|
||||
void DtoConstInitStruct(StructDeclaration* sd)
|
||||
{
|
||||
if (gIR->irDsymbol[sd].initialized) return;
|
||||
gIR->irDsymbol[sd].initialized = true;
|
||||
if (sd->ir.initialized) return;
|
||||
sd->ir.initialized = true;
|
||||
|
||||
Logger::println("DtoConstInitStruct(%s): %s", sd->toChars(), sd->loc.toChars());
|
||||
LOG_SCOPE;
|
||||
|
||||
IrStruct* irstruct = gIR->irDsymbol[sd].irStruct;
|
||||
IrStruct* irstruct = sd->ir.irStruct;
|
||||
gIR->structs.push_back(irstruct);
|
||||
|
||||
// make sure each offset knows its default initializer
|
||||
@@ -363,10 +363,10 @@ void DtoConstInitStruct(StructDeclaration* sd)
|
||||
IrStruct::Offset* so = &i->second;
|
||||
llvm::Constant* finit = DtoConstFieldInitializer(so->var->type, so->var->init);
|
||||
so->init = finit;
|
||||
gIR->irDsymbol[so->var].irField->constInit = finit;
|
||||
so->var->ir.irField->constInit = finit;
|
||||
}
|
||||
|
||||
const llvm::StructType* structtype = isaStruct(gIR->irType[sd->type].type->get());
|
||||
const llvm::StructType* structtype = isaStruct(sd->type->ir.type->get());
|
||||
|
||||
// go through the field inits and build the default initializer
|
||||
std::vector<llvm::Constant*> fieldinits_ll;
|
||||
@@ -374,7 +374,7 @@ void DtoConstInitStruct(StructDeclaration* sd)
|
||||
for (size_t i=0; i<nfi; ++i) {
|
||||
llvm::Constant* c;
|
||||
if (irstruct->defaultFields[i] != NULL) {
|
||||
c = gIR->irDsymbol[irstruct->defaultFields[i]].irField->constInit;
|
||||
c = irstruct->defaultFields[i]->ir.irField->constInit;
|
||||
assert(c);
|
||||
}
|
||||
else {
|
||||
@@ -386,7 +386,7 @@ void DtoConstInitStruct(StructDeclaration* sd)
|
||||
}
|
||||
|
||||
// generate the union mapper
|
||||
gIR->irDsymbol[sd].irStruct->dunion = new DUnion; // uses gIR->topstruct()
|
||||
sd->ir.irStruct->dunion = new DUnion; // uses gIR->topstruct()
|
||||
|
||||
// always generate the constant initalizer
|
||||
if (!sd->zeroInit) {
|
||||
@@ -402,11 +402,11 @@ void DtoConstInitStruct(StructDeclaration* sd)
|
||||
}
|
||||
Logger::cout() << "Initializer printed" << '\n';
|
||||
#endif
|
||||
gIR->irDsymbol[sd].irStruct->constInit = llvm::ConstantStruct::get(structtype,fieldinits_ll);
|
||||
sd->ir.irStruct->constInit = llvm::ConstantStruct::get(structtype,fieldinits_ll);
|
||||
}
|
||||
else {
|
||||
Logger::println("Zero initialized");
|
||||
gIR->irDsymbol[sd].irStruct->constInit = llvm::ConstantAggregateZero::get(structtype);
|
||||
sd->ir.irStruct->constInit = llvm::ConstantAggregateZero::get(structtype);
|
||||
}
|
||||
|
||||
gIR->structs.pop_back();
|
||||
@@ -420,17 +420,17 @@ void DtoConstInitStruct(StructDeclaration* sd)
|
||||
|
||||
void DtoDefineStruct(StructDeclaration* sd)
|
||||
{
|
||||
if (gIR->irDsymbol[sd].defined) return;
|
||||
gIR->irDsymbol[sd].defined = true;
|
||||
if (sd->ir.defined) return;
|
||||
sd->ir.defined = true;
|
||||
|
||||
Logger::println("DtoDefineStruct(%s): %s", sd->toChars(), sd->loc.toChars());
|
||||
LOG_SCOPE;
|
||||
|
||||
assert(sd->type->ty == Tstruct);
|
||||
TypeStruct* ts = (TypeStruct*)sd->type;
|
||||
gIR->irDsymbol[sd].irStruct->init->setInitializer(gIR->irDsymbol[sd].irStruct->constInit);
|
||||
sd->ir.irStruct->init->setInitializer(sd->ir.irStruct->constInit);
|
||||
|
||||
gIR->irDsymbol[sd].DModule = gIR->dmodule;
|
||||
sd->ir.DModule = gIR->dmodule;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Reference in New Issue
Block a user