Mercurial > projects > ldc
annotate gen/classes.cpp @ 102:027b8d8b71ec trunk
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
Basically it tries to do the following in order: Resolve types, Declare symbols, Create constant initializers, Apply initializers, Generate functions bodies.
ClassInfo is now has the most useful(biased?) members working.
Probably other stuf...
author | lindquist |
---|---|
date | Sun, 18 Nov 2007 06:52:57 +0100 |
parents | 5071469303d4 |
children | 855adfdb8d38 |
rev | line source |
---|---|
100 | 1 #include "gen/llvm.h" |
2 | |
3 #include "mtype.h" | |
4 #include "aggregate.h" | |
5 #include "init.h" | |
6 #include "declaration.h" | |
7 | |
8 #include "gen/irstate.h" | |
9 #include "gen/tollvm.h" | |
10 #include "gen/arrays.h" | |
11 #include "gen/logger.h" | |
12 #include "gen/classes.h" | |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
13 #include "gen/functions.h" |
100 | 14 |
15 ////////////////////////////////////////////////////////////////////////////////////////// | |
16 | |
17 static void LLVM_AddBaseClassData(BaseClasses* bcs) | |
18 { | |
19 // add base class data members first | |
20 for (int j=0; j<bcs->dim; j++) | |
21 { | |
22 BaseClass* bc = (BaseClass*)(bcs->data[j]); | |
23 assert(bc); | |
24 Logger::println("Adding base class members of %s", bc->base->toChars()); | |
25 LOG_SCOPE; | |
26 | |
27 LLVM_AddBaseClassData(&bc->base->baseclasses); | |
28 for (int k=0; k < bc->base->members->dim; k++) { | |
29 Dsymbol* dsym = (Dsymbol*)(bc->base->members->data[k]); | |
30 if (dsym->isVarDeclaration()) | |
31 { | |
32 dsym->toObjFile(); | |
33 } | |
34 } | |
35 } | |
36 } | |
37 | |
38 ////////////////////////////////////////////////////////////////////////////////////////// | |
39 | |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
40 void DtoResolveClass(ClassDeclaration* cd) |
100 | 41 { |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
42 if (cd->llvmResolved) return; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
43 cd->llvmResolved = true; |
100 | 44 |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
45 // first resolve the base class |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
46 if (cd->baseClass) { |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
47 DtoResolveClass(cd->baseClass); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
48 } |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
49 |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
50 Logger::println("DtoResolveClass(%s)", cd->toPrettyChars()); |
100 | 51 LOG_SCOPE; |
52 | |
53 assert(cd->type->ty == Tclass); | |
54 TypeClass* ts = (TypeClass*)cd->type; | |
55 | |
56 assert(!cd->llvmIRStruct); | |
57 IRStruct* irstruct = new IRStruct(ts); | |
58 cd->llvmIRStruct = irstruct; | |
59 | |
60 gIR->structs.push_back(irstruct); | |
61 gIR->classes.push_back(cd); | |
62 | |
63 // add vtable | |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
64 ts->llvmVtblType = new llvm::PATypeHolder(llvm::OpaqueType::get()); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
65 const llvm::Type* vtabty = llvm::PointerType::get(ts->llvmVtblType->get()); |
100 | 66 |
67 std::vector<const llvm::Type*> fieldtypes; | |
68 fieldtypes.push_back(vtabty); | |
69 | |
70 // base classes first | |
71 LLVM_AddBaseClassData(&cd->baseclasses); | |
72 | |
73 // then add own members | |
74 for (int k=0; k < cd->members->dim; k++) { | |
75 Dsymbol* dsym = (Dsymbol*)(cd->members->data[k]); | |
76 dsym->toObjFile(); | |
77 } | |
78 | |
79 // add field types | |
80 for (IRStruct::OffsetMap::iterator i=irstruct->offsets.begin(); i!=irstruct->offsets.end(); ++i) { | |
81 fieldtypes.push_back(i->second.type); | |
82 } | |
83 | |
84 const llvm::StructType* structtype = llvm::StructType::get(fieldtypes); | |
85 // refine abstract types for stuff like: class C {C next;} | |
86 assert(irstruct->recty != 0); | |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
87 |
100 | 88 llvm::PATypeHolder& spa = irstruct->recty; |
89 llvm::cast<llvm::OpaqueType>(spa.get())->refineAbstractTypeTo(structtype); | |
90 structtype = isaStruct(spa.get()); | |
91 | |
92 ts->llvmType = new llvm::PATypeHolder(structtype); | |
93 | |
94 bool needs_definition = false; | |
95 if (cd->parent->isModule()) { | |
96 gIR->module->addTypeName(cd->mangle(), ts->llvmType->get()); | |
97 needs_definition = (cd->getModule() == gIR->dmodule); | |
98 } | |
99 else { | |
100 assert(0 && "class parent is not a module"); | |
101 } | |
102 | |
103 // generate vtable | |
104 llvm::GlobalVariable* svtblVar = 0; | |
105 std::vector<const llvm::Type*> sinits_ty; | |
106 | |
107 for (int k=0; k < cd->vtbl.dim; k++) | |
108 { | |
109 Dsymbol* dsym = (Dsymbol*)cd->vtbl.data[k]; | |
110 assert(dsym); | |
111 //Logger::cout() << "vtblsym: " << dsym->toChars() << '\n'; | |
112 | |
113 if (FuncDeclaration* fd = dsym->isFuncDeclaration()) { | |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
114 DtoResolveFunction(fd); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
115 assert(fd->type->ty == Tfunction); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
116 TypeFunction* tf = (TypeFunction*)fd->type; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
117 const llvm::Type* fpty = llvm::PointerType::get(tf->llvmType->get()); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
118 sinits_ty.push_back(fpty); |
100 | 119 } |
120 else if (ClassDeclaration* cd = dsym->isClassDeclaration()) { | |
121 const llvm::Type* cty = llvm::PointerType::get(llvm::Type::Int8Ty); | |
122 sinits_ty.push_back(cty); | |
123 } | |
124 else | |
125 assert(0); | |
126 } | |
127 | |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
128 assert(!sinits_ty.empty()); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
129 const llvm::StructType* svtbl_ty = llvm::StructType::get(sinits_ty); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
130 |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
131 std::string styname(cd->mangle()); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
132 styname.append("__vtblType"); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
133 gIR->module->addTypeName(styname, svtbl_ty); |
100 | 134 |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
135 // refine for final vtable type |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
136 llvm::cast<llvm::OpaqueType>(ts->llvmVtblType->get())->refineAbstractTypeTo(svtbl_ty); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
137 |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
138 gIR->classes.pop_back(); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
139 gIR->structs.pop_back(); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
140 |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
141 gIR->declareList.push_back(cd); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
142 } |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
143 |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
144 ////////////////////////////////////////////////////////////////////////////////////////// |
100 | 145 |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
146 void DtoDeclareClass(ClassDeclaration* cd) |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
147 { |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
148 if (cd->llvmDeclared) return; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
149 cd->llvmDeclared = true; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
150 |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
151 Logger::println("DtoDeclareClass(%s)", cd->toPrettyChars()); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
152 LOG_SCOPE; |
100 | 153 |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
154 assert(cd->type->ty == Tclass); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
155 TypeClass* ts = (TypeClass*)cd->type; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
156 |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
157 assert(cd->llvmIRStruct); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
158 IRStruct* irstruct = cd->llvmIRStruct; |
100 | 159 |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
160 gIR->structs.push_back(irstruct); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
161 gIR->classes.push_back(cd); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
162 |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
163 bool needs_definition = false; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
164 if (cd->parent->isModule()) { |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
165 needs_definition = (cd->getModule() == gIR->dmodule); |
100 | 166 } |
167 | |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
168 // vtable |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
169 std::string varname("_D"); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
170 varname.append(cd->mangle()); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
171 varname.append("6__vtblZ"); |
100 | 172 |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
173 std::string styname(cd->mangle()); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
174 styname.append("__vtblTy"); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
175 |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
176 llvm::GlobalValue::LinkageTypes _linkage = llvm::GlobalValue::ExternalLinkage; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
177 |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
178 const llvm::StructType* svtbl_ty = isaStruct(ts->llvmVtblType->get()); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
179 cd->llvmVtbl = new llvm::GlobalVariable(svtbl_ty, true, _linkage, 0, varname, gIR->module); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
180 |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
181 // init |
100 | 182 std::string initname("_D"); |
183 initname.append(cd->mangle()); | |
184 initname.append("6__initZ"); | |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
185 |
100 | 186 llvm::GlobalVariable* initvar = new llvm::GlobalVariable(ts->llvmType->get(), true, _linkage, NULL, initname, gIR->module); |
187 ts->llvmInit = initvar; | |
188 | |
189 gIR->classes.pop_back(); | |
190 gIR->structs.pop_back(); | |
191 | |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
192 gIR->constInitList.push_back(cd); |
100 | 193 if (needs_definition) |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
194 gIR->defineList.push_back(cd); |
100 | 195 } |
196 | |
197 ////////////////////////////////////////////////////////////////////////////////////////// | |
198 | |
199 void DtoConstInitClass(ClassDeclaration* cd) | |
200 { | |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
201 if (cd->llvmInitialized) return; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
202 cd->llvmInitialized = true; |
100 | 203 |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
204 Logger::println("DtoConstInitClass(%s)", cd->toPrettyChars()); |
100 | 205 LOG_SCOPE; |
206 | |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
207 IRStruct* irstruct = cd->llvmIRStruct; |
100 | 208 gIR->structs.push_back(irstruct); |
209 gIR->classes.push_back(cd); | |
210 | |
211 // make sure each offset knows its default initializer | |
212 for (IRStruct::OffsetMap::iterator i=irstruct->offsets.begin(); i!=irstruct->offsets.end(); ++i) | |
213 { | |
214 IRStruct::Offset* so = &i->second; | |
215 llvm::Constant* finit = DtoConstFieldInitializer(so->var->type, so->var->init); | |
216 so->init = finit; | |
217 so->var->llvmConstInit = finit; | |
218 } | |
219 | |
220 // fill out fieldtypes/inits | |
221 std::vector<llvm::Constant*> fieldinits; | |
222 | |
223 // first field is always the vtable | |
224 assert(cd->llvmVtbl != 0); | |
225 fieldinits.push_back(cd->llvmVtbl); | |
226 | |
227 // rest | |
228 for (IRStruct::OffsetMap::iterator i=irstruct->offsets.begin(); i!=irstruct->offsets.end(); ++i) { | |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
229 Logger::println("adding fieldinit for: %s", i->second.var->toChars()); |
100 | 230 fieldinits.push_back(i->second.init); |
231 } | |
232 | |
233 // get the struct (class) type | |
234 assert(cd->type->ty == Tclass); | |
235 TypeClass* ts = (TypeClass*)cd->type; | |
236 const llvm::StructType* structtype = isaStruct(ts->llvmType->get()); | |
237 | |
238 // generate initializer | |
239 Logger::cout() << cd->toPrettyChars() << " | " << *structtype << '\n'; | |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
240 |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
241 for(size_t i=0; i<structtype->getNumElements(); ++i) { |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
242 Logger::cout() << "s#" << i << " = " << *structtype->getElementType(i) << '\n'; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
243 } |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
244 |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
245 for(size_t i=0; i<fieldinits.size(); ++i) { |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
246 Logger::cout() << "i#" << i << " = " << *fieldinits[i]->getType() << '\n'; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
247 } |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
248 |
100 | 249 llvm::Constant* _init = llvm::ConstantStruct::get(structtype, fieldinits); |
250 assert(_init); | |
251 cd->llvmInitZ = _init; | |
252 | |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
253 // generate vtable initializer |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
254 std::vector<llvm::Constant*> sinits; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
255 |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
256 for (int k=0; k < cd->vtbl.dim; k++) |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
257 { |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
258 Dsymbol* dsym = (Dsymbol*)cd->vtbl.data[k]; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
259 assert(dsym); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
260 //Logger::cout() << "vtblsym: " << dsym->toChars() << '\n'; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
261 |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
262 if (FuncDeclaration* fd = dsym->isFuncDeclaration()) { |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
263 DtoForceDeclareDsymbol(fd); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
264 assert(fd->llvmValue); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
265 llvm::Constant* c = llvm::cast<llvm::Constant>(fd->llvmValue); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
266 sinits.push_back(c); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
267 } |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
268 else if (ClassDeclaration* cd = dsym->isClassDeclaration()) { |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
269 const llvm::Type* cty = llvm::PointerType::get(llvm::Type::Int8Ty); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
270 llvm::Constant* c = llvm::Constant::getNullValue(cty); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
271 sinits.push_back(c); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
272 } |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
273 else |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
274 assert(0); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
275 } |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
276 |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
277 const llvm::StructType* svtbl_ty = isaStruct(ts->llvmVtblType->get()); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
278 |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
279 /*for (size_t i=0; i< sinits.size(); ++i) |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
280 { |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
281 Logger::cout() << "field[" << i << "] = " << *svtbl_ty->getElementType(i) << '\n'; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
282 Logger::cout() << "init [" << i << "] = " << *sinits[i]->getType() << '\n'; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
283 assert(svtbl_ty->getElementType(i) == sinits[i]->getType()); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
284 }*/ |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
285 |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
286 llvm::Constant* cvtblInit = llvm::ConstantStruct::get(svtbl_ty, sinits); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
287 cd->llvmConstVtbl = llvm::cast<llvm::ConstantStruct>(cvtblInit); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
288 |
100 | 289 gIR->classes.pop_back(); |
290 gIR->structs.pop_back(); | |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
291 |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
292 DtoDeclareClassInfo(cd); |
100 | 293 } |
294 | |
295 ////////////////////////////////////////////////////////////////////////////////////////// | |
296 | |
297 void DtoDefineClass(ClassDeclaration* cd) | |
298 { | |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
299 if (cd->llvmDefined) return; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
300 cd->llvmDefined = true; |
100 | 301 |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
302 Logger::println("DtoDefineClass(%s)", cd->toPrettyChars()); |
100 | 303 LOG_SCOPE; |
304 | |
305 // get the struct (class) type | |
306 assert(cd->type->ty == Tclass); | |
307 TypeClass* ts = (TypeClass*)cd->type; | |
308 | |
309 bool def = false; | |
310 if (cd->parent->isModule() && cd->getModule() == gIR->dmodule) { | |
311 ts->llvmInit->setInitializer(cd->llvmInitZ); | |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
312 cd->llvmVtbl->setInitializer(cd->llvmConstVtbl); |
100 | 313 def = true; |
314 } | |
315 | |
316 // generate classinfo | |
317 if (def) DtoDefineClassInfo(cd); | |
318 } | |
319 | |
320 ////////////////////////////////////////////////////////////////////////////////////////// | |
321 | |
322 void DtoCallClassDtors(TypeClass* tc, llvm::Value* instance) | |
323 { | |
324 Array* arr = &tc->sym->dtors; | |
325 for (size_t i=0; i<arr->dim; i++) | |
326 { | |
327 FuncDeclaration* fd = (FuncDeclaration*)arr->data[i]; | |
328 assert(fd->llvmValue); | |
329 new llvm::CallInst(fd->llvmValue, instance, "", gIR->scopebb()); | |
330 } | |
331 } | |
332 | |
333 ////////////////////////////////////////////////////////////////////////////////////////// | |
334 | |
335 void DtoInitClass(TypeClass* tc, llvm::Value* dst) | |
336 { | |
337 assert(gIR); | |
338 | |
339 assert(tc->llvmType); | |
340 uint64_t size_t_size = gTargetData->getTypeSize(DtoSize_t()); | |
341 uint64_t n = gTargetData->getTypeSize(tc->llvmType->get()) - size_t_size; | |
342 | |
343 // set vtable field | |
344 llvm::Value* vtblvar = DtoGEPi(dst,0,0,"tmp",gIR->scopebb()); | |
345 assert(tc->sym->llvmVtbl); | |
346 new llvm::StoreInst(tc->sym->llvmVtbl, vtblvar, gIR->scopebb()); | |
347 | |
348 // copy the static initializer | |
349 if (n > 0) { | |
350 assert(tc->llvmInit); | |
351 assert(dst->getType() == tc->llvmInit->getType()); | |
352 | |
353 llvm::Type* arrty = llvm::PointerType::get(llvm::Type::Int8Ty); | |
354 | |
355 llvm::Value* dstarr = new llvm::BitCastInst(dst,arrty,"tmp",gIR->scopebb()); | |
356 dstarr = DtoGEPi(dstarr,size_t_size,"tmp",gIR->scopebb()); | |
357 | |
358 llvm::Value* srcarr = new llvm::BitCastInst(tc->llvmInit,arrty,"tmp",gIR->scopebb()); | |
359 srcarr = DtoGEPi(srcarr,size_t_size,"tmp",gIR->scopebb()); | |
360 | |
361 llvm::Function* fn = LLVM_DeclareMemCpy32(); | |
362 std::vector<llvm::Value*> llargs; | |
363 llargs.resize(4); | |
364 llargs[0] = dstarr; | |
365 llargs[1] = srcarr; | |
366 llargs[2] = llvm::ConstantInt::get(llvm::Type::Int32Ty, n, false); | |
367 llargs[3] = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); | |
368 | |
369 new llvm::CallInst(fn, llargs.begin(), llargs.end(), "", gIR->scopebb()); | |
370 } | |
371 } | |
372 | |
373 ////////////////////////////////////////////////////////////////////////////////////////// | |
374 | |
375 void DtoDeclareClassInfo(ClassDeclaration* cd) | |
376 { | |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
377 if (cd->llvmClassDeclared) return; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
378 cd->llvmClassDeclared = true; |
100 | 379 |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
380 Logger::println("DtoDeclareClassInfo(%s)", cd->toChars()); |
100 | 381 LOG_SCOPE; |
382 | |
383 ClassDeclaration* cinfo = ClassDeclaration::classinfo; | |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
384 DtoResolveClass(cinfo); |
100 | 385 |
386 std::string gname("_D"); | |
387 gname.append(cd->mangle()); | |
388 gname.append("7__ClassZ"); | |
389 | |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
390 const llvm::Type* st = cinfo->type->llvmType->get(); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
391 |
100 | 392 cd->llvmClass = new llvm::GlobalVariable(st, true, llvm::GlobalValue::ExternalLinkage, NULL, gname, gIR->module); |
393 } | |
394 | |
395 void DtoDefineClassInfo(ClassDeclaration* cd) | |
396 { | |
397 // The layout is: | |
398 // { | |
399 // void **vptr; | |
400 // monitor_t monitor; | |
401 // byte[] initializer; // static initialization data | |
402 // char[] name; // class name | |
403 // void *[] vtbl; | |
404 // Interface[] interfaces; | |
405 // ClassInfo *base; // base class | |
406 // void *destructor; | |
407 // void *invariant; // class invariant | |
408 // uint flags; | |
409 // void *deallocator; | |
410 // OffsetTypeInfo[] offTi; | |
411 // void *defaultConstructor; | |
412 // } | |
413 | |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
414 if (cd->llvmClassDefined) return; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
415 cd->llvmClassDefined = true; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
416 |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
417 Logger::println("DtoDefineClassInfo(%s)", cd->toChars()); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
418 LOG_SCOPE; |
100 | 419 |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
420 assert(cd->type->ty == Tclass); |
100 | 421 assert(cd->llvmClass); |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
422 assert(cd->llvmInitZ); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
423 assert(cd->llvmVtbl); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
424 assert(cd->llvmConstVtbl); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
425 |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
426 TypeClass* cdty = (TypeClass*)cd->type; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
427 assert(cdty->llvmInit); |
100 | 428 |
429 // holds the list of initializers for llvm | |
430 std::vector<llvm::Constant*> inits; | |
431 | |
432 ClassDeclaration* cinfo = ClassDeclaration::classinfo; | |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
433 DtoForceConstInitDsymbol(cinfo); |
100 | 434 assert(cinfo->llvmInitZ); |
435 | |
436 llvm::Constant* c; | |
437 | |
438 // own vtable | |
439 c = cinfo->llvmInitZ->getOperand(0); | |
440 assert(c); | |
441 inits.push_back(c); | |
442 | |
443 // monitor | |
444 // TODO no monitors yet | |
445 | |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
446 // byte[] init |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
447 const llvm::Type* byteptrty = llvm::PointerType::get(llvm::Type::Int8Ty); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
448 c = llvm::ConstantExpr::getBitCast(cdty->llvmInit, byteptrty); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
449 assert(!cd->llvmInitZ->getType()->isAbstract()); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
450 size_t initsz = gTargetData->getTypeSize(cd->llvmInitZ->getType()); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
451 c = DtoConstSlice(DtoConstSize_t(initsz), c); |
100 | 452 inits.push_back(c); |
453 | |
454 // class name | |
455 // from dmd | |
456 char *name = cd->ident->toChars(); | |
457 size_t namelen = strlen(name); | |
458 if (!(namelen > 9 && memcmp(name, "TypeInfo_", 9) == 0)) | |
459 { | |
460 name = cd->toPrettyChars(); | |
461 namelen = strlen(name); | |
462 } | |
463 c = DtoConstString(name); | |
464 inits.push_back(c); | |
465 | |
466 // vtbl array | |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
467 const llvm::Type* byteptrptrty = llvm::PointerType::get(byteptrty); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
468 assert(!cd->llvmVtbl->getType()->isAbstract()); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
469 c = llvm::ConstantExpr::getBitCast(cd->llvmVtbl, byteptrptrty); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
470 assert(!cd->llvmConstVtbl->getType()->isAbstract()); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
471 size_t vtblsz = gTargetData->getTypeSize(cd->llvmConstVtbl->getType()); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
472 c = DtoConstSlice(DtoConstSize_t(vtblsz), c); |
100 | 473 inits.push_back(c); |
474 | |
475 // interfaces array | |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
476 // TODO |
100 | 477 c = cinfo->llvmInitZ->getOperand(4); |
478 inits.push_back(c); | |
479 | |
480 // base classinfo | |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
481 if (cd->baseClass) { |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
482 DtoDeclareClassInfo(cd->baseClass); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
483 c = cd->baseClass->llvmClass; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
484 assert(c); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
485 inits.push_back(c); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
486 } |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
487 else { |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
488 // null |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
489 c = cinfo->llvmInitZ->getOperand(5); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
490 inits.push_back(c); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
491 } |
100 | 492 |
493 // destructor | |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
494 // TODO |
100 | 495 c = cinfo->llvmInitZ->getOperand(6); |
496 inits.push_back(c); | |
497 | |
498 // invariant | |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
499 // TODO |
100 | 500 c = cinfo->llvmInitZ->getOperand(7); |
501 inits.push_back(c); | |
502 | |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
503 // uint flags, adapted from original dmd code |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
504 uint flags = 0; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
505 //flags |= 4; // has offTi |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
506 //flags |= isCOMclass(); // IUnknown |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
507 if (cd->ctor) flags |= 8; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
508 for (ClassDeclaration *cd2 = cd; cd2; cd2 = cd2->baseClass) |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
509 { |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
510 if (cd2->members) |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
511 { |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
512 for (size_t i = 0; i < cd2->members->dim; i++) |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
513 { |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
514 Dsymbol *sm = (Dsymbol *)cd2->members->data[i]; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
515 //printf("sm = %s %s\n", sm->kind(), sm->toChars()); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
516 if (sm->hasPointers()) |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
517 goto L2; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
518 } |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
519 } |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
520 } |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
521 flags |= 2; // no pointers |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
522 L2: |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
523 c = DtoConstUint(flags); |
100 | 524 inits.push_back(c); |
525 | |
526 // allocator | |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
527 // TODO |
100 | 528 c = cinfo->llvmInitZ->getOperand(9); |
529 inits.push_back(c); | |
530 | |
531 // offset typeinfo | |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
532 // TODO |
100 | 533 c = cinfo->llvmInitZ->getOperand(10); |
534 inits.push_back(c); | |
535 | |
536 // default constructor | |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
537 // TODO |
100 | 538 c = cinfo->llvmInitZ->getOperand(11); |
539 inits.push_back(c); | |
540 | |
541 /*size_t n = inits.size(); | |
542 for (size_t i=0; i<n; ++i) | |
543 { | |
544 Logger::cout() << "inits[" << i << "]: " << *inits[i] << '\n'; | |
545 }*/ | |
546 | |
547 // build the initializer | |
548 const llvm::StructType* st = isaStruct(cinfo->llvmInitZ->getType()); | |
549 llvm::Constant* finalinit = llvm::ConstantStruct::get(st, inits); | |
550 //Logger::cout() << "built the classinfo initializer:\n" << *finalinit <<'\n'; | |
551 | |
552 cd->llvmClassZ = finalinit; | |
553 cd->llvmClass->setInitializer(finalinit); | |
554 } |