mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-01 15:40:55 +03:00
Made ClassInfo.interfaces generation consistent with DMD, fixes #134
Removed unneeded includes from dmd/attrib.c
This commit is contained in:
parent
649b860d2b
commit
2788a2a0f1
4 changed files with 17 additions and 5 deletions
|
@ -32,7 +32,6 @@
|
||||||
#include "template.h"
|
#include "template.h"
|
||||||
|
|
||||||
#include "../gen/enums.h"
|
#include "../gen/enums.h"
|
||||||
#include "../gen/logger.h"
|
|
||||||
|
|
||||||
extern void obj_includelib(const char *name);
|
extern void obj_includelib(const char *name);
|
||||||
void obj_startaddress(Symbol *s);
|
void obj_startaddress(Symbol *s);
|
||||||
|
|
|
@ -32,7 +32,6 @@
|
||||||
#include "template.h"
|
#include "template.h"
|
||||||
|
|
||||||
#include "../gen/enums.h"
|
#include "../gen/enums.h"
|
||||||
#include "../gen/logger.h"
|
|
||||||
|
|
||||||
extern void obj_includelib(const char *name);
|
extern void obj_includelib(const char *name);
|
||||||
void obj_startaddress(Symbol *s);
|
void obj_startaddress(Symbol *s);
|
||||||
|
|
|
@ -51,9 +51,14 @@ static void add_interface(ClassDeclaration* target, BaseClass* b, int newinstanc
|
||||||
irstruct->interfaceMap[b->base] = iri;
|
irstruct->interfaceMap[b->base] = iri;
|
||||||
else
|
else
|
||||||
irstruct->interfaceMap.insert(std::make_pair(b->base, iri));
|
irstruct->interfaceMap.insert(std::make_pair(b->base, iri));
|
||||||
|
|
||||||
// add to ordered list
|
// add to ordered list
|
||||||
irstruct->interfaceVec.push_back(iri);
|
irstruct->interfaceVec.push_back(iri);
|
||||||
|
|
||||||
|
// add to classinfo interfaces
|
||||||
|
if (newinstance)
|
||||||
|
irstruct->classInfoInterfaces.push_back(iri);
|
||||||
|
|
||||||
// assign this iri to all base interfaces of this one
|
// assign this iri to all base interfaces of this one
|
||||||
for (unsigned j = 0; j < b->baseInterfaces_dim; j++)
|
for (unsigned j = 0; j < b->baseInterfaces_dim; j++)
|
||||||
{
|
{
|
||||||
|
@ -148,6 +153,7 @@ static void DtoResolveInterface(InterfaceDeclaration* cd)
|
||||||
// add to interfaceInfos
|
// add to interfaceInfos
|
||||||
IrInterface* iri = new IrInterface(bc);
|
IrInterface* iri = new IrInterface(bc);
|
||||||
irstruct->interfaceVec.push_back(iri);
|
irstruct->interfaceVec.push_back(iri);
|
||||||
|
irstruct->classInfoInterfaces.push_back(iri);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -378,7 +384,6 @@ void DtoDeclareClass(ClassDeclaration* cd)
|
||||||
|
|
||||||
// interface vtables
|
// interface vtables
|
||||||
unsigned idx = 0;
|
unsigned idx = 0;
|
||||||
|
|
||||||
for (IrStruct::InterfaceVectorIter i=irstruct->interfaceVec.begin(); i!=irstruct->interfaceVec.end(); ++i)
|
for (IrStruct::InterfaceVectorIter i=irstruct->interfaceVec.begin(); i!=irstruct->interfaceVec.end(); ++i)
|
||||||
{
|
{
|
||||||
IrInterface* iri = *i;
|
IrInterface* iri = *i;
|
||||||
|
@ -392,7 +397,7 @@ void DtoDeclareClass(ClassDeclaration* cd)
|
||||||
|
|
||||||
iri->vtbl = new llvm::GlobalVariable(iri->vtblInitTy.get(), true, _linkage, 0, nam, gIR->module);
|
iri->vtbl = new llvm::GlobalVariable(iri->vtblInitTy.get(), true, _linkage, 0, nam, gIR->module);
|
||||||
|
|
||||||
// always create interfaceinfos
|
// always set the interface info as it's need as the first vtbl entry
|
||||||
LLConstant* idxs[2] = {DtoConstUint(0), DtoConstUint(idx)};
|
LLConstant* idxs[2] = {DtoConstUint(0), DtoConstUint(idx)};
|
||||||
iri->info = llvm::ConstantExpr::getGetElementPtr(irstruct->interfaceInfos, idxs, 2);
|
iri->info = llvm::ConstantExpr::getGetElementPtr(irstruct->interfaceInfos, idxs, 2);
|
||||||
idx++;
|
idx++;
|
||||||
|
@ -1506,8 +1511,15 @@ void DtoDefineClassInfo(ClassDeclaration* cd)
|
||||||
c = LLConstant::getNullValue(intersTy);
|
c = LLConstant::getNullValue(intersTy);
|
||||||
else {
|
else {
|
||||||
const LLType* t = intersTy->getContainedType(1); // .ptr
|
const LLType* t = intersTy->getContainedType(1); // .ptr
|
||||||
|
// cast to Interface*
|
||||||
c = DtoBitCast(ir->interfaceInfos, t);
|
c = DtoBitCast(ir->interfaceInfos, t);
|
||||||
size_t iisz = ir->interfaceVec.size();
|
size_t isz = ir->interfaceVec.size();
|
||||||
|
size_t iisz = ir->classInfoInterfaces.size();
|
||||||
|
assert(iisz <= isz);
|
||||||
|
// offset - we only want the 'iisz' last ones
|
||||||
|
LLConstant* idx = DtoConstUint(isz - iisz);
|
||||||
|
c = llvm::ConstantExpr::getGetElementPtr(c, &idx, 1);
|
||||||
|
// make array
|
||||||
c = DtoConstSlice(DtoConstSize_t(iisz), c);
|
c = DtoConstSlice(DtoConstSize_t(iisz), c);
|
||||||
}
|
}
|
||||||
inits.push_back(c);
|
inits.push_back(c);
|
||||||
|
|
|
@ -142,6 +142,8 @@ struct IrStruct : IrBase
|
||||||
LLConstant* constClassInfo;
|
LLConstant* constClassInfo;
|
||||||
bool classInfoDeclared;
|
bool classInfoDeclared;
|
||||||
bool classInfoDefined;
|
bool classInfoDefined;
|
||||||
|
// vector of interfaces that should be put in ClassInfo.interfaces
|
||||||
|
InterfaceVector classInfoInterfaces;
|
||||||
|
|
||||||
// align(1) struct S { ... }
|
// align(1) struct S { ... }
|
||||||
bool packed;
|
bool packed;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue