Mercurial > projects > ldc
comparison gen/statements.cpp @ 268:23d0d9855cad trunk
[svn r289] Fixed: right shift >> was broken for unsigned types.
Fixed: debug info for classes now started.
author | lindquist |
---|---|
date | Sun, 15 Jun 2008 18:52:27 +0200 |
parents | c43911baea21 |
children | d9d5d59873d8 |
comparison
equal
deleted
inserted
replaced
267:c43911baea21 | 268:23d0d9855cad |
---|---|
174 void IfStatement::toIR(IRState* p) | 174 void IfStatement::toIR(IRState* p) |
175 { | 175 { |
176 Logger::println("IfStatement::toIR(): %s", loc.toChars()); | 176 Logger::println("IfStatement::toIR(): %s", loc.toChars()); |
177 LOG_SCOPE; | 177 LOG_SCOPE; |
178 | 178 |
179 if (global.params.symdebug) | |
180 DtoDwarfStopPoint(loc.linnum); | |
181 | |
179 if (match) | 182 if (match) |
180 { | 183 { |
181 LLValue* allocainst = new llvm::AllocaInst(DtoType(match->type), "._tmp_if_var", p->topallocapoint()); | 184 LLValue* allocainst = new llvm::AllocaInst(DtoType(match->type), "._tmp_if_var", p->topallocapoint()); |
182 match->ir.irLocal = new IrLocal(match); | 185 match->ir.irLocal = new IrLocal(match); |
183 match->ir.irLocal->value = allocainst; | 186 match->ir.irLocal->value = allocainst; |
201 | 204 |
202 // replace current scope | 205 // replace current scope |
203 gIR->scope() = IRScope(ifbb,elsebb); | 206 gIR->scope() = IRScope(ifbb,elsebb); |
204 | 207 |
205 // do scoped statements | 208 // do scoped statements |
206 ifbody->toIR(p); | 209 if (ifbody) |
210 ifbody->toIR(p); | |
207 if (!gIR->scopereturned()) { | 211 if (!gIR->scopereturned()) { |
208 llvm::BranchInst::Create(endbb,gIR->scopebb()); | 212 llvm::BranchInst::Create(endbb,gIR->scopebb()); |
209 } | 213 } |
210 | 214 |
211 if (elsebody) { | 215 if (elsebody) { |
262 void WhileStatement::toIR(IRState* p) | 266 void WhileStatement::toIR(IRState* p) |
263 { | 267 { |
264 Logger::println("WhileStatement::toIR(): %s", loc.toChars()); | 268 Logger::println("WhileStatement::toIR(): %s", loc.toChars()); |
265 LOG_SCOPE; | 269 LOG_SCOPE; |
266 | 270 |
271 if (global.params.symdebug) | |
272 DtoDwarfStopPoint(loc.linnum); | |
273 | |
267 // create while blocks | 274 // create while blocks |
268 llvm::BasicBlock* oldend = gIR->scopeend(); | 275 llvm::BasicBlock* oldend = gIR->scopeend(); |
269 llvm::BasicBlock* whilebb = llvm::BasicBlock::Create("whilecond", gIR->topfunc(), oldend); | 276 llvm::BasicBlock* whilebb = llvm::BasicBlock::Create("whilecond", gIR->topfunc(), oldend); |
270 llvm::BasicBlock* whilebodybb = llvm::BasicBlock::Create("whilebody", gIR->topfunc(), oldend); | 277 llvm::BasicBlock* whilebodybb = llvm::BasicBlock::Create("whilebody", gIR->topfunc(), oldend); |
271 llvm::BasicBlock* endbb = llvm::BasicBlock::Create("endwhile", gIR->topfunc(), oldend); | 278 llvm::BasicBlock* endbb = llvm::BasicBlock::Create("endwhile", gIR->topfunc(), oldend); |
306 void DoStatement::toIR(IRState* p) | 313 void DoStatement::toIR(IRState* p) |
307 { | 314 { |
308 Logger::println("DoStatement::toIR(): %s", loc.toChars()); | 315 Logger::println("DoStatement::toIR(): %s", loc.toChars()); |
309 LOG_SCOPE; | 316 LOG_SCOPE; |
310 | 317 |
318 if (global.params.symdebug) | |
319 DtoDwarfStopPoint(loc.linnum); | |
320 | |
311 // create while blocks | 321 // create while blocks |
312 llvm::BasicBlock* oldend = gIR->scopeend(); | 322 llvm::BasicBlock* oldend = gIR->scopeend(); |
313 llvm::BasicBlock* dowhilebb = llvm::BasicBlock::Create("dowhile", gIR->topfunc(), oldend); | 323 llvm::BasicBlock* dowhilebb = llvm::BasicBlock::Create("dowhile", gIR->topfunc(), oldend); |
314 llvm::BasicBlock* endbb = llvm::BasicBlock::Create("enddowhile", gIR->topfunc(), oldend); | 324 llvm::BasicBlock* endbb = llvm::BasicBlock::Create("enddowhile", gIR->topfunc(), oldend); |
315 | 325 |
341 | 351 |
342 void ForStatement::toIR(IRState* p) | 352 void ForStatement::toIR(IRState* p) |
343 { | 353 { |
344 Logger::println("ForStatement::toIR(): %s", loc.toChars()); | 354 Logger::println("ForStatement::toIR(): %s", loc.toChars()); |
345 LOG_SCOPE; | 355 LOG_SCOPE; |
356 | |
357 if (global.params.symdebug) | |
358 DtoDwarfStopPoint(loc.linnum); | |
346 | 359 |
347 // create for blocks | 360 // create for blocks |
348 llvm::BasicBlock* oldend = gIR->scopeend(); | 361 llvm::BasicBlock* oldend = gIR->scopeend(); |
349 llvm::BasicBlock* forbb = llvm::BasicBlock::Create("forcond", gIR->topfunc(), oldend); | 362 llvm::BasicBlock* forbb = llvm::BasicBlock::Create("forcond", gIR->topfunc(), oldend); |
350 llvm::BasicBlock* forbodybb = llvm::BasicBlock::Create("forbody", gIR->topfunc(), oldend); | 363 llvm::BasicBlock* forbodybb = llvm::BasicBlock::Create("forbody", gIR->topfunc(), oldend); |
409 | 422 |
410 // don't emit two terminators in a row | 423 // don't emit two terminators in a row |
411 // happens just before DMD generated default statements if the last case terminates | 424 // happens just before DMD generated default statements if the last case terminates |
412 if (p->scopereturned()) | 425 if (p->scopereturned()) |
413 return; | 426 return; |
427 | |
428 if (global.params.symdebug) | |
429 DtoDwarfStopPoint(loc.linnum); | |
414 | 430 |
415 if (ident != 0) { | 431 if (ident != 0) { |
416 Logger::println("ident = %s", ident->toChars()); | 432 Logger::println("ident = %s", ident->toChars()); |
417 | 433 |
418 emit_finallyblocks(p, enclosingtryfinally, target->enclosingtryfinally); | 434 emit_finallyblocks(p, enclosingtryfinally, target->enclosingtryfinally); |
444 void ContinueStatement::toIR(IRState* p) | 460 void ContinueStatement::toIR(IRState* p) |
445 { | 461 { |
446 Logger::println("ContinueStatement::toIR(): %s", loc.toChars()); | 462 Logger::println("ContinueStatement::toIR(): %s", loc.toChars()); |
447 LOG_SCOPE; | 463 LOG_SCOPE; |
448 | 464 |
465 if (global.params.symdebug) | |
466 DtoDwarfStopPoint(loc.linnum); | |
467 | |
449 if (ident != 0) { | 468 if (ident != 0) { |
450 Logger::println("ident = %s", ident->toChars()); | 469 Logger::println("ident = %s", ident->toChars()); |
451 | 470 |
452 emit_finallyblocks(p, enclosingtryfinally, target->enclosingtryfinally); | 471 emit_finallyblocks(p, enclosingtryfinally, target->enclosingtryfinally); |
453 | 472 |
489 void TryFinallyStatement::toIR(IRState* p) | 508 void TryFinallyStatement::toIR(IRState* p) |
490 { | 509 { |
491 Logger::println("TryFinallyStatement::toIR(): %s", loc.toChars()); | 510 Logger::println("TryFinallyStatement::toIR(): %s", loc.toChars()); |
492 LOG_SCOPE; | 511 LOG_SCOPE; |
493 | 512 |
513 if (global.params.symdebug) | |
514 DtoDwarfStopPoint(loc.linnum); | |
515 | |
494 // create basic blocks | 516 // create basic blocks |
495 llvm::BasicBlock* oldend = p->scopeend(); | 517 llvm::BasicBlock* oldend = p->scopeend(); |
496 | 518 |
497 llvm::BasicBlock* trybb = llvm::BasicBlock::Create("try", p->topfunc(), oldend); | 519 llvm::BasicBlock* trybb = llvm::BasicBlock::Create("try", p->topfunc(), oldend); |
498 llvm::BasicBlock* finallybb = llvm::BasicBlock::Create("finally", p->topfunc(), oldend); | 520 llvm::BasicBlock* finallybb = llvm::BasicBlock::Create("finally", p->topfunc(), oldend); |
532 { | 554 { |
533 Logger::println("TryCatchStatement::toIR(): %s", loc.toChars()); | 555 Logger::println("TryCatchStatement::toIR(): %s", loc.toChars()); |
534 LOG_SCOPE; | 556 LOG_SCOPE; |
535 | 557 |
536 Logger::attention(loc, "try-catch is not yet fully implemented"); | 558 Logger::attention(loc, "try-catch is not yet fully implemented"); |
559 | |
560 if (global.params.symdebug) | |
561 DtoDwarfStopPoint(loc.linnum); | |
537 | 562 |
538 // create basic blocks | 563 // create basic blocks |
539 llvm::BasicBlock* oldend = p->scopeend(); | 564 llvm::BasicBlock* oldend = p->scopeend(); |
540 | 565 |
541 llvm::BasicBlock* trybb = llvm::BasicBlock::Create("try", p->topfunc(), oldend); | 566 llvm::BasicBlock* trybb = llvm::BasicBlock::Create("try", p->topfunc(), oldend); |
574 { | 599 { |
575 Logger::println("ThrowStatement::toIR(): %s", loc.toChars()); | 600 Logger::println("ThrowStatement::toIR(): %s", loc.toChars()); |
576 LOG_SCOPE; | 601 LOG_SCOPE; |
577 | 602 |
578 Logger::attention(loc, "throw is not yet fully implemented"); | 603 Logger::attention(loc, "throw is not yet fully implemented"); |
604 | |
605 if (global.params.symdebug) | |
606 DtoDwarfStopPoint(loc.linnum); | |
579 | 607 |
580 assert(exp); | 608 assert(exp); |
581 DValue* e = exp->toElem(p); | 609 DValue* e = exp->toElem(p); |
582 llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_throw_exception"); | 610 llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_throw_exception"); |
583 //Logger::cout() << "calling: " << *fn << '\n'; | 611 //Logger::cout() << "calling: " << *fn << '\n'; |
651 | 679 |
652 void SwitchStatement::toIR(IRState* p) | 680 void SwitchStatement::toIR(IRState* p) |
653 { | 681 { |
654 Logger::println("SwitchStatement::toIR(): %s", loc.toChars()); | 682 Logger::println("SwitchStatement::toIR(): %s", loc.toChars()); |
655 LOG_SCOPE; | 683 LOG_SCOPE; |
684 | |
685 if (global.params.symdebug) | |
686 DtoDwarfStopPoint(loc.linnum); | |
656 | 687 |
657 llvm::BasicBlock* oldend = gIR->scopeend(); | 688 llvm::BasicBlock* oldend = gIR->scopeend(); |
658 | 689 |
659 // clear data from previous passes... :/ | 690 // clear data from previous passes... :/ |
660 for (int i=0; i<cases->dim; ++i) | 691 for (int i=0; i<cases->dim; ++i) |
820 void UnrolledLoopStatement::toIR(IRState* p) | 851 void UnrolledLoopStatement::toIR(IRState* p) |
821 { | 852 { |
822 Logger::println("UnrolledLoopStatement::toIR(): %s", loc.toChars()); | 853 Logger::println("UnrolledLoopStatement::toIR(): %s", loc.toChars()); |
823 LOG_SCOPE; | 854 LOG_SCOPE; |
824 | 855 |
856 if (global.params.symdebug) | |
857 DtoDwarfStopPoint(loc.linnum); | |
858 | |
825 llvm::BasicBlock* oldend = gIR->scopeend(); | 859 llvm::BasicBlock* oldend = gIR->scopeend(); |
826 llvm::BasicBlock* endbb = llvm::BasicBlock::Create("unrolledend", p->topfunc(), oldend); | 860 llvm::BasicBlock* endbb = llvm::BasicBlock::Create("unrolledend", p->topfunc(), oldend); |
827 | 861 |
828 p->scope() = IRScope(p->scopebb(),endbb); | 862 p->scope() = IRScope(p->scopebb(),endbb); |
829 p->loopbbs.push_back(IRLoopScope(this,enclosingtryfinally,p->scopebb(),endbb)); | 863 p->loopbbs.push_back(IRLoopScope(this,enclosingtryfinally,p->scopebb(),endbb)); |
844 | 878 |
845 void ForeachStatement::toIR(IRState* p) | 879 void ForeachStatement::toIR(IRState* p) |
846 { | 880 { |
847 Logger::println("ForeachStatement::toIR(): %s", loc.toChars()); | 881 Logger::println("ForeachStatement::toIR(): %s", loc.toChars()); |
848 LOG_SCOPE; | 882 LOG_SCOPE; |
883 | |
884 if (global.params.symdebug) | |
885 DtoDwarfStopPoint(loc.linnum); | |
849 | 886 |
850 //assert(arguments->dim == 1); | 887 //assert(arguments->dim == 1); |
851 assert(value != 0); | 888 assert(value != 0); |
852 assert(body != 0); | 889 assert(body != 0); |
853 assert(aggr != 0); | 890 assert(aggr != 0); |
1045 void GotoStatement::toIR(IRState* p) | 1082 void GotoStatement::toIR(IRState* p) |
1046 { | 1083 { |
1047 Logger::println("GotoStatement::toIR(): %s", loc.toChars()); | 1084 Logger::println("GotoStatement::toIR(): %s", loc.toChars()); |
1048 LOG_SCOPE; | 1085 LOG_SCOPE; |
1049 | 1086 |
1087 if (global.params.symdebug) | |
1088 DtoDwarfStopPoint(loc.linnum); | |
1089 | |
1050 assert(tf == NULL); | 1090 assert(tf == NULL); |
1051 | 1091 |
1052 llvm::BasicBlock* oldend = gIR->scopeend(); | 1092 llvm::BasicBlock* oldend = gIR->scopeend(); |
1053 llvm::BasicBlock* bb = llvm::BasicBlock::Create("aftergoto", p->topfunc(), oldend); | 1093 llvm::BasicBlock* bb = llvm::BasicBlock::Create("aftergoto", p->topfunc(), oldend); |
1054 | 1094 |
1078 void GotoDefaultStatement::toIR(IRState* p) | 1118 void GotoDefaultStatement::toIR(IRState* p) |
1079 { | 1119 { |
1080 Logger::println("GotoDefaultStatement::toIR(): %s", loc.toChars()); | 1120 Logger::println("GotoDefaultStatement::toIR(): %s", loc.toChars()); |
1081 LOG_SCOPE; | 1121 LOG_SCOPE; |
1082 | 1122 |
1123 if (global.params.symdebug) | |
1124 DtoDwarfStopPoint(loc.linnum); | |
1125 | |
1083 llvm::BasicBlock* oldend = gIR->scopeend(); | 1126 llvm::BasicBlock* oldend = gIR->scopeend(); |
1084 llvm::BasicBlock* bb = llvm::BasicBlock::Create("aftergotodefault", p->topfunc(), oldend); | 1127 llvm::BasicBlock* bb = llvm::BasicBlock::Create("aftergotodefault", p->topfunc(), oldend); |
1085 | 1128 |
1086 assert(!p->scopereturned()); | 1129 assert(!p->scopereturned()); |
1087 assert(sw->sdefault->bodyBB); | 1130 assert(sw->sdefault->bodyBB); |
1097 void GotoCaseStatement::toIR(IRState* p) | 1140 void GotoCaseStatement::toIR(IRState* p) |
1098 { | 1141 { |
1099 Logger::println("GotoCaseStatement::toIR(): %s", loc.toChars()); | 1142 Logger::println("GotoCaseStatement::toIR(): %s", loc.toChars()); |
1100 LOG_SCOPE; | 1143 LOG_SCOPE; |
1101 | 1144 |
1145 if (global.params.symdebug) | |
1146 DtoDwarfStopPoint(loc.linnum); | |
1147 | |
1102 llvm::BasicBlock* oldend = gIR->scopeend(); | 1148 llvm::BasicBlock* oldend = gIR->scopeend(); |
1103 llvm::BasicBlock* bb = llvm::BasicBlock::Create("aftergotocase", p->topfunc(), oldend); | 1149 llvm::BasicBlock* bb = llvm::BasicBlock::Create("aftergotocase", p->topfunc(), oldend); |
1104 | 1150 |
1105 assert(!p->scopereturned()); | 1151 assert(!p->scopereturned()); |
1106 if (!cs->bodyBB) | 1152 if (!cs->bodyBB) |
1118 | 1164 |
1119 void WithStatement::toIR(IRState* p) | 1165 void WithStatement::toIR(IRState* p) |
1120 { | 1166 { |
1121 Logger::println("WithStatement::toIR(): %s", loc.toChars()); | 1167 Logger::println("WithStatement::toIR(): %s", loc.toChars()); |
1122 LOG_SCOPE; | 1168 LOG_SCOPE; |
1169 | |
1170 if (global.params.symdebug) | |
1171 DtoDwarfStopPoint(loc.linnum); | |
1123 | 1172 |
1124 assert(exp); | 1173 assert(exp); |
1125 assert(body); | 1174 assert(body); |
1126 | 1175 |
1127 DValue* e = exp->toElem(p); | 1176 DValue* e = exp->toElem(p); |
1138 { | 1187 { |
1139 Logger::println("SynchronizedStatement::toIR(): %s", loc.toChars()); | 1188 Logger::println("SynchronizedStatement::toIR(): %s", loc.toChars()); |
1140 LOG_SCOPE; | 1189 LOG_SCOPE; |
1141 | 1190 |
1142 Logger::attention(loc, "synchronized is currently ignored. only the body will be emitted"); | 1191 Logger::attention(loc, "synchronized is currently ignored. only the body will be emitted"); |
1192 | |
1193 if (global.params.symdebug) | |
1194 DtoDwarfStopPoint(loc.linnum); | |
1143 | 1195 |
1144 body->toIR(p); | 1196 body->toIR(p); |
1145 } | 1197 } |
1146 | 1198 |
1147 ////////////////////////////////////////////////////////////////////////////// | 1199 ////////////////////////////////////////////////////////////////////////////// |
1183 | 1235 |
1184 void VolatileStatement::toIR(IRState* p) | 1236 void VolatileStatement::toIR(IRState* p) |
1185 { | 1237 { |
1186 Logger::println("VolatileStatement::toIR(): %s", loc.toChars()); | 1238 Logger::println("VolatileStatement::toIR(): %s", loc.toChars()); |
1187 LOG_SCOPE; | 1239 LOG_SCOPE; |
1240 | |
1241 if (global.params.symdebug) | |
1242 DtoDwarfStopPoint(loc.linnum); | |
1188 | 1243 |
1189 // mark in-volatile | 1244 // mark in-volatile |
1190 bool old = gIR->func()->inVolatile; | 1245 bool old = gIR->func()->inVolatile; |
1191 gIR->func()->inVolatile = true; | 1246 gIR->func()->inVolatile = true; |
1192 | 1247 |