annotate ir/irclass.cpp @ 1231:212ec2d9d176

Fixed some minitest regressions.
author Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
date Thu, 16 Apr 2009 19:21:30 +0200
parents e67c85d6e680
children ded6a557220a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
1 #include "llvm/Constants.h"
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
2 #include "llvm/DerivedTypes.h"
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
3
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
4 #include "aggregate.h"
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
5 #include "declaration.h"
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
6 #include "mtype.h"
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
7
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
8 #include "gen/irstate.h"
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
9 #include "gen/logger.h"
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
10 #include "gen/tollvm.h"
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
11 #include "gen/llvmhelpers.h"
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
12 #include "gen/utils.h"
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
13 #include "gen/arrays.h"
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
14
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
15 #include "ir/irstruct.h"
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
16 #include "ir/irtypeclass.h"
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
17
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
18 //////////////////////////////////////////////////////////////////////////////
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
19
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
20 extern LLConstant* get_default_initializer(VarDeclaration* vd, Initializer* init);
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
21 extern size_t add_zeros(std::vector<llvm::Constant*>& constants, size_t diff);
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
22
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
23 extern LLConstant* DtoDefineClassInfo(ClassDeclaration* cd);
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
24
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
25 //////////////////////////////////////////////////////////////////////////////
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
26
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
27 LLGlobalVariable * IrStruct::getVtblSymbol()
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
28 {
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
29 if (vtbl)
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
30 return vtbl;
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
31
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
32 // create the initZ symbol
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
33 std::string initname("_D");
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
34 initname.append(aggrdecl->mangle());
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
35 initname.append("6__vtblZ");
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
36
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
37 llvm::GlobalValue::LinkageTypes _linkage = DtoExternalLinkage(aggrdecl);
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
38
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
39 const LLType* vtblTy = type->irtype->isClass()->getVtbl();
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
40
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
41 vtbl = new llvm::GlobalVariable(
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
42 vtblTy, true, _linkage, NULL, initname, gIR->module);
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
43
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
44 return vtbl;
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
45 }
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
46
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
47 //////////////////////////////////////////////////////////////////////////////
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
48
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
49 LLGlobalVariable * IrStruct::getClassInfoSymbol()
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
50 {
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
51 if (classInfo)
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
52 return classInfo;
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
53
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
54 // create the initZ symbol
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
55 std::string initname("_D");
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
56 initname.append(aggrdecl->mangle());
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
57 if (aggrdecl->isInterfaceDeclaration())
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
58 initname.append("11__InterfaceZ");
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
59 else
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
60 initname.append("7__ClassZ");
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
61
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
62 llvm::GlobalValue::LinkageTypes _linkage = DtoExternalLinkage(aggrdecl);
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
63
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
64 ClassDeclaration* cinfo = ClassDeclaration::classinfo;
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
65 DtoType(cinfo->type);
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
66 IrTypeClass* tc = cinfo->type->irtype->isClass();
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
67 assert(tc && "invalid ClassInfo type");
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
68
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
69 classInfo = new llvm::GlobalVariable(
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
70 tc->getPA().get(), true, _linkage, NULL, initname, gIR->module);
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
71
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
72 return classInfo;
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
73 }
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
74
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
75 //////////////////////////////////////////////////////////////////////////////
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
76
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
77 LLGlobalVariable * IrStruct::getInterfaceArraySymbol()
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
78 {
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
79 if (classInterfacesArray)
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
80 return classInterfacesArray;
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
81
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
82 ClassDeclaration* cd = aggrdecl->isClassDeclaration();
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
83
1231
212ec2d9d176 Fixed some minitest regressions.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1230
diff changeset
84 // FIXME:
212ec2d9d176 Fixed some minitest regressions.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1230
diff changeset
85 // also happens for mini/s.d :(
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
86 assert(cd->vtblInterfaces && cd->vtblInterfaces->dim > 0 &&
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
87 "should not create interface info array for class with no explicit "
1229
fafe7c8d6734 Now compiles again, and fixed type of the Interface[N] ClassInfo symbol.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1228
diff changeset
88 "interface implementations");
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
89
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
90 VarDeclarationIter idx(ClassDeclaration::classinfo->fields, 3);
1229
fafe7c8d6734 Now compiles again, and fixed type of the Interface[N] ClassInfo symbol.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1228
diff changeset
91 const llvm::Type* InterfaceTy = DtoType(idx->type->next);
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
92
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
93 // create Interface[N]
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
94 const llvm::ArrayType* array_type = llvm::ArrayType::get(
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
95 InterfaceTy,
1230
e67c85d6e680 Completed interface implementation. Hopefully that's it for now..
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1229
diff changeset
96 type->irtype->isClass()->getNumInterfaceVtbls());
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
97
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
98 // put it in a global
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
99 std::string name("_D");
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
100 name.append(cd->mangle());
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
101 name.append("16__interfaceInfosZ");
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
102 classInterfacesArray = new llvm::GlobalVariable(array_type, true, DtoLinkage(cd), NULL, name, classInfo);
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
103
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
104 return classInterfacesArray;
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
105 }
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
106
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
107 //////////////////////////////////////////////////////////////////////////////
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
108
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
109 LLConstant * IrStruct::getVtblInit()
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
110 {
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
111 if (constVtbl)
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
112 return constVtbl;
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
113
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
114 IF_LOG Logger::println("Building vtbl initializer");
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
115 LOG_SCOPE;
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
116
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
117 ClassDeclaration* cd = aggrdecl->isClassDeclaration();
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
118 assert(cd && "not class");
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
119
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
120 std::vector<llvm::Constant*> constants;
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
121 constants.reserve(cd->vtbl.dim);
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
122
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
123 // start with the classinfo
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
124 llvm::Constant* c = getClassInfoSymbol();
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
125 c = DtoBitCast(c, DtoType(ClassDeclaration::classinfo->type));
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
126 constants.push_back(c);
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
127
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
128 // add virtual function pointers
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
129 size_t n = cd->vtbl.dim;
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
130 for (size_t i = 1; i < n; i++)
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
131 {
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
132 Dsymbol* dsym = (Dsymbol*)cd->vtbl.data[i];
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
133 assert(dsym && "null vtbl member");
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
134
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
135 FuncDeclaration* fd = dsym->isFuncDeclaration();
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
136 assert(fd && "vtbl entry not a function");
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
137
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
138 if (fd->isAbstract() && !fd->fbody)
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
139 {
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
140 c = getNullValue(DtoType(fd->type->pointerTo()));
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
141 }
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
142 else
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
143 {
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
144 fd->codegen(Type::sir);
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
145 assert(fd->ir.irFunc && "invalid vtbl function");
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
146 c = fd->ir.irFunc->func;
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
147 }
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
148 constants.push_back(c);
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
149 }
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
150
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
151 // build the constant struct
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
152 constVtbl = llvm::ConstantStruct::get(constants, false);
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
153
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
154 // sanity check
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
155 #if 0
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
156 IF_LOG Logger::cout() << "constVtbl type: " << *constVtbl->getType() << std::endl;
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
157 IF_LOG Logger::cout() << "vtbl type: " << *type->irtype->isClass()->getVtbl() << std::endl;
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
158 #endif
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
159
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
160 assert(constVtbl->getType() == type->irtype->isClass()->getVtbl() &&
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
161 "vtbl initializer type mismatch");
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
162
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
163 return constVtbl;
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
164 }
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
165
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
166 //////////////////////////////////////////////////////////////////////////////
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
167
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
168 LLConstant * IrStruct::getClassInfoInit()
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
169 {
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
170 if (constClassInfo)
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
171 return constClassInfo;
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
172 constClassInfo = DtoDefineClassInfo(aggrdecl->isClassDeclaration());
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
173 return constClassInfo;
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
174 }
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
175
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
176 //////////////////////////////////////////////////////////////////////////////
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
177
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
178 void IrStruct::addBaseClassInits(
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
179 std::vector<llvm::Constant*>& constants,
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
180 ClassDeclaration* base,
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
181 size_t& offset,
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
182 size_t& field_index)
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
183 {
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
184 if (base->baseClass)
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
185 {
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
186 addBaseClassInits(constants, base->baseClass, offset, field_index);
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
187 }
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
188
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
189 ArrayIter<VarDeclaration> it(base->fields);
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
190 for (; !it.done(); it.next())
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
191 {
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
192 VarDeclaration* vd = it.get();
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
193
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
194 // skip if offset moved backwards
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
195 if (vd->offset < offset)
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
196 {
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
197 IF_LOG Logger::println("Skipping field %s %s (+%u) for default", vd->type->toChars(), vd->toChars(), vd->offset);
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
198 continue;
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
199 }
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
200
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
201 IF_LOG Logger::println("Adding default field %s %s (+%u)", vd->type->toChars(), vd->toChars(), vd->offset);
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
202 LOG_SCOPE;
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
203
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
204 // get next aligned offset for this type
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
205 size_t alignsize = vd->type->alignsize();
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
206 size_t alignedoffset = (offset + alignsize - 1) & ~(alignsize - 1);
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
207
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
208 // insert explicit padding?
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
209 if (alignedoffset < vd->offset)
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
210 {
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
211 add_zeros(constants, vd->offset - alignedoffset);
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
212 }
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
213
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
214 // add default type
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
215 constants.push_back(get_default_initializer(vd, vd->init));
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
216
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
217 // advance offset to right past this field
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
218 offset = vd->offset + vd->type->size();
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
219 }
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
220
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
221 // has interface vtbls?
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
222 if (base->vtblInterfaces)
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
223 {
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
224 // false when it's not okay to use functions from super classes
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
225 bool newinsts = (base == aggrdecl->isClassDeclaration());
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
226
1230
e67c85d6e680 Completed interface implementation. Hopefully that's it for now..
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1229
diff changeset
227 size_t inter_idx = interfacesWithVtbls.size();
e67c85d6e680 Completed interface implementation. Hopefully that's it for now..
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1229
diff changeset
228
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
229 ArrayIter<BaseClass> it2(*base->vtblInterfaces);
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
230 for (; !it2.done(); it2.next())
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
231 {
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
232 BaseClass* b = it2.get();
1230
e67c85d6e680 Completed interface implementation. Hopefully that's it for now..
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1229
diff changeset
233 constants.push_back(getInterfaceVtbl(b, newinsts, inter_idx));
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
234 offset += PTRSIZE;
1230
e67c85d6e680 Completed interface implementation. Hopefully that's it for now..
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1229
diff changeset
235
e67c85d6e680 Completed interface implementation. Hopefully that's it for now..
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1229
diff changeset
236 // add to the interface list
e67c85d6e680 Completed interface implementation. Hopefully that's it for now..
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1229
diff changeset
237 interfacesWithVtbls.push_back(b);
e67c85d6e680 Completed interface implementation. Hopefully that's it for now..
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1229
diff changeset
238 inter_idx++;
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
239 }
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
240 }
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
241
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
242 // tail padding?
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
243 if (offset < base->structsize)
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
244 {
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
245 add_zeros(constants, base->structsize - offset);
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
246 offset = base->structsize;
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
247 }
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
248 }
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
249
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
250 //////////////////////////////////////////////////////////////////////////////
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
251
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
252 LLConstant * IrStruct::createClassDefaultInitializer()
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
253 {
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
254 ClassDeclaration* cd = aggrdecl->isClassDeclaration();
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
255 assert(cd && "invalid class aggregate");
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
256
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
257 IF_LOG Logger::println("Building class default initializer %s @ %s", cd->toPrettyChars(), cd->locToChars());
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
258 LOG_SCOPE;
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
259 IF_LOG Logger::println("Instance size: %u", cd->structsize);
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
260
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
261 // find the fields that contribute to the default initializer.
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
262 // these will define the default type.
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
263
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
264 std::vector<llvm::Constant*> constants;
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
265 constants.reserve(32);
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
266
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
267 // add vtbl
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
268 constants.push_back(getVtblSymbol());
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
269 // add monitor
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
270 constants.push_back(getNullValue(DtoType(Type::tvoid->pointerTo())));
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
271
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
272 // we start right after the vtbl and monitor
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
273 size_t offset = PTRSIZE * 2;
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
274 size_t field_index = 2;
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
275
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
276 // add data members recursively
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
277 addBaseClassInits(constants, cd, offset, field_index);
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
278
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
279 // build the constant
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
280 llvm::Constant* definit = llvm::ConstantStruct::get(constants, false);
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
281
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
282 // sanity check
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
283 assert(definit->getType() == type->irtype->getPA().get() && "class initializer type mismatch");
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
284
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
285 return definit;
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
286 }
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
287
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
288 //////////////////////////////////////////////////////////////////////////////
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
289
1230
e67c85d6e680 Completed interface implementation. Hopefully that's it for now..
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1229
diff changeset
290 llvm::GlobalVariable * IrStruct::getInterfaceVtbl(BaseClass * b, bool new_instance, size_t interfaces_index)
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
291 {
1230
e67c85d6e680 Completed interface implementation. Hopefully that's it for now..
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1229
diff changeset
292 ClassGlobalMap::iterator it = interfaceVtblMap.find(b->base);
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
293 if (it != interfaceVtblMap.end())
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
294 return it->second;
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
295
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
296 IF_LOG Logger::println("Building vtbl for implementation of interface %s in class %s",
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
297 b->base->toPrettyChars(), aggrdecl->toPrettyChars());
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
298 LOG_SCOPE;
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
299
1230
e67c85d6e680 Completed interface implementation. Hopefully that's it for now..
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1229
diff changeset
300 ClassDeclaration* cd = aggrdecl->isClassDeclaration();
e67c85d6e680 Completed interface implementation. Hopefully that's it for now..
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1229
diff changeset
301 assert(cd && "not a class aggregate");
e67c85d6e680 Completed interface implementation. Hopefully that's it for now..
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1229
diff changeset
302
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
303 Array vtbl_array;
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
304 b->fillVtbl(cd, &vtbl_array, new_instance);
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
305
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
306 std::vector<llvm::Constant*> constants;
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
307 constants.reserve(vtbl_array.dim);
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
308
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
309 // start with the interface info
1230
e67c85d6e680 Completed interface implementation. Hopefully that's it for now..
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1229
diff changeset
310 VarDeclarationIter interfaces_idx(ClassDeclaration::classinfo->fields, 3);
e67c85d6e680 Completed interface implementation. Hopefully that's it for now..
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1229
diff changeset
311 Type* first = interfaces_idx->type->next->pointerTo();
e67c85d6e680 Completed interface implementation. Hopefully that's it for now..
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1229
diff changeset
312
e67c85d6e680 Completed interface implementation. Hopefully that's it for now..
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1229
diff changeset
313 // index into the interfaces array
e67c85d6e680 Completed interface implementation. Hopefully that's it for now..
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1229
diff changeset
314 llvm::Constant* idxs[2] = {
e67c85d6e680 Completed interface implementation. Hopefully that's it for now..
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1229
diff changeset
315 DtoConstSize_t(0),
e67c85d6e680 Completed interface implementation. Hopefully that's it for now..
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1229
diff changeset
316 DtoConstSize_t(interfaces_index)
e67c85d6e680 Completed interface implementation. Hopefully that's it for now..
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1229
diff changeset
317 };
e67c85d6e680 Completed interface implementation. Hopefully that's it for now..
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1229
diff changeset
318
e67c85d6e680 Completed interface implementation. Hopefully that's it for now..
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1229
diff changeset
319 llvm::Constant* c = llvm::ConstantExpr::getGetElementPtr(
e67c85d6e680 Completed interface implementation. Hopefully that's it for now..
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1229
diff changeset
320 getInterfaceArraySymbol(), idxs, 2);
e67c85d6e680 Completed interface implementation. Hopefully that's it for now..
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1229
diff changeset
321
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
322 constants.push_back(c);
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
323
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
324 // add virtual function pointers
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
325 size_t n = vtbl_array.dim;
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
326 for (size_t i = 1; i < n; i++)
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
327 {
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
328 Dsymbol* dsym = (Dsymbol*)vtbl_array.data[i];
1231
212ec2d9d176 Fixed some minitest regressions.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1230
diff changeset
329 if (dsym == NULL)
212ec2d9d176 Fixed some minitest regressions.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1230
diff changeset
330 {
212ec2d9d176 Fixed some minitest regressions.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1230
diff changeset
331 // FIXME
212ec2d9d176 Fixed some minitest regressions.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1230
diff changeset
332 // why is this null?
212ec2d9d176 Fixed some minitest regressions.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1230
diff changeset
333 // happens for mini/s.d
212ec2d9d176 Fixed some minitest regressions.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1230
diff changeset
334 constants.push_back(getNullValue(getVoidPtrType()));
212ec2d9d176 Fixed some minitest regressions.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1230
diff changeset
335 continue;
212ec2d9d176 Fixed some minitest regressions.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1230
diff changeset
336 }
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
337
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
338 FuncDeclaration* fd = dsym->isFuncDeclaration();
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
339 assert(fd && "vtbl entry not a function");
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
340
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
341 assert(!(fd->isAbstract() && !fd->fbody) &&
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
342 "null symbol in interface implementation vtable");
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
343
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
344 fd->codegen(Type::sir);
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
345 assert(fd->ir.irFunc && "invalid vtbl function");
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
346
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
347 constants.push_back(fd->ir.irFunc->func);
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
348 }
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
349
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
350 // build the vtbl constant
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
351 llvm::Constant* vtbl_constant = llvm::ConstantStruct::get(constants, false);
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
352
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
353 // create the global variable to hold it
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
354 llvm::GlobalValue::LinkageTypes _linkage = DtoExternalLinkage(aggrdecl);
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
355
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
356 std::string mangle("_D");
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
357 mangle.append(cd->mangle());
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
358 mangle.append("11__interface");
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
359 mangle.append(b->base->mangle());
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
360 mangle.append("6__vtblZ");
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
361
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
362 llvm::GlobalVariable* GV = new llvm::GlobalVariable(
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
363 vtbl_constant->getType(),
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
364 true,
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
365 _linkage,
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
366 vtbl_constant,
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
367 mangle,
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
368 gIR->module
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
369 );
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
370
1230
e67c85d6e680 Completed interface implementation. Hopefully that's it for now..
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1229
diff changeset
371 // insert into the vtbl map
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
372 interfaceVtblMap.insert(std::make_pair(b->base, GV));
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
373
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
374 return GV;
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
375 }
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
376
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
377 //////////////////////////////////////////////////////////////////////////////
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
378
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
379 LLConstant * IrStruct::getClassInfoInterfaces()
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
380 {
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
381 IF_LOG Logger::println("Building ClassInfo.interfaces");
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
382 LOG_SCOPE;
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
383
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
384 ClassDeclaration* cd = aggrdecl->isClassDeclaration();
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
385 assert(cd);
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
386
1230
e67c85d6e680 Completed interface implementation. Hopefully that's it for now..
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1229
diff changeset
387 size_t n = interfacesWithVtbls.size();
e67c85d6e680 Completed interface implementation. Hopefully that's it for now..
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1229
diff changeset
388 assert(type->irtype->isClass()->getNumInterfaceVtbls() == n &&
e67c85d6e680 Completed interface implementation. Hopefully that's it for now..
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1229
diff changeset
389 "inconsistent number of interface vtables in this class");
e67c85d6e680 Completed interface implementation. Hopefully that's it for now..
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1229
diff changeset
390
e67c85d6e680 Completed interface implementation. Hopefully that's it for now..
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1229
diff changeset
391 if (n == 0)
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
392 {
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
393 VarDeclarationIter idx(ClassDeclaration::classinfo->fields, 3);
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
394 return getNullValue(DtoType(idx->type));
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
395 }
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
396
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
397 // Build array of:
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
398 //
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
399 // struct Interface
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
400 // {
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
401 // ClassInfo classinfo;
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
402 // void*[] vtbl;
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
403 // ptrdiff_t offset;
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
404 // }
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
405
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
406 LLSmallVector<LLConstant*, 6> constants;
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
407 constants.reserve(cd->vtblInterfaces->dim);
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
408
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
409 const LLType* classinfo_type = DtoType(ClassDeclaration::classinfo->type);
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
410 const LLType* voidptrptr_type = DtoType(
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
411 Type::tvoid->pointerTo()->pointerTo());
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
412
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
413 const LLType* our_type = type->irtype->isClass()->getPA().get();
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
414
1230
e67c85d6e680 Completed interface implementation. Hopefully that's it for now..
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1229
diff changeset
415 for (size_t i = 0; i < n; ++i)
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
416 {
1230
e67c85d6e680 Completed interface implementation. Hopefully that's it for now..
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1229
diff changeset
417 BaseClass* it = interfacesWithVtbls[i];
e67c85d6e680 Completed interface implementation. Hopefully that's it for now..
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1229
diff changeset
418
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
419 IF_LOG Logger::println("Adding interface %s", it->base->toPrettyChars());
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
420
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
421 IrStruct* irinter = it->base->ir.irStruct;
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
422 assert(irinter && "interface has null IrStruct");
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
423 IrTypeClass* itc = irinter->type->irtype->isClass();
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
424 assert(itc && "null interface IrTypeClass");
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
425
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
426 // classinfo
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
427 LLConstant* ci = irinter->getClassInfoSymbol();
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
428 ci = DtoBitCast(ci, classinfo_type);
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
429
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
430 // vtbl
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
431 ClassGlobalMap::iterator itv = interfaceVtblMap.find(it->base);
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
432 assert(itv != interfaceVtblMap.end() && "interface vtbl not found");
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
433 LLConstant* vtb = itv->second;
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
434 vtb = DtoBitCast(vtb, voidptrptr_type);
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
435 vtb = DtoConstSlice(DtoConstSize_t(itc->getVtblSize()), vtb);
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
436
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
437 // offset
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
438 LLConstant* off = DtoConstSize_t(it->offset);
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
439
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
440 // create Interface struct
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
441 LLConstant* inits[3] = { ci, vtb, off };
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
442 LLConstant* entry = llvm::ConstantStruct::get(inits, 3);
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
443 constants.push_back(entry);
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
444 }
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
445
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
446 // create Interface[N]
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
447 const llvm::ArrayType* array_type = llvm::ArrayType::get(
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
448 constants[0]->getType(),
1230
e67c85d6e680 Completed interface implementation. Hopefully that's it for now..
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1229
diff changeset
449 n);
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
450
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
451 LLConstant* arr = llvm::ConstantArray::get(
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
452 array_type,
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
453 &constants[0],
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
454 constants.size());
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
455
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
456 // apply the initializer
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
457 classInterfacesArray->setInitializer(arr);
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
458
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
459 LLConstant* idxs[2] = {
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
460 DtoConstSize_t(0),
1230
e67c85d6e680 Completed interface implementation. Hopefully that's it for now..
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1229
diff changeset
461 // only the interface explicitly implemented by this class
e67c85d6e680 Completed interface implementation. Hopefully that's it for now..
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1229
diff changeset
462 // (not super classes) should show in ClassInfo
e67c85d6e680 Completed interface implementation. Hopefully that's it for now..
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1229
diff changeset
463 DtoConstSize_t(n - cd->vtblInterfaces->dim)
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
464 };
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
465
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
466 // return as a slice
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
467 return DtoConstSlice(
1230
e67c85d6e680 Completed interface implementation. Hopefully that's it for now..
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1229
diff changeset
468 DtoConstSize_t(n),
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
469 llvm::ConstantExpr::getGetElementPtr(classInterfacesArray, idxs, 2));
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
470 }
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
471
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
472 //////////////////////////////////////////////////////////////////////////////