comparison gen/statements.cpp @ 144:a27941d00351 trunk

[svn r149] fixed: a bunch of D-style variadics problems. fixed: GotoDefaultStatement implemented. fixed: some other minor bugs.
author lindquist
date Sat, 26 Jan 2008 17:13:22 +0100
parents ce7b81fb957f
children 8f704cb9969b
comparison
equal deleted inserted replaced
143:336ec4f4bbb3 144:a27941d00351
50 Logger::println("ReturnStatement::toIR(): %s", loc.toChars()); 50 Logger::println("ReturnStatement::toIR(): %s", loc.toChars());
51 LOG_SCOPE; 51 LOG_SCOPE;
52 52
53 if (exp) 53 if (exp)
54 { 54 {
55 Logger::println("return type is: %s", exp->type->toChars());
56
57 Type* exptype = DtoDType(exp->type);
58 TY expty = exptype->ty;
59 if (p->topfunc()->getReturnType() == llvm::Type::VoidTy) { 55 if (p->topfunc()->getReturnType() == llvm::Type::VoidTy) {
60 assert(DtoIsPassedByRef(exptype));
61
62 IrFunction* f = p->func(); 56 IrFunction* f = p->func();
63 assert(f->type->llvmRetInPtr); 57 assert(f->type->llvmRetInPtr);
64 assert(f->decl->irFunc->retArg); 58 assert(f->decl->irFunc->retArg);
65 59
66 if (global.params.symdebug) DtoDwarfStopPoint(loc.linnum); 60 if (global.params.symdebug) DtoDwarfStopPoint(loc.linnum);
318 // init 312 // init
319 if (init != 0) 313 if (init != 0)
320 init->toIR(p); 314 init->toIR(p);
321 315
322 // move into the for condition block, ie. start the loop 316 // move into the for condition block, ie. start the loop
317 assert(!gIR->scopereturned());
323 new llvm::BranchInst(forbb, gIR->scopebb()); 318 new llvm::BranchInst(forbb, gIR->scopebb());
324 319
325 p->loopbbs.push_back(IRScope(forincbb,endbb)); 320 p->loopbbs.push_back(IRScope(forincbb,endbb));
326 321
327 // replace current scope 322 // replace current scope
331 DValue* cond_e = condition->toElem(p); 326 DValue* cond_e = condition->toElem(p);
332 llvm::Value* cond_val = DtoBoolean(cond_e->getRVal()); 327 llvm::Value* cond_val = DtoBoolean(cond_e->getRVal());
333 delete cond_e; 328 delete cond_e;
334 329
335 // conditional branch 330 // conditional branch
336 llvm::Value* ifbreak = new llvm::BranchInst(forbodybb, endbb, cond_val, forbb); 331 assert(!gIR->scopereturned());
332 new llvm::BranchInst(forbodybb, endbb, cond_val, gIR->scopebb());
337 333
338 // rewrite scope 334 // rewrite scope
339 gIR->scope() = IRScope(forbodybb,forincbb); 335 gIR->scope() = IRScope(forbodybb,forincbb);
340 336
341 // do for body code 337 // do for body code
672 668
673 // default 669 // default
674 llvm::BasicBlock* defbb = 0; 670 llvm::BasicBlock* defbb = 0;
675 if (!hasNoDefault) { 671 if (!hasNoDefault) {
676 defbb = new llvm::BasicBlock("default", p->topfunc(), oldend); 672 defbb = new llvm::BasicBlock("default", p->topfunc(), oldend);
673 defaultBB = defbb;
677 } 674 }
678 675
679 // end (break point) 676 // end (break point)
680 llvm::BasicBlock* endbb = new llvm::BasicBlock("switchend", p->topfunc(), oldend); 677 llvm::BasicBlock* endbb = new llvm::BasicBlock("switchend", p->topfunc(), oldend);
681 678
975 972
976 if (label->statement->llvmBB == NULL) 973 if (label->statement->llvmBB == NULL)
977 label->statement->llvmBB = new llvm::BasicBlock("label", p->topfunc()); 974 label->statement->llvmBB = new llvm::BasicBlock("label", p->topfunc());
978 assert(!p->scopereturned()); 975 assert(!p->scopereturned());
979 new llvm::BranchInst(label->statement->llvmBB, p->scopebb()); 976 new llvm::BranchInst(label->statement->llvmBB, p->scopebb());
977 p->scope() = IRScope(bb,oldend);
978 }
979
980 //////////////////////////////////////////////////////////////////////////////
981
982 void GotoDefaultStatement::toIR(IRState* p)
983 {
984 Logger::println("GotoDefaultStatement::toIR(): %s", loc.toChars());
985 LOG_SCOPE;
986
987 llvm::BasicBlock* oldend = gIR->scopeend();
988 llvm::BasicBlock* bb = new llvm::BasicBlock("aftergotodefault", p->topfunc(), oldend);
989
990 assert(!p->scopereturned());
991 assert(sw->defaultBB);
992 new llvm::BranchInst(sw->defaultBB, p->scopebb());
980 p->scope() = IRScope(bb,oldend); 993 p->scope() = IRScope(bb,oldend);
981 } 994 }
982 995
983 ////////////////////////////////////////////////////////////////////////////// 996 //////////////////////////////////////////////////////////////////////////////
984 997
1083 //STUBST(TryFinallyStatement); 1096 //STUBST(TryFinallyStatement);
1084 //STUBST(VolatileStatement); 1097 //STUBST(VolatileStatement);
1085 //STUBST(LabelStatement); 1098 //STUBST(LabelStatement);
1086 //STUBST(ThrowStatement); 1099 //STUBST(ThrowStatement);
1087 STUBST(GotoCaseStatement); 1100 STUBST(GotoCaseStatement);
1088 STUBST(GotoDefaultStatement); 1101 //STUBST(GotoDefaultStatement);
1089 //STUBST(GotoStatement); 1102 //STUBST(GotoStatement);
1090 //STUBST(UnrolledLoopStatement); 1103 //STUBST(UnrolledLoopStatement);
1091 //STUBST(OnScopeStatement); 1104 //STUBST(OnScopeStatement);