Mercurial > projects > ldc
comparison gen/statements.c @ 15:37a4fdab33fc trunk
[svn r19] * Added support for reassigning 'this' inside class constructors.
* Added preliminary support for UnrolledLoopStatement. That is foreach on a tuple.
author | lindquist |
---|---|
date | Wed, 03 Oct 2007 04:56:32 +0200 |
parents | 0e86428ee567 |
children | a86fe7496b58 |
comparison
equal
deleted
inserted
replaced
14:0e86428ee567 | 15:37a4fdab33fc |
---|---|
25 #include "gen/logger.h" | 25 #include "gen/logger.h" |
26 #include "gen/tollvm.h" | 26 #include "gen/tollvm.h" |
27 #include "gen/runtime.h" | 27 #include "gen/runtime.h" |
28 #include "gen/arrays.h" | 28 #include "gen/arrays.h" |
29 | 29 |
30 /* --------------------------------------------------------------------------------------- */ | 30 ////////////////////////////////////////////////////////////////////////////// |
31 | 31 |
32 void CompoundStatement::toIR(IRState* p) | 32 void CompoundStatement::toIR(IRState* p) |
33 { | 33 { |
34 static int csi = 0; | 34 static int csi = 0; |
35 Logger::println("CompoundStatement::toIR(%d):\n<<<\n%s>>>", csi++, toChars()); | 35 Logger::println("CompoundStatement::toIR(%d):\n<<<\n%s>>>", csi++, toChars()); |
68 Logger::println("NULL statement found in CompoundStatement !! :S"); | 68 Logger::println("NULL statement found in CompoundStatement !! :S"); |
69 } | 69 } |
70 | 70 |
71 //p->bbs.pop(); | 71 //p->bbs.pop(); |
72 } | 72 } |
73 | |
74 ////////////////////////////////////////////////////////////////////////////// | |
73 | 75 |
74 void ReturnStatement::toIR(IRState* p) | 76 void ReturnStatement::toIR(IRState* p) |
75 { | 77 { |
76 static int rsi = 0; | 78 static int rsi = 0; |
77 Logger::println("ReturnStatement::toIR(%d): %s", rsi++, toChars()); | 79 Logger::println("ReturnStatement::toIR(%d): %s", rsi++, toChars()); |
132 } | 134 } |
133 | 135 |
134 p->scope().returned = true; | 136 p->scope().returned = true; |
135 } | 137 } |
136 | 138 |
139 ////////////////////////////////////////////////////////////////////////////// | |
140 | |
137 void ExpStatement::toIR(IRState* p) | 141 void ExpStatement::toIR(IRState* p) |
138 { | 142 { |
139 static int esi = 0; | 143 static int esi = 0; |
140 Logger::println("ExpStatement::toIR(%d): %s", esi++, toChars()); | 144 Logger::println("ExpStatement::toIR(%d): %s", esi++, toChars()); |
141 LOG_SCOPE; | 145 LOG_SCOPE; |
147 /*elem* e = exp->toElem(p); | 151 /*elem* e = exp->toElem(p); |
148 p->buf.printf("%s", e->toChars()); | 152 p->buf.printf("%s", e->toChars()); |
149 delete e; | 153 delete e; |
150 p->buf.writenl();*/ | 154 p->buf.writenl();*/ |
151 } | 155 } |
156 | |
157 ////////////////////////////////////////////////////////////////////////////// | |
152 | 158 |
153 void IfStatement::toIR(IRState* p) | 159 void IfStatement::toIR(IRState* p) |
154 { | 160 { |
155 static int wsi = 0; | 161 static int wsi = 0; |
156 Logger::println("IfStatement::toIR(%d): %s", wsi++, toChars()); | 162 Logger::println("IfStatement::toIR(%d): %s", wsi++, toChars()); |
202 | 208 |
203 // rewrite the scope | 209 // rewrite the scope |
204 gIR->scope() = IRScope(endbb,oldend); | 210 gIR->scope() = IRScope(endbb,oldend); |
205 } | 211 } |
206 | 212 |
213 ////////////////////////////////////////////////////////////////////////////// | |
214 | |
207 void ScopeStatement::toIR(IRState* p) | 215 void ScopeStatement::toIR(IRState* p) |
208 { | 216 { |
209 Logger::println("ScopeStatement::toIR(): %s", toChars()); | 217 Logger::println("ScopeStatement::toIR(): %s", toChars()); |
210 LOG_SCOPE; | 218 LOG_SCOPE; |
211 | 219 |
238 // rewrite the scope | 246 // rewrite the scope |
239 gIR->scope() = IRScope(irs.end,oldend); | 247 gIR->scope() = IRScope(irs.end,oldend); |
240 */ | 248 */ |
241 } | 249 } |
242 | 250 |
251 ////////////////////////////////////////////////////////////////////////////// | |
252 | |
243 void WhileStatement::toIR(IRState* p) | 253 void WhileStatement::toIR(IRState* p) |
244 { | 254 { |
245 static int wsi = 0; | 255 static int wsi = 0; |
246 Logger::println("WhileStatement::toIR(%d): %s", wsi++, toChars()); | 256 Logger::println("WhileStatement::toIR(%d): %s", wsi++, toChars()); |
247 LOG_SCOPE; | 257 LOG_SCOPE; |
279 | 289 |
280 // rewrite the scope | 290 // rewrite the scope |
281 gIR->scope() = IRScope(endbb,oldend); | 291 gIR->scope() = IRScope(endbb,oldend); |
282 } | 292 } |
283 | 293 |
294 ////////////////////////////////////////////////////////////////////////////// | |
295 | |
284 void DoStatement::toIR(IRState* p) | 296 void DoStatement::toIR(IRState* p) |
285 { | 297 { |
286 static int wsi = 0; | 298 static int wsi = 0; |
287 Logger::println("DoStatement::toIR(%d): %s", wsi++, toChars()); | 299 Logger::println("DoStatement::toIR(%d): %s", wsi++, toChars()); |
288 LOG_SCOPE; | 300 LOG_SCOPE; |
310 llvm::Value* ifbreak = new llvm::BranchInst(dowhilebb, endbb, cond_val, gIR->scopebegin()); | 322 llvm::Value* ifbreak = new llvm::BranchInst(dowhilebb, endbb, cond_val, gIR->scopebegin()); |
311 | 323 |
312 // rewrite the scope | 324 // rewrite the scope |
313 gIR->scope() = IRScope(endbb,oldend); | 325 gIR->scope() = IRScope(endbb,oldend); |
314 } | 326 } |
327 | |
328 ////////////////////////////////////////////////////////////////////////////// | |
315 | 329 |
316 void ForStatement::toIR(IRState* p) | 330 void ForStatement::toIR(IRState* p) |
317 { | 331 { |
318 static int wsi = 0; | 332 static int wsi = 0; |
319 Logger::println("ForStatement::toIR(%d): %s", wsi++, toChars()); | 333 Logger::println("ForStatement::toIR(%d): %s", wsi++, toChars()); |
372 | 386 |
373 // rewrite the scope | 387 // rewrite the scope |
374 gIR->scope() = IRScope(endbb,oldend); | 388 gIR->scope() = IRScope(endbb,oldend); |
375 } | 389 } |
376 | 390 |
391 ////////////////////////////////////////////////////////////////////////////// | |
392 | |
377 void BreakStatement::toIR(IRState* p) | 393 void BreakStatement::toIR(IRState* p) |
378 { | 394 { |
379 static int wsi = 0; | 395 static int wsi = 0; |
380 Logger::println("BreakStatement::toIR(%d): %s", wsi++, toChars()); | 396 Logger::println("BreakStatement::toIR(%d): %s", wsi++, toChars()); |
381 LOG_SCOPE; | 397 LOG_SCOPE; |
387 else { | 403 else { |
388 new llvm::BranchInst(gIR->loopbbs.back().end, gIR->scopebegin()); | 404 new llvm::BranchInst(gIR->loopbbs.back().end, gIR->scopebegin()); |
389 } | 405 } |
390 } | 406 } |
391 | 407 |
408 ////////////////////////////////////////////////////////////////////////////// | |
409 | |
392 void ContinueStatement::toIR(IRState* p) | 410 void ContinueStatement::toIR(IRState* p) |
393 { | 411 { |
394 static int wsi = 0; | 412 static int wsi = 0; |
395 Logger::println("ContinueStatement::toIR(%d): %s", wsi++, toChars()); | 413 Logger::println("ContinueStatement::toIR(%d): %s", wsi++, toChars()); |
396 LOG_SCOPE; | 414 LOG_SCOPE; |
402 else { | 420 else { |
403 new llvm::BranchInst(gIR->loopbbs.back().begin, gIR->scopebegin()); | 421 new llvm::BranchInst(gIR->loopbbs.back().begin, gIR->scopebegin()); |
404 } | 422 } |
405 } | 423 } |
406 | 424 |
425 ////////////////////////////////////////////////////////////////////////////// | |
426 | |
407 void OnScopeStatement::toIR(IRState* p) | 427 void OnScopeStatement::toIR(IRState* p) |
408 { | 428 { |
409 static int wsi = 0; | 429 static int wsi = 0; |
410 Logger::println("OnScopeStatement::toIR(%d): %s", wsi++, toChars()); | 430 Logger::println("OnScopeStatement::toIR(%d): %s", wsi++, toChars()); |
411 LOG_SCOPE; | 431 LOG_SCOPE; |
412 | 432 |
413 assert(statement); | 433 assert(statement); |
414 //statement->toIR(p); // this seems to be redundant | 434 //statement->toIR(p); // this seems to be redundant |
415 } | 435 } |
436 | |
437 ////////////////////////////////////////////////////////////////////////////// | |
416 | 438 |
417 void TryFinallyStatement::toIR(IRState* p) | 439 void TryFinallyStatement::toIR(IRState* p) |
418 { | 440 { |
419 static int wsi = 0; | 441 static int wsi = 0; |
420 Logger::println("TryFinallyStatement::toIR(%d): %s", wsi++, toChars()); | 442 Logger::println("TryFinallyStatement::toIR(%d): %s", wsi++, toChars()); |
444 | 466 |
445 // rewrite the scope | 467 // rewrite the scope |
446 gIR->scope() = IRScope(endbb,oldend); | 468 gIR->scope() = IRScope(endbb,oldend); |
447 } | 469 } |
448 | 470 |
471 ////////////////////////////////////////////////////////////////////////////// | |
472 | |
449 void TryCatchStatement::toIR(IRState* p) | 473 void TryCatchStatement::toIR(IRState* p) |
450 { | 474 { |
451 static int wsi = 0; | 475 static int wsi = 0; |
452 Logger::println("TryCatchStatement::toIR(%d): %s", wsi++, toChars()); | 476 Logger::println("TryCatchStatement::toIR(%d): %s", wsi++, toChars()); |
453 LOG_SCOPE; | 477 LOG_SCOPE; |
462 { | 486 { |
463 Catch* c = (Catch*)catches->data[i]; | 487 Catch* c = (Catch*)catches->data[i]; |
464 c->handler->toIR(p); | 488 c->handler->toIR(p); |
465 } | 489 } |
466 } | 490 } |
491 | |
492 ////////////////////////////////////////////////////////////////////////////// | |
467 | 493 |
468 void ThrowStatement::toIR(IRState* p) | 494 void ThrowStatement::toIR(IRState* p) |
469 { | 495 { |
470 static int wsi = 0; | 496 static int wsi = 0; |
471 Logger::println("ThrowStatement::toIR(%d): %s", wsi++, toChars()); | 497 Logger::println("ThrowStatement::toIR(%d): %s", wsi++, toChars()); |
475 | 501 |
476 assert(exp); | 502 assert(exp); |
477 elem* e = exp->toElem(p); | 503 elem* e = exp->toElem(p); |
478 delete e; | 504 delete e; |
479 } | 505 } |
506 | |
507 ////////////////////////////////////////////////////////////////////////////// | |
480 | 508 |
481 void SwitchStatement::toIR(IRState* p) | 509 void SwitchStatement::toIR(IRState* p) |
482 { | 510 { |
483 Logger::println("SwitchStatement::toIR(): %s", toChars()); | 511 Logger::println("SwitchStatement::toIR(): %s", toChars()); |
484 LOG_SCOPE; | 512 LOG_SCOPE; |
558 } | 586 } |
559 } | 587 } |
560 | 588 |
561 gIR->scope() = IRScope(endbb,oldend); | 589 gIR->scope() = IRScope(endbb,oldend); |
562 } | 590 } |
591 | |
592 ////////////////////////////////////////////////////////////////////////////// | |
593 | |
594 void UnrolledLoopStatement::toIR(IRState* p) | |
595 { | |
596 Logger::println("UnrolledLoopStatement::toIR(): %s", toChars()); | |
597 LOG_SCOPE; | |
598 | |
599 llvm::BasicBlock* oldend = gIR->scopeend(); | |
600 llvm::BasicBlock* endbb = new llvm::BasicBlock("unrolledend", p->topfunc(), oldend); | |
601 | |
602 p->scope() = IRScope(p->scopebb(),endbb); | |
603 p->loopbbs.push_back(IRScope(p->scopebb(),endbb)); | |
604 | |
605 for (int i=0; i<statements->dim; ++i) | |
606 { | |
607 Statement* s = (Statement*)statements->data[i]; | |
608 s->toIR(p); | |
609 } | |
610 | |
611 p->loopbbs.pop_back(); | |
612 | |
613 new llvm::BranchInst(endbb, p->scopebb()); | |
614 p->scope() = IRScope(endbb,oldend); | |
615 } | |
616 | |
617 ////////////////////////////////////////////////////////////////////////////// | |
618 | |
619 ////////////////////////////////////////////////////////////////////////////// | |
563 | 620 |
564 #define STUBST(x) void x::toIR(IRState * p) {error("Statement type "#x" not implemented: %s", toChars());fatal();} | 621 #define STUBST(x) void x::toIR(IRState * p) {error("Statement type "#x" not implemented: %s", toChars());fatal();} |
565 //STUBST(BreakStatement); | 622 //STUBST(BreakStatement); |
566 //STUBST(ForStatement); | 623 //STUBST(ForStatement); |
567 STUBST(WithStatement); | 624 STUBST(WithStatement); |
587 STUBST(LabelStatement); | 644 STUBST(LabelStatement); |
588 //STUBST(ThrowStatement); | 645 //STUBST(ThrowStatement); |
589 STUBST(GotoCaseStatement); | 646 STUBST(GotoCaseStatement); |
590 STUBST(GotoDefaultStatement); | 647 STUBST(GotoDefaultStatement); |
591 STUBST(GotoStatement); | 648 STUBST(GotoStatement); |
592 STUBST(UnrolledLoopStatement); | 649 //STUBST(UnrolledLoopStatement); |
593 //STUBST(OnScopeStatement); | 650 //STUBST(OnScopeStatement); |