changeset 816:7d16ce7ad19d

Made ClassInfo.interfaces generation consistent with DMD, fixes #134 Removed unneeded includes from dmd/attrib.c
author Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
date Mon, 01 Dec 2008 18:34:02 +0100
parents 35de5ba7d36d
children f5d5bc9295b1
files dmd/attrib.c dmd2/attrib.c gen/classes.cpp ir/irstruct.h
diffstat 4 files changed, 17 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/dmd/attrib.c	Mon Dec 01 15:21:33 2008 +0100
+++ b/dmd/attrib.c	Mon Dec 01 18:34:02 2008 +0100
@@ -32,7 +32,6 @@
 #include "template.h"
 
 #include "../gen/enums.h"
-#include "../gen/logger.h"
 
 extern void obj_includelib(const char *name);
 void obj_startaddress(Symbol *s);
--- a/dmd2/attrib.c	Mon Dec 01 15:21:33 2008 +0100
+++ b/dmd2/attrib.c	Mon Dec 01 18:34:02 2008 +0100
@@ -32,7 +32,6 @@
 #include "template.h"
 
 #include "../gen/enums.h"
-#include "../gen/logger.h"
 
 extern void obj_includelib(const char *name);
 void obj_startaddress(Symbol *s);
--- a/gen/classes.cpp	Mon Dec 01 15:21:33 2008 +0100
+++ b/gen/classes.cpp	Mon Dec 01 18:34:02 2008 +0100
@@ -51,9 +51,14 @@
         irstruct->interfaceMap[b->base] = iri;
     else
         irstruct->interfaceMap.insert(std::make_pair(b->base, iri));
+
     // add to ordered list
     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
     for (unsigned j = 0; j < b->baseInterfaces_dim; j++)
     {
@@ -148,6 +153,7 @@
             // add to interfaceInfos
             IrInterface* iri = new IrInterface(bc);
             irstruct->interfaceVec.push_back(iri);
+            irstruct->classInfoInterfaces.push_back(iri);
         }
     }
 
@@ -378,7 +384,6 @@
 
     // interface vtables
     unsigned idx = 0;
-
     for (IrStruct::InterfaceVectorIter i=irstruct->interfaceVec.begin(); i!=irstruct->interfaceVec.end(); ++i)
     {
         IrInterface* iri = *i;
@@ -392,7 +397,7 @@
 
         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)};
         iri->info = llvm::ConstantExpr::getGetElementPtr(irstruct->interfaceInfos, idxs, 2);
         idx++;
@@ -1506,8 +1511,15 @@
         c = LLConstant::getNullValue(intersTy);
     else {
         const LLType* t = intersTy->getContainedType(1); // .ptr
+        // cast to Interface*
         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);
     }
     inits.push_back(c);
--- a/ir/irstruct.h	Mon Dec 01 15:21:33 2008 +0100
+++ b/ir/irstruct.h	Mon Dec 01 18:34:02 2008 +0100
@@ -142,6 +142,8 @@
     LLConstant* constClassInfo;
     bool classInfoDeclared;
     bool classInfoDefined;
+    // vector of interfaces that should be put in ClassInfo.interfaces
+    InterfaceVector classInfoInterfaces;
 
     // align(1) struct S { ... }
     bool packed;