comparison gen/functions.cpp @ 108:288fe1029e1f trunk

[svn r112] Fixed 'case 1,2,3:' style case statements. Fixed a bunch of bugs with return/break/continue in loops. Fixed support for the DMDFE hidden implicit return value variable. This can be needed for some foreach statements where the loop body is converted to a nested delegate, but also possibly returns from the function. Added std.math to phobos. Added AA runtime support code, done ground work for implementing AAs. Several other bugfixes.
author lindquist
date Tue, 20 Nov 2007 05:29:20 +0100
parents 027b8d8b71ec
children 5ab8e92611f9
comparison
equal deleted inserted replaced
107:3efbcc81ba45 108:288fe1029e1f
376 f->llvmRetArg = iarg; 376 f->llvmRetArg = iarg;
377 ++iarg; 377 ++iarg;
378 } 378 }
379 if (f->llvmUsesThis) { 379 if (f->llvmUsesThis) {
380 iarg->setName("this"); 380 iarg->setName("this");
381 fdecl->llvmThisVar = iarg;
382 assert(fdecl->llvmThisVar);
381 ++iarg; 383 ++iarg;
382 } 384 }
383 int varargs = -1; 385 int varargs = -1;
384 if (f->linkage == LINKd && f->varargs == 1) 386 if (f->linkage == LINKd && f->varargs == 1)
385 varargs = 0; 387 varargs = 0;
424 void DtoDefineFunc(FuncDeclaration* fd) 426 void DtoDefineFunc(FuncDeclaration* fd)
425 { 427 {
426 if (fd->llvmDefined) return; 428 if (fd->llvmDefined) return;
427 fd->llvmDefined = true; 429 fd->llvmDefined = true;
428 430
431 assert(fd->llvmDeclared);
432
429 Logger::println("DtoDefineFunc(%s)", fd->toPrettyChars()); 433 Logger::println("DtoDefineFunc(%s)", fd->toPrettyChars());
430 LOG_SCOPE; 434 LOG_SCOPE;
431 435
432 // debug info 436 // debug info
433 if (global.params.symdebug) { 437 if (global.params.symdebug) {
472 { 476 {
473 Logger::println("Doing function body for: %s", fd->toChars()); 477 Logger::println("Doing function body for: %s", fd->toChars());
474 assert(fd->llvmIRFunc); 478 assert(fd->llvmIRFunc);
475 gIR->functions.push_back(fd->llvmIRFunc); 479 gIR->functions.push_back(fd->llvmIRFunc);
476 480
481 /* // moved to declaration
477 // this handling 482 // this handling
478 if (f->llvmUsesThis) { 483 if (f->llvmUsesThis) {
479 Logger::println("uses this"); 484 Logger::println("uses this");
480 if (f->llvmRetInPtr) 485 if (f->llvmRetInPtr)
481 fd->llvmThisVar = ++func->arg_begin(); 486 fd->llvmThisVar = ++func->arg_begin();
482 else 487 else
483 fd->llvmThisVar = func->arg_begin(); 488 fd->llvmThisVar = func->arg_begin();
484 assert(fd->llvmThisVar != 0); 489 assert(fd->llvmThisVar != 0);
485 } 490 }
491 */
486 492
487 if (fd->isMain()) 493 if (fd->isMain())
488 gIR->emitMain = true; 494 gIR->emitMain = true;
489 495
490 llvm::BasicBlock* beginbb = new llvm::BasicBlock("entry",func); 496 llvm::BasicBlock* beginbb = new llvm::BasicBlock("entry",func);
494 gIR->scopes.push_back(IRScope(beginbb, endbb)); 500 gIR->scopes.push_back(IRScope(beginbb, endbb));
495 501
496 // create alloca point 502 // create alloca point
497 f->llvmAllocaPoint = new llvm::BitCastInst(llvm::ConstantInt::get(llvm::Type::Int32Ty,0,false),llvm::Type::Int32Ty,"alloca point",gIR->scopebb()); 503 f->llvmAllocaPoint = new llvm::BitCastInst(llvm::ConstantInt::get(llvm::Type::Int32Ty,0,false),llvm::Type::Int32Ty,"alloca point",gIR->scopebb());
498 gIR->func()->allocapoint = f->llvmAllocaPoint; 504 gIR->func()->allocapoint = f->llvmAllocaPoint;
505
506 // need result variable? (not nested)
507 if (fd->vresult && !fd->vresult->nestedref) {
508 Logger::println("non-nested vresult value");
509 fd->vresult->llvmValue = new llvm::AllocaInst(DtoType(fd->vresult->type),"function_vresult",f->llvmAllocaPoint);
510 }
499 511
500 // give arguments storage 512 // give arguments storage
501 size_t n = Argument::dim(f->parameters); 513 size_t n = Argument::dim(f->parameters);
502 for (int i=0; i < n; ++i) { 514 for (int i=0; i < n; ++i) {
503 Argument* arg = Argument::getNth(f->parameters, i); 515 Argument* arg = Argument::getNth(f->parameters, i);
522 // debug info 534 // debug info
523 if (global.params.symdebug) DtoDwarfFuncStart(fd); 535 if (global.params.symdebug) DtoDwarfFuncStart(fd);
524 536
525 llvm::Value* parentNested = NULL; 537 llvm::Value* parentNested = NULL;
526 if (FuncDeclaration* fd2 = fd->toParent()->isFuncDeclaration()) { 538 if (FuncDeclaration* fd2 = fd->toParent()->isFuncDeclaration()) {
527 parentNested = fd2->llvmNested; 539 if (!fd->isStatic())
540 parentNested = fd2->llvmNested;
541 }
542
543 // need result variable? (nested)
544 if (fd->vresult && fd->vresult->nestedref) {
545 Logger::println("nested vresult value: %s", fd->vresult->toChars());
546 fd->llvmNestedVars.insert(fd->vresult);
528 } 547 }
529 548
530 // construct nested variables struct 549 // construct nested variables struct
531 if (!fd->llvmNestedVars.empty() || parentNested) { 550 if (!fd->llvmNestedVars.empty() || parentNested) {
532 std::vector<const llvm::Type*> nestTypes; 551 std::vector<const llvm::Type*> nestTypes;