Wiki Roadmap Timeline Tickets New Ticket Source Search Help / Guide About Trac Login

Changeset 811:8e6135be6999

Show
Ignore:
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
  • dmd/mars.c

    r797 r811  
    375375        else if (strcmp(p + 1, "fPIC") == 0) 
    376376        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
    378378        global.params.symdebug = 1; 
     379        else if (strcmp(p + 1, "gc") == 0) 
     380        global.params.symdebug = 2; 
    379381        else if (strcmp(p + 1, "v") == 0) 
    380382        global.params.verbose = 1; 
  • dmd2/mars.c

    r797 r811  
    392392        else if (strcmp(p + 1, "fPIC") == 0) 
    393393        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
    395395        global.params.symdebug = 1; 
     396        else if (strcmp(p + 1, "gc") == 0) 
     397        global.params.symdebug = 2; 
    396398        else if (strcmp(p + 1, "v") == 0) 
    397399        global.params.verbose = 1; 
  • gen/todebug.cpp

    r797 r811  
    135135    vals[1] = DBG_CAST(getDwarfAnchor(DW_TAG_compile_unit)); 
    136136 
    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); 
    138141    vals[3] = DtoConstStringPtr(FileName::name(m->srcfile->name->toChars()), "llvm.metadata"); 
    139142    std::string srcpath(FileName::path(m->srcfile->name->toChars())); 
  • gen/tollvm.cpp

    r797 r811  
    674674} 
    675675 
     676LLConstant* getNullValue(const LLType* t) 
     677{ 
     678    return LLConstant::getNullValue(t); 
     679} 
     680 
    676681////////////////////////////////////////////////////////////////////////////////////////// 
    677682 
  • gen/tollvm.h

    r797 r811  
    8888const LLPointerType* getVoidPtrType(); 
    8989llvm::ConstantPointerNull* getNullPtr(const LLType* t); 
     90LLConstant* getNullValue(const LLType* t); 
    9091 
    9192// type sizes 
  • gen/toobj.cpp

    r810 r811  
    680680void Module::genmoduleinfo() 
    681681{ 
    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//         } 
    694696 
    695697    // resolve ModuleInfo 
     
    706708    // moduleinfo llvm struct type 
    707709    const llvm::StructType* moduleinfoTy = isaStruct(moduleinfo->type->ir.type->get()); 
    708  
    709710    // classinfo llvm struct type 
    710711    const llvm::StructType* classinfoTy = isaStruct(ClassDeclaration::classinfo->type->ir.type->get()); 
     
    734735        Module *m = (Module *)aimports.data[i]; 
    735736        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); 
    746746    } 
    747747    // has import array? 
     
    759759    } 
    760760    else 
    761         c = moduleinfo->ir.irStruct->constInit->getOperand(3); 
     761        c = DtoConstSlice( DtoConstSize_t(0), getNullValue(getPtrToType(moduleinfoTy)) ); 
    762762    initVec.push_back(c); 
    763763 
     
    790790        Logger::println("class: %s", cd->toPrettyChars()); 
    791791        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)); 
    793793        classInits.push_back(c); 
    794794    } 
     
    803803        assert(gIR->module->getGlobalVariable(m_name) == NULL); 
    804804        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)); 
    806806        c = DtoConstSlice(DtoConstSize_t(classInits.size()), c); 
    807807    } 
    808808    else 
    809         c = moduleinfo->ir.irStruct->constInit->getOperand(4); 
     809        c = DtoConstSlice( DtoConstSize_t(0), getNullValue(getPtrToType(classinfoTy)) ); 
    810810    initVec.push_back(c); 
    811811 
     
    816816    initVec.push_back(c); 
    817817 
     818    // function pointer type for next three fields 
     819    const LLType* fnptrTy = getPtrToType(LLFunctionType::get(LLType::VoidTy, std::vector<const LLType*>(), false)); 
     820 
    818821    // ctor 
    819822    llvm::Function* fctor = build_module_ctor(); 
    820     c = fctor ? fctor : moduleinfo->ir.irStruct->constInit->getOperand(6); 
     823    c = fctor ? fctor : getNullValue(fnptrTy); 
    821824    initVec.push_back(c); 
    822825 
    823826    // dtor 
    824827    llvm::Function* fdtor = build_module_dtor(); 
    825     c = fdtor ? fdtor : moduleinfo->ir.irStruct->constInit->getOperand(7); 
     828    c = fdtor ? fdtor : getNullValue(fnptrTy); 
    826829    initVec.push_back(c); 
    827830 
    828831    // unitTest 
    829832    llvm::Function* unittest = build_module_unittest(); 
    830     c = unittest ? unittest : moduleinfo->ir.irStruct->constInit->getOperand(8); 
     833    c = unittest ? unittest : getNullValue(fnptrTy); 
    831834    initVec.push_back(c); 
    832835 
    833836    // xgetMembers 
    834     c = moduleinfo->ir.irStruct->constInit->getOperand(9); 
     837    c = getNullValue(getVoidPtrType()); 
    835838    initVec.push_back(c); 
    836839 
    837840    // ictor 
    838     c = moduleinfo->ir.irStruct->constInit->getOperand(10); 
     841    c = getNullValue(fnptrTy); 
    839842    initVec.push_back(c); 
    840843 
Copyright © 2008, LDC Development Team.