Mercurial > projects > ldc
comparison gen/tollvm.cpp @ 91:3f949c6e2e9d trunk
[svn r95] added support for mains like:
T main(string[] args)
fixed a bug with slicing a pointer that is an argument with no storage
author | lindquist |
---|---|
date | Wed, 07 Nov 2007 04:52:56 +0100 |
parents | 16e88334bba7 |
children | 70d6113eeb8c |
comparison
equal
deleted
inserted
replaced
90:16e88334bba7 | 91:3f949c6e2e9d |
---|---|
658 | 658 |
659 llvm::BasicBlock* bb = new llvm::BasicBlock("entry",func); | 659 llvm::BasicBlock* bb = new llvm::BasicBlock("entry",func); |
660 | 660 |
661 // call static ctors | 661 // call static ctors |
662 llvm::Function* fn = LLVM_D_GetRuntimeFunction(ir.module,"_d_run_module_ctors"); | 662 llvm::Function* fn = LLVM_D_GetRuntimeFunction(ir.module,"_d_run_module_ctors"); |
663 new llvm::CallInst(fn,"",bb); | 663 llvm::Instruction* apt = new llvm::CallInst(fn,"",bb); |
664 | 664 |
665 // call user main function | 665 // call user main function |
666 llvm::CallInst* call = new llvm::CallInst(ir.mainFunc,"ret",bb); | 666 const llvm::FunctionType* mainty = ir.mainFunc->getFunctionType(); |
667 llvm::CallInst* call; | |
668 if (mainty->getNumParams() > 0) | |
669 { | |
670 // main with arguments | |
671 assert(mainty->getNumParams() == 1); | |
672 std::vector<llvm::Value*> args; | |
673 llvm::Function* mfn = LLVM_D_GetRuntimeFunction(ir.module,"_d_main_args"); | |
674 | |
675 llvm::Function::arg_iterator argi = func->arg_begin(); | |
676 args.push_back(argi++); | |
677 args.push_back(argi++); | |
678 | |
679 const llvm::Type* at = mainty->getParamType(0)->getContainedType(0); | |
680 llvm::Value* arr = new llvm::AllocaInst(at->getContainedType(1)->getContainedType(0), func->arg_begin(), "argstorage", apt); | |
681 llvm::Value* a = new llvm::AllocaInst(at, "argarray", apt); | |
682 llvm::Value* ptr = DtoGEPi(a,0,0,"tmp",bb); | |
683 llvm::Value* v = new llvm::ZExtInst(args[0], DtoSize_t(), "tmp", bb); | |
684 new llvm::StoreInst(v,ptr,bb); | |
685 ptr = DtoGEPi(a,0,1,"tmp",bb); | |
686 new llvm::StoreInst(arr,ptr,bb); | |
687 args.push_back(a); | |
688 new llvm::CallInst(mfn, args.begin(), args.end(), "", bb); | |
689 call = new llvm::CallInst(ir.mainFunc,a,"ret",bb); | |
690 } | |
691 else | |
692 { | |
693 // main with no arguments | |
694 call = new llvm::CallInst(ir.mainFunc,"ret",bb); | |
695 } | |
667 call->setCallingConv(ir.mainFunc->getCallingConv()); | 696 call->setCallingConv(ir.mainFunc->getCallingConv()); |
668 | 697 |
669 // call static dtors | 698 // call static dtors |
670 fn = LLVM_D_GetRuntimeFunction(ir.module,"_d_run_module_dtors"); | 699 fn = LLVM_D_GetRuntimeFunction(ir.module,"_d_run_module_dtors"); |
671 new llvm::CallInst(fn,"",bb); | 700 new llvm::CallInst(fn,"",bb); |