comparison gen/statements.cpp @ 100:5071469303d4 trunk

[svn r104] TONS OF FIXES. Split up declaration, constant initializer gen and definition for globals, structs, classes and functions. Improved ClassInfo support (not complete), not in vtable yet. Fixed a bunch of forward reference problems. Much more. Major commit! :)
author lindquist
date Fri, 16 Nov 2007 08:21:47 +0100
parents 6789050b5ad1
children 288fe1029e1f
comparison
equal deleted inserted replaced
99:a676a7743642 100:5071469303d4
69 p->exps.pop_back(); 69 p->exps.pop_back();
70 70
71 if (!e->inPlace()) 71 if (!e->inPlace())
72 DtoAssign(rvar, e); 72 DtoAssign(rvar, e);
73 73
74 IRFunction::FinallyVec& fin = p->func().finallys; 74 IRFunction::FinallyVec& fin = p->func()->finallys;
75 if (fin.empty()) { 75 if (fin.empty()) {
76 if (global.params.symdebug) DtoDwarfFuncEnd(p->func().decl); 76 if (global.params.symdebug) DtoDwarfFuncEnd(p->func()->decl);
77 new llvm::ReturnInst(p->scopebb()); 77 new llvm::ReturnInst(p->scopebb());
78 } 78 }
79 else { 79 else {
80 new llvm::BranchInst(fin.back().retbb, p->scopebb()); 80 new llvm::BranchInst(fin.back().retbb, p->scopebb());
81 } 81 }
85 DValue* e = exp->toElem(p); 85 DValue* e = exp->toElem(p);
86 llvm::Value* v = e->getRVal(); 86 llvm::Value* v = e->getRVal();
87 delete e; 87 delete e;
88 Logger::cout() << "return value is '" <<*v << "'\n"; 88 Logger::cout() << "return value is '" <<*v << "'\n";
89 89
90 IRFunction::FinallyVec& fin = p->func().finallys; 90 IRFunction::FinallyVec& fin = p->func()->finallys;
91 if (fin.empty()) { 91 if (fin.empty()) {
92 if (global.params.symdebug) DtoDwarfFuncEnd(p->func().decl); 92 if (global.params.symdebug) DtoDwarfFuncEnd(p->func()->decl);
93 new llvm::ReturnInst(v, p->scopebb()); 93 new llvm::ReturnInst(v, p->scopebb());
94 } 94 }
95 else { 95 else {
96 if (!p->func().finallyretval) 96 if (!p->func()->finallyretval)
97 p->func().finallyretval = new llvm::AllocaInst(v->getType(),"tmpreturn",p->topallocapoint()); 97 p->func()->finallyretval = new llvm::AllocaInst(v->getType(),"tmpreturn",p->topallocapoint());
98 llvm::Value* rettmp = p->func().finallyretval; 98 llvm::Value* rettmp = p->func()->finallyretval;
99 new llvm::StoreInst(v,rettmp,p->scopebb()); 99 new llvm::StoreInst(v,rettmp,p->scopebb());
100 new llvm::BranchInst(fin.back().retbb, p->scopebb()); 100 new llvm::BranchInst(fin.back().retbb, p->scopebb());
101 } 101 }
102 } 102 }
103 } 103 }
104 else 104 else
105 { 105 {
106 if (p->topfunc()->getReturnType() == llvm::Type::VoidTy) { 106 if (p->topfunc()->getReturnType() == llvm::Type::VoidTy) {
107 IRFunction::FinallyVec& fin = p->func().finallys; 107 IRFunction::FinallyVec& fin = p->func()->finallys;
108 if (fin.empty()) { 108 if (fin.empty()) {
109 if (global.params.symdebug) DtoDwarfFuncEnd(p->func().decl); 109 if (global.params.symdebug) DtoDwarfFuncEnd(p->func()->decl);
110 new llvm::ReturnInst(p->scopebb()); 110 new llvm::ReturnInst(p->scopebb());
111 } 111 }
112 else { 112 else {
113 new llvm::BranchInst(fin.back().retbb, p->scopebb()); 113 new llvm::BranchInst(fin.back().retbb, p->scopebb());
114 } 114 }
418 assert(!gIR->scopereturned()); 418 assert(!gIR->scopereturned());
419 new llvm::BranchInst(trybb, p->scopebb()); 419 new llvm::BranchInst(trybb, p->scopebb());
420 420
421 // do the try block 421 // do the try block
422 p->scope() = IRScope(trybb,finallybb); 422 p->scope() = IRScope(trybb,finallybb);
423 gIR->func().finallys.push_back(IRFinally(finallybb,finallyretbb)); 423 gIR->func()->finallys.push_back(IRFinally(finallybb,finallyretbb));
424 IRFinally& fin = p->func().finallys.back(); 424 IRFinally& fin = p->func()->finallys.back();
425 425
426 assert(body); 426 assert(body);
427 body->toIR(p); 427 body->toIR(p);
428 428
429 // terminate try BB 429 // terminate try BB
444 p->scope() = IRScope(finallyretbb,endbb); 444 p->scope() = IRScope(finallyretbb,endbb);
445 assert(finalbody); 445 assert(finalbody);
446 finalbody->toIR(p); // hope this will work, otherwise it's time it gets fixed 446 finalbody->toIR(p); // hope this will work, otherwise it's time it gets fixed
447 447
448 // terminate finally (return path) 448 // terminate finally (return path)
449 size_t nfin = p->func().finallys.size(); 449 size_t nfin = p->func()->finallys.size();
450 if (nfin > 1) { 450 if (nfin > 1) {
451 IRFinally& ofin = p->func().finallys[nfin-2]; 451 IRFinally& ofin = p->func()->finallys[nfin-2];
452 p->ir->CreateBr(ofin.retbb); 452 p->ir->CreateBr(ofin.retbb);
453 } 453 }
454 // no outer 454 // no outer
455 else 455 else
456 { 456 {
457 if (global.params.symdebug) DtoDwarfFuncEnd(p->func().decl); 457 if (global.params.symdebug) DtoDwarfFuncEnd(p->func()->decl);
458 llvm::Value* retval = p->func().finallyretval; 458 llvm::Value* retval = p->func()->finallyretval;
459 if (retval) { 459 if (retval) {
460 retval = p->ir->CreateLoad(retval,"tmp"); 460 retval = p->ir->CreateLoad(retval,"tmp");
461 p->ir->CreateRet(retval); 461 p->ir->CreateRet(retval);
462 } 462 }
463 else { 463 else {
464 FuncDeclaration* fd = p->func().decl; 464 FuncDeclaration* fd = p->func()->decl;
465 if (fd->isMain()) { 465 if (fd->isMain()) {
466 assert(fd->type->next->ty == Tvoid); 466 assert(fd->type->next->ty == Tvoid);
467 p->ir->CreateRet(DtoConstInt(0)); 467 p->ir->CreateRet(DtoConstInt(0));
468 } 468 }
469 else { 469 else {
471 } 471 }
472 } 472 }
473 } 473 }
474 474
475 // rewrite the scope 475 // rewrite the scope
476 p->func().finallys.pop_back(); 476 p->func()->finallys.pop_back();
477 p->scope() = IRScope(endbb,oldend); 477 p->scope() = IRScope(endbb,oldend);
478 } 478 }
479 479
480 ////////////////////////////////////////////////////////////////////////////// 480 //////////////////////////////////////////////////////////////////////////////
481 481