Mercurial > projects > ldc
comparison gen/toobj.cpp @ 1571:8d086d552909
IntegerType is now contextifed.
Requires llvm >= 78969. resistor says this will be the last context API change :)
author | Benjamin Kramer <benny.kra@gmail.com> |
---|---|
date | Fri, 14 Aug 2009 00:39:18 +0200 |
parents | 755abafbf25d |
children | 30bdcfb8299e |
comparison
equal
deleted
inserted
replaced
1570:ab03cfb3a212 | 1571:8d086d552909 |
---|---|
422 std::string name("_D"); | 422 std::string name("_D"); |
423 name.append(gIR->dmodule->mangle()); | 423 name.append(gIR->dmodule->mangle()); |
424 name.append("6__ctorZ"); | 424 name.append("6__ctorZ"); |
425 | 425 |
426 std::vector<const LLType*> argsTy; | 426 std::vector<const LLType*> argsTy; |
427 const llvm::FunctionType* fnTy = llvm::FunctionType::get(LLType::VoidTy,argsTy,false); | 427 const llvm::FunctionType* fnTy = llvm::FunctionType::get(LLType::getVoidTy(gIR->context()),argsTy,false); |
428 assert(gIR->module->getFunction(name) == NULL); | 428 assert(gIR->module->getFunction(name) == NULL); |
429 llvm::Function* fn = llvm::Function::Create(fnTy, llvm::GlobalValue::InternalLinkage, name, gIR->module); | 429 llvm::Function* fn = llvm::Function::Create(fnTy, llvm::GlobalValue::InternalLinkage, name, gIR->module); |
430 fn->setCallingConv(DtoCallingConv(0, LINKd)); | 430 fn->setCallingConv(DtoCallingConv(0, LINKd)); |
431 | 431 |
432 llvm::BasicBlock* bb = llvm::BasicBlock::Create("entry", fn); | 432 llvm::BasicBlock* bb = llvm::BasicBlock::Create(gIR->context(), "entry", fn); |
433 IRBuilder<> builder(bb); | 433 IRBuilder<> builder(bb); |
434 | 434 |
435 // debug info | 435 // debug info |
436 LLGlobalVariable* subprog; | 436 LLGlobalVariable* subprog; |
437 if(global.params.symdebug) { | 437 if(global.params.symdebug) { |
467 std::string name("_D"); | 467 std::string name("_D"); |
468 name.append(gIR->dmodule->mangle()); | 468 name.append(gIR->dmodule->mangle()); |
469 name.append("6__dtorZ"); | 469 name.append("6__dtorZ"); |
470 | 470 |
471 std::vector<const LLType*> argsTy; | 471 std::vector<const LLType*> argsTy; |
472 const llvm::FunctionType* fnTy = llvm::FunctionType::get(LLType::VoidTy,argsTy,false); | 472 const llvm::FunctionType* fnTy = llvm::FunctionType::get(LLType::getVoidTy(gIR->context()),argsTy,false); |
473 assert(gIR->module->getFunction(name) == NULL); | 473 assert(gIR->module->getFunction(name) == NULL); |
474 llvm::Function* fn = llvm::Function::Create(fnTy, llvm::GlobalValue::InternalLinkage, name, gIR->module); | 474 llvm::Function* fn = llvm::Function::Create(fnTy, llvm::GlobalValue::InternalLinkage, name, gIR->module); |
475 fn->setCallingConv(DtoCallingConv(0, LINKd)); | 475 fn->setCallingConv(DtoCallingConv(0, LINKd)); |
476 | 476 |
477 llvm::BasicBlock* bb = llvm::BasicBlock::Create("entry", fn); | 477 llvm::BasicBlock* bb = llvm::BasicBlock::Create(gIR->context(), "entry", fn); |
478 IRBuilder<> builder(bb); | 478 IRBuilder<> builder(bb); |
479 | 479 |
480 // debug info | 480 // debug info |
481 LLGlobalVariable* subprog; | 481 LLGlobalVariable* subprog; |
482 if(global.params.symdebug) { | 482 if(global.params.symdebug) { |
512 std::string name("_D"); | 512 std::string name("_D"); |
513 name.append(gIR->dmodule->mangle()); | 513 name.append(gIR->dmodule->mangle()); |
514 name.append("10__unittestZ"); | 514 name.append("10__unittestZ"); |
515 | 515 |
516 std::vector<const LLType*> argsTy; | 516 std::vector<const LLType*> argsTy; |
517 const llvm::FunctionType* fnTy = llvm::FunctionType::get(LLType::VoidTy,argsTy,false); | 517 const llvm::FunctionType* fnTy = llvm::FunctionType::get(LLType::getVoidTy(gIR->context()),argsTy,false); |
518 assert(gIR->module->getFunction(name) == NULL); | 518 assert(gIR->module->getFunction(name) == NULL); |
519 llvm::Function* fn = llvm::Function::Create(fnTy, llvm::GlobalValue::InternalLinkage, name, gIR->module); | 519 llvm::Function* fn = llvm::Function::Create(fnTy, llvm::GlobalValue::InternalLinkage, name, gIR->module); |
520 fn->setCallingConv(DtoCallingConv(0, LINKd)); | 520 fn->setCallingConv(DtoCallingConv(0, LINKd)); |
521 | 521 |
522 llvm::BasicBlock* bb = llvm::BasicBlock::Create("entry", fn); | 522 llvm::BasicBlock* bb = llvm::BasicBlock::Create(gIR->context(), "entry", fn); |
523 IRBuilder<> builder(bb); | 523 IRBuilder<> builder(bb); |
524 | 524 |
525 // debug info | 525 // debug info |
526 LLGlobalVariable* subprog; | 526 LLGlobalVariable* subprog; |
527 if(global.params.symdebug) { | 527 if(global.params.symdebug) { |
545 | 545 |
546 // build ModuleReference and register function, to register the module info in the global linked list | 546 // build ModuleReference and register function, to register the module info in the global linked list |
547 static LLFunction* build_module_reference_and_ctor(LLConstant* moduleinfo) | 547 static LLFunction* build_module_reference_and_ctor(LLConstant* moduleinfo) |
548 { | 548 { |
549 // build ctor type | 549 // build ctor type |
550 const LLFunctionType* fty = LLFunctionType::get(LLType::VoidTy, std::vector<const LLType*>(), false); | 550 const LLFunctionType* fty = LLFunctionType::get(LLType::getVoidTy(gIR->context()), std::vector<const LLType*>(), false); |
551 | 551 |
552 // build ctor name | 552 // build ctor name |
553 std::string fname = "_D"; | 553 std::string fname = "_D"; |
554 fname += gIR->dmodule->mangle(); | 554 fname += gIR->dmodule->mangle(); |
555 fname += "16__moduleinfoCtorZ"; | 555 fname += "16__moduleinfoCtorZ"; |
574 LLGlobalVariable* mref = gIR->module->getNamedGlobal("_Dmodule_ref"); | 574 LLGlobalVariable* mref = gIR->module->getNamedGlobal("_Dmodule_ref"); |
575 if (!mref) | 575 if (!mref) |
576 mref = new LLGlobalVariable(*gIR->module, getPtrToType(modulerefTy), false, LLGlobalValue::ExternalLinkage, NULL, "_Dmodule_ref"); | 576 mref = new LLGlobalVariable(*gIR->module, getPtrToType(modulerefTy), false, LLGlobalValue::ExternalLinkage, NULL, "_Dmodule_ref"); |
577 | 577 |
578 // make the function insert this moduleinfo as the beginning of the _Dmodule_ref linked list | 578 // make the function insert this moduleinfo as the beginning of the _Dmodule_ref linked list |
579 llvm::BasicBlock* bb = llvm::BasicBlock::Create("moduleinfoCtorEntry", ctor); | 579 llvm::BasicBlock* bb = llvm::BasicBlock::Create(gIR->context(), "moduleinfoCtorEntry", ctor); |
580 IRBuilder<> builder(bb); | 580 IRBuilder<> builder(bb); |
581 | 581 |
582 // debug info | 582 // debug info |
583 LLGlobalVariable* subprog; | 583 LLGlobalVariable* subprog; |
584 if(global.params.symdebug) { | 584 if(global.params.symdebug) { |
744 // flags (4 means MIstandalone) | 744 // flags (4 means MIstandalone) |
745 unsigned mi_flags = needmoduleinfo ? 0 : 4; | 745 unsigned mi_flags = needmoduleinfo ? 0 : 4; |
746 b.push_uint(mi_flags); | 746 b.push_uint(mi_flags); |
747 | 747 |
748 // function pointer type for next three fields | 748 // function pointer type for next three fields |
749 const LLType* fnptrTy = getPtrToType(LLFunctionType::get(LLType::VoidTy, std::vector<const LLType*>(), false)); | 749 const LLType* fnptrTy = getPtrToType(LLFunctionType::get(LLType::getVoidTy(gIR->context()), std::vector<const LLType*>(), false)); |
750 | 750 |
751 // ctor | 751 // ctor |
752 llvm::Function* fctor = build_module_ctor(); | 752 llvm::Function* fctor = build_module_ctor(); |
753 c = fctor ? fctor : getNullValue(fnptrTy); | 753 c = fctor ? fctor : getNullValue(fnptrTy); |
754 b.push(c); | 754 b.push(c); |
805 | 805 |
806 // build the modulereference and ctor for registering it | 806 // build the modulereference and ctor for registering it |
807 LLFunction* mictor = build_module_reference_and_ctor(gvar); | 807 LLFunction* mictor = build_module_reference_and_ctor(gvar); |
808 | 808 |
809 // register this ctor in the magic llvm.global_ctors appending array | 809 // register this ctor in the magic llvm.global_ctors appending array |
810 const LLFunctionType* magicfty = LLFunctionType::get(LLType::VoidTy, std::vector<const LLType*>(), false); | 810 const LLFunctionType* magicfty = LLFunctionType::get(LLType::getVoidTy(gIR->context()), std::vector<const LLType*>(), false); |
811 std::vector<const LLType*> magictypes; | 811 std::vector<const LLType*> magictypes; |
812 magictypes.push_back(LLType::Int32Ty); | 812 magictypes.push_back(LLType::getInt32Ty(gIR->context())); |
813 magictypes.push_back(getPtrToType(magicfty)); | 813 magictypes.push_back(getPtrToType(magicfty)); |
814 const LLStructType* magicsty = LLStructType::get(gIR->context(), magictypes); | 814 const LLStructType* magicsty = LLStructType::get(gIR->context(), magictypes); |
815 | 815 |
816 // make the constant element | 816 // make the constant element |
817 std::vector<LLConstant*> magicconstants; | 817 std::vector<LLConstant*> magicconstants; |