Mercurial > projects > ldc
comparison gen/toobj.cpp @ 1529:ad7f2f1862d6
Adjust LDC to work with the LLVMContext LLVM changes.
This means we now require a fairly new LLVM revision. I use 75234.
author | Christian Kamm <kamm incasoftware de> |
---|---|
date | Fri, 10 Jul 2009 21:30:02 +0200 |
parents | 982eb70e83b2 |
children | c88b16d4a13c |
comparison
equal
deleted
inserted
replaced
1528:15f1707721fa | 1529:ad7f2f1862d6 |
---|---|
170 // emit usedArray | 170 // emit usedArray |
171 if (!ir.usedArray.empty()) | 171 if (!ir.usedArray.empty()) |
172 { | 172 { |
173 const LLArrayType* usedTy = LLArrayType::get(getVoidPtrType(), ir.usedArray.size()); | 173 const LLArrayType* usedTy = LLArrayType::get(getVoidPtrType(), ir.usedArray.size()); |
174 LLConstant* usedInit = LLConstantArray::get(usedTy, ir.usedArray); | 174 LLConstant* usedInit = LLConstantArray::get(usedTy, ir.usedArray); |
175 LLGlobalVariable* usedArray = new LLGlobalVariable(usedTy, true, LLGlobalValue::AppendingLinkage, usedInit, "llvm.used", ir.module); | 175 LLGlobalVariable* usedArray = new LLGlobalVariable(*ir.module, usedTy, true, LLGlobalValue::AppendingLinkage, usedInit, "llvm.used"); |
176 usedArray->setSection("llvm.metadata"); | 176 usedArray->setSection("llvm.metadata"); |
177 } | 177 } |
178 | 178 |
179 // verify the llvm | 179 // verify the llvm |
180 if (!noVerify) { | 180 if (!noVerify) { |
576 | 576 |
577 // create the ModuleReference node for this module | 577 // create the ModuleReference node for this module |
578 std::string thismrefname = "_D"; | 578 std::string thismrefname = "_D"; |
579 thismrefname += gIR->dmodule->mangle(); | 579 thismrefname += gIR->dmodule->mangle(); |
580 thismrefname += "11__moduleRefZ"; | 580 thismrefname += "11__moduleRefZ"; |
581 LLGlobalVariable* thismref = new LLGlobalVariable(modulerefTy, false, LLGlobalValue::InternalLinkage, thismrefinit, thismrefname, gIR->module); | 581 LLGlobalVariable* thismref = new LLGlobalVariable(*gIR->module, modulerefTy, false, LLGlobalValue::InternalLinkage, thismrefinit, thismrefname); |
582 | 582 |
583 // make sure _Dmodule_ref is declared | 583 // make sure _Dmodule_ref is declared |
584 LLGlobalVariable* mref = gIR->module->getNamedGlobal("_Dmodule_ref"); | 584 LLGlobalVariable* mref = gIR->module->getNamedGlobal("_Dmodule_ref"); |
585 if (!mref) | 585 if (!mref) |
586 mref = new LLGlobalVariable(getPtrToType(modulerefTy), false, LLGlobalValue::ExternalLinkage, NULL, "_Dmodule_ref", gIR->module); | 586 mref = new LLGlobalVariable(*gIR->module, getPtrToType(modulerefTy), false, LLGlobalValue::ExternalLinkage, NULL, "_Dmodule_ref"); |
587 | 587 |
588 // make the function insert this moduleinfo as the beginning of the _Dmodule_ref linked list | 588 // make the function insert this moduleinfo as the beginning of the _Dmodule_ref linked list |
589 llvm::BasicBlock* bb = llvm::BasicBlock::Create("moduleinfoCtorEntry", ctor); | 589 llvm::BasicBlock* bb = llvm::BasicBlock::Create("moduleinfoCtorEntry", ctor); |
590 IRBuilder<> builder(bb); | 590 IRBuilder<> builder(bb); |
591 | 591 |
678 // declare the imported module info | 678 // declare the imported module info |
679 std::string m_name("_D"); | 679 std::string m_name("_D"); |
680 m_name.append(m->mangle()); | 680 m_name.append(m->mangle()); |
681 m_name.append("8__ModuleZ"); | 681 m_name.append("8__ModuleZ"); |
682 llvm::GlobalVariable* m_gvar = gIR->module->getGlobalVariable(m_name); | 682 llvm::GlobalVariable* m_gvar = gIR->module->getGlobalVariable(m_name); |
683 if (!m_gvar) m_gvar = new llvm::GlobalVariable(moduleinfoTy, false, llvm::GlobalValue::ExternalLinkage, NULL, m_name, gIR->module); | 683 if (!m_gvar) m_gvar = new llvm::GlobalVariable(*gIR->module, moduleinfoTy, false, llvm::GlobalValue::ExternalLinkage, NULL, m_name); |
684 importInits.push_back(m_gvar); | 684 importInits.push_back(m_gvar); |
685 } | 685 } |
686 // has import array? | 686 // has import array? |
687 if (!importInits.empty()) | 687 if (!importInits.empty()) |
688 { | 688 { |
690 c = llvm::ConstantArray::get(importArrTy, importInits); | 690 c = llvm::ConstantArray::get(importArrTy, importInits); |
691 std::string m_name("_D"); | 691 std::string m_name("_D"); |
692 m_name.append(mangle()); | 692 m_name.append(mangle()); |
693 m_name.append("9__importsZ"); | 693 m_name.append("9__importsZ"); |
694 llvm::GlobalVariable* m_gvar = gIR->module->getGlobalVariable(m_name); | 694 llvm::GlobalVariable* m_gvar = gIR->module->getGlobalVariable(m_name); |
695 if (!m_gvar) m_gvar = new llvm::GlobalVariable(importArrTy, true, llvm::GlobalValue::InternalLinkage, c, m_name, gIR->module); | 695 if (!m_gvar) m_gvar = new llvm::GlobalVariable(*gIR->module, importArrTy, true, llvm::GlobalValue::InternalLinkage, c, m_name); |
696 c = llvm::ConstantExpr::getBitCast(m_gvar, getPtrToType(importArrTy->getElementType())); | 696 c = llvm::ConstantExpr::getBitCast(m_gvar, getPtrToType(importArrTy->getElementType())); |
697 c = DtoConstSlice(DtoConstSize_t(importInits.size()), c); | 697 c = DtoConstSlice(DtoConstSize_t(importInits.size()), c); |
698 } | 698 } |
699 else | 699 else |
700 { | 700 { |
741 c = llvm::ConstantArray::get(classArrTy, classInits); | 741 c = llvm::ConstantArray::get(classArrTy, classInits); |
742 std::string m_name("_D"); | 742 std::string m_name("_D"); |
743 m_name.append(mangle()); | 743 m_name.append(mangle()); |
744 m_name.append("9__classesZ"); | 744 m_name.append("9__classesZ"); |
745 assert(gIR->module->getGlobalVariable(m_name) == NULL); | 745 assert(gIR->module->getGlobalVariable(m_name) == NULL); |
746 llvm::GlobalVariable* m_gvar = new llvm::GlobalVariable(classArrTy, true, llvm::GlobalValue::InternalLinkage, c, m_name, gIR->module); | 746 llvm::GlobalVariable* m_gvar = new llvm::GlobalVariable(*gIR->module, classArrTy, true, llvm::GlobalValue::InternalLinkage, c, m_name); |
747 c = DtoGEPi(m_gvar, 0, 0); | 747 c = DtoGEPi(m_gvar, 0, 0); |
748 c = DtoConstSlice(DtoConstSize_t(classInits.size()), c); | 748 c = DtoConstSlice(DtoConstSize_t(classInits.size()), c); |
749 } | 749 } |
750 else | 750 else |
751 c = DtoConstSlice( DtoConstSize_t(0), getNullValue(getPtrToType(getPtrToType(classinfoTy))) ); | 751 c = DtoConstSlice( DtoConstSize_t(0), getNullValue(getPtrToType(getPtrToType(classinfoTy))) ); |
809 // declare global | 809 // declare global |
810 // flags will be modified at runtime so can't make it constant | 810 // flags will be modified at runtime so can't make it constant |
811 | 811 |
812 // it makes no sense that the our own module info already exists! | 812 // it makes no sense that the our own module info already exists! |
813 assert(!gIR->module->getGlobalVariable(MIname)); | 813 assert(!gIR->module->getGlobalVariable(MIname)); |
814 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(constMI->getType(), false, llvm::GlobalValue::ExternalLinkage, constMI, MIname, gIR->module); | 814 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(*gIR->module, constMI->getType(), false, llvm::GlobalValue::ExternalLinkage, constMI, MIname); |
815 | 815 |
816 // build the modulereference and ctor for registering it | 816 // build the modulereference and ctor for registering it |
817 LLFunction* mictor = build_module_reference_and_ctor(gvar); | 817 LLFunction* mictor = build_module_reference_and_ctor(gvar); |
818 | 818 |
819 // register this ctor in the magic llvm.global_ctors appending array | 819 // register this ctor in the magic llvm.global_ctors appending array |
832 // declare the appending array | 832 // declare the appending array |
833 const llvm::ArrayType* appendArrTy = llvm::ArrayType::get(magicsty, 1); | 833 const llvm::ArrayType* appendArrTy = llvm::ArrayType::get(magicsty, 1); |
834 std::vector<LLConstant*> appendInits(1, magicinit); | 834 std::vector<LLConstant*> appendInits(1, magicinit); |
835 LLConstant* appendInit = llvm::ConstantArray::get(appendArrTy, appendInits); | 835 LLConstant* appendInit = llvm::ConstantArray::get(appendArrTy, appendInits); |
836 std::string appendName("llvm.global_ctors"); | 836 std::string appendName("llvm.global_ctors"); |
837 llvm::GlobalVariable* appendVar = new llvm::GlobalVariable(appendArrTy, true, llvm::GlobalValue::AppendingLinkage, appendInit, appendName, gIR->module); | 837 llvm::GlobalVariable* appendVar = new llvm::GlobalVariable(*gIR->module, appendArrTy, true, llvm::GlobalValue::AppendingLinkage, appendInit, appendName); |
838 } | 838 } |