comparison gen/classes.cpp @ 173:db9890b3fb64 trunk

[svn r189] moving IR data back into DMD frontend nodes
author ChristianK
date Tue, 06 May 2008 07:56:03 +0200
parents 2df270e1ba59
children cea8dcfa76df
comparison
equal deleted inserted replaced
172:68a7dd38c03c 173:db9890b3fb64
33 33
34 // resolve interfaces while we're at it 34 // resolve interfaces while we're at it
35 if (bc->base->isInterfaceDeclaration()) 35 if (bc->base->isInterfaceDeclaration())
36 { 36 {
37 // don't add twice 37 // don't add twice
38 if (gIR->irDsymbol[target].irStruct->interfaceMap.find(bc->base) == gIR->irDsymbol[target].irStruct->interfaceMap.end()) 38 if (target->ir.irStruct->interfaceMap.find(bc->base) == target->ir.irStruct->interfaceMap.end())
39 { 39 {
40 Logger::println("adding interface '%s'", bc->base->toPrettyChars()); 40 Logger::println("adding interface '%s'", bc->base->toPrettyChars());
41 IrInterface* iri = new IrInterface(bc, NULL); 41 IrInterface* iri = new IrInterface(bc, NULL);
42 42
43 // add to map 43 // add to map
44 gIR->irDsymbol[target].irStruct->interfaceMap.insert(std::make_pair(bc->base, iri)); 44 target->ir.irStruct->interfaceMap.insert(std::make_pair(bc->base, iri));
45 // add to ordered list 45 // add to ordered list
46 gIR->irDsymbol[target].irStruct->interfaceVec.push_back(iri); 46 target->ir.irStruct->interfaceVec.push_back(iri);
47 47
48 // Fill in vtbl[] 48 // Fill in vtbl[]
49 if (!target->isAbstract()) { 49 if (!target->isAbstract()) {
50 bc->fillVtbl(target, &bc->vtbl, 0); 50 bc->fillVtbl(target, &bc->vtbl, 0);
51 } 51 }
86 86
87 ////////////////////////////////////////////////////////////////////////////////////////// 87 //////////////////////////////////////////////////////////////////////////////////////////
88 88
89 void DtoResolveClass(ClassDeclaration* cd) 89 void DtoResolveClass(ClassDeclaration* cd)
90 { 90 {
91 if (gIR->irDsymbol[cd].resolved) return; 91 if (cd->ir.resolved) return;
92 gIR->irDsymbol[cd].resolved = true; 92 cd->ir.resolved = true;
93 93
94 Logger::println("DtoResolveClass(%s): %s", cd->toPrettyChars(), cd->loc.toChars()); 94 Logger::println("DtoResolveClass(%s): %s", cd->toPrettyChars(), cd->loc.toChars());
95 LOG_SCOPE; 95 LOG_SCOPE;
96 96
97 // get the TypeClass 97 // get the TypeClass
98 assert(cd->type->ty == Tclass); 98 assert(cd->type->ty == Tclass);
99 TypeClass* ts = (TypeClass*)cd->type; 99 TypeClass* ts = (TypeClass*)cd->type;
100 100
101 // make sure the IrStruct is created 101 // make sure the IrStruct is created
102 IrStruct* irstruct = gIR->irDsymbol[cd].irStruct; 102 IrStruct* irstruct = cd->ir.irStruct;
103 if (!irstruct) { 103 if (!irstruct) {
104 irstruct = new IrStruct(ts); 104 irstruct = new IrStruct(ts);
105 gIR->irDsymbol[cd].irStruct = irstruct; 105 cd->ir.irStruct = irstruct;
106 } 106 }
107 107
108 // resolve the base class 108 // resolve the base class
109 if (cd->baseClass) { 109 if (cd->baseClass) {
110 DtoResolveClass(cd->baseClass); 110 DtoResolveClass(cd->baseClass);
126 126
127 gIR->structs.push_back(irstruct); 127 gIR->structs.push_back(irstruct);
128 gIR->classes.push_back(cd); 128 gIR->classes.push_back(cd);
129 129
130 // add vtable 130 // add vtable
131 gIR->irType[ts].vtblType = new llvm::PATypeHolder(llvm::OpaqueType::get()); 131 ts->ir.vtblType = new llvm::PATypeHolder(llvm::OpaqueType::get());
132 const llvm::Type* vtabty = getPtrToType(gIR->irType[ts].vtblType->get()); 132 const llvm::Type* vtabty = getPtrToType(ts->ir.vtblType->get());
133 133
134 std::vector<const llvm::Type*> fieldtypes; 134 std::vector<const llvm::Type*> fieldtypes;
135 fieldtypes.push_back(vtabty); 135 fieldtypes.push_back(vtabty);
136 136
137 // add monitor 137 // add monitor
167 if (lastoffset == (unsigned)-1) { 167 if (lastoffset == (unsigned)-1) {
168 lastoffset = i->first; 168 lastoffset = i->first;
169 fieldtype = i->second.type; 169 fieldtype = i->second.type;
170 fieldinit = i->second.var; 170 fieldinit = i->second.var;
171 prevsize = getABITypeSize(fieldtype); 171 prevsize = getABITypeSize(fieldtype);
172 gIR->irDsymbol[i->second.var].irField->index = idx; 172 i->second.var->ir.irField->index = idx;
173 } 173 }
174 // colliding offset? 174 // colliding offset?
175 else if (lastoffset == i->first) { 175 else if (lastoffset == i->first) {
176 size_t s = getABITypeSize(i->second.type); 176 size_t s = getABITypeSize(i->second.type);
177 if (s > prevsize) { 177 if (s > prevsize) {
178 fieldpad += s - prevsize; 178 fieldpad += s - prevsize;
179 prevsize = s; 179 prevsize = s;
180 } 180 }
181 gIR->irDsymbol[cd].irStruct->hasUnions = true; 181 cd->ir.irStruct->hasUnions = true;
182 gIR->irDsymbol[i->second.var].irField->index = idx; 182 i->second.var->ir.irField->index = idx;
183 } 183 }
184 // intersecting offset? 184 // intersecting offset?
185 else if (i->first < (lastoffset + prevsize)) { 185 else if (i->first < (lastoffset + prevsize)) {
186 size_t s = getABITypeSize(i->second.type); 186 size_t s = getABITypeSize(i->second.type);
187 assert((i->first + s) <= (lastoffset + prevsize)); // this holds because all types are aligned to their size 187 assert((i->first + s) <= (lastoffset + prevsize)); // this holds because all types are aligned to their size
188 gIR->irDsymbol[cd].irStruct->hasUnions = true; 188 cd->ir.irStruct->hasUnions = true;
189 gIR->irDsymbol[i->second.var].irField->index = idx; 189 i->second.var->ir.irField->index = idx;
190 gIR->irDsymbol[i->second.var].irField->indexOffset = (i->first - lastoffset) / s; 190 i->second.var->ir.irField->indexOffset = (i->first - lastoffset) / s;
191 } 191 }
192 // fresh offset 192 // fresh offset
193 else { 193 else {
194 // commit the field 194 // commit the field
195 fieldtypes.push_back(fieldtype); 195 fieldtypes.push_back(fieldtype);
205 // start new 205 // start new
206 lastoffset = i->first; 206 lastoffset = i->first;
207 fieldtype = i->second.type; 207 fieldtype = i->second.type;
208 fieldinit = i->second.var; 208 fieldinit = i->second.var;
209 prevsize = getABITypeSize(fieldtype); 209 prevsize = getABITypeSize(fieldtype);
210 gIR->irDsymbol[i->second.var].irField->index = idx; 210 i->second.var->ir.irField->index = idx;
211 fieldpad = 0; 211 fieldpad = 0;
212 } 212 }
213 } 213 }
214 fieldtypes.push_back(fieldtype); 214 fieldtypes.push_back(fieldtype);
215 irstruct->defaultFields.push_back(fieldinit); 215 irstruct->defaultFields.push_back(fieldinit);
222 // populate interface map 222 // populate interface map
223 { 223 {
224 Logger::println("Adding interfaces to '%s'", cd->toPrettyChars()); 224 Logger::println("Adding interfaces to '%s'", cd->toPrettyChars());
225 LOG_SCOPE; 225 LOG_SCOPE;
226 LLVM_AddBaseClassInterfaces(cd, &cd->baseclasses); 226 LLVM_AddBaseClassInterfaces(cd, &cd->baseclasses);
227 Logger::println("%d interfaces added", gIR->irDsymbol[cd].irStruct->interfaceVec.size()); 227 Logger::println("%d interfaces added", cd->ir.irStruct->interfaceVec.size());
228 assert(gIR->irDsymbol[cd].irStruct->interfaceVec.size() == gIR->irDsymbol[cd].irStruct->interfaceMap.size()); 228 assert(cd->ir.irStruct->interfaceVec.size() == cd->ir.irStruct->interfaceMap.size());
229 } 229 }
230 230
231 // add interface vtables at the end 231 // add interface vtables at the end
232 int interIdx = (int)fieldtypes.size(); 232 int interIdx = (int)fieldtypes.size();
233 for (IrStruct::InterfaceVectorIter i=irstruct->interfaceVec.begin(); i!=irstruct->interfaceVec.end(); ++i) 233 for (IrStruct::InterfaceVectorIter i=irstruct->interfaceVec.begin(); i!=irstruct->interfaceVec.end(); ++i)
235 IrInterface* iri = *i; 235 IrInterface* iri = *i;
236 ClassDeclaration* id = iri->decl; 236 ClassDeclaration* id = iri->decl;
237 237
238 // set vtbl type 238 // set vtbl type
239 TypeClass* itc = (TypeClass*)id->type; 239 TypeClass* itc = (TypeClass*)id->type;
240 const llvm::Type* ivtblTy = getPtrToType(gIR->irType[itc].vtblType->get()); 240 const llvm::Type* ivtblTy = getPtrToType(itc->ir.vtblType->get());
241 fieldtypes.push_back(ivtblTy); 241 fieldtypes.push_back(ivtblTy);
242 242
243 // fix the interface vtable type 243 // fix the interface vtable type
244 iri->vtblTy = isaStruct(gIR->irType[itc].vtblType->get()); 244 iri->vtblTy = isaStruct(itc->ir.vtblType->get());
245 245
246 // set index 246 // set index
247 iri->index = interIdx++; 247 iri->index = interIdx++;
248 } 248 }
249 Logger::println("%d interface vtables added", gIR->irDsymbol[cd].irStruct->interfaceVec.size()); 249 Logger::println("%d interface vtables added", cd->ir.irStruct->interfaceVec.size());
250 assert(gIR->irDsymbol[cd].irStruct->interfaceVec.size() == gIR->irDsymbol[cd].irStruct->interfaceMap.size()); 250 assert(cd->ir.irStruct->interfaceVec.size() == cd->ir.irStruct->interfaceMap.size());
251 251
252 // create type 252 // create type
253 const llvm::StructType* structtype = llvm::StructType::get(fieldtypes); 253 const llvm::StructType* structtype = llvm::StructType::get(fieldtypes);
254 254
255 // refine abstract types for stuff like: class C {C next;} 255 // refine abstract types for stuff like: class C {C next;}
257 llvm::PATypeHolder& spa = irstruct->recty; 257 llvm::PATypeHolder& spa = irstruct->recty;
258 llvm::cast<llvm::OpaqueType>(spa.get())->refineAbstractTypeTo(structtype); 258 llvm::cast<llvm::OpaqueType>(spa.get())->refineAbstractTypeTo(structtype);
259 structtype = isaStruct(spa.get()); 259 structtype = isaStruct(spa.get());
260 260
261 // make it official 261 // make it official
262 if (!gIR->irType[ts].type) 262 if (!ts->ir.type)
263 gIR->irType[ts].type = new llvm::PATypeHolder(structtype); 263 ts->ir.type = new llvm::PATypeHolder(structtype);
264 else 264 else
265 *gIR->irType[ts].type = structtype; 265 *ts->ir.type = structtype;
266 spa = *gIR->irType[ts].type; 266 spa = *ts->ir.type;
267 267
268 // name the type 268 // name the type
269 gIR->module->addTypeName(cd->mangle(), gIR->irType[ts].type->get()); 269 gIR->module->addTypeName(cd->mangle(), ts->ir.type->get());
270 270
271 // get interface info type 271 // get interface info type
272 const llvm::StructType* infoTy = DtoInterfaceInfoType(); 272 const llvm::StructType* infoTy = DtoInterfaceInfoType();
273 273
274 // create vtable type 274 // create vtable type
283 283
284 if (FuncDeclaration* fd = dsym->isFuncDeclaration()) { 284 if (FuncDeclaration* fd = dsym->isFuncDeclaration()) {
285 DtoResolveFunction(fd); 285 DtoResolveFunction(fd);
286 //assert(fd->type->ty == Tfunction); 286 //assert(fd->type->ty == Tfunction);
287 //TypeFunction* tf = (TypeFunction*)fd->type; 287 //TypeFunction* tf = (TypeFunction*)fd->type;
288 //const llvm::Type* fpty = getPtrToType(gIR->irType[tf].type->get()); 288 //const llvm::Type* fpty = getPtrToType(tf->ir.type->get());
289 const llvm::FunctionType* vfty = DtoBaseFunctionType(fd); 289 const llvm::FunctionType* vfty = DtoBaseFunctionType(fd);
290 const llvm::Type* vfpty = getPtrToType(vfty); 290 const llvm::Type* vfpty = getPtrToType(vfty);
291 sinits_ty.push_back(vfpty); 291 sinits_ty.push_back(vfpty);
292 } 292 }
293 else if (ClassDeclaration* cd2 = dsym->isClassDeclaration()) { 293 else if (ClassDeclaration* cd2 = dsym->isClassDeclaration()) {
295 const llvm::Type* cinfoty; 295 const llvm::Type* cinfoty;
296 if (cd->isInterfaceDeclaration()) { 296 if (cd->isInterfaceDeclaration()) {
297 cinfoty = infoTy; 297 cinfoty = infoTy;
298 } 298 }
299 else if (cd != ClassDeclaration::classinfo) { 299 else if (cd != ClassDeclaration::classinfo) {
300 cinfoty = gIR->irType[ClassDeclaration::classinfo->type].type->get(); 300 cinfoty = ClassDeclaration::classinfo->type->ir.type->get();
301 } 301 }
302 else { 302 else {
303 // this is the ClassInfo class, the type is this type 303 // this is the ClassInfo class, the type is this type
304 cinfoty = gIR->irType[ts].type->get(); 304 cinfoty = ts->ir.type->get();
305 } 305 }
306 const llvm::Type* cty = getPtrToType(cinfoty); 306 const llvm::Type* cty = getPtrToType(cinfoty);
307 sinits_ty.push_back(cty); 307 sinits_ty.push_back(cty);
308 } 308 }
309 else 309 else
316 std::string styname(cd->mangle()); 316 std::string styname(cd->mangle());
317 styname.append("__vtblType"); 317 styname.append("__vtblType");
318 gIR->module->addTypeName(styname, svtbl_ty); 318 gIR->module->addTypeName(styname, svtbl_ty);
319 319
320 // refine for final vtable type 320 // refine for final vtable type
321 llvm::cast<llvm::OpaqueType>(gIR->irType[ts].vtblType->get())->refineAbstractTypeTo(svtbl_ty); 321 llvm::cast<llvm::OpaqueType>(ts->ir.vtblType->get())->refineAbstractTypeTo(svtbl_ty);
322 322
323 gIR->classes.pop_back(); 323 gIR->classes.pop_back();
324 gIR->structs.pop_back(); 324 gIR->structs.pop_back();
325 325
326 gIR->declareList.push_back(cd); 326 gIR->declareList.push_back(cd);
328 328
329 ////////////////////////////////////////////////////////////////////////////////////////// 329 //////////////////////////////////////////////////////////////////////////////////////////
330 330
331 void DtoDeclareClass(ClassDeclaration* cd) 331 void DtoDeclareClass(ClassDeclaration* cd)
332 { 332 {
333 if (gIR->irDsymbol[cd].declared) return; 333 if (cd->ir.declared) return;
334 gIR->irDsymbol[cd].declared = true; 334 cd->ir.declared = true;
335 335
336 Logger::println("DtoDeclareClass(%s): %s", cd->toPrettyChars(), cd->loc.toChars()); 336 Logger::println("DtoDeclareClass(%s): %s", cd->toPrettyChars(), cd->loc.toChars());
337 LOG_SCOPE; 337 LOG_SCOPE;
338 338
339 assert(cd->type->ty == Tclass); 339 assert(cd->type->ty == Tclass);
340 TypeClass* ts = (TypeClass*)cd->type; 340 TypeClass* ts = (TypeClass*)cd->type;
341 341
342 assert(gIR->irDsymbol[cd].irStruct); 342 assert(cd->ir.irStruct);
343 IrStruct* irstruct = gIR->irDsymbol[cd].irStruct; 343 IrStruct* irstruct = cd->ir.irStruct;
344 344
345 gIR->structs.push_back(irstruct); 345 gIR->structs.push_back(irstruct);
346 gIR->classes.push_back(cd); 346 gIR->classes.push_back(cd);
347 347
348 bool needs_definition = false; 348 bool needs_definition = false;
358 // vtable 358 // vtable
359 std::string varname("_D"); 359 std::string varname("_D");
360 varname.append(cd->mangle()); 360 varname.append(cd->mangle());
361 varname.append("6__vtblZ"); 361 varname.append("6__vtblZ");
362 362
363 const llvm::StructType* svtbl_ty = isaStruct(gIR->irType[ts].vtblType->get()); 363 const llvm::StructType* svtbl_ty = isaStruct(ts->ir.vtblType->get());
364 gIR->irDsymbol[cd].irStruct->vtbl = new llvm::GlobalVariable(svtbl_ty, true, _linkage, 0, varname, gIR->module); 364 cd->ir.irStruct->vtbl = new llvm::GlobalVariable(svtbl_ty, true, _linkage, 0, varname, gIR->module);
365 } 365 }
366 366
367 // get interface info type 367 // get interface info type
368 const llvm::StructType* infoTy = DtoInterfaceInfoType(); 368 const llvm::StructType* infoTy = DtoInterfaceInfoType();
369 369
370 // interface info array 370 // interface info array
371 if (!gIR->irDsymbol[cd].irStruct->interfaceVec.empty()) { 371 if (!cd->ir.irStruct->interfaceVec.empty()) {
372 // symbol name 372 // symbol name
373 std::string nam = "_D"; 373 std::string nam = "_D";
374 nam.append(cd->mangle()); 374 nam.append(cd->mangle());
375 nam.append("16__interfaceInfosZ"); 375 nam.append("16__interfaceInfosZ");
376 // resolve array type 376 // resolve array type
377 const llvm::ArrayType* arrTy = llvm::ArrayType::get(infoTy, gIR->irDsymbol[cd].irStruct->interfaceVec.size()); 377 const llvm::ArrayType* arrTy = llvm::ArrayType::get(infoTy, cd->ir.irStruct->interfaceVec.size());
378 // declare global 378 // declare global
379 irstruct->interfaceInfosTy = arrTy; 379 irstruct->interfaceInfosTy = arrTy;
380 irstruct->interfaceInfos = new llvm::GlobalVariable(arrTy, true, _linkage, NULL, nam, gIR->module); 380 irstruct->interfaceInfos = new llvm::GlobalVariable(arrTy, true, _linkage, NULL, nam, gIR->module);
381 } 381 }
382 382
406 // init 406 // init
407 std::string initname("_D"); 407 std::string initname("_D");
408 initname.append(cd->mangle()); 408 initname.append(cd->mangle());
409 initname.append("6__initZ"); 409 initname.append("6__initZ");
410 410
411 llvm::GlobalVariable* initvar = new llvm::GlobalVariable(gIR->irType[ts].type->get(), true, _linkage, NULL, initname, gIR->module); 411 llvm::GlobalVariable* initvar = new llvm::GlobalVariable(ts->ir.type->get(), true, _linkage, NULL, initname, gIR->module);
412 gIR->irDsymbol[cd].irStruct->init = initvar; 412 cd->ir.irStruct->init = initvar;
413 } 413 }
414 414
415 gIR->classes.pop_back(); 415 gIR->classes.pop_back();
416 gIR->structs.pop_back(); 416 gIR->structs.pop_back();
417 417
429 429
430 ////////////////////////////////////////////////////////////////////////////////////////// 430 //////////////////////////////////////////////////////////////////////////////////////////
431 431
432 void DtoConstInitClass(ClassDeclaration* cd) 432 void DtoConstInitClass(ClassDeclaration* cd)
433 { 433 {
434 if (gIR->irDsymbol[cd].initialized) return; 434 if (cd->ir.initialized) return;
435 gIR->irDsymbol[cd].initialized = true; 435 cd->ir.initialized = true;
436 436
437 if (cd->isInterfaceDeclaration()) 437 if (cd->isInterfaceDeclaration())
438 return; // nothing to do 438 return; // nothing to do
439 439
440 Logger::println("DtoConstInitClass(%s): %s", cd->toPrettyChars(), cd->loc.toChars()); 440 Logger::println("DtoConstInitClass(%s): %s", cd->toPrettyChars(), cd->loc.toChars());
441 LOG_SCOPE; 441 LOG_SCOPE;
442 442
443 IrStruct* irstruct = gIR->irDsymbol[cd].irStruct; 443 IrStruct* irstruct = cd->ir.irStruct;
444 gIR->structs.push_back(irstruct); 444 gIR->structs.push_back(irstruct);
445 gIR->classes.push_back(cd); 445 gIR->classes.push_back(cd);
446 446
447 // get the struct (class) type 447 // get the struct (class) type
448 assert(cd->type->ty == Tclass); 448 assert(cd->type->ty == Tclass);
449 TypeClass* ts = (TypeClass*)cd->type; 449 TypeClass* ts = (TypeClass*)cd->type;
450 const llvm::StructType* structtype = isaStruct(gIR->irType[ts].type->get()); 450 const llvm::StructType* structtype = isaStruct(ts->ir.type->get());
451 const llvm::StructType* vtbltype = isaStruct(gIR->irType[ts].vtblType->get()); 451 const llvm::StructType* vtbltype = isaStruct(ts->ir.vtblType->get());
452 452
453 // make sure each offset knows its default initializer 453 // make sure each offset knows its default initializer
454 for (IrStruct::OffsetMap::iterator i=irstruct->offsets.begin(); i!=irstruct->offsets.end(); ++i) 454 for (IrStruct::OffsetMap::iterator i=irstruct->offsets.begin(); i!=irstruct->offsets.end(); ++i)
455 { 455 {
456 IrStruct::Offset* so = &i->second; 456 IrStruct::Offset* so = &i->second;
457 llvm::Constant* finit = DtoConstFieldInitializer(so->var->type, so->var->init); 457 llvm::Constant* finit = DtoConstFieldInitializer(so->var->type, so->var->init);
458 so->init = finit; 458 so->init = finit;
459 gIR->irDsymbol[so->var].irField->constInit = finit; 459 so->var->ir.irField->constInit = finit;
460 } 460 }
461 461
462 // fill out fieldtypes/inits 462 // fill out fieldtypes/inits
463 std::vector<llvm::Constant*> fieldinits; 463 std::vector<llvm::Constant*> fieldinits;
464 464
466 if (cd->isAbstract()) 466 if (cd->isAbstract())
467 { 467 {
468 fieldinits.push_back( 468 fieldinits.push_back(
469 llvm::ConstantPointerNull::get( 469 llvm::ConstantPointerNull::get(
470 getPtrToType( 470 getPtrToType(
471 gIR->irType[ts].vtblType->get() 471 ts->ir.vtblType->get()
472 ) 472 )
473 ) 473 )
474 ); 474 );
475 } 475 }
476 else 476 else
477 { 477 {
478 assert(gIR->irDsymbol[cd].irStruct->vtbl != 0); 478 assert(cd->ir.irStruct->vtbl != 0);
479 fieldinits.push_back(gIR->irDsymbol[cd].irStruct->vtbl); 479 fieldinits.push_back(cd->ir.irStruct->vtbl);
480 } 480 }
481 481
482 // then comes monitor 482 // then comes monitor
483 fieldinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(llvm::Type::Int8Ty))); 483 fieldinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(llvm::Type::Int8Ty)));
484 484
485 // go through the field inits and build the default initializer 485 // go through the field inits and build the default initializer
486 size_t nfi = irstruct->defaultFields.size(); 486 size_t nfi = irstruct->defaultFields.size();
487 for (size_t i=0; i<nfi; ++i) { 487 for (size_t i=0; i<nfi; ++i) {
488 llvm::Constant* c; 488 llvm::Constant* c;
489 if (irstruct->defaultFields[i]) { 489 if (irstruct->defaultFields[i]) {
490 c = gIR->irDsymbol[irstruct->defaultFields[i]].irField->constInit; 490 c = irstruct->defaultFields[i]->ir.irField->constInit;
491 assert(c); 491 assert(c);
492 } 492 }
493 else { 493 else {
494 const llvm::ArrayType* arrty = isaArray(structtype->getElementType(i+2)); 494 const llvm::ArrayType* arrty = isaArray(structtype->getElementType(i+2));
495 assert(arrty); 495 assert(arrty);
534 } 534 }
535 #endif 535 #endif
536 536
537 llvm::Constant* _init = llvm::ConstantStruct::get(structtype, fieldinits); 537 llvm::Constant* _init = llvm::ConstantStruct::get(structtype, fieldinits);
538 assert(_init); 538 assert(_init);
539 gIR->irDsymbol[cd].irStruct->constInit = _init; 539 cd->ir.irStruct->constInit = _init;
540 540
541 // abstract classes have no static vtable 541 // abstract classes have no static vtable
542 // neither do interfaces (on their own, the implementing class supplies the vtable) 542 // neither do interfaces (on their own, the implementing class supplies the vtable)
543 if (!cd->isInterfaceDeclaration() && !cd->isAbstract()) 543 if (!cd->isInterfaceDeclaration() && !cd->isAbstract())
544 { 544 {
551 assert(dsym); 551 assert(dsym);
552 //Logger::cout() << "vtblsym: " << dsym->toChars() << '\n'; 552 //Logger::cout() << "vtblsym: " << dsym->toChars() << '\n';
553 553
554 if (FuncDeclaration* fd = dsym->isFuncDeclaration()) { 554 if (FuncDeclaration* fd = dsym->isFuncDeclaration()) {
555 DtoForceDeclareDsymbol(fd); 555 DtoForceDeclareDsymbol(fd);
556 assert(gIR->irDsymbol[fd].irFunc->func); 556 assert(fd->ir.irFunc->func);
557 llvm::Constant* c = llvm::cast<llvm::Constant>(gIR->irDsymbol[fd].irFunc->func); 557 llvm::Constant* c = llvm::cast<llvm::Constant>(fd->ir.irFunc->func);
558 // cast if necessary (overridden method) 558 // cast if necessary (overridden method)
559 if (c->getType() != vtbltype->getElementType(k)) 559 if (c->getType() != vtbltype->getElementType(k))
560 c = llvm::ConstantExpr::getBitCast(c, vtbltype->getElementType(k)); 560 c = llvm::ConstantExpr::getBitCast(c, vtbltype->getElementType(k));
561 sinits.push_back(c); 561 sinits.push_back(c);
562 } 562 }
563 else if (ClassDeclaration* cd2 = dsym->isClassDeclaration()) { 563 else if (ClassDeclaration* cd2 = dsym->isClassDeclaration()) {
564 assert(gIR->irDsymbol[cd].irStruct->classInfo); 564 assert(cd->ir.irStruct->classInfo);
565 llvm::Constant* c = gIR->irDsymbol[cd].irStruct->classInfo; 565 llvm::Constant* c = cd->ir.irStruct->classInfo;
566 sinits.push_back(c); 566 sinits.push_back(c);
567 } 567 }
568 else 568 else
569 assert(0); 569 assert(0);
570 } 570 }
571 571
572 const llvm::StructType* svtbl_ty = isaStruct(gIR->irType[ts].vtblType->get()); 572 const llvm::StructType* svtbl_ty = isaStruct(ts->ir.vtblType->get());
573 573
574 #if 0 574 #if 0
575 for (size_t i=0; i< sinits.size(); ++i) 575 for (size_t i=0; i< sinits.size(); ++i)
576 { 576 {
577 Logger::cout() << "field[" << i << "] = " << *svtbl_ty->getElementType(i) << '\n'; 577 Logger::cout() << "field[" << i << "] = " << *svtbl_ty->getElementType(i) << '\n';
579 assert(svtbl_ty->getElementType(i) == sinits[i]->getType()); 579 assert(svtbl_ty->getElementType(i) == sinits[i]->getType());
580 } 580 }
581 #endif 581 #endif
582 582
583 llvm::Constant* cvtblInit = llvm::ConstantStruct::get(svtbl_ty, sinits); 583 llvm::Constant* cvtblInit = llvm::ConstantStruct::get(svtbl_ty, sinits);
584 gIR->irDsymbol[cd].irStruct->constVtbl = llvm::cast<llvm::ConstantStruct>(cvtblInit); 584 cd->ir.irStruct->constVtbl = llvm::cast<llvm::ConstantStruct>(cvtblInit);
585 585
586 // create interface vtable const initalizers 586 // create interface vtable const initalizers
587 for (IrStruct::InterfaceVectorIter i=irstruct->interfaceVec.begin(); i!=irstruct->interfaceVec.end(); ++i) 587 for (IrStruct::InterfaceVectorIter i=irstruct->interfaceVec.begin(); i!=irstruct->interfaceVec.end(); ++i)
588 { 588 {
589 IrInterface* iri = *i; 589 IrInterface* iri = *i;
591 591
592 ClassDeclaration* id = iri->decl; 592 ClassDeclaration* id = iri->decl;
593 assert(id->type->ty == Tclass); 593 assert(id->type->ty == Tclass);
594 TypeClass* its = (TypeClass*)id->type; 594 TypeClass* its = (TypeClass*)id->type;
595 595
596 const llvm::StructType* ivtbl_ty = isaStruct(gIR->irType[its].vtblType->get()); 596 const llvm::StructType* ivtbl_ty = isaStruct(its->ir.vtblType->get());
597 597
598 // generate interface info initializer 598 // generate interface info initializer
599 std::vector<llvm::Constant*> infoInits; 599 std::vector<llvm::Constant*> infoInits;
600 600
601 // classinfo 601 // classinfo
602 assert(gIR->irDsymbol[id].irStruct->classInfo); 602 assert(id->ir.irStruct->classInfo);
603 llvm::Constant* c = gIR->irDsymbol[id].irStruct->classInfo; 603 llvm::Constant* c = id->ir.irStruct->classInfo;
604 infoInits.push_back(c); 604 infoInits.push_back(c);
605 605
606 // vtbl 606 // vtbl
607 const llvm::Type* byteptrptrty = getPtrToType(getPtrToType(llvm::Type::Int8Ty)); 607 const llvm::Type* byteptrptrty = getPtrToType(getPtrToType(llvm::Type::Int8Ty));
608 c = llvm::ConstantExpr::getBitCast(iri->vtbl, byteptrptrty); 608 c = llvm::ConstantExpr::getBitCast(iri->vtbl, byteptrptrty);
610 infoInits.push_back(c); 610 infoInits.push_back(c);
611 611
612 // offset 612 // offset
613 // generate target independent offset with constGEP 613 // generate target independent offset with constGEP
614 /*llvm::Value* cidx = DtoConstInt(iri->index); 614 /*llvm::Value* cidx = DtoConstInt(iri->index);
615 Logger::cout() << "offset to interface in class type: " << *gIR->irType[cd->type].type->get() << '\n'; 615 Logger::cout() << "offset to interface in class type: " << *cd->type->ir.type->get() << '\n';
616 size_t ioff = gTargetData->getIndexedOffset(gIR->irType[cd->type].type->get(), &cidx, 1); 616 size_t ioff = gTargetData->getIndexedOffset(cd->type->ir.type->get(), &cidx, 1);
617 infoInits.push_back(DtoConstUint(ioff));*/ 617 infoInits.push_back(DtoConstUint(ioff));*/
618 assert(iri->index >= 0); 618 assert(iri->index >= 0);
619 size_t ioff = gTargetData->getStructLayout(isaStruct(gIR->irType[cd->type].type->get()))->getElementOffset(iri->index); 619 size_t ioff = gTargetData->getStructLayout(isaStruct(cd->type->ir.type->get()))->getElementOffset(iri->index);
620 infoInits.push_back(DtoConstUint(ioff)); 620 infoInits.push_back(DtoConstUint(ioff));
621 621
622 // create interface info initializer constant 622 // create interface info initializer constant
623 iri->infoInit = llvm::cast<llvm::ConstantStruct>(llvm::ConstantStruct::get(iri->infoTy, infoInits)); 623 iri->infoInit = llvm::cast<llvm::ConstantStruct>(llvm::ConstantStruct::get(iri->infoTy, infoInits));
624 624
634 Dsymbol* dsym = (Dsymbol*)b->vtbl.data[k]; 634 Dsymbol* dsym = (Dsymbol*)b->vtbl.data[k];
635 assert(dsym); 635 assert(dsym);
636 FuncDeclaration* fd = dsym->isFuncDeclaration(); 636 FuncDeclaration* fd = dsym->isFuncDeclaration();
637 assert(fd); 637 assert(fd);
638 DtoForceDeclareDsymbol(fd); 638 DtoForceDeclareDsymbol(fd);
639 assert(gIR->irDsymbol[fd].irFunc->func); 639 assert(fd->ir.irFunc->func);
640 llvm::Constant* c = llvm::cast<llvm::Constant>(gIR->irDsymbol[fd].irFunc->func); 640 llvm::Constant* c = llvm::cast<llvm::Constant>(fd->ir.irFunc->func);
641 641
642 // we have to bitcast, as the type created in ResolveClass expects a different this type 642 // we have to bitcast, as the type created in ResolveClass expects a different this type
643 c = llvm::ConstantExpr::getBitCast(c, iri->vtblTy->getContainedType(k)); 643 c = llvm::ConstantExpr::getBitCast(c, iri->vtblTy->getContainedType(k));
644 iinits.push_back(c); 644 iinits.push_back(c);
645 } 645 }
671 671
672 // generate interface info initializer 672 // generate interface info initializer
673 std::vector<llvm::Constant*> infoInits; 673 std::vector<llvm::Constant*> infoInits;
674 674
675 // classinfo 675 // classinfo
676 assert(gIR->irDsymbol[id].irStruct->classInfo); 676 assert(id->ir.irStruct->classInfo);
677 llvm::Constant* c = gIR->irDsymbol[id].irStruct->classInfo; 677 llvm::Constant* c = id->ir.irStruct->classInfo;
678 infoInits.push_back(c); 678 infoInits.push_back(c);
679 679
680 // vtbl 680 // vtbl
681 const llvm::Type* byteptrptrty = getPtrToType(getPtrToType(llvm::Type::Int8Ty)); 681 const llvm::Type* byteptrptrty = getPtrToType(getPtrToType(llvm::Type::Int8Ty));
682 c = DtoConstSlice(DtoConstSize_t(0), getNullPtr(byteptrptrty)); 682 c = DtoConstSlice(DtoConstSize_t(0), getNullPtr(byteptrptrty));
696 696
697 ////////////////////////////////////////////////////////////////////////////////////////// 697 //////////////////////////////////////////////////////////////////////////////////////////
698 698
699 void DtoDefineClass(ClassDeclaration* cd) 699 void DtoDefineClass(ClassDeclaration* cd)
700 { 700 {
701 if (gIR->irDsymbol[cd].defined) return; 701 if (cd->ir.defined) return;
702 gIR->irDsymbol[cd].defined = true; 702 cd->ir.defined = true;
703 703
704 Logger::println("DtoDefineClass(%s): %s", cd->toPrettyChars(), cd->loc.toChars()); 704 Logger::println("DtoDefineClass(%s): %s", cd->toPrettyChars(), cd->loc.toChars());
705 LOG_SCOPE; 705 LOG_SCOPE;
706 706
707 // get the struct (class) type 707 // get the struct (class) type
711 if (cd->getModule() == gIR->dmodule || DtoIsTemplateInstance(cd)) { 711 if (cd->getModule() == gIR->dmodule || DtoIsTemplateInstance(cd)) {
712 // interfaces don't have initializers 712 // interfaces don't have initializers
713 // neither do abstract classes 713 // neither do abstract classes
714 if (!cd->isInterfaceDeclaration() && !cd->isAbstract()) 714 if (!cd->isInterfaceDeclaration() && !cd->isAbstract())
715 { 715 {
716 gIR->irDsymbol[cd].irStruct->init->setInitializer(gIR->irDsymbol[cd].irStruct->constInit); 716 cd->ir.irStruct->init->setInitializer(cd->ir.irStruct->constInit);
717 gIR->irDsymbol[cd].irStruct->vtbl->setInitializer(gIR->irDsymbol[cd].irStruct->constVtbl); 717 cd->ir.irStruct->vtbl->setInitializer(cd->ir.irStruct->constVtbl);
718 718
719 // initialize interface vtables 719 // initialize interface vtables
720 IrStruct* irstruct = gIR->irDsymbol[cd].irStruct; 720 IrStruct* irstruct = cd->ir.irStruct;
721 std::vector<llvm::Constant*> infoInits; 721 std::vector<llvm::Constant*> infoInits;
722 for (IrStruct::InterfaceVectorIter i=irstruct->interfaceVec.begin(); i!=irstruct->interfaceVec.end(); ++i) 722 for (IrStruct::InterfaceVectorIter i=irstruct->interfaceVec.begin(); i!=irstruct->interfaceVec.end(); ++i)
723 { 723 {
724 IrInterface* iri = *i; 724 IrInterface* iri = *i;
725 iri->vtbl->setInitializer(iri->vtblInit); 725 iri->vtbl->setInitializer(iri->vtblInit);
753 } 753 }
754 else 754 else
755 { 755 {
756 llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_newclass"); 756 llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_newclass");
757 std::vector<llvm::Value*> args; 757 std::vector<llvm::Value*> args;
758 args.push_back(gIR->irDsymbol[tc->sym].irStruct->classInfo); 758 args.push_back(tc->sym->ir.irStruct->classInfo);
759 mem = gIR->ir->CreateCall(fn, args.begin(), args.end(), "newclass_gc_alloc"); 759 mem = gIR->ir->CreateCall(fn, args.begin(), args.end(), "newclass_gc_alloc");
760 mem = DtoBitCast(mem, DtoType(tc), "newclass_gc"); 760 mem = DtoBitCast(mem, DtoType(tc), "newclass_gc");
761 } 761 }
762 762
763 // init 763 // init
767 if (newexp->thisexp) 767 if (newexp->thisexp)
768 { 768 {
769 Logger::println("Resolving outer class"); 769 Logger::println("Resolving outer class");
770 LOG_SCOPE; 770 LOG_SCOPE;
771 DValue* thisval = newexp->thisexp->toElem(gIR); 771 DValue* thisval = newexp->thisexp->toElem(gIR);
772 size_t idx = 2 + gIR->irDsymbol[tc->sym->vthis].irField->index; 772 size_t idx = 2 + tc->sym->vthis->ir.irField->index;
773 llvm::Value* src = thisval->getRVal(); 773 llvm::Value* src = thisval->getRVal();
774 llvm::Value* dst = DtoGEPi(mem,0,idx,"tmp"); 774 llvm::Value* dst = DtoGEPi(mem,0,idx,"tmp");
775 Logger::cout() << "dst: " << *dst << "\nsrc: " << *src << '\n'; 775 Logger::cout() << "dst: " << *dst << "\nsrc: " << *src << '\n';
776 DtoStore(src, dst); 776 DtoStore(src, dst);
777 } 777 }
779 else if (tc->sym->isNested()) 779 else if (tc->sym->isNested())
780 { 780 {
781 Logger::println("Resolving nested context"); 781 Logger::println("Resolving nested context");
782 LOG_SCOPE; 782 LOG_SCOPE;
783 size_t idx = 2; 783 size_t idx = 2;
784 //idx += gIR->irDsymbol[tc->sym].irStruct->interfaces.size(); 784 //idx += tc->sym->ir.irStruct->interfaces.size();
785 llvm::Value* nest = gIR->irDsymbol[gIR->func()->decl].irFunc->nestedVar; 785 llvm::Value* nest = gIR->func()->decl->ir.irFunc->nestedVar;
786 if (!nest) 786 if (!nest)
787 nest = gIR->irDsymbol[gIR->func()->decl].irFunc->thisVar; 787 nest = gIR->func()->decl->ir.irFunc->thisVar;
788 assert(nest); 788 assert(nest);
789 llvm::Value* gep = DtoGEPi(mem,0,idx,"tmp"); 789 llvm::Value* gep = DtoGEPi(mem,0,idx,"tmp");
790 nest = DtoBitCast(nest, gep->getType()->getContainedType(0)); 790 nest = DtoBitCast(nest, gep->getType()->getContainedType(0));
791 DtoStore(nest, gep); 791 DtoStore(nest, gep);
792 } 792 }
805 ////////////////////////////////////////////////////////////////////////////////////////// 805 //////////////////////////////////////////////////////////////////////////////////////////
806 806
807 void DtoInitClass(TypeClass* tc, llvm::Value* dst) 807 void DtoInitClass(TypeClass* tc, llvm::Value* dst)
808 { 808 {
809 size_t presz = 2*getABITypeSize(DtoSize_t()); 809 size_t presz = 2*getABITypeSize(DtoSize_t());
810 uint64_t n = getABITypeSize(gIR->irType[tc].type->get()) - presz; 810 uint64_t n = getABITypeSize(tc->ir.type->get()) - presz;
811 811
812 // set vtable field seperately, this might give better optimization 812 // set vtable field seperately, this might give better optimization
813 assert(gIR->irDsymbol[tc->sym].irStruct->vtbl); 813 assert(tc->sym->ir.irStruct->vtbl);
814 DtoStore(gIR->irDsymbol[tc->sym].irStruct->vtbl, DtoGEPi(dst,0,0,"vtbl")); 814 DtoStore(tc->sym->ir.irStruct->vtbl, DtoGEPi(dst,0,0,"vtbl"));
815 815
816 // monitor always defaults to zero 816 // monitor always defaults to zero
817 llvm::Value* tmp = DtoGEPi(dst,0,1,"monitor"); 817 llvm::Value* tmp = DtoGEPi(dst,0,1,"monitor");
818 DtoStore(llvm::Constant::getNullValue(tmp->getType()->getContainedType(0)), tmp); 818 DtoStore(llvm::Constant::getNullValue(tmp->getType()->getContainedType(0)), tmp);
819 819
820 // done? 820 // done?
821 if (n == 0) 821 if (n == 0)
822 return; 822 return;
823 823
824 // copy the rest from the static initializer 824 // copy the rest from the static initializer
825 assert(gIR->irDsymbol[tc->sym].irStruct->init); 825 assert(tc->sym->ir.irStruct->init);
826 assert(dst->getType() == gIR->irDsymbol[tc->sym].irStruct->init->getType()); 826 assert(dst->getType() == tc->sym->ir.irStruct->init->getType());
827 827
828 const llvm::Type* arrty = getPtrToType(llvm::Type::Int8Ty); 828 const llvm::Type* arrty = getPtrToType(llvm::Type::Int8Ty);
829 829
830 llvm::Value* dstarr = DtoGEPi(dst,0,2,"tmp"); 830 llvm::Value* dstarr = DtoGEPi(dst,0,2,"tmp");
831 dstarr = DtoBitCast(dstarr, arrty); 831 dstarr = DtoBitCast(dstarr, arrty);
832 832
833 llvm::Value* srcarr = DtoGEPi(gIR->irDsymbol[tc->sym].irStruct->init,0,2,"tmp"); 833 llvm::Value* srcarr = DtoGEPi(tc->sym->ir.irStruct->init,0,2,"tmp");
834 srcarr = DtoBitCast(srcarr, arrty); 834 srcarr = DtoBitCast(srcarr, arrty);
835 835
836 llvm::Function* fn = LLVM_DeclareMemCpy32(); 836 llvm::Function* fn = LLVM_DeclareMemCpy32();
837 std::vector<llvm::Value*> llargs; 837 std::vector<llvm::Value*> llargs;
838 llargs.resize(4); 838 llargs.resize(4);
851 Logger::println("Calling constructor"); 851 Logger::println("Calling constructor");
852 LOG_SCOPE; 852 LOG_SCOPE;
853 853
854 assert(ctor); 854 assert(ctor);
855 DtoForceDeclareDsymbol(ctor); 855 DtoForceDeclareDsymbol(ctor);
856 llvm::Function* fn = gIR->irDsymbol[ctor].irFunc->func; 856 llvm::Function* fn = ctor->ir.irFunc->func;
857 TypeFunction* tf = (TypeFunction*)DtoDType(ctor->type); 857 TypeFunction* tf = (TypeFunction*)DtoDType(ctor->type);
858 858
859 std::vector<llvm::Value*> ctorargs; 859 std::vector<llvm::Value*> ctorargs;
860 ctorargs.push_back(mem); 860 ctorargs.push_back(mem);
861 for (size_t i=0; i<arguments->dim; ++i) 861 for (size_t i=0; i<arguments->dim; ++i)
881 { 881 {
882 Array* arr = &tc->sym->dtors; 882 Array* arr = &tc->sym->dtors;
883 for (size_t i=0; i<arr->dim; i++) 883 for (size_t i=0; i<arr->dim; i++)
884 { 884 {
885 FuncDeclaration* fd = (FuncDeclaration*)arr->data[i]; 885 FuncDeclaration* fd = (FuncDeclaration*)arr->data[i];
886 assert(gIR->irDsymbol[fd].irFunc->func); 886 assert(fd->ir.irFunc->func);
887 new llvm::CallInst(gIR->irDsymbol[fd].irFunc->func, instance, "", gIR->scopebb()); 887 new llvm::CallInst(fd->ir.irFunc->func, instance, "", gIR->scopebb());
888 } 888 }
889 } 889 }
890 890
891 ////////////////////////////////////////////////////////////////////////////////////////// 891 //////////////////////////////////////////////////////////////////////////////////////////
892 892
961 assert(funcTy->getParamType(0) == tmp->getType()); 961 assert(funcTy->getParamType(0) == tmp->getType());
962 962
963 // ClassInfo c 963 // ClassInfo c
964 TypeClass* to = (TypeClass*)DtoDType(_to); 964 TypeClass* to = (TypeClass*)DtoDType(_to);
965 DtoForceDeclareDsymbol(to->sym); 965 DtoForceDeclareDsymbol(to->sym);
966 assert(gIR->irDsymbol[to->sym].irStruct->classInfo); 966 assert(to->sym->ir.irStruct->classInfo);
967 tmp = gIR->irDsymbol[to->sym].irStruct->classInfo; 967 tmp = to->sym->ir.irStruct->classInfo;
968 // unfortunately this is needed as the implementation of object differs somehow from the declaration 968 // unfortunately this is needed as the implementation of object differs somehow from the declaration
969 // this could happen in user code as well :/ 969 // this could happen in user code as well :/
970 tmp = DtoBitCast(tmp, funcTy->getParamType(1)); 970 tmp = DtoBitCast(tmp, funcTy->getParamType(1));
971 args.push_back(tmp); 971 args.push_back(tmp);
972 assert(funcTy->getParamType(1) == tmp->getType()); 972 assert(funcTy->getParamType(1) == tmp->getType());
1027 args.push_back(tmp); 1027 args.push_back(tmp);
1028 1028
1029 // ClassInfo c 1029 // ClassInfo c
1030 TypeClass* to = (TypeClass*)DtoDType(_to); 1030 TypeClass* to = (TypeClass*)DtoDType(_to);
1031 DtoForceDeclareDsymbol(to->sym); 1031 DtoForceDeclareDsymbol(to->sym);
1032 assert(gIR->irDsymbol[to->sym].irStruct->classInfo); 1032 assert(to->sym->ir.irStruct->classInfo);
1033 tmp = gIR->irDsymbol[to->sym].irStruct->classInfo; 1033 tmp = to->sym->ir.irStruct->classInfo;
1034 // unfortunately this is needed as the implementation of object differs somehow from the declaration 1034 // unfortunately this is needed as the implementation of object differs somehow from the declaration
1035 // this could happen in user code as well :/ 1035 // this could happen in user code as well :/
1036 tmp = DtoBitCast(tmp, funcTy->getParamType(1)); 1036 tmp = DtoBitCast(tmp, funcTy->getParamType(1));
1037 args.push_back(tmp); 1037 args.push_back(tmp);
1038 1038
1093 if (idxs.empty()) 1093 if (idxs.empty())
1094 idxs.push_back(0); 1094 idxs.push_back(0);
1095 1095
1096 const llvm::Type* st = DtoType(cd->type); 1096 const llvm::Type* st = DtoType(cd->type);
1097 if (ptr->getType() != st) { 1097 if (ptr->getType() != st) {
1098 //assert(gIR->irDsymbol[cd].irStruct->hasUnions); 1098 //assert(cd->ir.irStruct->hasUnions);
1099 ptr = gIR->ir->CreateBitCast(ptr, st, "tmp"); 1099 ptr = gIR->ir->CreateBitCast(ptr, st, "tmp");
1100 } 1100 }
1101 1101
1102 const llvm::Type* llt = getPtrToType(DtoType(t)); 1102 const llvm::Type* llt = getPtrToType(DtoType(t));
1103 unsigned dataoffset = 2; 1103 unsigned dataoffset = 2;
1104 1104
1105 IrStruct* irstruct = gIR->irDsymbol[cd].irStruct; 1105 IrStruct* irstruct = cd->ir.irStruct;
1106 for (IrStruct::OffsetMap::iterator i=irstruct->offsets.begin(); i!=irstruct->offsets.end(); ++i) { 1106 for (IrStruct::OffsetMap::iterator i=irstruct->offsets.begin(); i!=irstruct->offsets.end(); ++i) {
1107 //for (unsigned i=0; i<cd->fields.dim; ++i) { 1107 //for (unsigned i=0; i<cd->fields.dim; ++i) {
1108 //VarDeclaration* vd = (VarDeclaration*)cd->fields.data[i]; 1108 //VarDeclaration* vd = (VarDeclaration*)cd->fields.data[i];
1109 VarDeclaration* vd = i->second.var; 1109 VarDeclaration* vd = i->second.var;
1110 assert(vd); 1110 assert(vd);
1111 Type* vdtype = DtoDType(vd->type); 1111 Type* vdtype = DtoDType(vd->type);
1112 //Logger::println("found %u type %s", vd->offset, vdtype->toChars()); 1112 //Logger::println("found %u type %s", vd->offset, vdtype->toChars());
1113 assert(gIR->irDsymbol[vd].irField->index >= 0); 1113 assert(vd->ir.irField->index >= 0);
1114 if (os == vd->offset && vdtype == t) { 1114 if (os == vd->offset && vdtype == t) {
1115 Logger::println("found %s %s", vdtype->toChars(), vd->toChars()); 1115 Logger::println("found %s %s", vdtype->toChars(), vd->toChars());
1116 idxs.push_back(gIR->irDsymbol[vd].irField->index + dataoffset); 1116 idxs.push_back(vd->ir.irField->index + dataoffset);
1117 //Logger::cout() << "indexing: " << *ptr << '\n'; 1117 //Logger::cout() << "indexing: " << *ptr << '\n';
1118 ptr = DtoGEP(ptr, idxs, "tmp"); 1118 ptr = DtoGEP(ptr, idxs, "tmp");
1119 if (ptr->getType() != llt) 1119 if (ptr->getType() != llt)
1120 ptr = gIR->ir->CreateBitCast(ptr, llt, "tmp"); 1120 ptr = gIR->ir->CreateBitCast(ptr, llt, "tmp");
1121 //Logger::cout() << "indexing: " << *ptr << '\n'; 1121 //Logger::cout() << "indexing: " << *ptr << '\n';
1122 if (gIR->irDsymbol[vd].irField->indexOffset) 1122 if (vd->ir.irField->indexOffset)
1123 ptr = new llvm::GetElementPtrInst(ptr, DtoConstUint(gIR->irDsymbol[vd].irField->indexOffset), "tmp", gIR->scopebb()); 1123 ptr = new llvm::GetElementPtrInst(ptr, DtoConstUint(vd->ir.irField->indexOffset), "tmp", gIR->scopebb());
1124 //Logger::cout() << "indexing: " << *ptr << '\n'; 1124 //Logger::cout() << "indexing: " << *ptr << '\n';
1125 return ptr; 1125 return ptr;
1126 } 1126 }
1127 else if (vdtype->ty == Tstruct && (vd->offset + vdtype->size()) > os) { 1127 else if (vdtype->ty == Tstruct && (vd->offset + vdtype->size()) > os) {
1128 TypeStruct* ts = (TypeStruct*)vdtype; 1128 TypeStruct* ts = (TypeStruct*)vdtype;
1129 StructDeclaration* ssd = ts->sym; 1129 StructDeclaration* ssd = ts->sym;
1130 idxs.push_back(gIR->irDsymbol[vd].irField->index + dataoffset); 1130 idxs.push_back(vd->ir.irField->index + dataoffset);
1131 if (gIR->irDsymbol[vd].irField->indexOffset) { 1131 if (vd->ir.irField->indexOffset) {
1132 Logger::println("has union field offset"); 1132 Logger::println("has union field offset");
1133 ptr = DtoGEP(ptr, idxs, "tmp"); 1133 ptr = DtoGEP(ptr, idxs, "tmp");
1134 if (ptr->getType() != llt) 1134 if (ptr->getType() != llt)
1135 ptr = gIR->ir->CreateBitCast(ptr, llt, "tmp"); 1135 ptr = gIR->ir->CreateBitCast(ptr, llt, "tmp");
1136 ptr = new llvm::GetElementPtrInst(ptr, DtoConstUint(gIR->irDsymbol[vd].irField->indexOffset), "tmp", gIR->scopebb()); 1136 ptr = new llvm::GetElementPtrInst(ptr, DtoConstUint(vd->ir.irField->indexOffset), "tmp", gIR->scopebb());
1137 std::vector<unsigned> tmp; 1137 std::vector<unsigned> tmp;
1138 return DtoIndexStruct(ptr, ssd, t, os-vd->offset, tmp); 1138 return DtoIndexStruct(ptr, ssd, t, os-vd->offset, tmp);
1139 } 1139 }
1140 else { 1140 else {
1141 const llvm::Type* sty = getPtrToType(DtoType(vd->type)); 1141 const llvm::Type* sty = getPtrToType(DtoType(vd->type));
1184 1184
1185 ////////////////////////////////////////////////////////////////////////////////////////// 1185 //////////////////////////////////////////////////////////////////////////////////////////
1186 1186
1187 void DtoDeclareClassInfo(ClassDeclaration* cd) 1187 void DtoDeclareClassInfo(ClassDeclaration* cd)
1188 { 1188 {
1189 if (gIR->irDsymbol[cd].irStruct->classDeclared) return; 1189 if (cd->ir.irStruct->classDeclared) return;
1190 gIR->irDsymbol[cd].irStruct->classDeclared = true; 1190 cd->ir.irStruct->classDeclared = true;
1191 1191
1192 Logger::println("DtoDeclareClassInfo(%s)", cd->toChars()); 1192 Logger::println("DtoDeclareClassInfo(%s)", cd->toChars());
1193 LOG_SCOPE; 1193 LOG_SCOPE;
1194 1194
1195 ClassDeclaration* cinfo = ClassDeclaration::classinfo; 1195 ClassDeclaration* cinfo = ClassDeclaration::classinfo;
1200 if (!cd->isInterfaceDeclaration()) 1200 if (!cd->isInterfaceDeclaration())
1201 gname.append("7__ClassZ"); 1201 gname.append("7__ClassZ");
1202 else 1202 else
1203 gname.append("11__InterfaceZ"); 1203 gname.append("11__InterfaceZ");
1204 1204
1205 const llvm::Type* st = gIR->irType[cinfo->type].type->get(); 1205 const llvm::Type* st = cinfo->type->ir.type->get();
1206 1206
1207 gIR->irDsymbol[cd].irStruct->classInfo = new llvm::GlobalVariable(st, true, DtoLinkage(cd), NULL, gname, gIR->module); 1207 cd->ir.irStruct->classInfo = new llvm::GlobalVariable(st, true, DtoLinkage(cd), NULL, gname, gIR->module);
1208 } 1208 }
1209 1209
1210 static llvm::Constant* build_offti_entry(VarDeclaration* vd) 1210 static llvm::Constant* build_offti_entry(VarDeclaration* vd)
1211 { 1211 {
1212 std::vector<const llvm::Type*> types; 1212 std::vector<const llvm::Type*> types;
1223 inits.push_back(DtoConstSize_t(offset)); 1223 inits.push_back(DtoConstSize_t(offset));
1224 1224
1225 vd->type->getTypeInfo(NULL); 1225 vd->type->getTypeInfo(NULL);
1226 assert(vd->type->vtinfo); 1226 assert(vd->type->vtinfo);
1227 DtoForceDeclareDsymbol(vd->type->vtinfo); 1227 DtoForceDeclareDsymbol(vd->type->vtinfo);
1228 llvm::Constant* c = isaConstant(gIR->irDsymbol[vd->type->vtinfo].getIrValue()); 1228 llvm::Constant* c = isaConstant(vd->type->vtinfo->ir.getIrValue());
1229 1229
1230 const llvm::Type* tiTy = getPtrToType(gIR->irType[Type::typeinfo->type].type->get()); 1230 const llvm::Type* tiTy = getPtrToType(Type::typeinfo->type->ir.type->get());
1231 //Logger::cout() << "tiTy = " << *tiTy << '\n'; 1231 //Logger::cout() << "tiTy = " << *tiTy << '\n';
1232 1232
1233 types.push_back(tiTy); 1233 types.push_back(tiTy);
1234 inits.push_back(llvm::ConstantExpr::getBitCast(c, tiTy)); 1234 inits.push_back(llvm::ConstantExpr::getBitCast(c, tiTy));
1235 1235
1266 1266
1267 if (ninits > 0) { 1267 if (ninits > 0) {
1268 // OffsetTypeInfo type 1268 // OffsetTypeInfo type
1269 std::vector<const llvm::Type*> elemtypes; 1269 std::vector<const llvm::Type*> elemtypes;
1270 elemtypes.push_back(DtoSize_t()); 1270 elemtypes.push_back(DtoSize_t());
1271 const llvm::Type* tiTy = getPtrToType(gIR->irType[Type::typeinfo->type].type->get()); 1271 const llvm::Type* tiTy = getPtrToType(Type::typeinfo->type->ir.type->get());
1272 elemtypes.push_back(tiTy); 1272 elemtypes.push_back(tiTy);
1273 const llvm::StructType* sTy = llvm::StructType::get(elemtypes); 1273 const llvm::StructType* sTy = llvm::StructType::get(elemtypes);
1274 1274
1275 // array type 1275 // array type
1276 const llvm::ArrayType* arrTy = llvm::ArrayType::get(sTy, ninits); 1276 const llvm::ArrayType* arrTy = llvm::ArrayType::get(sTy, ninits);
1291 1291
1292 static llvm::Constant* build_class_dtor(ClassDeclaration* cd) 1292 static llvm::Constant* build_class_dtor(ClassDeclaration* cd)
1293 { 1293 {
1294 // construct the function 1294 // construct the function
1295 std::vector<const llvm::Type*> paramTypes; 1295 std::vector<const llvm::Type*> paramTypes;
1296 paramTypes.push_back(getPtrToType(gIR->irType[cd->type].type->get())); 1296 paramTypes.push_back(getPtrToType(cd->type->ir.type->get()));
1297 1297
1298 const llvm::FunctionType* fnTy = llvm::FunctionType::get(llvm::Type::VoidTy, paramTypes, false); 1298 const llvm::FunctionType* fnTy = llvm::FunctionType::get(llvm::Type::VoidTy, paramTypes, false);
1299 1299
1300 if (cd->dtors.dim == 0) { 1300 if (cd->dtors.dim == 0) {
1301 return llvm::ConstantPointerNull::get(getPtrToType(llvm::Type::Int8Ty)); 1301 return llvm::ConstantPointerNull::get(getPtrToType(llvm::Type::Int8Ty));
1302 } 1302 }
1303 else if (cd->dtors.dim == 1) { 1303 else if (cd->dtors.dim == 1) {
1304 DtorDeclaration *d = (DtorDeclaration *)cd->dtors.data[0]; 1304 DtorDeclaration *d = (DtorDeclaration *)cd->dtors.data[0];
1305 DtoForceDeclareDsymbol(d); 1305 DtoForceDeclareDsymbol(d);
1306 assert(gIR->irDsymbol[d].irFunc->func); 1306 assert(d->ir.irFunc->func);
1307 return llvm::ConstantExpr::getBitCast(isaConstant(gIR->irDsymbol[d].irFunc->func), getPtrToType(llvm::Type::Int8Ty)); 1307 return llvm::ConstantExpr::getBitCast(isaConstant(d->ir.irFunc->func), getPtrToType(llvm::Type::Int8Ty));
1308 } 1308 }
1309 1309
1310 std::string gname("_D"); 1310 std::string gname("_D");
1311 gname.append(cd->mangle()); 1311 gname.append(cd->mangle());
1312 gname.append("12__destructorMFZv"); 1312 gname.append("12__destructorMFZv");
1320 1320
1321 for (size_t i = 0; i < cd->dtors.dim; i++) 1321 for (size_t i = 0; i < cd->dtors.dim; i++)
1322 { 1322 {
1323 DtorDeclaration *d = (DtorDeclaration *)cd->dtors.data[i]; 1323 DtorDeclaration *d = (DtorDeclaration *)cd->dtors.data[i];
1324 DtoForceDeclareDsymbol(d); 1324 DtoForceDeclareDsymbol(d);
1325 assert(gIR->irDsymbol[d].irFunc->func); 1325 assert(d->ir.irFunc->func);
1326 builder.CreateCall(gIR->irDsymbol[d].irFunc->func, thisptr); 1326 builder.CreateCall(d->ir.irFunc->func, thisptr);
1327 } 1327 }
1328 builder.CreateRetVoid(); 1328 builder.CreateRetVoid();
1329 1329
1330 return llvm::ConstantExpr::getBitCast(func, getPtrToType(llvm::Type::Int8Ty)); 1330 return llvm::ConstantExpr::getBitCast(func, getPtrToType(llvm::Type::Int8Ty));
1331 } 1331 }
1376 // void *deallocator; 1376 // void *deallocator;
1377 // OffsetTypeInfo[] offTi; 1377 // OffsetTypeInfo[] offTi;
1378 // void *defaultConstructor; 1378 // void *defaultConstructor;
1379 // } 1379 // }
1380 1380
1381 if (gIR->irDsymbol[cd].irStruct->classDefined) return; 1381 if (cd->ir.irStruct->classDefined) return;
1382 gIR->irDsymbol[cd].irStruct->classDefined = true; 1382 cd->ir.irStruct->classDefined = true;
1383 1383
1384 Logger::println("DtoDefineClassInfo(%s)", cd->toChars()); 1384 Logger::println("DtoDefineClassInfo(%s)", cd->toChars());
1385 LOG_SCOPE; 1385 LOG_SCOPE;
1386 1386
1387 assert(cd->type->ty == Tclass); 1387 assert(cd->type->ty == Tclass);
1388 assert(gIR->irDsymbol[cd].irStruct->classInfo); 1388 assert(cd->ir.irStruct->classInfo);
1389 1389
1390 TypeClass* cdty = (TypeClass*)cd->type; 1390 TypeClass* cdty = (TypeClass*)cd->type;
1391 if (!cd->isInterfaceDeclaration() && !cd->isAbstract()) { 1391 if (!cd->isInterfaceDeclaration() && !cd->isAbstract()) {
1392 assert(gIR->irDsymbol[cd].irStruct->init); 1392 assert(cd->ir.irStruct->init);
1393 assert(gIR->irDsymbol[cd].irStruct->constInit); 1393 assert(cd->ir.irStruct->constInit);
1394 assert(gIR->irDsymbol[cd].irStruct->vtbl); 1394 assert(cd->ir.irStruct->vtbl);
1395 assert(gIR->irDsymbol[cd].irStruct->constVtbl); 1395 assert(cd->ir.irStruct->constVtbl);
1396 } 1396 }
1397 1397
1398 // holds the list of initializers for llvm 1398 // holds the list of initializers for llvm
1399 std::vector<llvm::Constant*> inits; 1399 std::vector<llvm::Constant*> inits;
1400 1400
1401 ClassDeclaration* cinfo = ClassDeclaration::classinfo; 1401 ClassDeclaration* cinfo = ClassDeclaration::classinfo;
1402 DtoForceConstInitDsymbol(cinfo); 1402 DtoForceConstInitDsymbol(cinfo);
1403 assert(gIR->irDsymbol[cinfo].irStruct->constInit); 1403 assert(cinfo->ir.irStruct->constInit);
1404 1404
1405 llvm::Constant* c; 1405 llvm::Constant* c;
1406 1406
1407 // own vtable 1407 // own vtable
1408 c = gIR->irDsymbol[cinfo].irStruct->constInit->getOperand(0); 1408 c = cinfo->ir.irStruct->constInit->getOperand(0);
1409 assert(c); 1409 assert(c);
1410 inits.push_back(c); 1410 inits.push_back(c);
1411 1411
1412 // monitor 1412 // monitor
1413 c = gIR->irDsymbol[cinfo].irStruct->constInit->getOperand(1); 1413 c = cinfo->ir.irStruct->constInit->getOperand(1);
1414 inits.push_back(c); 1414 inits.push_back(c);
1415 1415
1416 // byte[] init 1416 // byte[] init
1417 const llvm::Type* byteptrty = getPtrToType(llvm::Type::Int8Ty); 1417 const llvm::Type* byteptrty = getPtrToType(llvm::Type::Int8Ty);
1418 if (cd->isInterfaceDeclaration() || cd->isAbstract()) { 1418 if (cd->isInterfaceDeclaration() || cd->isAbstract()) {
1419 c = gIR->irDsymbol[cinfo].irStruct->constInit->getOperand(2); 1419 c = cinfo->ir.irStruct->constInit->getOperand(2);
1420 } 1420 }
1421 else { 1421 else {
1422 c = llvm::ConstantExpr::getBitCast(gIR->irDsymbol[cd].irStruct->init, byteptrty); 1422 c = llvm::ConstantExpr::getBitCast(cd->ir.irStruct->init, byteptrty);
1423 assert(!gIR->irDsymbol[cd].irStruct->constInit->getType()->isAbstract()); 1423 assert(!cd->ir.irStruct->constInit->getType()->isAbstract());
1424 size_t initsz = getABITypeSize(gIR->irDsymbol[cd].irStruct->constInit->getType()); 1424 size_t initsz = getABITypeSize(cd->ir.irStruct->constInit->getType());
1425 c = DtoConstSlice(DtoConstSize_t(initsz), c); 1425 c = DtoConstSlice(DtoConstSize_t(initsz), c);
1426 } 1426 }
1427 inits.push_back(c); 1427 inits.push_back(c);
1428 1428
1429 // class name 1429 // class name
1438 c = DtoConstString(name); 1438 c = DtoConstString(name);
1439 inits.push_back(c); 1439 inits.push_back(c);
1440 1440
1441 // vtbl array 1441 // vtbl array
1442 if (cd->isInterfaceDeclaration() || cd->isAbstract()) { 1442 if (cd->isInterfaceDeclaration() || cd->isAbstract()) {
1443 c = gIR->irDsymbol[cinfo].irStruct->constInit->getOperand(4); 1443 c = cinfo->ir.irStruct->constInit->getOperand(4);
1444 } 1444 }
1445 else { 1445 else {
1446 const llvm::Type* byteptrptrty = getPtrToType(byteptrty); 1446 const llvm::Type* byteptrptrty = getPtrToType(byteptrty);
1447 assert(!gIR->irDsymbol[cd].irStruct->vtbl->getType()->isAbstract()); 1447 assert(!cd->ir.irStruct->vtbl->getType()->isAbstract());
1448 c = llvm::ConstantExpr::getBitCast(gIR->irDsymbol[cd].irStruct->vtbl, byteptrptrty); 1448 c = llvm::ConstantExpr::getBitCast(cd->ir.irStruct->vtbl, byteptrptrty);
1449 assert(!gIR->irDsymbol[cd].irStruct->constVtbl->getType()->isAbstract()); 1449 assert(!cd->ir.irStruct->constVtbl->getType()->isAbstract());
1450 size_t vtblsz = gIR->irDsymbol[cd].irStruct->constVtbl->getType()->getNumElements(); 1450 size_t vtblsz = cd->ir.irStruct->constVtbl->getType()->getNumElements();
1451 c = DtoConstSlice(DtoConstSize_t(vtblsz), c); 1451 c = DtoConstSlice(DtoConstSize_t(vtblsz), c);
1452 } 1452 }
1453 inits.push_back(c); 1453 inits.push_back(c);
1454 1454
1455 // interfaces array 1455 // interfaces array
1456 IrStruct* irstruct = gIR->irDsymbol[cd].irStruct; 1456 IrStruct* irstruct = cd->ir.irStruct;
1457 if (cd->isInterfaceDeclaration() || !irstruct->interfaceInfos || cd->isAbstract()) { 1457 if (cd->isInterfaceDeclaration() || !irstruct->interfaceInfos || cd->isAbstract()) {
1458 c = gIR->irDsymbol[cinfo].irStruct->constInit->getOperand(5); 1458 c = cinfo->ir.irStruct->constInit->getOperand(5);
1459 } 1459 }
1460 else { 1460 else {
1461 const llvm::Type* t = gIR->irDsymbol[cinfo].irStruct->constInit->getOperand(5)->getType()->getContainedType(1); 1461 const llvm::Type* t = cinfo->ir.irStruct->constInit->getOperand(5)->getType()->getContainedType(1);
1462 c = llvm::ConstantExpr::getBitCast(irstruct->interfaceInfos, t); 1462 c = llvm::ConstantExpr::getBitCast(irstruct->interfaceInfos, t);
1463 size_t iisz = irstruct->interfaceInfosTy->getNumElements(); 1463 size_t iisz = irstruct->interfaceInfosTy->getNumElements();
1464 c = DtoConstSlice(DtoConstSize_t(iisz), c); 1464 c = DtoConstSlice(DtoConstSize_t(iisz), c);
1465 } 1465 }
1466 inits.push_back(c); 1466 inits.push_back(c);
1467 1467
1468 // base classinfo 1468 // base classinfo
1469 if (cd->baseClass && !cd->isInterfaceDeclaration() && !cd->isAbstract()) { 1469 if (cd->baseClass && !cd->isInterfaceDeclaration() && !cd->isAbstract()) {
1470 DtoDeclareClassInfo(cd->baseClass); 1470 DtoDeclareClassInfo(cd->baseClass);
1471 c = gIR->irDsymbol[cd->baseClass].irStruct->classInfo; 1471 c = cd->baseClass->ir.irStruct->classInfo;
1472 assert(c); 1472 assert(c);
1473 inits.push_back(c); 1473 inits.push_back(c);
1474 } 1474 }
1475 else { 1475 else {
1476 // null 1476 // null
1477 c = gIR->irDsymbol[cinfo].irStruct->constInit->getOperand(6); 1477 c = cinfo->ir.irStruct->constInit->getOperand(6);
1478 inits.push_back(c); 1478 inits.push_back(c);
1479 } 1479 }
1480 1480
1481 // destructor 1481 // destructor
1482 if (cd->isInterfaceDeclaration() || cd->isAbstract()) { 1482 if (cd->isInterfaceDeclaration() || cd->isAbstract()) {
1483 c = gIR->irDsymbol[cinfo].irStruct->constInit->getOperand(7); 1483 c = cinfo->ir.irStruct->constInit->getOperand(7);
1484 } 1484 }
1485 else { 1485 else {
1486 c = build_class_dtor(cd); 1486 c = build_class_dtor(cd);
1487 } 1487 }
1488 inits.push_back(c); 1488 inits.push_back(c);
1489 1489
1490 // invariant 1490 // invariant
1491 // TODO 1491 // TODO
1492 c = gIR->irDsymbol[cinfo].irStruct->constInit->getOperand(8); 1492 c = cinfo->ir.irStruct->constInit->getOperand(8);
1493 inits.push_back(c); 1493 inits.push_back(c);
1494 1494
1495 // uint flags 1495 // uint flags
1496 if (cd->isInterfaceDeclaration() || cd->isAbstract()) { 1496 if (cd->isInterfaceDeclaration() || cd->isAbstract()) {
1497 c = gIR->irDsymbol[cinfo].irStruct->constInit->getOperand(9); 1497 c = cinfo->ir.irStruct->constInit->getOperand(9);
1498 } 1498 }
1499 else { 1499 else {
1500 uint flags = build_classinfo_flags(cd); 1500 uint flags = build_classinfo_flags(cd);
1501 c = DtoConstUint(flags); 1501 c = DtoConstUint(flags);
1502 } 1502 }
1503 inits.push_back(c); 1503 inits.push_back(c);
1504 1504
1505 // allocator 1505 // allocator
1506 // TODO 1506 // TODO
1507 c = gIR->irDsymbol[cinfo].irStruct->constInit->getOperand(10); 1507 c = cinfo->ir.irStruct->constInit->getOperand(10);
1508 inits.push_back(c); 1508 inits.push_back(c);
1509 1509
1510 // offset typeinfo 1510 // offset typeinfo
1511 if (cd->isInterfaceDeclaration() || cd->isAbstract()) { 1511 if (cd->isInterfaceDeclaration() || cd->isAbstract()) {
1512 c = gIR->irDsymbol[cinfo].irStruct->constInit->getOperand(11); 1512 c = cinfo->ir.irStruct->constInit->getOperand(11);
1513 } 1513 }
1514 else { 1514 else {
1515 c = build_offti_array(cd, gIR->irDsymbol[cinfo].irStruct->constInit->getOperand(11)); 1515 c = build_offti_array(cd, cinfo->ir.irStruct->constInit->getOperand(11));
1516 } 1516 }
1517 inits.push_back(c); 1517 inits.push_back(c);
1518 1518
1519 // default constructor 1519 // default constructor
1520 if (cd->defaultCtor && !cd->isInterfaceDeclaration() && !cd->isAbstract()) { 1520 if (cd->defaultCtor && !cd->isInterfaceDeclaration() && !cd->isAbstract()) {
1521 DtoForceDeclareDsymbol(cd->defaultCtor); 1521 DtoForceDeclareDsymbol(cd->defaultCtor);
1522 c = isaConstant(gIR->irDsymbol[cd->defaultCtor].irFunc->func); 1522 c = isaConstant(cd->defaultCtor->ir.irFunc->func);
1523 const llvm::Type* toTy = gIR->irDsymbol[cinfo].irStruct->constInit->getOperand(12)->getType(); 1523 const llvm::Type* toTy = cinfo->ir.irStruct->constInit->getOperand(12)->getType();
1524 c = llvm::ConstantExpr::getBitCast(c, toTy); 1524 c = llvm::ConstantExpr::getBitCast(c, toTy);
1525 } 1525 }
1526 else { 1526 else {
1527 c = gIR->irDsymbol[cinfo].irStruct->constInit->getOperand(12); 1527 c = cinfo->ir.irStruct->constInit->getOperand(12);
1528 } 1528 }
1529 inits.push_back(c); 1529 inits.push_back(c);
1530 1530
1531 /*size_t n = inits.size(); 1531 /*size_t n = inits.size();
1532 for (size_t i=0; i<n; ++i) 1532 for (size_t i=0; i<n; ++i)
1533 { 1533 {
1534 Logger::cout() << "inits[" << i << "]: " << *inits[i] << '\n'; 1534 Logger::cout() << "inits[" << i << "]: " << *inits[i] << '\n';
1535 }*/ 1535 }*/
1536 1536
1537 // build the initializer 1537 // build the initializer
1538 const llvm::StructType* st = isaStruct(gIR->irDsymbol[cinfo].irStruct->constInit->getType()); 1538 const llvm::StructType* st = isaStruct(cinfo->ir.irStruct->constInit->getType());
1539 llvm::Constant* finalinit = llvm::ConstantStruct::get(st, inits); 1539 llvm::Constant* finalinit = llvm::ConstantStruct::get(st, inits);
1540 //Logger::cout() << "built the classinfo initializer:\n" << *finalinit <<'\n'; 1540 //Logger::cout() << "built the classinfo initializer:\n" << *finalinit <<'\n';
1541 1541
1542 gIR->irDsymbol[cd].irStruct->constClassInfo = finalinit; 1542 cd->ir.irStruct->constClassInfo = finalinit;
1543 gIR->irDsymbol[cd].irStruct->classInfo->setInitializer(finalinit); 1543 cd->ir.irStruct->classInfo->setInitializer(finalinit);
1544 } 1544 }