comparison gen/toobj.cpp @ 132:1700239cab2e trunk

[svn r136] MAJOR UNSTABLE UPDATE!!! Initial commit after moving to Tango instead of Phobos. Lots of bugfixes... This build is not suitable for most things.
author lindquist
date Fri, 11 Jan 2008 17:57:40 +0100
parents 5825d48b27d1
children 44a95ac7368a
comparison
equal deleted inserted replaced
131:5825d48b27d1 132:1700239cab2e
349 // fill inits 349 // fill inits
350 std::vector<llvm::Constant*> classInits; 350 std::vector<llvm::Constant*> classInits;
351 for (size_t i = 0; i < aclasses.dim; i++) 351 for (size_t i = 0; i < aclasses.dim; i++)
352 { 352 {
353 ClassDeclaration* cd = (ClassDeclaration*)aclasses.data[i]; 353 ClassDeclaration* cd = (ClassDeclaration*)aclasses.data[i];
354 Logger::println("class: %s", cd->toPrettyChars());
354 assert(cd->llvmClass); 355 assert(cd->llvmClass);
355 classInits.push_back(cd->llvmClass); 356 classInits.push_back(cd->llvmClass);
356 } 357 }
357 // has class array? 358 // has class array?
358 if (!classInits.empty()) { 359 if (!classInits.empty()) {
368 else 369 else
369 c = moduleinfo->llvmConstInit->getOperand(4); 370 c = moduleinfo->llvmConstInit->getOperand(4);
370 initVec.push_back(c); 371 initVec.push_back(c);
371 372
372 // flags 373 // flags
373 if (needmoduleinfo) 374 c = DtoConstUint(0);
374 c = DtoConstUint(0); // flags (4 means MIstandalone) 375 if (!needmoduleinfo)
375 else
376 c = DtoConstUint(4); // flags (4 means MIstandalone) 376 c = DtoConstUint(4); // flags (4 means MIstandalone)
377 initVec.push_back(c); 377 initVec.push_back(c);
378 378
379 // ctor 379 // ctor
380 llvm::Function* fctor = build_module_ctor(); 380 llvm::Function* fctor = build_module_ctor();
388 388
389 // unitTest 389 // unitTest
390 llvm::Function* unittest = build_module_unittest(); 390 llvm::Function* unittest = build_module_unittest();
391 c = unittest ? unittest : moduleinfo->llvmConstInit->getOperand(8); 391 c = unittest ? unittest : moduleinfo->llvmConstInit->getOperand(8);
392 initVec.push_back(c); 392 initVec.push_back(c);
393
394 // xgetMembers
395 c = moduleinfo->llvmConstInit->getOperand(9);
396 initVec.push_back(c);
397
398 // ictor
399 c = moduleinfo->llvmConstInit->getOperand(10);
400 initVec.push_back(c);
401
402 /*Logger::println("MODULE INFO INITIALIZERS");
403 for (size_t i=0; i<initVec.size(); ++i)
404 {
405 Logger::cout() << *initVec[i] << '\n';
406 if (initVec[i]->getType() != moduleinfoTy->getElementType(i))
407 assert(0);
408 }*/
393 409
394 // create initializer 410 // create initializer
395 llvm::Constant* constMI = llvm::ConstantStruct::get(moduleinfoTy, initVec); 411 llvm::Constant* constMI = llvm::ConstantStruct::get(moduleinfoTy, initVec);
396 412
397 // create name 413 // create name
440 gIR->resolveList.push_back(this); 456 gIR->resolveList.push_back(this);
441 } 457 }
442 458
443 /* ================================================================== */ 459 /* ================================================================== */
444 460
445 static unsigned LLVM_ClassOffsetToIndex(ClassDeclaration* cd, unsigned os, unsigned& idx)
446 {
447 // start at the bottom of the inheritance chain
448 if (cd->baseClass != 0) {
449 unsigned o = LLVM_ClassOffsetToIndex(cd->baseClass, os, idx);
450 if (o != (unsigned)-1)
451 return o;
452 }
453
454 // check this class
455 unsigned i;
456 for (i=0; i<cd->fields.dim; ++i) {
457 VarDeclaration* vd = (VarDeclaration*)cd->fields.data[i];
458 if (os == vd->offset)
459 return i+idx;
460 }
461 idx += i;
462
463 return (unsigned)-1;
464 }
465
466 void ClassDeclaration::offsetToIndex(Type* t, unsigned os, std::vector<unsigned>& result)
467 {
468 unsigned idx = 0;
469 unsigned r = LLVM_ClassOffsetToIndex(this, os, idx);
470 assert(r != (unsigned)-1 && "Offset not found in any aggregate field");
471 // vtable is 0, monitor is 1
472 r += 2;
473 // interface offset further
474 r += vtblInterfaces->dim;
475 // the final index was not pushed
476 result.push_back(r);
477 }
478
479 /* ================================================================== */
480
481 void ClassDeclaration::toObjFile() 461 void ClassDeclaration::toObjFile()
482 { 462 {
483 gIR->resolveList.push_back(this); 463 gIR->resolveList.push_back(this);
484 } 464 }
485 465
508 } 488 }
509 489
510 // global variable or magic 490 // global variable or magic
511 if (isDataseg()) 491 if (isDataseg())
512 { 492 {
493 // we don't want to touch private static members at all !!!
494 if ((prot() & PROTprivate) && getModule() != gIR->dmodule)
495 return;
496
497 // don't duplicate work
513 if (llvmResolved) return; 498 if (llvmResolved) return;
514 llvmResolved = true; 499 llvmResolved = true;
515 llvmDeclared = true; 500 llvmDeclared = true;
516 501
517 llvmIRGlobal = new IRGlobal(this); 502 llvmIRGlobal = new IRGlobal(this);
546 531
547 if (static_local) 532 if (static_local)
548 DtoConstInitGlobal(this); 533 DtoConstInitGlobal(this);
549 else 534 else
550 gIR->constInitList.push_back(this); 535 gIR->constInitList.push_back(this);
551
552 //if (storage_class & STCprivate)
553 // gvar->setVisibility(llvm::GlobalValue::ProtectedVisibility);
554 } 536 }
555 537
556 // inside aggregate declaration. declare a field. 538 // inside aggregate declaration. declare a field.
557 else 539 else
558 { 540 {