Mercurial > projects > ldc
comparison gen/statements.cpp @ 133:44a95ac7368a trunk
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
In particular, assertions has been fixed to include file/line info, and much more!
author | lindquist |
---|---|
date | Mon, 14 Jan 2008 05:11:54 +0100 |
parents | 1700239cab2e |
children | 0e28624814e8 |
comparison
equal
deleted
inserted
replaced
132:1700239cab2e | 133:44a95ac7368a |
---|---|
6 #include <fstream> | 6 #include <fstream> |
7 #include <iostream> | 7 #include <iostream> |
8 | 8 |
9 #include "gen/llvm.h" | 9 #include "gen/llvm.h" |
10 #include "llvm/InlineAsm.h" | 10 #include "llvm/InlineAsm.h" |
11 #include "llvm/Support/CFG.h" | |
11 | 12 |
12 #include "mars.h" | 13 #include "mars.h" |
13 #include "total.h" | 14 #include "total.h" |
14 #include "init.h" | 15 #include "init.h" |
15 #include "mtype.h" | 16 #include "mtype.h" |
486 void TryCatchStatement::toIR(IRState* p) | 487 void TryCatchStatement::toIR(IRState* p) |
487 { | 488 { |
488 Logger::println("TryCatchStatement::toIR(): %s", loc.toChars()); | 489 Logger::println("TryCatchStatement::toIR(): %s", loc.toChars()); |
489 LOG_SCOPE; | 490 LOG_SCOPE; |
490 | 491 |
491 Logger::attention(loc, "try-catch is not yet fully implemented, only the try block will be emitted."); | 492 Logger::attention(loc, "try-catch is not yet fully implemented"); |
492 | 493 |
494 // create basic blocks | |
495 llvm::BasicBlock* oldend = p->scopeend(); | |
496 | |
497 llvm::BasicBlock* trybb = new llvm::BasicBlock("try", p->topfunc(), oldend); | |
498 llvm::BasicBlock* catchbb = new llvm::BasicBlock("catch", p->topfunc(), oldend); | |
499 llvm::BasicBlock* endbb = new llvm::BasicBlock("endtrycatch", p->topfunc(), oldend); | |
500 | |
501 // pass the previous BB into this | |
502 assert(!gIR->scopereturned()); | |
503 new llvm::BranchInst(trybb, p->scopebb()); | |
504 | |
505 // do the try block | |
506 p->scope() = IRScope(trybb,catchbb); | |
493 assert(body); | 507 assert(body); |
494 body->toIR(p); | 508 body->toIR(p); |
495 | 509 |
510 if (!gIR->scopereturned()) | |
511 new llvm::BranchInst(endbb, p->scopebb()); | |
512 | |
513 // do catch | |
514 p->scope() = IRScope(catchbb,oldend); | |
515 new llvm::BranchInst(endbb, p->scopebb()); | |
496 /*assert(catches); | 516 /*assert(catches); |
497 for(size_t i=0; i<catches->dim; ++i) | 517 for(size_t i=0; i<catches->dim; ++i) |
498 { | 518 { |
499 Catch* c = (Catch*)catches->data[i]; | 519 Catch* c = (Catch*)catches->data[i]; |
500 c->handler->toIR(p); | 520 c->handler->toIR(p); |
501 }*/ | 521 }*/ |
522 | |
523 // rewrite the scope | |
524 p->scope() = IRScope(endbb,oldend); | |
502 } | 525 } |
503 | 526 |
504 ////////////////////////////////////////////////////////////////////////////// | 527 ////////////////////////////////////////////////////////////////////////////// |
505 | 528 |
506 void ThrowStatement::toIR(IRState* p) | 529 void ThrowStatement::toIR(IRState* p) |
507 { | 530 { |
508 Logger::println("ThrowStatement::toIR(): %s", loc.toChars()); | 531 Logger::println("ThrowStatement::toIR(): %s", loc.toChars()); |
509 LOG_SCOPE; | 532 LOG_SCOPE; |
510 | 533 |
511 Logger::attention(loc, "throw is not yet implemented, replacing expression with assert(0);"); | 534 Logger::attention(loc, "throw is not yet fully implemented"); |
512 | 535 |
513 DtoAssert(NULL, &loc, NULL); | |
514 | |
515 /* | |
516 assert(exp); | 536 assert(exp); |
517 DValue* e = exp->toElem(p); | 537 DValue* e = exp->toElem(p); |
518 delete e; | 538 llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_throw_exception"); |
519 */ | 539 //Logger::cout() << "calling: " << *fn << '\n'; |
540 llvm::Value* arg = DtoBitCast(e->getRVal(), fn->getFunctionType()->getParamType(0)); | |
541 //Logger::cout() << "arg: " << *arg << '\n'; | |
542 gIR->ir->CreateCall(fn, arg, ""); | |
543 gIR->ir->CreateUnreachable(); | |
520 } | 544 } |
521 | 545 |
522 ////////////////////////////////////////////////////////////////////////////// | 546 ////////////////////////////////////////////////////////////////////////////// |
523 | 547 |
524 // used to build the sorted list of cases | 548 // used to build the sorted list of cases |
627 const llvm::Type* elemTy = DtoType(condition->type); | 651 const llvm::Type* elemTy = DtoType(condition->type); |
628 const llvm::ArrayType* arrTy = llvm::ArrayType::get(elemTy, inits.size()); | 652 const llvm::ArrayType* arrTy = llvm::ArrayType::get(elemTy, inits.size()); |
629 llvm::Constant* arrInit = llvm::ConstantArray::get(arrTy, inits); | 653 llvm::Constant* arrInit = llvm::ConstantArray::get(arrTy, inits); |
630 llvm::GlobalVariable* arr = new llvm::GlobalVariable(arrTy, true, llvm::GlobalValue::InternalLinkage, arrInit, "string_switch_table_data", gIR->module); | 654 llvm::GlobalVariable* arr = new llvm::GlobalVariable(arrTy, true, llvm::GlobalValue::InternalLinkage, arrInit, "string_switch_table_data", gIR->module); |
631 | 655 |
632 const llvm::Type* elemPtrTy = llvm::PointerType::get(elemTy); | 656 const llvm::Type* elemPtrTy = getPtrToType(elemTy); |
633 llvm::Constant* arrPtr = llvm::ConstantExpr::getBitCast(arr, elemPtrTy); | 657 llvm::Constant* arrPtr = llvm::ConstantExpr::getBitCast(arr, elemPtrTy); |
634 | 658 |
635 // build the static table | 659 // build the static table |
636 std::vector<const llvm::Type*> types; | 660 std::vector<const llvm::Type*> types; |
637 types.push_back(DtoSize_t()); | 661 types.push_back(DtoSize_t()); |
822 assert(0 && "aggregate type is not Tarray or Tsarray"); | 846 assert(0 && "aggregate type is not Tarray or Tsarray"); |
823 } | 847 } |
824 | 848 |
825 if (niters->getType() != keytype) | 849 if (niters->getType() != keytype) |
826 { | 850 { |
827 size_t sz1 = gTargetData->getTypeSize(niters->getType()); | 851 size_t sz1 = getTypeBitSize(niters->getType()); |
828 size_t sz2 = gTargetData->getTypeSize(keytype); | 852 size_t sz2 = getTypeBitSize(keytype); |
829 if (sz1 < sz2) | 853 if (sz1 < sz2) |
830 niters = gIR->ir->CreateZExt(niters, keytype, "foreachtrunckey"); | 854 niters = gIR->ir->CreateZExt(niters, keytype, "foreachtrunckey"); |
831 else if (sz1 > sz2) | 855 else if (sz1 > sz2) |
832 niters = gIR->ir->CreateTrunc(niters, keytype, "foreachtrunckey"); | 856 niters = gIR->ir->CreateTrunc(niters, keytype, "foreachtrunckey"); |
833 else | 857 else |