Mercurial > projects > ldc
diff gen/functions.cpp @ 234:9760f54af0b7 trunk
[svn r250] Fixed the warning about dropping arguments to _Dmain when optimizing.
Did a few cleanups in inline asm code.
author | lindquist |
---|---|
date | Sun, 08 Jun 2008 08:03:19 +0200 |
parents | 74701ba40398 |
children | 0db62b770a49 |
line wrap: on
line diff
--- a/gen/functions.cpp Sun Jun 08 06:45:54 2008 +0200 +++ b/gen/functions.cpp Sun Jun 08 08:03:19 2008 +0200 @@ -44,11 +44,21 @@ bool retinptr = false; bool usesthis = false; - if (ismain) { + // parameter types + std::vector<const LLType*> paramvec; + + if (ismain) + { rettype = llvm::Type::Int32Ty; actualRettype = rettype; + if (Argument::dim(f->parameters) == 0) + { + const LLType* arrTy = DtoArrayType(LLType::Int8Ty); + const LLType* arrArrTy = DtoArrayType(arrTy); + paramvec.push_back(getPtrToType(arrArrTy)); + } } - else { + else{ assert(rt); Type* rtfin = DtoDType(rt); if (DtoIsReturnedInArg(rt)) { @@ -62,9 +72,6 @@ } } - // parameter types - std::vector<const LLType*> paramvec; - if (retinptr) { //Logger::cout() << "returning through pointer parameter: " << *rettype << '\n'; paramvec.push_back(rettype); @@ -403,6 +410,16 @@ int nbyval = 0; + if (fdecl->isMain() && Argument::dim(f->parameters) == 0) + { + llvm::ParamAttrsWithIndex PAWI; + PAWI.Index = llidx; + PAWI.Attrs = llvm::ParamAttr::ByVal; + attrs.push_back(PAWI); + llidx++; + nbyval++; + } + for (; llidx <= funcNumArgs && f->parameters->dim > k; ++llidx,++k) { Argument* fnarg = (Argument*)f->parameters->data[k]; @@ -714,84 +731,6 @@ ////////////////////////////////////////////////////////////////////////////////////////// -void DtoMain() -{ - // emit main function llvm style - // int main(int argc, char**argv, char**env); - - assert(gIR != 0); - IRState& ir = *gIR; - - assert(ir.emitMain && ir.mainFunc); - - // parameter types - std::vector<const LLType*> pvec; - pvec.push_back((const LLType*)llvm::Type::Int32Ty); - const LLType* chPtrType = (const LLType*)getPtrToType(llvm::Type::Int8Ty); - pvec.push_back((const LLType*)getPtrToType(chPtrType)); - pvec.push_back((const LLType*)getPtrToType(chPtrType)); - const LLType* rettype = (const LLType*)llvm::Type::Int32Ty; - - llvm::FunctionType* functype = llvm::FunctionType::get(rettype, pvec, false); - llvm::Function* func = llvm::Function::Create(functype,llvm::GlobalValue::ExternalLinkage,"main",ir.module); - - llvm::BasicBlock* bb = llvm::BasicBlock::Create("entry",func); - - // call static ctors - llvm::Function* fn = LLVM_D_GetRuntimeFunction(ir.module,"_moduleCtor"); - llvm::Instruction* apt = llvm::CallInst::Create(fn,"",bb); - - // run unit tests if -unittest is provided - if (global.params.useUnitTests) { - fn = LLVM_D_GetRuntimeFunction(ir.module,"_moduleUnitTests"); - llvm::Instruction* apt = llvm::CallInst::Create(fn,"",bb); - } - - // call user main function - const llvm::FunctionType* mainty = ir.mainFunc->getFunctionType(); - llvm::CallInst* call; - if (mainty->getNumParams() > 0) - { - // main with arguments - assert(mainty->getNumParams() == 1); - std::vector<LLValue*> args; - llvm::Function* mfn = LLVM_D_GetRuntimeFunction(ir.module,"_d_main_args"); - - llvm::Function::arg_iterator argi = func->arg_begin(); - args.push_back(argi++); - args.push_back(argi++); - - const LLType* at = mainty->getParamType(0)->getContainedType(0); - LLValue* arr = new llvm::AllocaInst(at->getContainedType(1)->getContainedType(0), func->arg_begin(), "argstorage", apt); - LLValue* a = new llvm::AllocaInst(at, "argarray", apt); - LLValue* ptr = DtoGEPi(a,0,0,"tmp",bb); - LLValue* v = args[0]; - if (v->getType() != DtoSize_t()) - v = new llvm::ZExtInst(v, DtoSize_t(), "tmp", bb); - new llvm::StoreInst(v,ptr,bb); - ptr = DtoGEPi(a,0,1,"tmp",bb); - new llvm::StoreInst(arr,ptr,bb); - args.push_back(a); - llvm::CallInst::Create(mfn, args.begin(), args.end(), "", bb); - call = llvm::CallInst::Create(ir.mainFunc,a,"ret",bb); - } - else - { - // main with no arguments - call = llvm::CallInst::Create(ir.mainFunc,"ret",bb); - } - call->setCallingConv(ir.mainFunc->getCallingConv()); - - // call static dtors - fn = LLVM_D_GetRuntimeFunction(ir.module,"_moduleDtor"); - llvm::CallInst::Create(fn,"",bb); - - // return - llvm::ReturnInst::Create(call,bb); -} - -////////////////////////////////////////////////////////////////////////////////////////// - const llvm::FunctionType* DtoBaseFunctionType(FuncDeclaration* fdecl) { Dsymbol* parent = fdecl->toParent();