Mercurial > projects > ldc
comparison gen/statements.c @ 34:4648206ca213 trunk
[svn r38] * resizing dynamic arrays support
* throw is replaced with assert(0)
* catch is ignored
* better foreach support
* various bugfixes
author | lindquist |
---|---|
date | Tue, 09 Oct 2007 02:50:00 +0200 |
parents | bc641b23a714 |
children | 77cdca8c210f |
comparison
equal
deleted
inserted
replaced
33:bc641b23a714 | 34:4648206ca213 |
---|---|
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()); |
36 LOG_SCOPE; | 36 LOG_SCOPE; |
37 | 37 |
38 /* | 38 for (int i=0; i<statements->dim; i++) |
39 const char* labelname; | |
40 bool insterm = false; | |
41 | |
42 if (!p->scopes()) { | |
43 labelname = "bb"; | |
44 insterm = true; | |
45 } | |
46 else | |
47 labelname = "entry"; | |
48 | |
49 //if (!llvm::isa<llvm::TerminatorInst>(p->topfunc()->back().back())) | |
50 // insterm = true; | |
51 | |
52 llvm::BasicBlock* bb = new llvm::BasicBlock(labelname, p->topfunc()); | |
53 | |
54 if (insterm) { | |
55 new llvm::BranchInst(bb,p->topbb()); | |
56 } | |
57 | |
58 p->bbs.push(bb); | |
59 */ | |
60 | |
61 size_t n = statements->dim; | |
62 for (size_t i=0; i<n; i++) | |
63 { | 39 { |
64 Statement* s = (Statement*)statements->data[i]; | 40 Statement* s = (Statement*)statements->data[i]; |
65 if (s) | 41 if (s) |
66 s->toIR(p); | 42 s->toIR(p); |
67 else | 43 else { |
68 Logger::println("NULL statement found in CompoundStatement !! :S"); | 44 Logger::println("NULL statement found in CompoundStatement !! :S"); |
69 } | 45 assert(0); |
70 | 46 } |
71 //p->bbs.pop(); | 47 } |
48 | |
72 } | 49 } |
73 | 50 |
74 ////////////////////////////////////////////////////////////////////////////// | 51 ////////////////////////////////////////////////////////////////////////////// |
75 | 52 |
76 void ReturnStatement::toIR(IRState* p) | 53 void ReturnStatement::toIR(IRState* p) |
474 { | 451 { |
475 static int wsi = 0; | 452 static int wsi = 0; |
476 Logger::println("TryCatchStatement::toIR(%d): %s", wsi++, toChars()); | 453 Logger::println("TryCatchStatement::toIR(%d): %s", wsi++, toChars()); |
477 LOG_SCOPE; | 454 LOG_SCOPE; |
478 | 455 |
479 assert(0 && "try-catch is not properly"); | 456 Logger::println("*** ATTENTION: try-catch is not yet fully implemented, only the try block will be emitted."); |
480 | 457 |
481 assert(body); | 458 assert(body); |
482 body->toIR(p); | 459 body->toIR(p); |
483 | 460 |
484 assert(catches); | 461 /*assert(catches); |
485 for(size_t i=0; i<catches->dim; ++i) | 462 for(size_t i=0; i<catches->dim; ++i) |
486 { | 463 { |
487 Catch* c = (Catch*)catches->data[i]; | 464 Catch* c = (Catch*)catches->data[i]; |
488 c->handler->toIR(p); | 465 c->handler->toIR(p); |
489 } | 466 }*/ |
490 } | 467 } |
491 | 468 |
492 ////////////////////////////////////////////////////////////////////////////// | 469 ////////////////////////////////////////////////////////////////////////////// |
493 | 470 |
494 void ThrowStatement::toIR(IRState* p) | 471 void ThrowStatement::toIR(IRState* p) |
495 { | 472 { |
496 static int wsi = 0; | 473 static int wsi = 0; |
497 Logger::println("ThrowStatement::toIR(%d): %s", wsi++, toChars()); | 474 Logger::println("ThrowStatement::toIR(%d): %s", wsi++, toChars()); |
498 LOG_SCOPE; | 475 LOG_SCOPE; |
499 | 476 |
500 assert(0 && "throw is not implemented"); | 477 Logger::println("*** ATTENTION: throw is not yet implemented, replacing expression with assert(0);"); |
501 | 478 |
479 llvm::Value* line = llvm::ConstantInt::get(llvm::Type::Int32Ty, loc.linnum, false); | |
480 LLVM_DtoAssert(NULL, line, NULL); | |
481 | |
482 /* | |
502 assert(exp); | 483 assert(exp); |
503 elem* e = exp->toElem(p); | 484 elem* e = exp->toElem(p); |
504 delete e; | 485 delete e; |
486 */ | |
505 } | 487 } |
506 | 488 |
507 ////////////////////////////////////////////////////////////////////////////// | 489 ////////////////////////////////////////////////////////////////////////////// |
508 | 490 |
509 void SwitchStatement::toIR(IRState* p) | 491 void SwitchStatement::toIR(IRState* p) |
620 { | 602 { |
621 Logger::println("ForeachStatement::toIR(): %s", toChars()); | 603 Logger::println("ForeachStatement::toIR(): %s", toChars()); |
622 LOG_SCOPE; | 604 LOG_SCOPE; |
623 | 605 |
624 //assert(arguments->dim == 1); | 606 //assert(arguments->dim == 1); |
625 assert(key == 0); | |
626 assert(value != 0); | 607 assert(value != 0); |
627 assert(body != 0); | 608 assert(body != 0); |
628 assert(aggr != 0); | 609 assert(aggr != 0); |
629 assert(func != 0); | 610 assert(func != 0); |
630 | 611 |
640 | 621 |
641 llvm::Value* numiters = 0; | 622 llvm::Value* numiters = 0; |
642 | 623 |
643 const llvm::Type* keytype = key ? LLVM_DtoType(key->type) : LLVM_DtoSize_t(); | 624 const llvm::Type* keytype = key ? LLVM_DtoType(key->type) : LLVM_DtoSize_t(); |
644 llvm::Value* keyvar = new llvm::AllocaInst(keytype, "foreachkey", p->topallocapoint()); | 625 llvm::Value* keyvar = new llvm::AllocaInst(keytype, "foreachkey", p->topallocapoint()); |
626 if (key) key->llvmValue = keyvar; | |
645 | 627 |
646 const llvm::Type* valtype = LLVM_DtoType(value->type); | 628 const llvm::Type* valtype = LLVM_DtoType(value->type); |
647 llvm::Value* valvar = new llvm::AllocaInst(keytype, "foreachval", p->topallocapoint()); | 629 llvm::Value* valvar = new llvm::AllocaInst(keytype, "foreachval", p->topallocapoint()); |
648 | 630 |
649 if (aggr->type->ty == Tsarray) | 631 if (aggr->type->ty == Tsarray) |