Changeset 811:8e6135be6999
- Timestamp:
- 11/30/08 20:10:16
(1 month ago)
- Author:
- Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
- branch:
- default
- Message:
Fixed ModuleInfo? generation to no longer use the ModuleInfo? class' default initializer for types/defaults, it's unsafe as initializers don't necesarily match the "formal" type. There might be explicit padding.
Changed -g switch to emit DW_LANG_D debug info, make demangling work with a patched GDB, still more work to do for full support of D's Dwarf extensions.
Added getNullValue helper method.
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r797 |
r811 |
|
| 375 | 375 | else if (strcmp(p + 1, "fPIC") == 0) |
|---|
| 376 | 376 | global.params.pic = 1; |
|---|
| 377 | | else if (strcmp(p + 1, "g") == 0 || strcmp(p + 1, "gc") == 0) |
|---|
| | 377 | else if (strcmp(p + 1, "g") == 0) |
|---|
| 378 | 378 | global.params.symdebug = 1; |
|---|
| | 379 | else if (strcmp(p + 1, "gc") == 0) |
|---|
| | 380 | global.params.symdebug = 2; |
|---|
| 379 | 381 | else if (strcmp(p + 1, "v") == 0) |
|---|
| 380 | 382 | global.params.verbose = 1; |
|---|
| r797 |
r811 |
|
| 392 | 392 | else if (strcmp(p + 1, "fPIC") == 0) |
|---|
| 393 | 393 | global.params.pic = 1; |
|---|
| 394 | | else if (strcmp(p + 1, "g") == 0 || strcmp(p + 1, "gc") == 0) |
|---|
| | 394 | else if (strcmp(p + 1, "g") == 0) |
|---|
| 395 | 395 | global.params.symdebug = 1; |
|---|
| | 396 | else if (strcmp(p + 1, "gc") == 0) |
|---|
| | 397 | global.params.symdebug = 2; |
|---|
| 396 | 398 | else if (strcmp(p + 1, "v") == 0) |
|---|
| 397 | 399 | global.params.verbose = 1; |
|---|
| r797 |
r811 |
|
| 135 | 135 | vals[1] = DBG_CAST(getDwarfAnchor(DW_TAG_compile_unit)); |
|---|
| 136 | 136 | |
|---|
| 137 | | vals[2] = DtoConstUint(DW_LANG_C);// _D)); // doesn't seem to work |
|---|
| | 137 | if (global.params.symdebug == 2) |
|---|
| | 138 | vals[2] = DtoConstUint(DW_LANG_C); |
|---|
| | 139 | else |
|---|
| | 140 | vals[2] = DtoConstUint(DW_LANG_D); |
|---|
| 138 | 141 | vals[3] = DtoConstStringPtr(FileName::name(m->srcfile->name->toChars()), "llvm.metadata"); |
|---|
| 139 | 142 | std::string srcpath(FileName::path(m->srcfile->name->toChars())); |
|---|
| r797 |
r811 |
|
| 674 | 674 | } |
|---|
| 675 | 675 | |
|---|
| | 676 | LLConstant* getNullValue(const LLType* t) |
|---|
| | 677 | { |
|---|
| | 678 | return LLConstant::getNullValue(t); |
|---|
| | 679 | } |
|---|
| | 680 | |
|---|
| 676 | 681 | ////////////////////////////////////////////////////////////////////////////////////////// |
|---|
| 677 | 682 | |
|---|
| r797 |
r811 |
|
| 88 | 88 | const LLPointerType* getVoidPtrType(); |
|---|
| 89 | 89 | llvm::ConstantPointerNull* getNullPtr(const LLType* t); |
|---|
| | 90 | LLConstant* getNullValue(const LLType* t); |
|---|
| 90 | 91 | |
|---|
| 91 | 92 | // type sizes |
|---|
| r810 |
r811 |
|
| 680 | 680 | void Module::genmoduleinfo() |
|---|
| 681 | 681 | { |
|---|
| 682 | | // The layout is: |
|---|
| 683 | | // { |
|---|
| 684 | | // void **vptr; |
|---|
| 685 | | // monitor_t monitor; |
|---|
| 686 | | // char[] name; // class name |
|---|
| 687 | | // ModuleInfo importedModules[]; |
|---|
| 688 | | // ClassInfo localClasses[]; |
|---|
| 689 | | // uint flags; // initialization state |
|---|
| 690 | | // void *ctor; |
|---|
| 691 | | // void *dtor; |
|---|
| 692 | | // void *unitTest; |
|---|
| 693 | | // } |
|---|
| | 682 | // The layout is: |
|---|
| | 683 | // { |
|---|
| | 684 | // char[] name; |
|---|
| | 685 | // ModuleInfo[] importedModules; |
|---|
| | 686 | // ClassInfo[] localClasses; |
|---|
| | 687 | // uint flags; |
|---|
| | 688 | // |
|---|
| | 689 | // void function() ctor; |
|---|
| | 690 | // void function() dtor; |
|---|
| | 691 | // void function() unitTest; |
|---|
| | 692 | // |
|---|
| | 693 | // void* xgetMembers; |
|---|
| | 694 | // void function() ictor; |
|---|
| | 695 | // } |
|---|
| 694 | 696 | |
|---|
| 695 | 697 | // resolve ModuleInfo |
|---|
| … | … | |
| 706 | 708 | // moduleinfo llvm struct type |
|---|
| 707 | 709 | const llvm::StructType* moduleinfoTy = isaStruct(moduleinfo->type->ir.type->get()); |
|---|
| 708 | | |
|---|
| 709 | 710 | // classinfo llvm struct type |
|---|
| 710 | 711 | const llvm::StructType* classinfoTy = isaStruct(ClassDeclaration::classinfo->type->ir.type->get()); |
|---|
| … | … | |
| 734 | 735 | Module *m = (Module *)aimports.data[i]; |
|---|
| 735 | 736 | if (!m->needModuleInfo()) |
|---|
| 736 | | aimports_dim--; |
|---|
| 737 | | else { // declare |
|---|
| 738 | | // create name |
|---|
| 739 | | std::string m_name("_D"); |
|---|
| 740 | | m_name.append(m->mangle()); |
|---|
| 741 | | m_name.append("8__ModuleZ"); |
|---|
| 742 | | llvm::GlobalVariable* m_gvar = gIR->module->getGlobalVariable(m_name); |
|---|
| 743 | | if (!m_gvar) m_gvar = new llvm::GlobalVariable(moduleinfoTy, false, llvm::GlobalValue::ExternalLinkage, NULL, m_name, gIR->module); |
|---|
| 744 | | importInits.push_back(m_gvar); |
|---|
| 745 | | } |
|---|
| | 737 | continue; |
|---|
| | 738 | |
|---|
| | 739 | // declare the imported module info |
|---|
| | 740 | std::string m_name("_D"); |
|---|
| | 741 | m_name.append(m->mangle()); |
|---|
| | 742 | m_name.append("8__ModuleZ"); |
|---|
| | 743 | llvm::GlobalVariable* m_gvar = gIR->module->getGlobalVariable(m_name); |
|---|
| | 744 | if (!m_gvar) m_gvar = new llvm::GlobalVariable(moduleinfoTy, false, llvm::GlobalValue::ExternalLinkage, NULL, m_name, gIR->module); |
|---|
| | 745 | importInits.push_back(m_gvar); |
|---|
| 746 | 746 | } |
|---|
| 747 | 747 | // has import array? |
|---|
| … | … | |
| 759 | 759 | } |
|---|
| 760 | 760 | else |
|---|
| 761 | | c = moduleinfo->ir.irStruct->constInit->getOperand(3); |
|---|
| | 761 | c = DtoConstSlice( DtoConstSize_t(0), getNullValue(getPtrToType(moduleinfoTy)) ); |
|---|
| 762 | 762 | initVec.push_back(c); |
|---|
| 763 | 763 | |
|---|
| … | … | |
| 790 | 790 | Logger::println("class: %s", cd->toPrettyChars()); |
|---|
| 791 | 791 | assert(cd->ir.irStruct->classInfo); |
|---|
| 792 | | c = llvm::ConstantExpr::getBitCast(cd->ir.irStruct->classInfo, getPtrToType(classinfoTy)); |
|---|
| | 792 | c = DtoBitCast(cd->ir.irStruct->classInfo, getPtrToType(classinfoTy)); |
|---|
| 793 | 793 | classInits.push_back(c); |
|---|
| 794 | 794 | } |
|---|
| … | … | |
| 803 | 803 | assert(gIR->module->getGlobalVariable(m_name) == NULL); |
|---|
| 804 | 804 | llvm::GlobalVariable* m_gvar = new llvm::GlobalVariable(classArrTy, true, llvm::GlobalValue::InternalLinkage, c, m_name, gIR->module); |
|---|
| 805 | | c = llvm::ConstantExpr::getBitCast(m_gvar, getPtrToType(classArrTy->getElementType())); |
|---|
| | 805 | c = DtoBitCast(m_gvar, getPtrToType(classinfoTy)); |
|---|
| 806 | 806 | c = DtoConstSlice(DtoConstSize_t(classInits.size()), c); |
|---|
| 807 | 807 | } |
|---|
| 808 | 808 | else |
|---|
| 809 | | c = moduleinfo->ir.irStruct->constInit->getOperand(4); |
|---|
| | 809 | c = DtoConstSlice( DtoConstSize_t(0), getNullValue(getPtrToType(classinfoTy)) ); |
|---|
| 810 | 810 | initVec.push_back(c); |
|---|
| 811 | 811 | |
|---|
| … | … | |
| 816 | 816 | initVec.push_back(c); |
|---|
| 817 | 817 | |
|---|
| | 818 | // function pointer type for next three fields |
|---|
| | 819 | const LLType* fnptrTy = getPtrToType(LLFunctionType::get(LLType::VoidTy, std::vector<const LLType*>(), false)); |
|---|
| | 820 | |
|---|
| 818 | 821 | // ctor |
|---|
| 819 | 822 | llvm::Function* fctor = build_module_ctor(); |
|---|
| 820 | | c = fctor ? fctor : moduleinfo->ir.irStruct->constInit->getOperand(6); |
|---|
| | 823 | c = fctor ? fctor : getNullValue(fnptrTy); |
|---|
| 821 | 824 | initVec.push_back(c); |
|---|
| 822 | 825 | |
|---|
| 823 | 826 | // dtor |
|---|
| 824 | 827 | llvm::Function* fdtor = build_module_dtor(); |
|---|
| 825 | | c = fdtor ? fdtor : moduleinfo->ir.irStruct->constInit->getOperand(7); |
|---|
| | 828 | c = fdtor ? fdtor : getNullValue(fnptrTy); |
|---|
| 826 | 829 | initVec.push_back(c); |
|---|
| 827 | 830 | |
|---|
| 828 | 831 | // unitTest |
|---|
| 829 | 832 | llvm::Function* unittest = build_module_unittest(); |
|---|
| 830 | | c = unittest ? unittest : moduleinfo->ir.irStruct->constInit->getOperand(8); |
|---|
| | 833 | c = unittest ? unittest : getNullValue(fnptrTy); |
|---|
| 831 | 834 | initVec.push_back(c); |
|---|
| 832 | 835 | |
|---|
| 833 | 836 | // xgetMembers |
|---|
| 834 | | c = moduleinfo->ir.irStruct->constInit->getOperand(9); |
|---|
| | 837 | c = getNullValue(getVoidPtrType()); |
|---|
| 835 | 838 | initVec.push_back(c); |
|---|
| 836 | 839 | |
|---|
| 837 | 840 | // ictor |
|---|
| 838 | | c = moduleinfo->ir.irStruct->constInit->getOperand(10); |
|---|
| | 841 | c = getNullValue(fnptrTy); |
|---|
| 839 | 842 | initVec.push_back(c); |
|---|
| 840 | 843 | |
|---|